aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-07-01 03:57:25 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-07-01 03:57:25 -0400
commit24a72acac155576d630cf4304fa9cefb9b62ea1f (patch)
tree84d09427b319c613512316c658a3f6d6d8fe3dd1 /fs
parent6e0b8bc965d25a8e0701eaca3fca5941b4f4b2b2 (diff)
parent8bb495e3f02401ee6f76d1b1d77f3ac9f079e376 (diff)
Merge tag 'v3.10' into next
Merge 3.10 in order to get some of the last minute powerpc changes, resolve conflicts and add additional fixes on top of them.
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/disk-io.c10
-rw-r--r--fs/btrfs/inode.c3
-rw-r--r--fs/btrfs/relocation.c9
-rw-r--r--fs/exec.c16
-rw-r--r--fs/file_table.c19
-rw-r--r--fs/fuse/file.c12
-rw-r--r--fs/internal.h6
-rw-r--r--fs/namei.c4
-rw-r--r--fs/ncpfs/dir.c9
-rw-r--r--fs/read_write.c24
-rw-r--r--fs/splice.c32
-rw-r--r--fs/ubifs/dir.c54
-rw-r--r--fs/xfs/xfs_attr_leaf.h1
-rw-r--r--fs/xfs/xfs_btree.c10
-rw-r--r--fs/xfs/xfs_dir2_format.h5
-rw-r--r--fs/xfs/xfs_log_recover.c19
-rw-r--r--fs/xfs/xfs_mount.c18
17 files changed, 164 insertions, 87 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e7b3cb5286a5..b8b60b660c8f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2859,8 +2859,8 @@ fail_qgroup:
2859 btrfs_free_qgroup_config(fs_info); 2859 btrfs_free_qgroup_config(fs_info);
2860fail_trans_kthread: 2860fail_trans_kthread:
2861 kthread_stop(fs_info->transaction_kthread); 2861 kthread_stop(fs_info->transaction_kthread);
2862 del_fs_roots(fs_info);
2863 btrfs_cleanup_transaction(fs_info->tree_root); 2862 btrfs_cleanup_transaction(fs_info->tree_root);
2863 del_fs_roots(fs_info);
2864fail_cleaner: 2864fail_cleaner:
2865 kthread_stop(fs_info->cleaner_kthread); 2865 kthread_stop(fs_info->cleaner_kthread);
2866 2866
@@ -3512,15 +3512,15 @@ int close_ctree(struct btrfs_root *root)
3512 percpu_counter_sum(&fs_info->delalloc_bytes)); 3512 percpu_counter_sum(&fs_info->delalloc_bytes));
3513 } 3513 }
3514 3514
3515 free_root_pointers(fs_info, 1);
3516
3517 btrfs_free_block_groups(fs_info); 3515 btrfs_free_block_groups(fs_info);
3518 3516
3517 btrfs_stop_all_workers(fs_info);
3518
3519 del_fs_roots(fs_info); 3519 del_fs_roots(fs_info);
3520 3520
3521 iput(fs_info->btree_inode); 3521 free_root_pointers(fs_info, 1);
3522 3522
3523 btrfs_stop_all_workers(fs_info); 3523 iput(fs_info->btree_inode);
3524 3524
3525#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 3525#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3526 if (btrfs_test_opt(root, CHECK_INTEGRITY)) 3526 if (btrfs_test_opt(root, CHECK_INTEGRITY))
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index af978f7682b3..17f3064b4a3e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8012,6 +8012,9 @@ int btrfs_drop_inode(struct inode *inode)
8012{ 8012{
8013 struct btrfs_root *root = BTRFS_I(inode)->root; 8013 struct btrfs_root *root = BTRFS_I(inode)->root;
8014 8014
8015 if (root == NULL)
8016 return 1;
8017
8015 /* the snap/subvol tree is on deleting */ 8018 /* the snap/subvol tree is on deleting */
8016 if (btrfs_root_refs(&root->root_item) == 0 && 8019 if (btrfs_root_refs(&root->root_item) == 0 &&
8017 root != root->fs_info->tree_root) 8020 root != root->fs_info->tree_root)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 395b82031a42..4febca4fc2de 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4082,7 +4082,7 @@ out:
4082 return inode; 4082 return inode;
4083} 4083}
4084 4084
4085static struct reloc_control *alloc_reloc_control(void) 4085static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info)
4086{ 4086{
4087 struct reloc_control *rc; 4087 struct reloc_control *rc;
4088 4088
@@ -4093,7 +4093,8 @@ static struct reloc_control *alloc_reloc_control(void)
4093 INIT_LIST_HEAD(&rc->reloc_roots); 4093 INIT_LIST_HEAD(&rc->reloc_roots);
4094 backref_cache_init(&rc->backref_cache); 4094 backref_cache_init(&rc->backref_cache);
4095 mapping_tree_init(&rc->reloc_root_tree); 4095 mapping_tree_init(&rc->reloc_root_tree);
4096 extent_io_tree_init(&rc->processed_blocks, NULL); 4096 extent_io_tree_init(&rc->processed_blocks,
4097 fs_info->btree_inode->i_mapping);
4097 return rc; 4098 return rc;
4098} 4099}
4099 4100
@@ -4110,7 +4111,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)
4110 int rw = 0; 4111 int rw = 0;
4111 int err = 0; 4112 int err = 0;
4112 4113
4113 rc = alloc_reloc_control(); 4114 rc = alloc_reloc_control(fs_info);
4114 if (!rc) 4115 if (!rc)
4115 return -ENOMEM; 4116 return -ENOMEM;
4116 4117
@@ -4311,7 +4312,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
4311 if (list_empty(&reloc_roots)) 4312 if (list_empty(&reloc_roots))
4312 goto out; 4313 goto out;
4313 4314
4314 rc = alloc_reloc_control(); 4315 rc = alloc_reloc_control(root->fs_info);
4315 if (!rc) { 4316 if (!rc) {
4316 err = -ENOMEM; 4317 err = -ENOMEM;
4317 goto out; 4318 goto out;
diff --git a/fs/exec.c b/fs/exec.c
index 643019585574..ffd7a813ad3d 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1135,13 +1135,6 @@ void setup_new_exec(struct linux_binprm * bprm)
1135 set_dumpable(current->mm, suid_dumpable); 1135 set_dumpable(current->mm, suid_dumpable);
1136 } 1136 }
1137 1137
1138 /*
1139 * Flush performance counters when crossing a
1140 * security domain:
1141 */
1142 if (!get_dumpable(current->mm))
1143 perf_event_exit_task(current);
1144
1145 /* An exec changes our domain. We are no longer part of the thread 1138 /* An exec changes our domain. We are no longer part of the thread
1146 group */ 1139 group */
1147 1140
@@ -1205,6 +1198,15 @@ void install_exec_creds(struct linux_binprm *bprm)
1205 1198
1206 commit_creds(bprm->cred); 1199 commit_creds(bprm->cred);
1207 bprm->cred = NULL; 1200 bprm->cred = NULL;
1201
1202 /*
1203 * Disable monitoring for regular users
1204 * when executing setuid binaries. Must
1205 * wait until new credentials are committed
1206 * by commit_creds() above
1207 */
1208 if (get_dumpable(current->mm) != SUID_DUMP_USER)
1209 perf_event_exit_task(current);
1208 /* 1210 /*
1209 * cred_guard_mutex must be held at least to this point to prevent 1211 * cred_guard_mutex must be held at least to this point to prevent
1210 * ptrace_attach() from altering our determination of the task's 1212 * ptrace_attach() from altering our determination of the task's
diff --git a/fs/file_table.c b/fs/file_table.c
index cd4d87a82951..485dc0eddd67 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -306,17 +306,18 @@ void fput(struct file *file)
306{ 306{
307 if (atomic_long_dec_and_test(&file->f_count)) { 307 if (atomic_long_dec_and_test(&file->f_count)) {
308 struct task_struct *task = current; 308 struct task_struct *task = current;
309 unsigned long flags;
310
309 file_sb_list_del(file); 311 file_sb_list_del(file);
310 if (unlikely(in_interrupt() || task->flags & PF_KTHREAD)) { 312 if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) {
311 unsigned long flags; 313 init_task_work(&file->f_u.fu_rcuhead, ____fput);
312 spin_lock_irqsave(&delayed_fput_lock, flags); 314 if (!task_work_add(task, &file->f_u.fu_rcuhead, true))
313 list_add(&file->f_u.fu_list, &delayed_fput_list); 315 return;
314 schedule_work(&delayed_fput_work);
315 spin_unlock_irqrestore(&delayed_fput_lock, flags);
316 return;
317 } 316 }
318 init_task_work(&file->f_u.fu_rcuhead, ____fput); 317 spin_lock_irqsave(&delayed_fput_lock, flags);
319 task_work_add(task, &file->f_u.fu_rcuhead, true); 318 list_add(&file->f_u.fu_list, &delayed_fput_list);
319 schedule_work(&delayed_fput_work);
320 spin_unlock_irqrestore(&delayed_fput_lock, flags);
320 } 321 }
321} 322}
322 323
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e570081f9f76..35f281033142 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2470,13 +2470,16 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2470 .mode = mode 2470 .mode = mode
2471 }; 2471 };
2472 int err; 2472 int err;
2473 bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
2474 (mode & FALLOC_FL_PUNCH_HOLE);
2473 2475
2474 if (fc->no_fallocate) 2476 if (fc->no_fallocate)
2475 return -EOPNOTSUPP; 2477 return -EOPNOTSUPP;
2476 2478
2477 if (mode & FALLOC_FL_PUNCH_HOLE) { 2479 if (lock_inode) {
2478 mutex_lock(&inode->i_mutex); 2480 mutex_lock(&inode->i_mutex);
2479 fuse_set_nowrite(inode); 2481 if (mode & FALLOC_FL_PUNCH_HOLE)
2482 fuse_set_nowrite(inode);
2480 } 2483 }
2481 2484
2482 req = fuse_get_req_nopages(fc); 2485 req = fuse_get_req_nopages(fc);
@@ -2511,8 +2514,9 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2511 fuse_invalidate_attr(inode); 2514 fuse_invalidate_attr(inode);
2512 2515
2513out: 2516out:
2514 if (mode & FALLOC_FL_PUNCH_HOLE) { 2517 if (lock_inode) {
2515 fuse_release_nowrite(inode); 2518 if (mode & FALLOC_FL_PUNCH_HOLE)
2519 fuse_release_nowrite(inode);
2516 mutex_unlock(&inode->i_mutex); 2520 mutex_unlock(&inode->i_mutex);
2517 } 2521 }
2518 2522
diff --git a/fs/internal.h b/fs/internal.h
index eaa75f75b625..68121584ae37 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -132,6 +132,12 @@ extern struct dentry *__d_alloc(struct super_block *, const struct qstr *);
132extern ssize_t __kernel_write(struct file *, const char *, size_t, loff_t *); 132extern ssize_t __kernel_write(struct file *, const char *, size_t, loff_t *);
133 133
134/* 134/*
135 * splice.c
136 */
137extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
138 loff_t *opos, size_t len, unsigned int flags);
139
140/*
135 * pipe.c 141 * pipe.c
136 */ 142 */
137extern const struct file_operations pipefifo_fops; 143extern const struct file_operations pipefifo_fops;
diff --git a/fs/namei.c b/fs/namei.c
index 85e40d1c0a8f..9ed9361223c0 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1976,7 +1976,7 @@ static int path_lookupat(int dfd, const char *name,
1976 err = complete_walk(nd); 1976 err = complete_walk(nd);
1977 1977
1978 if (!err && nd->flags & LOOKUP_DIRECTORY) { 1978 if (!err && nd->flags & LOOKUP_DIRECTORY) {
1979 if (!nd->inode->i_op->lookup) { 1979 if (!can_lookup(nd->inode)) {
1980 path_put(&nd->path); 1980 path_put(&nd->path);
1981 err = -ENOTDIR; 1981 err = -ENOTDIR;
1982 } 1982 }
@@ -2850,7 +2850,7 @@ finish_lookup:
2850 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode)) 2850 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
2851 goto out; 2851 goto out;
2852 error = -ENOTDIR; 2852 error = -ENOTDIR;
2853 if ((nd->flags & LOOKUP_DIRECTORY) && !nd->inode->i_op->lookup) 2853 if ((nd->flags & LOOKUP_DIRECTORY) && !can_lookup(nd->inode))
2854 goto out; 2854 goto out;
2855 audit_inode(name, nd->path.dentry, 0); 2855 audit_inode(name, nd->path.dentry, 0);
2856finish_open: 2856finish_open:
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index 816326093656..6792ce11f2bf 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -1029,15 +1029,6 @@ static int ncp_rmdir(struct inode *dir, struct dentry *dentry)
1029 DPRINTK("ncp_rmdir: removing %s/%s\n", 1029 DPRINTK("ncp_rmdir: removing %s/%s\n",
1030 dentry->d_parent->d_name.name, dentry->d_name.name); 1030 dentry->d_parent->d_name.name, dentry->d_name.name);
1031 1031
1032 /*
1033 * fail with EBUSY if there are still references to this
1034 * directory.
1035 */
1036 dentry_unhash(dentry);
1037 error = -EBUSY;
1038 if (!d_unhashed(dentry))
1039 goto out;
1040
1041 len = sizeof(__name); 1032 len = sizeof(__name);
1042 error = ncp_io2vol(server, __name, &len, dentry->d_name.name, 1033 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
1043 dentry->d_name.len, !ncp_preserve_case(dir)); 1034 dentry->d_name.len, !ncp_preserve_case(dir));
diff --git a/fs/read_write.c b/fs/read_write.c
index 03430008704e..2cefa417be34 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1064,6 +1064,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1064 struct fd in, out; 1064 struct fd in, out;
1065 struct inode *in_inode, *out_inode; 1065 struct inode *in_inode, *out_inode;
1066 loff_t pos; 1066 loff_t pos;
1067 loff_t out_pos;
1067 ssize_t retval; 1068 ssize_t retval;
1068 int fl; 1069 int fl;
1069 1070
@@ -1077,12 +1078,14 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1077 if (!(in.file->f_mode & FMODE_READ)) 1078 if (!(in.file->f_mode & FMODE_READ))
1078 goto fput_in; 1079 goto fput_in;
1079 retval = -ESPIPE; 1080 retval = -ESPIPE;
1080 if (!ppos) 1081 if (!ppos) {
1081 ppos = &in.file->f_pos; 1082 pos = in.file->f_pos;
1082 else 1083 } else {
1084 pos = *ppos;
1083 if (!(in.file->f_mode & FMODE_PREAD)) 1085 if (!(in.file->f_mode & FMODE_PREAD))
1084 goto fput_in; 1086 goto fput_in;
1085 retval = rw_verify_area(READ, in.file, ppos, count); 1087 }
1088 retval = rw_verify_area(READ, in.file, &pos, count);
1086 if (retval < 0) 1089 if (retval < 0)
1087 goto fput_in; 1090 goto fput_in;
1088 count = retval; 1091 count = retval;
@@ -1099,7 +1102,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1099 retval = -EINVAL; 1102 retval = -EINVAL;
1100 in_inode = file_inode(in.file); 1103 in_inode = file_inode(in.file);
1101 out_inode = file_inode(out.file); 1104 out_inode = file_inode(out.file);
1102 retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count); 1105 out_pos = out.file->f_pos;
1106 retval = rw_verify_area(WRITE, out.file, &out_pos, count);
1103 if (retval < 0) 1107 if (retval < 0)
1104 goto fput_out; 1108 goto fput_out;
1105 count = retval; 1109 count = retval;
@@ -1107,7 +1111,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1107 if (!max) 1111 if (!max)
1108 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes); 1112 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
1109 1113
1110 pos = *ppos;
1111 if (unlikely(pos + count > max)) { 1114 if (unlikely(pos + count > max)) {
1112 retval = -EOVERFLOW; 1115 retval = -EOVERFLOW;
1113 if (pos >= max) 1116 if (pos >= max)
@@ -1126,18 +1129,23 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1126 if (in.file->f_flags & O_NONBLOCK) 1129 if (in.file->f_flags & O_NONBLOCK)
1127 fl = SPLICE_F_NONBLOCK; 1130 fl = SPLICE_F_NONBLOCK;
1128#endif 1131#endif
1129 retval = do_splice_direct(in.file, ppos, out.file, count, fl); 1132 retval = do_splice_direct(in.file, &pos, out.file, &out_pos, count, fl);
1130 1133
1131 if (retval > 0) { 1134 if (retval > 0) {
1132 add_rchar(current, retval); 1135 add_rchar(current, retval);
1133 add_wchar(current, retval); 1136 add_wchar(current, retval);
1134 fsnotify_access(in.file); 1137 fsnotify_access(in.file);
1135 fsnotify_modify(out.file); 1138 fsnotify_modify(out.file);
1139 out.file->f_pos = out_pos;
1140 if (ppos)
1141 *ppos = pos;
1142 else
1143 in.file->f_pos = pos;
1136 } 1144 }
1137 1145
1138 inc_syscr(current); 1146 inc_syscr(current);
1139 inc_syscw(current); 1147 inc_syscw(current);
1140 if (*ppos > max) 1148 if (pos > max)
1141 retval = -EOVERFLOW; 1149 retval = -EOVERFLOW;
1142 1150
1143fput_out: 1151fput_out:
diff --git a/fs/splice.c b/fs/splice.c
index e6b25598c8c4..d37431dd60a1 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1274,7 +1274,7 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
1274{ 1274{
1275 struct file *file = sd->u.file; 1275 struct file *file = sd->u.file;
1276 1276
1277 return do_splice_from(pipe, file, &file->f_pos, sd->total_len, 1277 return do_splice_from(pipe, file, sd->opos, sd->total_len,
1278 sd->flags); 1278 sd->flags);
1279} 1279}
1280 1280
@@ -1283,6 +1283,7 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
1283 * @in: file to splice from 1283 * @in: file to splice from
1284 * @ppos: input file offset 1284 * @ppos: input file offset
1285 * @out: file to splice to 1285 * @out: file to splice to
1286 * @opos: output file offset
1286 * @len: number of bytes to splice 1287 * @len: number of bytes to splice
1287 * @flags: splice modifier flags 1288 * @flags: splice modifier flags
1288 * 1289 *
@@ -1294,7 +1295,7 @@ static int direct_splice_actor(struct pipe_inode_info *pipe,
1294 * 1295 *
1295 */ 1296 */
1296long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, 1297long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1297 size_t len, unsigned int flags) 1298 loff_t *opos, size_t len, unsigned int flags)
1298{ 1299{
1299 struct splice_desc sd = { 1300 struct splice_desc sd = {
1300 .len = len, 1301 .len = len,
@@ -1302,6 +1303,7 @@ long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1302 .flags = flags, 1303 .flags = flags,
1303 .pos = *ppos, 1304 .pos = *ppos,
1304 .u.file = out, 1305 .u.file = out,
1306 .opos = opos,
1305 }; 1307 };
1306 long ret; 1308 long ret;
1307 1309
@@ -1325,7 +1327,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1325{ 1327{
1326 struct pipe_inode_info *ipipe; 1328 struct pipe_inode_info *ipipe;
1327 struct pipe_inode_info *opipe; 1329 struct pipe_inode_info *opipe;
1328 loff_t offset, *off; 1330 loff_t offset;
1329 long ret; 1331 long ret;
1330 1332
1331 ipipe = get_pipe_info(in); 1333 ipipe = get_pipe_info(in);
@@ -1356,13 +1358,15 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1356 return -EINVAL; 1358 return -EINVAL;
1357 if (copy_from_user(&offset, off_out, sizeof(loff_t))) 1359 if (copy_from_user(&offset, off_out, sizeof(loff_t)))
1358 return -EFAULT; 1360 return -EFAULT;
1359 off = &offset; 1361 } else {
1360 } else 1362 offset = out->f_pos;
1361 off = &out->f_pos; 1363 }
1362 1364
1363 ret = do_splice_from(ipipe, out, off, len, flags); 1365 ret = do_splice_from(ipipe, out, &offset, len, flags);
1364 1366
1365 if (off_out && copy_to_user(off_out, off, sizeof(loff_t))) 1367 if (!off_out)
1368 out->f_pos = offset;
1369 else if (copy_to_user(off_out, &offset, sizeof(loff_t)))
1366 ret = -EFAULT; 1370 ret = -EFAULT;
1367 1371
1368 return ret; 1372 return ret;
@@ -1376,13 +1380,15 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1376 return -EINVAL; 1380 return -EINVAL;
1377 if (copy_from_user(&offset, off_in, sizeof(loff_t))) 1381 if (copy_from_user(&offset, off_in, sizeof(loff_t)))
1378 return -EFAULT; 1382 return -EFAULT;
1379 off = &offset; 1383 } else {
1380 } else 1384 offset = in->f_pos;
1381 off = &in->f_pos; 1385 }
1382 1386
1383 ret = do_splice_to(in, off, opipe, len, flags); 1387 ret = do_splice_to(in, &offset, opipe, len, flags);
1384 1388
1385 if (off_in && copy_to_user(off_in, off, sizeof(loff_t))) 1389 if (!off_in)
1390 in->f_pos = offset;
1391 else if (copy_to_user(off_in, &offset, sizeof(loff_t)))
1386 ret = -EFAULT; 1392 ret = -EFAULT;
1387 1393
1388 return ret; 1394 return ret;
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index de08c92f2e23..605af512aec2 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -349,31 +349,50 @@ static unsigned int vfs_dent_type(uint8_t type)
349static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir) 349static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
350{ 350{
351 int err, over = 0; 351 int err, over = 0;
352 loff_t pos = file->f_pos;
352 struct qstr nm; 353 struct qstr nm;
353 union ubifs_key key; 354 union ubifs_key key;
354 struct ubifs_dent_node *dent; 355 struct ubifs_dent_node *dent;
355 struct inode *dir = file_inode(file); 356 struct inode *dir = file_inode(file);
356 struct ubifs_info *c = dir->i_sb->s_fs_info; 357 struct ubifs_info *c = dir->i_sb->s_fs_info;
357 358
358 dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, file->f_pos); 359 dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, pos);
359 360
360 if (file->f_pos > UBIFS_S_KEY_HASH_MASK || file->f_pos == 2) 361 if (pos > UBIFS_S_KEY_HASH_MASK || pos == 2)
361 /* 362 /*
362 * The directory was seek'ed to a senseless position or there 363 * The directory was seek'ed to a senseless position or there
363 * are no more entries. 364 * are no more entries.
364 */ 365 */
365 return 0; 366 return 0;
366 367
368 if (file->f_version == 0) {
369 /*
370 * The file was seek'ed, which means that @file->private_data
371 * is now invalid. This may also be just the first
372 * 'ubifs_readdir()' invocation, in which case
373 * @file->private_data is NULL, and the below code is
374 * basically a no-op.
375 */
376 kfree(file->private_data);
377 file->private_data = NULL;
378 }
379
380 /*
381 * 'generic_file_llseek()' unconditionally sets @file->f_version to
382 * zero, and we use this for detecting whether the file was seek'ed.
383 */
384 file->f_version = 1;
385
367 /* File positions 0 and 1 correspond to "." and ".." */ 386 /* File positions 0 and 1 correspond to "." and ".." */
368 if (file->f_pos == 0) { 387 if (pos == 0) {
369 ubifs_assert(!file->private_data); 388 ubifs_assert(!file->private_data);
370 over = filldir(dirent, ".", 1, 0, dir->i_ino, DT_DIR); 389 over = filldir(dirent, ".", 1, 0, dir->i_ino, DT_DIR);
371 if (over) 390 if (over)
372 return 0; 391 return 0;
373 file->f_pos = 1; 392 file->f_pos = pos = 1;
374 } 393 }
375 394
376 if (file->f_pos == 1) { 395 if (pos == 1) {
377 ubifs_assert(!file->private_data); 396 ubifs_assert(!file->private_data);
378 over = filldir(dirent, "..", 2, 1, 397 over = filldir(dirent, "..", 2, 1,
379 parent_ino(file->f_path.dentry), DT_DIR); 398 parent_ino(file->f_path.dentry), DT_DIR);
@@ -389,7 +408,7 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
389 goto out; 408 goto out;
390 } 409 }
391 410
392 file->f_pos = key_hash_flash(c, &dent->key); 411 file->f_pos = pos = key_hash_flash(c, &dent->key);
393 file->private_data = dent; 412 file->private_data = dent;
394 } 413 }
395 414
@@ -397,17 +416,16 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
397 if (!dent) { 416 if (!dent) {
398 /* 417 /*
399 * The directory was seek'ed to and is now readdir'ed. 418 * The directory was seek'ed to and is now readdir'ed.
400 * Find the entry corresponding to @file->f_pos or the 419 * Find the entry corresponding to @pos or the closest one.
401 * closest one.
402 */ 420 */
403 dent_key_init_hash(c, &key, dir->i_ino, file->f_pos); 421 dent_key_init_hash(c, &key, dir->i_ino, pos);
404 nm.name = NULL; 422 nm.name = NULL;
405 dent = ubifs_tnc_next_ent(c, &key, &nm); 423 dent = ubifs_tnc_next_ent(c, &key, &nm);
406 if (IS_ERR(dent)) { 424 if (IS_ERR(dent)) {
407 err = PTR_ERR(dent); 425 err = PTR_ERR(dent);
408 goto out; 426 goto out;
409 } 427 }
410 file->f_pos = key_hash_flash(c, &dent->key); 428 file->f_pos = pos = key_hash_flash(c, &dent->key);
411 file->private_data = dent; 429 file->private_data = dent;
412 } 430 }
413 431
@@ -419,7 +437,7 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
419 ubifs_inode(dir)->creat_sqnum); 437 ubifs_inode(dir)->creat_sqnum);
420 438
421 nm.len = le16_to_cpu(dent->nlen); 439 nm.len = le16_to_cpu(dent->nlen);
422 over = filldir(dirent, dent->name, nm.len, file->f_pos, 440 over = filldir(dirent, dent->name, nm.len, pos,
423 le64_to_cpu(dent->inum), 441 le64_to_cpu(dent->inum),
424 vfs_dent_type(dent->type)); 442 vfs_dent_type(dent->type));
425 if (over) 443 if (over)
@@ -435,9 +453,17 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
435 } 453 }
436 454
437 kfree(file->private_data); 455 kfree(file->private_data);
438 file->f_pos = key_hash_flash(c, &dent->key); 456 file->f_pos = pos = key_hash_flash(c, &dent->key);
439 file->private_data = dent; 457 file->private_data = dent;
440 cond_resched(); 458 cond_resched();
459
460 if (file->f_version == 0)
461 /*
462 * The file was seek'ed meanwhile, lets return and start
463 * reading direntries from the new position on the next
464 * invocation.
465 */
466 return 0;
441 } 467 }
442 468
443out: 469out:
@@ -448,15 +474,13 @@ out:
448 474
449 kfree(file->private_data); 475 kfree(file->private_data);
450 file->private_data = NULL; 476 file->private_data = NULL;
477 /* 2 is a special value indicating that there are no more direntries */
451 file->f_pos = 2; 478 file->f_pos = 2;
452 return 0; 479 return 0;
453} 480}
454 481
455/* If a directory is seeked, we have to free saved readdir() state */
456static loff_t ubifs_dir_llseek(struct file *file, loff_t offset, int whence) 482static loff_t ubifs_dir_llseek(struct file *file, loff_t offset, int whence)
457{ 483{
458 kfree(file->private_data);
459 file->private_data = NULL;
460 return generic_file_llseek(file, offset, whence); 484 return generic_file_llseek(file, offset, whence);
461} 485}
462 486
diff --git a/fs/xfs/xfs_attr_leaf.h b/fs/xfs/xfs_attr_leaf.h
index f9d7846097e2..444a7704596c 100644
--- a/fs/xfs/xfs_attr_leaf.h
+++ b/fs/xfs/xfs_attr_leaf.h
@@ -128,6 +128,7 @@ struct xfs_attr3_leaf_hdr {
128 __u8 holes; 128 __u8 holes;
129 __u8 pad1; 129 __u8 pad1;
130 struct xfs_attr_leaf_map freemap[XFS_ATTR_LEAF_MAPSIZE]; 130 struct xfs_attr_leaf_map freemap[XFS_ATTR_LEAF_MAPSIZE];
131 __be32 pad2; /* 64 bit alignment */
131}; 132};
132 133
133#define XFS_ATTR3_LEAF_CRC_OFF (offsetof(struct xfs_attr3_leaf_hdr, info.crc)) 134#define XFS_ATTR3_LEAF_CRC_OFF (offsetof(struct xfs_attr3_leaf_hdr, info.crc))
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c
index 8804b8a3c310..0903960410a2 100644
--- a/fs/xfs/xfs_btree.c
+++ b/fs/xfs/xfs_btree.c
@@ -2544,7 +2544,17 @@ xfs_btree_new_iroot(
2544 if (error) 2544 if (error)
2545 goto error0; 2545 goto error0;
2546 2546
2547 /*
2548 * we can't just memcpy() the root in for CRC enabled btree blocks.
2549 * In that case have to also ensure the blkno remains correct
2550 */
2547 memcpy(cblock, block, xfs_btree_block_len(cur)); 2551 memcpy(cblock, block, xfs_btree_block_len(cur));
2552 if (cur->bc_flags & XFS_BTREE_CRC_BLOCKS) {
2553 if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
2554 cblock->bb_u.l.bb_blkno = cpu_to_be64(cbp->b_bn);
2555 else
2556 cblock->bb_u.s.bb_blkno = cpu_to_be64(cbp->b_bn);
2557 }
2548 2558
2549 be16_add_cpu(&block->bb_level, 1); 2559 be16_add_cpu(&block->bb_level, 1);
2550 xfs_btree_set_numrecs(block, 1); 2560 xfs_btree_set_numrecs(block, 1);
diff --git a/fs/xfs/xfs_dir2_format.h b/fs/xfs/xfs_dir2_format.h
index 995f1f505a52..7826782b8d78 100644
--- a/fs/xfs/xfs_dir2_format.h
+++ b/fs/xfs/xfs_dir2_format.h
@@ -266,6 +266,7 @@ struct xfs_dir3_blk_hdr {
266struct xfs_dir3_data_hdr { 266struct xfs_dir3_data_hdr {
267 struct xfs_dir3_blk_hdr hdr; 267 struct xfs_dir3_blk_hdr hdr;
268 xfs_dir2_data_free_t best_free[XFS_DIR2_DATA_FD_COUNT]; 268 xfs_dir2_data_free_t best_free[XFS_DIR2_DATA_FD_COUNT];
269 __be32 pad; /* 64 bit alignment */
269}; 270};
270 271
271#define XFS_DIR3_DATA_CRC_OFF offsetof(struct xfs_dir3_data_hdr, hdr.crc) 272#define XFS_DIR3_DATA_CRC_OFF offsetof(struct xfs_dir3_data_hdr, hdr.crc)
@@ -477,7 +478,7 @@ struct xfs_dir3_leaf_hdr {
477 struct xfs_da3_blkinfo info; /* header for da routines */ 478 struct xfs_da3_blkinfo info; /* header for da routines */
478 __be16 count; /* count of entries */ 479 __be16 count; /* count of entries */
479 __be16 stale; /* count of stale entries */ 480 __be16 stale; /* count of stale entries */
480 __be32 pad; 481 __be32 pad; /* 64 bit alignment */
481}; 482};
482 483
483struct xfs_dir3_icleaf_hdr { 484struct xfs_dir3_icleaf_hdr {
@@ -715,7 +716,7 @@ struct xfs_dir3_free_hdr {
715 __be32 firstdb; /* db of first entry */ 716 __be32 firstdb; /* db of first entry */
716 __be32 nvalid; /* count of valid entries */ 717 __be32 nvalid; /* count of valid entries */
717 __be32 nused; /* count of used entries */ 718 __be32 nused; /* count of used entries */
718 __be32 pad; /* 64 bit alignment. */ 719 __be32 pad; /* 64 bit alignment */
719}; 720};
720 721
721struct xfs_dir3_free { 722struct xfs_dir3_free {
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 45a85ff84da1..7cf5e4eafe28 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -1845,7 +1845,13 @@ xlog_recover_do_inode_buffer(
1845 xfs_agino_t *buffer_nextp; 1845 xfs_agino_t *buffer_nextp;
1846 1846
1847 trace_xfs_log_recover_buf_inode_buf(mp->m_log, buf_f); 1847 trace_xfs_log_recover_buf_inode_buf(mp->m_log, buf_f);
1848 bp->b_ops = &xfs_inode_buf_ops; 1848
1849 /*
1850 * Post recovery validation only works properly on CRC enabled
1851 * filesystems.
1852 */
1853 if (xfs_sb_version_hascrc(&mp->m_sb))
1854 bp->b_ops = &xfs_inode_buf_ops;
1849 1855
1850 inodes_per_buf = BBTOB(bp->b_io_length) >> mp->m_sb.sb_inodelog; 1856 inodes_per_buf = BBTOB(bp->b_io_length) >> mp->m_sb.sb_inodelog;
1851 for (i = 0; i < inodes_per_buf; i++) { 1857 for (i = 0; i < inodes_per_buf; i++) {
@@ -2205,7 +2211,16 @@ xlog_recover_do_reg_buffer(
2205 /* Shouldn't be any more regions */ 2211 /* Shouldn't be any more regions */
2206 ASSERT(i == item->ri_total); 2212 ASSERT(i == item->ri_total);
2207 2213
2208 xlog_recovery_validate_buf_type(mp, bp, buf_f); 2214 /*
2215 * We can only do post recovery validation on items on CRC enabled
2216 * fielsystems as we need to know when the buffer was written to be able
2217 * to determine if we should have replayed the item. If we replay old
2218 * metadata over a newer buffer, then it will enter a temporarily
2219 * inconsistent state resulting in verification failures. Hence for now
2220 * just avoid the verification stage for non-crc filesystems
2221 */
2222 if (xfs_sb_version_hascrc(&mp->m_sb))
2223 xlog_recovery_validate_buf_type(mp, bp, buf_f);
2209} 2224}
2210 2225
2211/* 2226/*
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index f6bfbd734669..e8e310c05097 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -314,7 +314,8 @@ STATIC int
314xfs_mount_validate_sb( 314xfs_mount_validate_sb(
315 xfs_mount_t *mp, 315 xfs_mount_t *mp,
316 xfs_sb_t *sbp, 316 xfs_sb_t *sbp,
317 bool check_inprogress) 317 bool check_inprogress,
318 bool check_version)
318{ 319{
319 320
320 /* 321 /*
@@ -337,9 +338,10 @@ xfs_mount_validate_sb(
337 338
338 /* 339 /*
339 * Version 5 superblock feature mask validation. Reject combinations the 340 * Version 5 superblock feature mask validation. Reject combinations the
340 * kernel cannot support up front before checking anything else. 341 * kernel cannot support up front before checking anything else. For
342 * write validation, we don't need to check feature masks.
341 */ 343 */
342 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) { 344 if (check_version && XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) {
343 xfs_alert(mp, 345 xfs_alert(mp,
344"Version 5 superblock detected. This kernel has EXPERIMENTAL support enabled!\n" 346"Version 5 superblock detected. This kernel has EXPERIMENTAL support enabled!\n"
345"Use of these features in this kernel is at your own risk!"); 347"Use of these features in this kernel is at your own risk!");
@@ -675,7 +677,8 @@ xfs_sb_to_disk(
675 677
676static int 678static int
677xfs_sb_verify( 679xfs_sb_verify(
678 struct xfs_buf *bp) 680 struct xfs_buf *bp,
681 bool check_version)
679{ 682{
680 struct xfs_mount *mp = bp->b_target->bt_mount; 683 struct xfs_mount *mp = bp->b_target->bt_mount;
681 struct xfs_sb sb; 684 struct xfs_sb sb;
@@ -686,7 +689,8 @@ xfs_sb_verify(
686 * Only check the in progress field for the primary superblock as 689 * Only check the in progress field for the primary superblock as
687 * mkfs.xfs doesn't clear it from secondary superblocks. 690 * mkfs.xfs doesn't clear it from secondary superblocks.
688 */ 691 */
689 return xfs_mount_validate_sb(mp, &sb, bp->b_bn == XFS_SB_DADDR); 692 return xfs_mount_validate_sb(mp, &sb, bp->b_bn == XFS_SB_DADDR,
693 check_version);
690} 694}
691 695
692/* 696/*
@@ -719,7 +723,7 @@ xfs_sb_read_verify(
719 goto out_error; 723 goto out_error;
720 } 724 }
721 } 725 }
722 error = xfs_sb_verify(bp); 726 error = xfs_sb_verify(bp, true);
723 727
724out_error: 728out_error:
725 if (error) { 729 if (error) {
@@ -758,7 +762,7 @@ xfs_sb_write_verify(
758 struct xfs_buf_log_item *bip = bp->b_fspriv; 762 struct xfs_buf_log_item *bip = bp->b_fspriv;
759 int error; 763 int error;
760 764
761 error = xfs_sb_verify(bp); 765 error = xfs_sb_verify(bp, false);
762 if (error) { 766 if (error) {
763 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr); 767 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
764 xfs_buf_ioerror(bp, error); 768 xfs_buf_ioerror(bp, error);