Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
fs: fix address space warnings in ioctl_fiemap()
aio: check return value of create_workqueue()
hpfs_setattr error case avoids unlock_kernel
compat: copy missing fields in compat_statfs64 to user
compat: update comment of compat statfs syscalls
compat: remove unnecessary assignment in compat_rw_copy_check_uvector()
fs: FS_POSIX_ACL does not depend on BLOCK
fs: Remove unlikely() from fget_light()
fs: Remove unlikely() from fput_light()
fallocate should be a file operation
make the feature checks in ->fallocate future proof
staging: smbfs building fix
tidy up around finish_automount()
don't drop newmnt on error in do_add_mount()
Take the completion of automount into new helper

+515 -524
+1 -2
Documentation/filesystems/Locking
··· 60 ssize_t (*listxattr) (struct dentry *, char *, size_t); 61 int (*removexattr) (struct dentry *, const char *); 62 void (*truncate_range)(struct inode *, loff_t, loff_t); 63 - long (*fallocate)(struct inode *inode, int mode, loff_t offset, loff_t len); 64 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len); 65 66 locking rules: ··· 87 listxattr: no 88 removexattr: yes 89 truncate_range: yes 90 - fallocate: no 91 fiemap: no 92 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on 93 victim. ··· 435 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, 436 size_t, unsigned int); 437 int (*setlease)(struct file *, long, struct file_lock **); 438 }; 439 440 locking rules:
··· 60 ssize_t (*listxattr) (struct dentry *, char *, size_t); 61 int (*removexattr) (struct dentry *, const char *); 62 void (*truncate_range)(struct inode *, loff_t, loff_t); 63 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len); 64 65 locking rules: ··· 88 listxattr: no 89 removexattr: yes 90 truncate_range: yes 91 fiemap: no 92 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on 93 victim. ··· 437 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, 438 size_t, unsigned int); 439 int (*setlease)(struct file *, long, struct file_lock **); 440 + long (*fallocate)(struct file *, int, loff_t, loff_t); 441 }; 442 443 locking rules:
+2 -2
drivers/staging/smbfs/dir.c
··· 283 unsigned int, const char *, const struct qstr *); 284 static int smb_delete_dentry(const struct dentry *); 285 286 - static const struct dentry_operations smbfs_dentry_operations = 287 { 288 .d_revalidate = smb_lookup_validate, 289 .d_hash = smb_hash_dentry, ··· 291 .d_delete = smb_delete_dentry, 292 }; 293 294 - static const struct dentry_operations smbfs_dentry_operations_case = 295 { 296 .d_revalidate = smb_lookup_validate, 297 .d_delete = smb_delete_dentry,
··· 283 unsigned int, const char *, const struct qstr *); 284 static int smb_delete_dentry(const struct dentry *); 285 286 + const struct dentry_operations smbfs_dentry_operations = 287 { 288 .d_revalidate = smb_lookup_validate, 289 .d_hash = smb_hash_dentry, ··· 291 .d_delete = smb_delete_dentry, 292 }; 293 294 + const struct dentry_operations smbfs_dentry_operations_case = 295 { 296 .d_revalidate = smb_lookup_validate, 297 .d_delete = smb_delete_dentry,
+8 -9
fs/Kconfig
··· 30 source "fs/reiserfs/Kconfig" 31 source "fs/jfs/Kconfig" 32 33 - config FS_POSIX_ACL 34 - # Posix ACL utility routines (for now, only ext2/ext3/jfs/reiserfs/nfs4) 35 - # 36 - # NOTE: you can implement Posix ACLs without these helpers (XFS does). 37 - # Never use this symbol for ifdefs. 38 - # 39 - bool 40 - default n 41 - 42 source "fs/xfs/Kconfig" 43 source "fs/gfs2/Kconfig" 44 source "fs/ocfs2/Kconfig" ··· 37 source "fs/nilfs2/Kconfig" 38 39 endif # BLOCK 40 41 config EXPORTFS 42 tristate
··· 30 source "fs/reiserfs/Kconfig" 31 source "fs/jfs/Kconfig" 32 33 source "fs/xfs/Kconfig" 34 source "fs/gfs2/Kconfig" 35 source "fs/ocfs2/Kconfig" ··· 46 source "fs/nilfs2/Kconfig" 47 48 endif # BLOCK 49 + 50 + # Posix ACL utility routines 51 + # 52 + # Note: Posix ACLs can be implemented without these helpers. Never use 53 + # this symbol for ifdefs in core code. 54 + # 55 + config FS_POSIX_ACL 56 + def_bool n 57 58 config EXPORTFS 59 tristate
+1 -1
fs/aio.c
··· 87 88 aio_wq = create_workqueue("aio"); 89 abe_pool = mempool_create_kmalloc_pool(1, sizeof(struct aio_batch_entry)); 90 - BUG_ON(!abe_pool); 91 92 pr_debug("aio_setup: sizeof(struct page) = %d\n", (int)sizeof(struct page)); 93
··· 87 88 aio_wq = create_workqueue("aio"); 89 abe_pool = mempool_create_kmalloc_pool(1, sizeof(struct aio_batch_entry)); 90 + BUG_ON(!aio_wq || !abe_pool); 91 92 pr_debug("aio_setup: sizeof(struct page) = %d\n", (int)sizeof(struct page)); 93
+113
fs/btrfs/file.c
··· 24 #include <linux/string.h> 25 #include <linux/backing-dev.h> 26 #include <linux/mpage.h> 27 #include <linux/swap.h> 28 #include <linux/writeback.h> 29 #include <linux/statfs.h> ··· 1238 return 0; 1239 } 1240 1241 const struct file_operations btrfs_file_operations = { 1242 .llseek = generic_file_llseek, 1243 .read = do_sync_read, ··· 1360 .open = generic_file_open, 1361 .release = btrfs_release_file, 1362 .fsync = btrfs_sync_file, 1363 .unlocked_ioctl = btrfs_ioctl, 1364 #ifdef CONFIG_COMPAT 1365 .compat_ioctl = btrfs_ioctl,
··· 24 #include <linux/string.h> 25 #include <linux/backing-dev.h> 26 #include <linux/mpage.h> 27 + #include <linux/falloc.h> 28 #include <linux/swap.h> 29 #include <linux/writeback.h> 30 #include <linux/statfs.h> ··· 1237 return 0; 1238 } 1239 1240 + static long btrfs_fallocate(struct file *file, int mode, 1241 + loff_t offset, loff_t len) 1242 + { 1243 + struct inode *inode = file->f_path.dentry->d_inode; 1244 + struct extent_state *cached_state = NULL; 1245 + u64 cur_offset; 1246 + u64 last_byte; 1247 + u64 alloc_start; 1248 + u64 alloc_end; 1249 + u64 alloc_hint = 0; 1250 + u64 locked_end; 1251 + u64 mask = BTRFS_I(inode)->root->sectorsize - 1; 1252 + struct extent_map *em; 1253 + int ret; 1254 + 1255 + alloc_start = offset & ~mask; 1256 + alloc_end = (offset + len + mask) & ~mask; 1257 + 1258 + /* We only support the FALLOC_FL_KEEP_SIZE mode */ 1259 + if (mode & ~FALLOC_FL_KEEP_SIZE) 1260 + return -EOPNOTSUPP; 1261 + 1262 + /* 1263 + * wait for ordered IO before we have any locks. We'll loop again 1264 + * below with the locks held. 1265 + */ 1266 + btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start); 1267 + 1268 + mutex_lock(&inode->i_mutex); 1269 + ret = inode_newsize_ok(inode, alloc_end); 1270 + if (ret) 1271 + goto out; 1272 + 1273 + if (alloc_start > inode->i_size) { 1274 + ret = btrfs_cont_expand(inode, alloc_start); 1275 + if (ret) 1276 + goto out; 1277 + } 1278 + 1279 + ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); 1280 + if (ret) 1281 + goto out; 1282 + 1283 + locked_end = alloc_end - 1; 1284 + while (1) { 1285 + struct btrfs_ordered_extent *ordered; 1286 + 1287 + /* the extent lock is ordered inside the running 1288 + * transaction 1289 + */ 1290 + lock_extent_bits(&BTRFS_I(inode)->io_tree, alloc_start, 1291 + locked_end, 0, &cached_state, GFP_NOFS); 1292 + ordered = btrfs_lookup_first_ordered_extent(inode, 1293 + alloc_end - 1); 1294 + if (ordered && 1295 + ordered->file_offset + ordered->len > alloc_start && 1296 + ordered->file_offset < alloc_end) { 1297 + btrfs_put_ordered_extent(ordered); 1298 + unlock_extent_cached(&BTRFS_I(inode)->io_tree, 1299 + alloc_start, locked_end, 1300 + &cached_state, GFP_NOFS); 1301 + /* 1302 + * we can't wait on the range with the transaction 1303 + * running or with the extent lock held 1304 + */ 1305 + btrfs_wait_ordered_range(inode, alloc_start, 1306 + alloc_end - alloc_start); 1307 + } else { 1308 + if (ordered) 1309 + btrfs_put_ordered_extent(ordered); 1310 + break; 1311 + } 1312 + } 1313 + 1314 + cur_offset = alloc_start; 1315 + while (1) { 1316 + em = btrfs_get_extent(inode, NULL, 0, cur_offset, 1317 + alloc_end - cur_offset, 0); 1318 + BUG_ON(IS_ERR(em) || !em); 1319 + last_byte = min(extent_map_end(em), alloc_end); 1320 + last_byte = (last_byte + mask) & ~mask; 1321 + if (em->block_start == EXTENT_MAP_HOLE || 1322 + (cur_offset >= inode->i_size && 1323 + !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { 1324 + ret = btrfs_prealloc_file_range(inode, mode, cur_offset, 1325 + last_byte - cur_offset, 1326 + 1 << inode->i_blkbits, 1327 + offset + len, 1328 + &alloc_hint); 1329 + if (ret < 0) { 1330 + free_extent_map(em); 1331 + break; 1332 + } 1333 + } 1334 + free_extent_map(em); 1335 + 1336 + cur_offset = last_byte; 1337 + if (cur_offset >= alloc_end) { 1338 + ret = 0; 1339 + break; 1340 + } 1341 + } 1342 + unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, 1343 + &cached_state, GFP_NOFS); 1344 + 1345 + btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); 1346 + out: 1347 + mutex_unlock(&inode->i_mutex); 1348 + return ret; 1349 + } 1350 + 1351 const struct file_operations btrfs_file_operations = { 1352 .llseek = generic_file_llseek, 1353 .read = do_sync_read, ··· 1248 .open = generic_file_open, 1249 .release = btrfs_release_file, 1250 .fsync = btrfs_sync_file, 1251 + .fallocate = btrfs_fallocate, 1252 .unlocked_ioctl = btrfs_ioctl, 1253 #ifdef CONFIG_COMPAT 1254 .compat_ioctl = btrfs_ioctl,
-111
fs/btrfs/inode.c
··· 7098 min_size, actual_len, alloc_hint, trans); 7099 } 7100 7101 - static long btrfs_fallocate(struct inode *inode, int mode, 7102 - loff_t offset, loff_t len) 7103 - { 7104 - struct extent_state *cached_state = NULL; 7105 - u64 cur_offset; 7106 - u64 last_byte; 7107 - u64 alloc_start; 7108 - u64 alloc_end; 7109 - u64 alloc_hint = 0; 7110 - u64 locked_end; 7111 - u64 mask = BTRFS_I(inode)->root->sectorsize - 1; 7112 - struct extent_map *em; 7113 - int ret; 7114 - 7115 - alloc_start = offset & ~mask; 7116 - alloc_end = (offset + len + mask) & ~mask; 7117 - 7118 - /* We only support the FALLOC_FL_KEEP_SIZE mode */ 7119 - if (mode && (mode != FALLOC_FL_KEEP_SIZE)) 7120 - return -EOPNOTSUPP; 7121 - 7122 - /* 7123 - * wait for ordered IO before we have any locks. We'll loop again 7124 - * below with the locks held. 7125 - */ 7126 - btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start); 7127 - 7128 - mutex_lock(&inode->i_mutex); 7129 - ret = inode_newsize_ok(inode, alloc_end); 7130 - if (ret) 7131 - goto out; 7132 - 7133 - if (alloc_start > inode->i_size) { 7134 - ret = btrfs_cont_expand(inode, alloc_start); 7135 - if (ret) 7136 - goto out; 7137 - } 7138 - 7139 - ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); 7140 - if (ret) 7141 - goto out; 7142 - 7143 - locked_end = alloc_end - 1; 7144 - while (1) { 7145 - struct btrfs_ordered_extent *ordered; 7146 - 7147 - /* the extent lock is ordered inside the running 7148 - * transaction 7149 - */ 7150 - lock_extent_bits(&BTRFS_I(inode)->io_tree, alloc_start, 7151 - locked_end, 0, &cached_state, GFP_NOFS); 7152 - ordered = btrfs_lookup_first_ordered_extent(inode, 7153 - alloc_end - 1); 7154 - if (ordered && 7155 - ordered->file_offset + ordered->len > alloc_start && 7156 - ordered->file_offset < alloc_end) { 7157 - btrfs_put_ordered_extent(ordered); 7158 - unlock_extent_cached(&BTRFS_I(inode)->io_tree, 7159 - alloc_start, locked_end, 7160 - &cached_state, GFP_NOFS); 7161 - /* 7162 - * we can't wait on the range with the transaction 7163 - * running or with the extent lock held 7164 - */ 7165 - btrfs_wait_ordered_range(inode, alloc_start, 7166 - alloc_end - alloc_start); 7167 - } else { 7168 - if (ordered) 7169 - btrfs_put_ordered_extent(ordered); 7170 - break; 7171 - } 7172 - } 7173 - 7174 - cur_offset = alloc_start; 7175 - while (1) { 7176 - em = btrfs_get_extent(inode, NULL, 0, cur_offset, 7177 - alloc_end - cur_offset, 0); 7178 - BUG_ON(IS_ERR(em) || !em); 7179 - last_byte = min(extent_map_end(em), alloc_end); 7180 - last_byte = (last_byte + mask) & ~mask; 7181 - if (em->block_start == EXTENT_MAP_HOLE || 7182 - (cur_offset >= inode->i_size && 7183 - !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { 7184 - ret = btrfs_prealloc_file_range(inode, mode, cur_offset, 7185 - last_byte - cur_offset, 7186 - 1 << inode->i_blkbits, 7187 - offset + len, 7188 - &alloc_hint); 7189 - if (ret < 0) { 7190 - free_extent_map(em); 7191 - break; 7192 - } 7193 - } 7194 - free_extent_map(em); 7195 - 7196 - cur_offset = last_byte; 7197 - if (cur_offset >= alloc_end) { 7198 - ret = 0; 7199 - break; 7200 - } 7201 - } 7202 - unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, 7203 - &cached_state, GFP_NOFS); 7204 - 7205 - btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); 7206 - out: 7207 - mutex_unlock(&inode->i_mutex); 7208 - return ret; 7209 - } 7210 - 7211 static int btrfs_set_page_dirty(struct page *page) 7212 { 7213 return __set_page_dirty_nobuffers(page); ··· 7200 .listxattr = btrfs_listxattr, 7201 .removexattr = btrfs_removexattr, 7202 .permission = btrfs_permission, 7203 - .fallocate = btrfs_fallocate, 7204 .fiemap = btrfs_fiemap, 7205 }; 7206 static const struct inode_operations btrfs_special_inode_operations = {
··· 7098 min_size, actual_len, alloc_hint, trans); 7099 } 7100 7101 static int btrfs_set_page_dirty(struct page *page) 7102 { 7103 return __set_page_dirty_nobuffers(page); ··· 7310 .listxattr = btrfs_listxattr, 7311 .removexattr = btrfs_removexattr, 7312 .permission = btrfs_permission, 7313 .fiemap = btrfs_fiemap, 7314 }; 7315 static const struct inode_operations btrfs_special_inode_operations = {
+5 -5
fs/compat.c
··· 257 } 258 259 /* 260 - * The following statfs calls are copies of code from fs/open.c and 261 * should be checked against those from time to time 262 */ 263 asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_statfs __user *buf) ··· 320 __put_user(kbuf->f_namelen, &ubuf->f_namelen) || 321 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || 322 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || 323 - __put_user(kbuf->f_frsize, &ubuf->f_frsize)) 324 return -EFAULT; 325 return 0; 326 } ··· 599 if (nr_segs > fast_segs) { 600 ret = -ENOMEM; 601 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL); 602 - if (iov == NULL) { 603 - *ret_pointer = fast_pointer; 604 goto out; 605 - } 606 } 607 *ret_pointer = iov; 608
··· 257 } 258 259 /* 260 + * The following statfs calls are copies of code from fs/statfs.c and 261 * should be checked against those from time to time 262 */ 263 asmlinkage long compat_sys_statfs(const char __user *pathname, struct compat_statfs __user *buf) ··· 320 __put_user(kbuf->f_namelen, &ubuf->f_namelen) || 321 __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || 322 __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || 323 + __put_user(kbuf->f_frsize, &ubuf->f_frsize) || 324 + __put_user(kbuf->f_flags, &ubuf->f_flags) || 325 + __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare))) 326 return -EFAULT; 327 return 0; 328 } ··· 597 if (nr_segs > fast_segs) { 598 ret = -ENOMEM; 599 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL); 600 + if (iov == NULL) 601 goto out; 602 } 603 *ret_pointer = iov; 604
+1 -1
fs/ext4/ext4.h
··· 2065 extern void ext4_ext_truncate(struct inode *); 2066 extern void ext4_ext_init(struct super_block *); 2067 extern void ext4_ext_release(struct super_block *); 2068 - extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset, 2069 loff_t len); 2070 extern int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, 2071 ssize_t len);
··· 2065 extern void ext4_ext_truncate(struct inode *); 2066 extern void ext4_ext_init(struct super_block *); 2067 extern void ext4_ext_release(struct super_block *); 2068 + extern long ext4_fallocate(struct file *file, int mode, loff_t offset, 2069 loff_t len); 2070 extern int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, 2071 ssize_t len);
+4 -7
fs/ext4/extents.c
··· 3627 } 3628 3629 /* 3630 - * preallocate space for a file. This implements ext4's fallocate inode 3631 * operation, which gets called from sys_fallocate system call. 3632 * For block-mapped files, posix_fallocate should fall back to the method 3633 * of writing zeroes to the required new blocks (the same behavior which is 3634 * expected for file systems which do not support fallocate() system call). 3635 */ 3636 - long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len) 3637 { 3638 handle_t *handle; 3639 loff_t new_size; 3640 unsigned int max_blocks; ··· 3646 unsigned int credits, blkbits = inode->i_blkbits; 3647 3648 /* We only support the FALLOC_FL_KEEP_SIZE mode */ 3649 - if (mode && (mode != FALLOC_FL_KEEP_SIZE)) 3650 return -EOPNOTSUPP; 3651 3652 /* ··· 3655 */ 3656 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) 3657 return -EOPNOTSUPP; 3658 - 3659 - /* preallocation to directories is currently not supported */ 3660 - if (S_ISDIR(inode->i_mode)) 3661 - return -ENODEV; 3662 3663 map.m_lblk = offset >> blkbits; 3664 /*
··· 3627 } 3628 3629 /* 3630 + * preallocate space for a file. This implements ext4's fallocate file 3631 * operation, which gets called from sys_fallocate system call. 3632 * For block-mapped files, posix_fallocate should fall back to the method 3633 * of writing zeroes to the required new blocks (the same behavior which is 3634 * expected for file systems which do not support fallocate() system call). 3635 */ 3636 + long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) 3637 { 3638 + struct inode *inode = file->f_path.dentry->d_inode; 3639 handle_t *handle; 3640 loff_t new_size; 3641 unsigned int max_blocks; ··· 3645 unsigned int credits, blkbits = inode->i_blkbits; 3646 3647 /* We only support the FALLOC_FL_KEEP_SIZE mode */ 3648 + if (mode & ~FALLOC_FL_KEEP_SIZE) 3649 return -EOPNOTSUPP; 3650 3651 /* ··· 3654 */ 3655 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) 3656 return -EOPNOTSUPP; 3657 3658 map.m_lblk = offset >> blkbits; 3659 /*
+1 -1
fs/ext4/file.c
··· 210 .fsync = ext4_sync_file, 211 .splice_read = generic_file_splice_read, 212 .splice_write = generic_file_splice_write, 213 }; 214 215 const struct inode_operations ext4_file_inode_operations = { ··· 224 .removexattr = generic_removexattr, 225 #endif 226 .check_acl = ext4_check_acl, 227 - .fallocate = ext4_fallocate, 228 .fiemap = ext4_fiemap, 229 }; 230
··· 210 .fsync = ext4_sync_file, 211 .splice_read = generic_file_splice_read, 212 .splice_write = generic_file_splice_write, 213 + .fallocate = ext4_fallocate, 214 }; 215 216 const struct inode_operations ext4_file_inode_operations = { ··· 223 .removexattr = generic_removexattr, 224 #endif 225 .check_acl = ext4_check_acl, 226 .fiemap = ext4_fiemap, 227 }; 228
+1 -1
fs/file_table.c
··· 311 struct files_struct *files = current->files; 312 313 *fput_needed = 0; 314 - if (likely((atomic_read(&files->count) == 1))) { 315 file = fcheck_files(files, fd); 316 } else { 317 rcu_read_lock();
··· 311 struct files_struct *files = current->files; 312 313 *fput_needed = 0; 314 + if (atomic_read(&files->count) == 1) { 315 file = fcheck_files(files, fd); 316 } else { 317 rcu_read_lock();
+258
fs/gfs2/file.c
··· 19 #include <linux/fs.h> 20 #include <linux/gfs2_ondisk.h> 21 #include <linux/ext2_fs.h> 22 #include <linux/crc32.h> 23 #include <linux/writeback.h> 24 #include <asm/uaccess.h> ··· 612 return generic_file_aio_write(iocb, iov, nr_segs, pos); 613 } 614 615 #ifdef CONFIG_GFS2_FS_LOCKING_DLM 616 617 /** ··· 1021 .splice_read = generic_file_splice_read, 1022 .splice_write = generic_file_splice_write, 1023 .setlease = gfs2_setlease, 1024 }; 1025 1026 const struct file_operations gfs2_dir_fops = { ··· 1051 .splice_read = generic_file_splice_read, 1052 .splice_write = generic_file_splice_write, 1053 .setlease = generic_setlease, 1054 }; 1055 1056 const struct file_operations gfs2_dir_fops_nolock = {
··· 19 #include <linux/fs.h> 20 #include <linux/gfs2_ondisk.h> 21 #include <linux/ext2_fs.h> 22 + #include <linux/falloc.h> 23 + #include <linux/swap.h> 24 #include <linux/crc32.h> 25 #include <linux/writeback.h> 26 #include <asm/uaccess.h> ··· 610 return generic_file_aio_write(iocb, iov, nr_segs, pos); 611 } 612 613 + static void empty_write_end(struct page *page, unsigned from, 614 + unsigned to) 615 + { 616 + struct gfs2_inode *ip = GFS2_I(page->mapping->host); 617 + 618 + page_zero_new_buffers(page, from, to); 619 + flush_dcache_page(page); 620 + mark_page_accessed(page); 621 + 622 + if (!gfs2_is_writeback(ip)) 623 + gfs2_page_add_databufs(ip, page, from, to); 624 + 625 + block_commit_write(page, from, to); 626 + } 627 + 628 + static int write_empty_blocks(struct page *page, unsigned from, unsigned to) 629 + { 630 + unsigned start, end, next; 631 + struct buffer_head *bh, *head; 632 + int error; 633 + 634 + if (!page_has_buffers(page)) { 635 + error = __block_write_begin(page, from, to - from, gfs2_block_map); 636 + if (unlikely(error)) 637 + return error; 638 + 639 + empty_write_end(page, from, to); 640 + return 0; 641 + } 642 + 643 + bh = head = page_buffers(page); 644 + next = end = 0; 645 + while (next < from) { 646 + next += bh->b_size; 647 + bh = bh->b_this_page; 648 + } 649 + start = next; 650 + do { 651 + next += bh->b_size; 652 + if (buffer_mapped(bh)) { 653 + if (end) { 654 + error = __block_write_begin(page, start, end - start, 655 + gfs2_block_map); 656 + if (unlikely(error)) 657 + return error; 658 + empty_write_end(page, start, end); 659 + end = 0; 660 + } 661 + start = next; 662 + } 663 + else 664 + end = next; 665 + bh = bh->b_this_page; 666 + } while (next < to); 667 + 668 + if (end) { 669 + error = __block_write_begin(page, start, end - start, gfs2_block_map); 670 + if (unlikely(error)) 671 + return error; 672 + empty_write_end(page, start, end); 673 + } 674 + 675 + return 0; 676 + } 677 + 678 + static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, 679 + int mode) 680 + { 681 + struct gfs2_inode *ip = GFS2_I(inode); 682 + struct buffer_head *dibh; 683 + int error; 684 + u64 start = offset >> PAGE_CACHE_SHIFT; 685 + unsigned int start_offset = offset & ~PAGE_CACHE_MASK; 686 + u64 end = (offset + len - 1) >> PAGE_CACHE_SHIFT; 687 + pgoff_t curr; 688 + struct page *page; 689 + unsigned int end_offset = (offset + len) & ~PAGE_CACHE_MASK; 690 + unsigned int from, to; 691 + 692 + if (!end_offset) 693 + end_offset = PAGE_CACHE_SIZE; 694 + 695 + error = gfs2_meta_inode_buffer(ip, &dibh); 696 + if (unlikely(error)) 697 + goto out; 698 + 699 + gfs2_trans_add_bh(ip->i_gl, dibh, 1); 700 + 701 + if (gfs2_is_stuffed(ip)) { 702 + error = gfs2_unstuff_dinode(ip, NULL); 703 + if (unlikely(error)) 704 + goto out; 705 + } 706 + 707 + curr = start; 708 + offset = start << PAGE_CACHE_SHIFT; 709 + from = start_offset; 710 + to = PAGE_CACHE_SIZE; 711 + while (curr <= end) { 712 + page = grab_cache_page_write_begin(inode->i_mapping, curr, 713 + AOP_FLAG_NOFS); 714 + if (unlikely(!page)) { 715 + error = -ENOMEM; 716 + goto out; 717 + } 718 + 719 + if (curr == end) 720 + to = end_offset; 721 + error = write_empty_blocks(page, from, to); 722 + if (!error && offset + to > inode->i_size && 723 + !(mode & FALLOC_FL_KEEP_SIZE)) { 724 + i_size_write(inode, offset + to); 725 + } 726 + unlock_page(page); 727 + page_cache_release(page); 728 + if (error) 729 + goto out; 730 + curr++; 731 + offset += PAGE_CACHE_SIZE; 732 + from = 0; 733 + } 734 + 735 + gfs2_dinode_out(ip, dibh->b_data); 736 + mark_inode_dirty(inode); 737 + 738 + brelse(dibh); 739 + 740 + out: 741 + return error; 742 + } 743 + 744 + static void calc_max_reserv(struct gfs2_inode *ip, loff_t max, loff_t *len, 745 + unsigned int *data_blocks, unsigned int *ind_blocks) 746 + { 747 + const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 748 + unsigned int max_blocks = ip->i_alloc->al_rgd->rd_free_clone; 749 + unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1); 750 + 751 + for (tmp = max_data; tmp > sdp->sd_diptrs;) { 752 + tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs); 753 + max_data -= tmp; 754 + } 755 + /* This calculation isn't the exact reverse of gfs2_write_calc_reserve, 756 + so it might end up with fewer data blocks */ 757 + if (max_data <= *data_blocks) 758 + return; 759 + *data_blocks = max_data; 760 + *ind_blocks = max_blocks - max_data; 761 + *len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift; 762 + if (*len > max) { 763 + *len = max; 764 + gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks); 765 + } 766 + } 767 + 768 + static long gfs2_fallocate(struct file *file, int mode, loff_t offset, 769 + loff_t len) 770 + { 771 + struct inode *inode = file->f_path.dentry->d_inode; 772 + struct gfs2_sbd *sdp = GFS2_SB(inode); 773 + struct gfs2_inode *ip = GFS2_I(inode); 774 + unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 775 + loff_t bytes, max_bytes; 776 + struct gfs2_alloc *al; 777 + int error; 778 + loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift; 779 + next = (next + 1) << sdp->sd_sb.sb_bsize_shift; 780 + 781 + /* We only support the FALLOC_FL_KEEP_SIZE mode */ 782 + if (mode & ~FALLOC_FL_KEEP_SIZE) 783 + return -EOPNOTSUPP; 784 + 785 + offset = (offset >> sdp->sd_sb.sb_bsize_shift) << 786 + sdp->sd_sb.sb_bsize_shift; 787 + 788 + len = next - offset; 789 + bytes = sdp->sd_max_rg_data * sdp->sd_sb.sb_bsize / 2; 790 + if (!bytes) 791 + bytes = UINT_MAX; 792 + 793 + gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh); 794 + error = gfs2_glock_nq(&ip->i_gh); 795 + if (unlikely(error)) 796 + goto out_uninit; 797 + 798 + if (!gfs2_write_alloc_required(ip, offset, len)) 799 + goto out_unlock; 800 + 801 + while (len > 0) { 802 + if (len < bytes) 803 + bytes = len; 804 + al = gfs2_alloc_get(ip); 805 + if (!al) { 806 + error = -ENOMEM; 807 + goto out_unlock; 808 + } 809 + 810 + error = gfs2_quota_lock_check(ip); 811 + if (error) 812 + goto out_alloc_put; 813 + 814 + retry: 815 + gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks); 816 + 817 + al->al_requested = data_blocks + ind_blocks; 818 + error = gfs2_inplace_reserve(ip); 819 + if (error) { 820 + if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) { 821 + bytes >>= 1; 822 + goto retry; 823 + } 824 + goto out_qunlock; 825 + } 826 + max_bytes = bytes; 827 + calc_max_reserv(ip, len, &max_bytes, &data_blocks, &ind_blocks); 828 + al->al_requested = data_blocks + ind_blocks; 829 + 830 + rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + 831 + RES_RG_HDR + gfs2_rg_blocks(al); 832 + if (gfs2_is_jdata(ip)) 833 + rblocks += data_blocks ? data_blocks : 1; 834 + 835 + error = gfs2_trans_begin(sdp, rblocks, 836 + PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); 837 + if (error) 838 + goto out_trans_fail; 839 + 840 + error = fallocate_chunk(inode, offset, max_bytes, mode); 841 + gfs2_trans_end(sdp); 842 + 843 + if (error) 844 + goto out_trans_fail; 845 + 846 + len -= max_bytes; 847 + offset += max_bytes; 848 + gfs2_inplace_release(ip); 849 + gfs2_quota_unlock(ip); 850 + gfs2_alloc_put(ip); 851 + } 852 + goto out_unlock; 853 + 854 + out_trans_fail: 855 + gfs2_inplace_release(ip); 856 + out_qunlock: 857 + gfs2_quota_unlock(ip); 858 + out_alloc_put: 859 + gfs2_alloc_put(ip); 860 + out_unlock: 861 + gfs2_glock_dq(&ip->i_gh); 862 + out_uninit: 863 + gfs2_holder_uninit(&ip->i_gh); 864 + return error; 865 + } 866 + 867 #ifdef CONFIG_GFS2_FS_LOCKING_DLM 868 869 /** ··· 765 .splice_read = generic_file_splice_read, 766 .splice_write = generic_file_splice_write, 767 .setlease = gfs2_setlease, 768 + .fallocate = gfs2_fallocate, 769 }; 770 771 const struct file_operations gfs2_dir_fops = { ··· 794 .splice_read = generic_file_splice_read, 795 .splice_write = generic_file_splice_write, 796 .setlease = generic_setlease, 797 + .fallocate = gfs2_fallocate, 798 }; 799 800 const struct file_operations gfs2_dir_fops_nolock = {
-258
fs/gfs2/ops_inode.c
··· 18 #include <linux/gfs2_ondisk.h> 19 #include <linux/crc32.h> 20 #include <linux/fiemap.h> 21 - #include <linux/swap.h> 22 - #include <linux/falloc.h> 23 #include <asm/uaccess.h> 24 25 #include "gfs2.h" ··· 1255 return ret; 1256 } 1257 1258 - static void empty_write_end(struct page *page, unsigned from, 1259 - unsigned to) 1260 - { 1261 - struct gfs2_inode *ip = GFS2_I(page->mapping->host); 1262 - 1263 - page_zero_new_buffers(page, from, to); 1264 - flush_dcache_page(page); 1265 - mark_page_accessed(page); 1266 - 1267 - if (!gfs2_is_writeback(ip)) 1268 - gfs2_page_add_databufs(ip, page, from, to); 1269 - 1270 - block_commit_write(page, from, to); 1271 - } 1272 - 1273 - 1274 - static int write_empty_blocks(struct page *page, unsigned from, unsigned to) 1275 - { 1276 - unsigned start, end, next; 1277 - struct buffer_head *bh, *head; 1278 - int error; 1279 - 1280 - if (!page_has_buffers(page)) { 1281 - error = __block_write_begin(page, from, to - from, gfs2_block_map); 1282 - if (unlikely(error)) 1283 - return error; 1284 - 1285 - empty_write_end(page, from, to); 1286 - return 0; 1287 - } 1288 - 1289 - bh = head = page_buffers(page); 1290 - next = end = 0; 1291 - while (next < from) { 1292 - next += bh->b_size; 1293 - bh = bh->b_this_page; 1294 - } 1295 - start = next; 1296 - do { 1297 - next += bh->b_size; 1298 - if (buffer_mapped(bh)) { 1299 - if (end) { 1300 - error = __block_write_begin(page, start, end - start, 1301 - gfs2_block_map); 1302 - if (unlikely(error)) 1303 - return error; 1304 - empty_write_end(page, start, end); 1305 - end = 0; 1306 - } 1307 - start = next; 1308 - } 1309 - else 1310 - end = next; 1311 - bh = bh->b_this_page; 1312 - } while (next < to); 1313 - 1314 - if (end) { 1315 - error = __block_write_begin(page, start, end - start, gfs2_block_map); 1316 - if (unlikely(error)) 1317 - return error; 1318 - empty_write_end(page, start, end); 1319 - } 1320 - 1321 - return 0; 1322 - } 1323 - 1324 - static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, 1325 - int mode) 1326 - { 1327 - struct gfs2_inode *ip = GFS2_I(inode); 1328 - struct buffer_head *dibh; 1329 - int error; 1330 - u64 start = offset >> PAGE_CACHE_SHIFT; 1331 - unsigned int start_offset = offset & ~PAGE_CACHE_MASK; 1332 - u64 end = (offset + len - 1) >> PAGE_CACHE_SHIFT; 1333 - pgoff_t curr; 1334 - struct page *page; 1335 - unsigned int end_offset = (offset + len) & ~PAGE_CACHE_MASK; 1336 - unsigned int from, to; 1337 - 1338 - if (!end_offset) 1339 - end_offset = PAGE_CACHE_SIZE; 1340 - 1341 - error = gfs2_meta_inode_buffer(ip, &dibh); 1342 - if (unlikely(error)) 1343 - goto out; 1344 - 1345 - gfs2_trans_add_bh(ip->i_gl, dibh, 1); 1346 - 1347 - if (gfs2_is_stuffed(ip)) { 1348 - error = gfs2_unstuff_dinode(ip, NULL); 1349 - if (unlikely(error)) 1350 - goto out; 1351 - } 1352 - 1353 - curr = start; 1354 - offset = start << PAGE_CACHE_SHIFT; 1355 - from = start_offset; 1356 - to = PAGE_CACHE_SIZE; 1357 - while (curr <= end) { 1358 - page = grab_cache_page_write_begin(inode->i_mapping, curr, 1359 - AOP_FLAG_NOFS); 1360 - if (unlikely(!page)) { 1361 - error = -ENOMEM; 1362 - goto out; 1363 - } 1364 - 1365 - if (curr == end) 1366 - to = end_offset; 1367 - error = write_empty_blocks(page, from, to); 1368 - if (!error && offset + to > inode->i_size && 1369 - !(mode & FALLOC_FL_KEEP_SIZE)) { 1370 - i_size_write(inode, offset + to); 1371 - } 1372 - unlock_page(page); 1373 - page_cache_release(page); 1374 - if (error) 1375 - goto out; 1376 - curr++; 1377 - offset += PAGE_CACHE_SIZE; 1378 - from = 0; 1379 - } 1380 - 1381 - gfs2_dinode_out(ip, dibh->b_data); 1382 - mark_inode_dirty(inode); 1383 - 1384 - brelse(dibh); 1385 - 1386 - out: 1387 - return error; 1388 - } 1389 - 1390 - static void calc_max_reserv(struct gfs2_inode *ip, loff_t max, loff_t *len, 1391 - unsigned int *data_blocks, unsigned int *ind_blocks) 1392 - { 1393 - const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1394 - unsigned int max_blocks = ip->i_alloc->al_rgd->rd_free_clone; 1395 - unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1); 1396 - 1397 - for (tmp = max_data; tmp > sdp->sd_diptrs;) { 1398 - tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs); 1399 - max_data -= tmp; 1400 - } 1401 - /* This calculation isn't the exact reverse of gfs2_write_calc_reserve, 1402 - so it might end up with fewer data blocks */ 1403 - if (max_data <= *data_blocks) 1404 - return; 1405 - *data_blocks = max_data; 1406 - *ind_blocks = max_blocks - max_data; 1407 - *len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift; 1408 - if (*len > max) { 1409 - *len = max; 1410 - gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks); 1411 - } 1412 - } 1413 - 1414 - static long gfs2_fallocate(struct inode *inode, int mode, loff_t offset, 1415 - loff_t len) 1416 - { 1417 - struct gfs2_sbd *sdp = GFS2_SB(inode); 1418 - struct gfs2_inode *ip = GFS2_I(inode); 1419 - unsigned int data_blocks = 0, ind_blocks = 0, rblocks; 1420 - loff_t bytes, max_bytes; 1421 - struct gfs2_alloc *al; 1422 - int error; 1423 - loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift; 1424 - next = (next + 1) << sdp->sd_sb.sb_bsize_shift; 1425 - 1426 - /* We only support the FALLOC_FL_KEEP_SIZE mode */ 1427 - if (mode && (mode != FALLOC_FL_KEEP_SIZE)) 1428 - return -EOPNOTSUPP; 1429 - 1430 - offset = (offset >> sdp->sd_sb.sb_bsize_shift) << 1431 - sdp->sd_sb.sb_bsize_shift; 1432 - 1433 - len = next - offset; 1434 - bytes = sdp->sd_max_rg_data * sdp->sd_sb.sb_bsize / 2; 1435 - if (!bytes) 1436 - bytes = UINT_MAX; 1437 - 1438 - gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh); 1439 - error = gfs2_glock_nq(&ip->i_gh); 1440 - if (unlikely(error)) 1441 - goto out_uninit; 1442 - 1443 - if (!gfs2_write_alloc_required(ip, offset, len)) 1444 - goto out_unlock; 1445 - 1446 - while (len > 0) { 1447 - if (len < bytes) 1448 - bytes = len; 1449 - al = gfs2_alloc_get(ip); 1450 - if (!al) { 1451 - error = -ENOMEM; 1452 - goto out_unlock; 1453 - } 1454 - 1455 - error = gfs2_quota_lock_check(ip); 1456 - if (error) 1457 - goto out_alloc_put; 1458 - 1459 - retry: 1460 - gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks); 1461 - 1462 - al->al_requested = data_blocks + ind_blocks; 1463 - error = gfs2_inplace_reserve(ip); 1464 - if (error) { 1465 - if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) { 1466 - bytes >>= 1; 1467 - goto retry; 1468 - } 1469 - goto out_qunlock; 1470 - } 1471 - max_bytes = bytes; 1472 - calc_max_reserv(ip, len, &max_bytes, &data_blocks, &ind_blocks); 1473 - al->al_requested = data_blocks + ind_blocks; 1474 - 1475 - rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + 1476 - RES_RG_HDR + gfs2_rg_blocks(al); 1477 - if (gfs2_is_jdata(ip)) 1478 - rblocks += data_blocks ? data_blocks : 1; 1479 - 1480 - error = gfs2_trans_begin(sdp, rblocks, 1481 - PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); 1482 - if (error) 1483 - goto out_trans_fail; 1484 - 1485 - error = fallocate_chunk(inode, offset, max_bytes, mode); 1486 - gfs2_trans_end(sdp); 1487 - 1488 - if (error) 1489 - goto out_trans_fail; 1490 - 1491 - len -= max_bytes; 1492 - offset += max_bytes; 1493 - gfs2_inplace_release(ip); 1494 - gfs2_quota_unlock(ip); 1495 - gfs2_alloc_put(ip); 1496 - } 1497 - goto out_unlock; 1498 - 1499 - out_trans_fail: 1500 - gfs2_inplace_release(ip); 1501 - out_qunlock: 1502 - gfs2_quota_unlock(ip); 1503 - out_alloc_put: 1504 - gfs2_alloc_put(ip); 1505 - out_unlock: 1506 - gfs2_glock_dq(&ip->i_gh); 1507 - out_uninit: 1508 - gfs2_holder_uninit(&ip->i_gh); 1509 - return error; 1510 - } 1511 - 1512 - 1513 static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1514 u64 start, u64 len) 1515 { ··· 1305 .getxattr = gfs2_getxattr, 1306 .listxattr = gfs2_listxattr, 1307 .removexattr = gfs2_removexattr, 1308 - .fallocate = gfs2_fallocate, 1309 .fiemap = gfs2_fiemap, 1310 }; 1311
··· 18 #include <linux/gfs2_ondisk.h> 19 #include <linux/crc32.h> 20 #include <linux/fiemap.h> 21 #include <asm/uaccess.h> 22 23 #include "gfs2.h" ··· 1257 return ret; 1258 } 1259 1260 static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1261 u64 start, u64 len) 1262 { ··· 1562 .getxattr = gfs2_getxattr, 1563 .listxattr = gfs2_listxattr, 1564 .removexattr = gfs2_removexattr, 1565 .fiemap = gfs2_fiemap, 1566 }; 1567
+1 -1
fs/hpfs/inode.c
··· 281 attr->ia_size != i_size_read(inode)) { 282 error = vmtruncate(inode, attr->ia_size); 283 if (error) 284 - return error; 285 } 286 287 setattr_copy(inode, attr);
··· 281 attr->ia_size != i_size_read(inode)) { 282 error = vmtruncate(inode, attr->ia_size); 283 if (error) 284 + goto out_unlock; 285 } 286 287 setattr_copy(inode, attr);
+1 -2
fs/internal.h
··· 70 extern void release_mounts(struct list_head *); 71 extern void umount_tree(struct vfsmount *, int, struct list_head *); 72 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); 73 - extern int do_add_mount(struct vfsmount *, struct path *, int); 74 - extern void mnt_clear_expiry(struct vfsmount *); 75 76 extern void mnt_make_longterm(struct vfsmount *); 77 extern void mnt_make_shortterm(struct vfsmount *);
··· 70 extern void release_mounts(struct list_head *); 71 extern void umount_tree(struct vfsmount *, int, struct list_head *); 72 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); 73 + extern int finish_automount(struct vfsmount *, struct path *); 74 75 extern void mnt_make_longterm(struct vfsmount *); 76 extern void mnt_make_shortterm(struct vfsmount *);
+5 -5
fs/ioctl.c
··· 86 u64 phys, u64 len, u32 flags) 87 { 88 struct fiemap_extent extent; 89 - struct fiemap_extent *dest = fieinfo->fi_extents_start; 90 91 /* only count the extents */ 92 if (fieinfo->fi_extents_max == 0) { ··· 173 static int ioctl_fiemap(struct file *filp, unsigned long arg) 174 { 175 struct fiemap fiemap; 176 struct fiemap_extent_info fieinfo = { 0, }; 177 struct inode *inode = filp->f_path.dentry->d_inode; 178 struct super_block *sb = inode->i_sb; ··· 183 if (!inode->i_op->fiemap) 184 return -EOPNOTSUPP; 185 186 - if (copy_from_user(&fiemap, (struct fiemap __user *)arg, 187 - sizeof(struct fiemap))) 188 return -EFAULT; 189 190 if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS) ··· 196 197 fieinfo.fi_flags = fiemap.fm_flags; 198 fieinfo.fi_extents_max = fiemap.fm_extent_count; 199 - fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap)); 200 201 if (fiemap.fm_extent_count != 0 && 202 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start, ··· 209 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len); 210 fiemap.fm_flags = fieinfo.fi_flags; 211 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped; 212 - if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap))) 213 error = -EFAULT; 214 215 return error;
··· 86 u64 phys, u64 len, u32 flags) 87 { 88 struct fiemap_extent extent; 89 + struct fiemap_extent __user *dest = fieinfo->fi_extents_start; 90 91 /* only count the extents */ 92 if (fieinfo->fi_extents_max == 0) { ··· 173 static int ioctl_fiemap(struct file *filp, unsigned long arg) 174 { 175 struct fiemap fiemap; 176 + struct fiemap __user *ufiemap = (struct fiemap __user *) arg; 177 struct fiemap_extent_info fieinfo = { 0, }; 178 struct inode *inode = filp->f_path.dentry->d_inode; 179 struct super_block *sb = inode->i_sb; ··· 182 if (!inode->i_op->fiemap) 183 return -EOPNOTSUPP; 184 185 + if (copy_from_user(&fiemap, ufiemap, sizeof(fiemap))) 186 return -EFAULT; 187 188 if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS) ··· 196 197 fieinfo.fi_flags = fiemap.fm_flags; 198 fieinfo.fi_extents_max = fiemap.fm_extent_count; 199 + fieinfo.fi_extents_start = ufiemap->fm_extents; 200 201 if (fiemap.fm_extent_count != 0 && 202 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start, ··· 209 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len); 210 fiemap.fm_flags = fieinfo.fi_flags; 211 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped; 212 + if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap))) 213 error = -EFAULT; 214 215 return error;
+5 -26
fs/namei.c
··· 923 if (!mnt) /* mount collision */ 924 return 0; 925 926 - /* The new mount record should have at least 2 refs to prevent it being 927 - * expired before we get a chance to add it 928 - */ 929 - BUG_ON(mnt_get_count(mnt) < 2); 930 931 - if (mnt->mnt_sb == path->mnt->mnt_sb && 932 - mnt->mnt_root == path->dentry) { 933 - mnt_clear_expiry(mnt); 934 - mntput(mnt); 935 - mntput(mnt); 936 - return -ELOOP; 937 - } 938 - 939 - /* We need to add the mountpoint to the parent. The filesystem may 940 - * have placed it on an expiry list, and so we need to make sure it 941 - * won't be expired under us if do_add_mount() fails (do_add_mount() 942 - * will eat a reference unconditionally). 943 - */ 944 - mntget(mnt); 945 - err = do_add_mount(mnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE); 946 switch (err) { 947 case -EBUSY: 948 /* Someone else made a mount here whilst we were busy */ 949 - err = 0; 950 - default: 951 - mnt_clear_expiry(mnt); 952 - mntput(mnt); 953 - mntput(mnt); 954 - return err; 955 case 0: 956 - mntput(mnt); 957 dput(path->dentry); 958 if (*need_mntput) 959 mntput(path->mnt); ··· 937 path->dentry = dget(mnt->mnt_root); 938 *need_mntput = true; 939 return 0; 940 } 941 } 942 943 /*
··· 923 if (!mnt) /* mount collision */ 924 return 0; 925 926 + err = finish_automount(mnt, path); 927 928 switch (err) { 929 case -EBUSY: 930 /* Someone else made a mount here whilst we were busy */ 931 + return 0; 932 case 0: 933 dput(path->dentry); 934 if (*need_mntput) 935 mntput(path->mnt); ··· 961 path->dentry = dget(mnt->mnt_root); 962 *need_mntput = true; 963 return 0; 964 + default: 965 + return err; 966 } 967 + 968 } 969 970 /*
+40 -23
fs/namespace.c
··· 1872 return err; 1873 } 1874 1875 /* 1876 * create a new mount for userspace and request it to be added into the 1877 * namespace's tree ··· 1882 int mnt_flags, char *name, void *data) 1883 { 1884 struct vfsmount *mnt; 1885 1886 if (!type) 1887 return -EINVAL; ··· 1895 if (IS_ERR(mnt)) 1896 return PTR_ERR(mnt); 1897 1898 - return do_add_mount(mnt, path, mnt_flags); 1899 } 1900 1901 /* 1902 * add a mount into a namespace's mount tree 1903 - * - this unconditionally eats one of the caller's references to newmnt. 1904 */ 1905 - int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags) 1906 { 1907 int err; 1908 ··· 1962 goto unlock; 1963 1964 newmnt->mnt_flags = mnt_flags; 1965 - if ((err = graft_tree(newmnt, path))) 1966 - goto unlock; 1967 - 1968 - up_write(&namespace_sem); 1969 - return 0; 1970 1971 unlock: 1972 up_write(&namespace_sem); 1973 - mntput(newmnt); 1974 return err; 1975 } 1976 ··· 1985 up_write(&namespace_sem); 1986 } 1987 EXPORT_SYMBOL(mnt_set_expiry); 1988 - 1989 - /* 1990 - * Remove a vfsmount from any expiration list it may be on 1991 - */ 1992 - void mnt_clear_expiry(struct vfsmount *mnt) 1993 - { 1994 - if (!list_empty(&mnt->mnt_expire)) { 1995 - down_write(&namespace_sem); 1996 - br_write_lock(vfsmount_lock); 1997 - list_del_init(&mnt->mnt_expire); 1998 - br_write_unlock(vfsmount_lock); 1999 - up_write(&namespace_sem); 2000 - } 2001 - } 2002 2003 /* 2004 * process a list of expirable mountpoints with the intent of discarding any
··· 1872 return err; 1873 } 1874 1875 + static int do_add_mount(struct vfsmount *, struct path *, int); 1876 + 1877 /* 1878 * create a new mount for userspace and request it to be added into the 1879 * namespace's tree ··· 1880 int mnt_flags, char *name, void *data) 1881 { 1882 struct vfsmount *mnt; 1883 + int err; 1884 1885 if (!type) 1886 return -EINVAL; ··· 1892 if (IS_ERR(mnt)) 1893 return PTR_ERR(mnt); 1894 1895 + err = do_add_mount(mnt, path, mnt_flags); 1896 + if (err) 1897 + mntput(mnt); 1898 + return err; 1899 + } 1900 + 1901 + int finish_automount(struct vfsmount *m, struct path *path) 1902 + { 1903 + int err; 1904 + /* The new mount record should have at least 2 refs to prevent it being 1905 + * expired before we get a chance to add it 1906 + */ 1907 + BUG_ON(mnt_get_count(m) < 2); 1908 + 1909 + if (m->mnt_sb == path->mnt->mnt_sb && 1910 + m->mnt_root == path->dentry) { 1911 + err = -ELOOP; 1912 + goto fail; 1913 + } 1914 + 1915 + err = do_add_mount(m, path, path->mnt->mnt_flags | MNT_SHRINKABLE); 1916 + if (!err) 1917 + return 0; 1918 + fail: 1919 + /* remove m from any expiration list it may be on */ 1920 + if (!list_empty(&m->mnt_expire)) { 1921 + down_write(&namespace_sem); 1922 + br_write_lock(vfsmount_lock); 1923 + list_del_init(&m->mnt_expire); 1924 + br_write_unlock(vfsmount_lock); 1925 + up_write(&namespace_sem); 1926 + } 1927 + mntput(m); 1928 + mntput(m); 1929 + return err; 1930 } 1931 1932 /* 1933 * add a mount into a namespace's mount tree 1934 */ 1935 + static int do_add_mount(struct vfsmount *newmnt, struct path *path, int mnt_flags) 1936 { 1937 int err; 1938 ··· 1926 goto unlock; 1927 1928 newmnt->mnt_flags = mnt_flags; 1929 + err = graft_tree(newmnt, path); 1930 1931 unlock: 1932 up_write(&namespace_sem); 1933 return err; 1934 } 1935 ··· 1954 up_write(&namespace_sem); 1955 } 1956 EXPORT_SYMBOL(mnt_set_expiry); 1957 1958 /* 1959 * process a list of expirable mountpoints with the intent of discarding any
+5 -5
fs/ocfs2/file.c
··· 1989 return __ocfs2_change_file_space(file, inode, file->f_pos, cmd, sr, 0); 1990 } 1991 1992 - static long ocfs2_fallocate(struct inode *inode, int mode, loff_t offset, 1993 loff_t len) 1994 { 1995 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1996 struct ocfs2_space_resv sr; 1997 int change_size = 1; 1998 int cmd = OCFS2_IOC_RESVSP64; 1999 2000 if (!ocfs2_writes_unwritten_extents(osb)) 2001 return -EOPNOTSUPP; 2002 - 2003 - if (S_ISDIR(inode->i_mode)) 2004 - return -ENODEV; 2005 2006 if (mode & FALLOC_FL_KEEP_SIZE) 2007 change_size = 0; ··· 2610 .getxattr = generic_getxattr, 2611 .listxattr = ocfs2_listxattr, 2612 .removexattr = generic_removexattr, 2613 - .fallocate = ocfs2_fallocate, 2614 .fiemap = ocfs2_fiemap, 2615 }; 2616 ··· 2641 .flock = ocfs2_flock, 2642 .splice_read = ocfs2_file_splice_read, 2643 .splice_write = ocfs2_file_splice_write, 2644 }; 2645 2646 const struct file_operations ocfs2_dops = {
··· 1989 return __ocfs2_change_file_space(file, inode, file->f_pos, cmd, sr, 0); 1990 } 1991 1992 + static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, 1993 loff_t len) 1994 { 1995 + struct inode *inode = file->f_path.dentry->d_inode; 1996 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1997 struct ocfs2_space_resv sr; 1998 int change_size = 1; 1999 int cmd = OCFS2_IOC_RESVSP64; 2000 2001 + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) 2002 + return -EOPNOTSUPP; 2003 if (!ocfs2_writes_unwritten_extents(osb)) 2004 return -EOPNOTSUPP; 2005 2006 if (mode & FALLOC_FL_KEEP_SIZE) 2007 change_size = 0; ··· 2610 .getxattr = generic_getxattr, 2611 .listxattr = ocfs2_listxattr, 2612 .removexattr = generic_removexattr, 2613 .fiemap = ocfs2_fiemap, 2614 }; 2615 ··· 2642 .flock = ocfs2_flock, 2643 .splice_read = ocfs2_file_splice_read, 2644 .splice_write = ocfs2_file_splice_write, 2645 + .fallocate = ocfs2_fallocate, 2646 }; 2647 2648 const struct file_operations ocfs2_dops = {
+2 -2
fs/open.c
··· 255 if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0)) 256 return -EFBIG; 257 258 - if (!inode->i_op->fallocate) 259 return -EOPNOTSUPP; 260 261 - return inode->i_op->fallocate(inode, mode, offset, len); 262 } 263 264 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
··· 255 if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0)) 256 return -EFBIG; 257 258 + if (!file->f_op->fallocate) 259 return -EOPNOTSUPP; 260 261 + return file->f_op->fallocate(file, mode, offset, len); 262 } 263 264 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)
+56
fs/xfs/linux-2.6/xfs_file.c
··· 37 #include "xfs_trace.h" 38 39 #include <linux/dcache.h> 40 41 static const struct vm_operations_struct xfs_file_vm_ops; 42 ··· 883 return ret; 884 } 885 886 STATIC int 887 xfs_file_open( 888 struct inode *inode, ··· 1055 .open = xfs_file_open, 1056 .release = xfs_file_release, 1057 .fsync = xfs_file_fsync, 1058 }; 1059 1060 const struct file_operations xfs_dir_file_operations = {
··· 37 #include "xfs_trace.h" 38 39 #include <linux/dcache.h> 40 + #include <linux/falloc.h> 41 42 static const struct vm_operations_struct xfs_file_vm_ops; 43 ··· 882 return ret; 883 } 884 885 + STATIC long 886 + xfs_file_fallocate( 887 + struct file *file, 888 + int mode, 889 + loff_t offset, 890 + loff_t len) 891 + { 892 + struct inode *inode = file->f_path.dentry->d_inode; 893 + long error; 894 + loff_t new_size = 0; 895 + xfs_flock64_t bf; 896 + xfs_inode_t *ip = XFS_I(inode); 897 + int cmd = XFS_IOC_RESVSP; 898 + 899 + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) 900 + return -EOPNOTSUPP; 901 + 902 + bf.l_whence = 0; 903 + bf.l_start = offset; 904 + bf.l_len = len; 905 + 906 + xfs_ilock(ip, XFS_IOLOCK_EXCL); 907 + 908 + if (mode & FALLOC_FL_PUNCH_HOLE) 909 + cmd = XFS_IOC_UNRESVSP; 910 + 911 + /* check the new inode size is valid before allocating */ 912 + if (!(mode & FALLOC_FL_KEEP_SIZE) && 913 + offset + len > i_size_read(inode)) { 914 + new_size = offset + len; 915 + error = inode_newsize_ok(inode, new_size); 916 + if (error) 917 + goto out_unlock; 918 + } 919 + 920 + error = -xfs_change_file_space(ip, cmd, &bf, 0, XFS_ATTR_NOLOCK); 921 + if (error) 922 + goto out_unlock; 923 + 924 + /* Change file size if needed */ 925 + if (new_size) { 926 + struct iattr iattr; 927 + 928 + iattr.ia_valid = ATTR_SIZE; 929 + iattr.ia_size = new_size; 930 + error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK); 931 + } 932 + 933 + out_unlock: 934 + xfs_iunlock(ip, XFS_IOLOCK_EXCL); 935 + return error; 936 + } 937 + 938 + 939 STATIC int 940 xfs_file_open( 941 struct inode *inode, ··· 1000 .open = xfs_file_open, 1001 .release = xfs_file_release, 1002 .fsync = xfs_file_fsync, 1003 + .fallocate = xfs_file_fallocate, 1004 }; 1005 1006 const struct file_operations xfs_dir_file_operations = {
-57
fs/xfs/linux-2.6/xfs_iops.c
··· 46 #include <linux/namei.h> 47 #include <linux/posix_acl.h> 48 #include <linux/security.h> 49 - #include <linux/falloc.h> 50 #include <linux/fiemap.h> 51 #include <linux/slab.h> 52 ··· 504 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0); 505 } 506 507 - STATIC long 508 - xfs_vn_fallocate( 509 - struct inode *inode, 510 - int mode, 511 - loff_t offset, 512 - loff_t len) 513 - { 514 - long error; 515 - loff_t new_size = 0; 516 - xfs_flock64_t bf; 517 - xfs_inode_t *ip = XFS_I(inode); 518 - int cmd = XFS_IOC_RESVSP; 519 - 520 - /* preallocation on directories not yet supported */ 521 - error = -ENODEV; 522 - if (S_ISDIR(inode->i_mode)) 523 - goto out_error; 524 - 525 - bf.l_whence = 0; 526 - bf.l_start = offset; 527 - bf.l_len = len; 528 - 529 - xfs_ilock(ip, XFS_IOLOCK_EXCL); 530 - 531 - if (mode & FALLOC_FL_PUNCH_HOLE) 532 - cmd = XFS_IOC_UNRESVSP; 533 - 534 - /* check the new inode size is valid before allocating */ 535 - if (!(mode & FALLOC_FL_KEEP_SIZE) && 536 - offset + len > i_size_read(inode)) { 537 - new_size = offset + len; 538 - error = inode_newsize_ok(inode, new_size); 539 - if (error) 540 - goto out_unlock; 541 - } 542 - 543 - error = -xfs_change_file_space(ip, cmd, &bf, 0, XFS_ATTR_NOLOCK); 544 - if (error) 545 - goto out_unlock; 546 - 547 - /* Change file size if needed */ 548 - if (new_size) { 549 - struct iattr iattr; 550 - 551 - iattr.ia_valid = ATTR_SIZE; 552 - iattr.ia_size = new_size; 553 - error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK); 554 - } 555 - 556 - out_unlock: 557 - xfs_iunlock(ip, XFS_IOLOCK_EXCL); 558 - out_error: 559 - return error; 560 - } 561 - 562 #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) 563 564 /* ··· 597 .getxattr = generic_getxattr, 598 .removexattr = generic_removexattr, 599 .listxattr = xfs_vn_listxattr, 600 - .fallocate = xfs_vn_fallocate, 601 .fiemap = xfs_vn_fiemap, 602 }; 603
··· 46 #include <linux/namei.h> 47 #include <linux/posix_acl.h> 48 #include <linux/security.h> 49 #include <linux/fiemap.h> 50 #include <linux/slab.h> 51 ··· 505 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0); 506 } 507 508 #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) 509 510 /* ··· 653 .getxattr = generic_getxattr, 654 .removexattr = generic_removexattr, 655 .listxattr = xfs_vn_listxattr, 656 .fiemap = xfs_vn_fiemap, 657 }; 658
+1 -1
include/linux/file.h
··· 23 24 static inline void fput_light(struct file *file, int fput_needed) 25 { 26 - if (unlikely(fput_needed)) 27 fput(file); 28 } 29
··· 23 24 static inline void fput_light(struct file *file, int fput_needed) 25 { 26 + if (fput_needed) 27 fput(file); 28 } 29
+4 -4
include/linux/fs.h
··· 1483 unsigned int fi_flags; /* Flags as passed from user */ 1484 unsigned int fi_extents_mapped; /* Number of mapped extents */ 1485 unsigned int fi_extents_max; /* Size of fiemap_extent array */ 1486 - struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent 1487 - * array */ 1488 }; 1489 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, 1490 u64 phys, u64 len, u32 flags); ··· 1552 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1553 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1554 int (*setlease)(struct file *, long, struct file_lock **); 1555 }; 1556 1557 #define IPERM_FLAG_RCU 0x0001 ··· 1584 ssize_t (*listxattr) (struct dentry *, char *, size_t); 1585 int (*removexattr) (struct dentry *, const char *); 1586 void (*truncate_range)(struct inode *, loff_t, loff_t); 1587 - long (*fallocate)(struct inode *inode, int mode, loff_t offset, 1588 - loff_t len); 1589 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1590 u64 len); 1591 } ____cacheline_aligned;
··· 1483 unsigned int fi_flags; /* Flags as passed from user */ 1484 unsigned int fi_extents_mapped; /* Number of mapped extents */ 1485 unsigned int fi_extents_max; /* Size of fiemap_extent array */ 1486 + struct fiemap_extent __user *fi_extents_start; /* Start of 1487 + fiemap_extent array */ 1488 }; 1489 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, 1490 u64 phys, u64 len, u32 flags); ··· 1552 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1553 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1554 int (*setlease)(struct file *, long, struct file_lock **); 1555 + long (*fallocate)(struct file *file, int mode, loff_t offset, 1556 + loff_t len); 1557 }; 1558 1559 #define IPERM_FLAG_RCU 0x0001 ··· 1582 ssize_t (*listxattr) (struct dentry *, char *, size_t); 1583 int (*removexattr) (struct dentry *, const char *); 1584 void (*truncate_range)(struct inode *, loff_t, loff_t); 1585 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1586 u64 len); 1587 } ____cacheline_aligned;