diff options
Diffstat (limited to 'fs')
191 files changed, 7134 insertions, 3072 deletions
diff --git a/fs/9p/acl.c b/fs/9p/acl.c index 9a1d42630751..15b679166201 100644 --- a/fs/9p/acl.c +++ b/fs/9p/acl.c | |||
@@ -37,7 +37,7 @@ static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name) | |||
37 | return ERR_PTR(-ENOMEM); | 37 | return ERR_PTR(-ENOMEM); |
38 | size = v9fs_fid_xattr_get(fid, name, value, size); | 38 | size = v9fs_fid_xattr_get(fid, name, value, size); |
39 | if (size > 0) { | 39 | if (size > 0) { |
40 | acl = posix_acl_from_xattr(value, size); | 40 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
41 | if (IS_ERR(acl)) | 41 | if (IS_ERR(acl)) |
42 | goto err_out; | 42 | goto err_out; |
43 | } | 43 | } |
@@ -131,7 +131,7 @@ static int v9fs_set_acl(struct dentry *dentry, int type, struct posix_acl *acl) | |||
131 | buffer = kmalloc(size, GFP_KERNEL); | 131 | buffer = kmalloc(size, GFP_KERNEL); |
132 | if (!buffer) | 132 | if (!buffer) |
133 | return -ENOMEM; | 133 | return -ENOMEM; |
134 | retval = posix_acl_to_xattr(acl, buffer, size); | 134 | retval = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
135 | if (retval < 0) | 135 | if (retval < 0) |
136 | goto err_free_out; | 136 | goto err_free_out; |
137 | switch (type) { | 137 | switch (type) { |
@@ -251,7 +251,7 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, | |||
251 | return PTR_ERR(acl); | 251 | return PTR_ERR(acl); |
252 | if (acl == NULL) | 252 | if (acl == NULL) |
253 | return -ENODATA; | 253 | return -ENODATA; |
254 | error = posix_acl_to_xattr(acl, buffer, size); | 254 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
255 | posix_acl_release(acl); | 255 | posix_acl_release(acl); |
256 | 256 | ||
257 | return error; | 257 | return error; |
@@ -304,7 +304,7 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, | |||
304 | return -EPERM; | 304 | return -EPERM; |
305 | if (value) { | 305 | if (value) { |
306 | /* update the cached acl value */ | 306 | /* update the cached acl value */ |
307 | acl = posix_acl_from_xattr(value, size); | 307 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
308 | if (IS_ERR(acl)) | 308 | if (IS_ERR(acl)) |
309 | return PTR_ERR(acl); | 309 | return PTR_ERR(acl); |
310 | else if (acl) { | 310 | else if (acl) { |
diff --git a/fs/adfs/adfs.h b/fs/adfs/adfs.h index 718ac1f440c6..585adafb0cc2 100644 --- a/fs/adfs/adfs.h +++ b/fs/adfs/adfs.h | |||
@@ -46,8 +46,8 @@ struct adfs_sb_info { | |||
46 | struct adfs_discmap *s_map; /* bh list containing map */ | 46 | struct adfs_discmap *s_map; /* bh list containing map */ |
47 | struct adfs_dir_ops *s_dir; /* directory operations */ | 47 | struct adfs_dir_ops *s_dir; /* directory operations */ |
48 | 48 | ||
49 | uid_t s_uid; /* owner uid */ | 49 | kuid_t s_uid; /* owner uid */ |
50 | gid_t s_gid; /* owner gid */ | 50 | kgid_t s_gid; /* owner gid */ |
51 | umode_t s_owner_mask; /* ADFS owner perm -> unix perm */ | 51 | umode_t s_owner_mask; /* ADFS owner perm -> unix perm */ |
52 | umode_t s_other_mask; /* ADFS other perm -> unix perm */ | 52 | umode_t s_other_mask; /* ADFS other perm -> unix perm */ |
53 | int s_ftsuffix; /* ,xyz hex filetype suffix option */ | 53 | int s_ftsuffix; /* ,xyz hex filetype suffix option */ |
diff --git a/fs/adfs/inode.c b/fs/adfs/inode.c index 1dab6a174d6a..e9bad5093a3f 100644 --- a/fs/adfs/inode.c +++ b/fs/adfs/inode.c | |||
@@ -304,8 +304,8 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr) | |||
304 | * we can't change the UID or GID of any file - | 304 | * we can't change the UID or GID of any file - |
305 | * we have a global UID/GID in the superblock | 305 | * we have a global UID/GID in the superblock |
306 | */ | 306 | */ |
307 | if ((ia_valid & ATTR_UID && attr->ia_uid != ADFS_SB(sb)->s_uid) || | 307 | if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, ADFS_SB(sb)->s_uid)) || |
308 | (ia_valid & ATTR_GID && attr->ia_gid != ADFS_SB(sb)->s_gid)) | 308 | (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, ADFS_SB(sb)->s_gid))) |
309 | error = -EPERM; | 309 | error = -EPERM; |
310 | 310 | ||
311 | if (error) | 311 | if (error) |
diff --git a/fs/adfs/super.c b/fs/adfs/super.c index c830c857c663..d57122935793 100644 --- a/fs/adfs/super.c +++ b/fs/adfs/super.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/seq_file.h> | 15 | #include <linux/seq_file.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/statfs.h> | 17 | #include <linux/statfs.h> |
18 | #include <linux/user_namespace.h> | ||
18 | #include "adfs.h" | 19 | #include "adfs.h" |
19 | #include "dir_f.h" | 20 | #include "dir_f.h" |
20 | #include "dir_fplus.h" | 21 | #include "dir_fplus.h" |
@@ -130,10 +131,10 @@ static int adfs_show_options(struct seq_file *seq, struct dentry *root) | |||
130 | { | 131 | { |
131 | struct adfs_sb_info *asb = ADFS_SB(root->d_sb); | 132 | struct adfs_sb_info *asb = ADFS_SB(root->d_sb); |
132 | 133 | ||
133 | if (asb->s_uid != 0) | 134 | if (!uid_eq(asb->s_uid, GLOBAL_ROOT_UID)) |
134 | seq_printf(seq, ",uid=%u", asb->s_uid); | 135 | seq_printf(seq, ",uid=%u", from_kuid_munged(&init_user_ns, asb->s_uid)); |
135 | if (asb->s_gid != 0) | 136 | if (!gid_eq(asb->s_gid, GLOBAL_ROOT_GID)) |
136 | seq_printf(seq, ",gid=%u", asb->s_gid); | 137 | seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, asb->s_gid)); |
137 | if (asb->s_owner_mask != ADFS_DEFAULT_OWNER_MASK) | 138 | if (asb->s_owner_mask != ADFS_DEFAULT_OWNER_MASK) |
138 | seq_printf(seq, ",ownmask=%o", asb->s_owner_mask); | 139 | seq_printf(seq, ",ownmask=%o", asb->s_owner_mask); |
139 | if (asb->s_other_mask != ADFS_DEFAULT_OTHER_MASK) | 140 | if (asb->s_other_mask != ADFS_DEFAULT_OTHER_MASK) |
@@ -175,12 +176,16 @@ static int parse_options(struct super_block *sb, char *options) | |||
175 | case Opt_uid: | 176 | case Opt_uid: |
176 | if (match_int(args, &option)) | 177 | if (match_int(args, &option)) |
177 | return -EINVAL; | 178 | return -EINVAL; |
178 | asb->s_uid = option; | 179 | asb->s_uid = make_kuid(current_user_ns(), option); |
180 | if (!uid_valid(asb->s_uid)) | ||
181 | return -EINVAL; | ||
179 | break; | 182 | break; |
180 | case Opt_gid: | 183 | case Opt_gid: |
181 | if (match_int(args, &option)) | 184 | if (match_int(args, &option)) |
182 | return -EINVAL; | 185 | return -EINVAL; |
183 | asb->s_gid = option; | 186 | asb->s_gid = make_kgid(current_user_ns(), option); |
187 | if (!gid_valid(asb->s_gid)) | ||
188 | return -EINVAL; | ||
184 | break; | 189 | break; |
185 | case Opt_ownmask: | 190 | case Opt_ownmask: |
186 | if (match_octal(args, &option)) | 191 | if (match_octal(args, &option)) |
@@ -374,8 +379,8 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) | |||
374 | sb->s_fs_info = asb; | 379 | sb->s_fs_info = asb; |
375 | 380 | ||
376 | /* set default options */ | 381 | /* set default options */ |
377 | asb->s_uid = 0; | 382 | asb->s_uid = GLOBAL_ROOT_UID; |
378 | asb->s_gid = 0; | 383 | asb->s_gid = GLOBAL_ROOT_GID; |
379 | asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK; | 384 | asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK; |
380 | asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK; | 385 | asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK; |
381 | asb->s_ftsuffix = 0; | 386 | asb->s_ftsuffix = 0; |
diff --git a/fs/affs/affs.h b/fs/affs/affs.h index 6e216419f340..3952121f2f28 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h | |||
@@ -88,8 +88,8 @@ struct affs_sb_info { | |||
88 | u32 s_root_block; /* FFS root block number. */ | 88 | u32 s_root_block; /* FFS root block number. */ |
89 | int s_hashsize; /* Size of hash table. */ | 89 | int s_hashsize; /* Size of hash table. */ |
90 | unsigned long s_flags; /* See below. */ | 90 | unsigned long s_flags; /* See below. */ |
91 | uid_t s_uid; /* uid to override */ | 91 | kuid_t s_uid; /* uid to override */ |
92 | gid_t s_gid; /* gid to override */ | 92 | kgid_t s_gid; /* gid to override */ |
93 | umode_t s_mode; /* mode to override */ | 93 | umode_t s_mode; /* mode to override */ |
94 | struct buffer_head *s_root_bh; /* Cached root block. */ | 94 | struct buffer_head *s_root_bh; /* Cached root block. */ |
95 | struct mutex s_bmlock; /* Protects bitmap access. */ | 95 | struct mutex s_bmlock; /* Protects bitmap access. */ |
diff --git a/fs/affs/inode.c b/fs/affs/inode.c index 8bc4a59f4e7e..15c484268229 100644 --- a/fs/affs/inode.c +++ b/fs/affs/inode.c | |||
@@ -80,17 +80,17 @@ struct inode *affs_iget(struct super_block *sb, unsigned long ino) | |||
80 | if (id == 0 || sbi->s_flags & SF_SETUID) | 80 | if (id == 0 || sbi->s_flags & SF_SETUID) |
81 | inode->i_uid = sbi->s_uid; | 81 | inode->i_uid = sbi->s_uid; |
82 | else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) | 82 | else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) |
83 | inode->i_uid = 0; | 83 | i_uid_write(inode, 0); |
84 | else | 84 | else |
85 | inode->i_uid = id; | 85 | i_uid_write(inode, id); |
86 | 86 | ||
87 | id = be16_to_cpu(tail->gid); | 87 | id = be16_to_cpu(tail->gid); |
88 | if (id == 0 || sbi->s_flags & SF_SETGID) | 88 | if (id == 0 || sbi->s_flags & SF_SETGID) |
89 | inode->i_gid = sbi->s_gid; | 89 | inode->i_gid = sbi->s_gid; |
90 | else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) | 90 | else if (id == 0xFFFF && sbi->s_flags & SF_MUFS) |
91 | inode->i_gid = 0; | 91 | i_gid_write(inode, 0); |
92 | else | 92 | else |
93 | inode->i_gid = id; | 93 | i_gid_write(inode, id); |
94 | 94 | ||
95 | switch (be32_to_cpu(tail->stype)) { | 95 | switch (be32_to_cpu(tail->stype)) { |
96 | case ST_ROOT: | 96 | case ST_ROOT: |
@@ -193,13 +193,13 @@ affs_write_inode(struct inode *inode, struct writeback_control *wbc) | |||
193 | tail->size = cpu_to_be32(inode->i_size); | 193 | tail->size = cpu_to_be32(inode->i_size); |
194 | secs_to_datestamp(inode->i_mtime.tv_sec,&tail->change); | 194 | secs_to_datestamp(inode->i_mtime.tv_sec,&tail->change); |
195 | if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) { | 195 | if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) { |
196 | uid = inode->i_uid; | 196 | uid = i_uid_read(inode); |
197 | gid = inode->i_gid; | 197 | gid = i_gid_read(inode); |
198 | if (AFFS_SB(sb)->s_flags & SF_MUFS) { | 198 | if (AFFS_SB(sb)->s_flags & SF_MUFS) { |
199 | if (inode->i_uid == 0 || inode->i_uid == 0xFFFF) | 199 | if (uid == 0 || uid == 0xFFFF) |
200 | uid = inode->i_uid ^ ~0; | 200 | uid = uid ^ ~0; |
201 | if (inode->i_gid == 0 || inode->i_gid == 0xFFFF) | 201 | if (gid == 0 || gid == 0xFFFF) |
202 | gid = inode->i_gid ^ ~0; | 202 | gid = gid ^ ~0; |
203 | } | 203 | } |
204 | if (!(AFFS_SB(sb)->s_flags & SF_SETUID)) | 204 | if (!(AFFS_SB(sb)->s_flags & SF_SETUID)) |
205 | tail->uid = cpu_to_be16(uid); | 205 | tail->uid = cpu_to_be16(uid); |
diff --git a/fs/affs/super.c b/fs/affs/super.c index 2f57053bf26c..b84dc7352502 100644 --- a/fs/affs/super.c +++ b/fs/affs/super.c | |||
@@ -193,7 +193,7 @@ static const match_table_t tokens = { | |||
193 | }; | 193 | }; |
194 | 194 | ||
195 | static int | 195 | static int |
196 | parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s32 *root, | 196 | parse_options(char *options, kuid_t *uid, kgid_t *gid, int *mode, int *reserved, s32 *root, |
197 | int *blocksize, char **prefix, char *volume, unsigned long *mount_opts) | 197 | int *blocksize, char **prefix, char *volume, unsigned long *mount_opts) |
198 | { | 198 | { |
199 | char *p; | 199 | char *p; |
@@ -258,13 +258,17 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s | |||
258 | case Opt_setgid: | 258 | case Opt_setgid: |
259 | if (match_int(&args[0], &option)) | 259 | if (match_int(&args[0], &option)) |
260 | return 0; | 260 | return 0; |
261 | *gid = option; | 261 | *gid = make_kgid(current_user_ns(), option); |
262 | if (!gid_valid(*gid)) | ||
263 | return 0; | ||
262 | *mount_opts |= SF_SETGID; | 264 | *mount_opts |= SF_SETGID; |
263 | break; | 265 | break; |
264 | case Opt_setuid: | 266 | case Opt_setuid: |
265 | if (match_int(&args[0], &option)) | 267 | if (match_int(&args[0], &option)) |
266 | return 0; | 268 | return 0; |
267 | *uid = option; | 269 | *uid = make_kuid(current_user_ns(), option); |
270 | if (!uid_valid(*uid)) | ||
271 | return 0; | ||
268 | *mount_opts |= SF_SETUID; | 272 | *mount_opts |= SF_SETUID; |
269 | break; | 273 | break; |
270 | case Opt_verbose: | 274 | case Opt_verbose: |
@@ -306,8 +310,8 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent) | |||
306 | int num_bm; | 310 | int num_bm; |
307 | int i, j; | 311 | int i, j; |
308 | s32 key; | 312 | s32 key; |
309 | uid_t uid; | 313 | kuid_t uid; |
310 | gid_t gid; | 314 | kgid_t gid; |
311 | int reserved; | 315 | int reserved; |
312 | unsigned long mount_flags; | 316 | unsigned long mount_flags; |
313 | int tmp_flags; /* fix remount prototype... */ | 317 | int tmp_flags; /* fix remount prototype... */ |
@@ -532,8 +536,8 @@ affs_remount(struct super_block *sb, int *flags, char *data) | |||
532 | { | 536 | { |
533 | struct affs_sb_info *sbi = AFFS_SB(sb); | 537 | struct affs_sb_info *sbi = AFFS_SB(sb); |
534 | int blocksize; | 538 | int blocksize; |
535 | uid_t uid; | 539 | kuid_t uid; |
536 | gid_t gid; | 540 | kgid_t gid; |
537 | int mode; | 541 | int mode; |
538 | int reserved; | 542 | int reserved; |
539 | int root_block; | 543 | int root_block; |
@@ -556,7 +560,7 @@ affs_remount(struct super_block *sb, int *flags, char *data) | |||
556 | return -EINVAL; | 560 | return -EINVAL; |
557 | } | 561 | } |
558 | 562 | ||
559 | flush_delayed_work_sync(&sbi->sb_work); | 563 | flush_delayed_work(&sbi->sb_work); |
560 | replace_mount_options(sb, new_opts); | 564 | replace_mount_options(sb, new_opts); |
561 | 565 | ||
562 | sbi->s_flags = mount_flags; | 566 | sbi->s_flags = mount_flags; |
diff --git a/fs/afs/callback.c b/fs/afs/callback.c index 587ef5123cd8..7ef637d7f3a5 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c | |||
@@ -351,9 +351,7 @@ void afs_dispatch_give_up_callbacks(struct work_struct *work) | |||
351 | */ | 351 | */ |
352 | void afs_flush_callback_breaks(struct afs_server *server) | 352 | void afs_flush_callback_breaks(struct afs_server *server) |
353 | { | 353 | { |
354 | cancel_delayed_work(&server->cb_break_work); | 354 | mod_delayed_work(afs_callback_update_worker, &server->cb_break_work, 0); |
355 | queue_delayed_work(afs_callback_update_worker, | ||
356 | &server->cb_break_work, 0); | ||
357 | } | 355 | } |
358 | 356 | ||
359 | #if 0 | 357 | #if 0 |
diff --git a/fs/afs/server.c b/fs/afs/server.c index d59b7516e943..f342acf3547d 100644 --- a/fs/afs/server.c +++ b/fs/afs/server.c | |||
@@ -285,12 +285,7 @@ static void afs_reap_server(struct work_struct *work) | |||
285 | expiry = server->time_of_death + afs_server_timeout; | 285 | expiry = server->time_of_death + afs_server_timeout; |
286 | if (expiry > now) { | 286 | if (expiry > now) { |
287 | delay = (expiry - now) * HZ; | 287 | delay = (expiry - now) * HZ; |
288 | if (!queue_delayed_work(afs_wq, &afs_server_reaper, | 288 | mod_delayed_work(afs_wq, &afs_server_reaper, delay); |
289 | delay)) { | ||
290 | cancel_delayed_work(&afs_server_reaper); | ||
291 | queue_delayed_work(afs_wq, &afs_server_reaper, | ||
292 | delay); | ||
293 | } | ||
294 | break; | 289 | break; |
295 | } | 290 | } |
296 | 291 | ||
@@ -323,6 +318,5 @@ static void afs_reap_server(struct work_struct *work) | |||
323 | void __exit afs_purge_servers(void) | 318 | void __exit afs_purge_servers(void) |
324 | { | 319 | { |
325 | afs_server_timeout = 0; | 320 | afs_server_timeout = 0; |
326 | cancel_delayed_work(&afs_server_reaper); | 321 | mod_delayed_work(afs_wq, &afs_server_reaper, 0); |
327 | queue_delayed_work(afs_wq, &afs_server_reaper, 0); | ||
328 | } | 322 | } |
diff --git a/fs/afs/vlocation.c b/fs/afs/vlocation.c index 431984d2e372..57bcb1596530 100644 --- a/fs/afs/vlocation.c +++ b/fs/afs/vlocation.c | |||
@@ -561,12 +561,7 @@ static void afs_vlocation_reaper(struct work_struct *work) | |||
561 | if (expiry > now) { | 561 | if (expiry > now) { |
562 | delay = (expiry - now) * HZ; | 562 | delay = (expiry - now) * HZ; |
563 | _debug("delay %lu", delay); | 563 | _debug("delay %lu", delay); |
564 | if (!queue_delayed_work(afs_wq, &afs_vlocation_reap, | 564 | mod_delayed_work(afs_wq, &afs_vlocation_reap, delay); |
565 | delay)) { | ||
566 | cancel_delayed_work(&afs_vlocation_reap); | ||
567 | queue_delayed_work(afs_wq, &afs_vlocation_reap, | ||
568 | delay); | ||
569 | } | ||
570 | break; | 565 | break; |
571 | } | 566 | } |
572 | 567 | ||
@@ -614,13 +609,10 @@ void afs_vlocation_purge(void) | |||
614 | spin_lock(&afs_vlocation_updates_lock); | 609 | spin_lock(&afs_vlocation_updates_lock); |
615 | list_del_init(&afs_vlocation_updates); | 610 | list_del_init(&afs_vlocation_updates); |
616 | spin_unlock(&afs_vlocation_updates_lock); | 611 | spin_unlock(&afs_vlocation_updates_lock); |
617 | cancel_delayed_work(&afs_vlocation_update); | 612 | mod_delayed_work(afs_vlocation_update_worker, &afs_vlocation_update, 0); |
618 | queue_delayed_work(afs_vlocation_update_worker, | ||
619 | &afs_vlocation_update, 0); | ||
620 | destroy_workqueue(afs_vlocation_update_worker); | 613 | destroy_workqueue(afs_vlocation_update_worker); |
621 | 614 | ||
622 | cancel_delayed_work(&afs_vlocation_reap); | 615 | mod_delayed_work(afs_wq, &afs_vlocation_reap, 0); |
623 | queue_delayed_work(afs_wq, &afs_vlocation_reap, 0); | ||
624 | } | 616 | } |
625 | 617 | ||
626 | /* | 618 | /* |
diff --git a/fs/befs/befs.h b/fs/befs/befs.h index d9a40abda6b7..b26642839156 100644 --- a/fs/befs/befs.h +++ b/fs/befs/befs.h | |||
@@ -20,8 +20,8 @@ typedef u64 befs_blocknr_t; | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | typedef struct befs_mount_options { | 22 | typedef struct befs_mount_options { |
23 | gid_t gid; | 23 | kgid_t gid; |
24 | uid_t uid; | 24 | kuid_t uid; |
25 | int use_gid; | 25 | int use_gid; |
26 | int use_uid; | 26 | int use_uid; |
27 | int debug; | 27 | int debug; |
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 962b4f8f7994..2b3bda8d5e68 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/vfs.h> | 15 | #include <linux/vfs.h> |
16 | #include <linux/parser.h> | 16 | #include <linux/parser.h> |
17 | #include <linux/namei.h> | 17 | #include <linux/namei.h> |
18 | #include <linux/sched.h> | ||
18 | 19 | ||
19 | #include "befs.h" | 20 | #include "befs.h" |
20 | #include "btree.h" | 21 | #include "btree.h" |
@@ -352,9 +353,11 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino) | |||
352 | */ | 353 | */ |
353 | 354 | ||
354 | inode->i_uid = befs_sb->mount_opts.use_uid ? | 355 | inode->i_uid = befs_sb->mount_opts.use_uid ? |
355 | befs_sb->mount_opts.uid : (uid_t) fs32_to_cpu(sb, raw_inode->uid); | 356 | befs_sb->mount_opts.uid : |
357 | make_kuid(&init_user_ns, fs32_to_cpu(sb, raw_inode->uid)); | ||
356 | inode->i_gid = befs_sb->mount_opts.use_gid ? | 358 | inode->i_gid = befs_sb->mount_opts.use_gid ? |
357 | befs_sb->mount_opts.gid : (gid_t) fs32_to_cpu(sb, raw_inode->gid); | 359 | befs_sb->mount_opts.gid : |
360 | make_kgid(&init_user_ns, fs32_to_cpu(sb, raw_inode->gid)); | ||
358 | 361 | ||
359 | set_nlink(inode, 1); | 362 | set_nlink(inode, 1); |
360 | 363 | ||
@@ -679,10 +682,12 @@ parse_options(char *options, befs_mount_options * opts) | |||
679 | char *p; | 682 | char *p; |
680 | substring_t args[MAX_OPT_ARGS]; | 683 | substring_t args[MAX_OPT_ARGS]; |
681 | int option; | 684 | int option; |
685 | kuid_t uid; | ||
686 | kgid_t gid; | ||
682 | 687 | ||
683 | /* Initialize options */ | 688 | /* Initialize options */ |
684 | opts->uid = 0; | 689 | opts->uid = GLOBAL_ROOT_UID; |
685 | opts->gid = 0; | 690 | opts->gid = GLOBAL_ROOT_GID; |
686 | opts->use_uid = 0; | 691 | opts->use_uid = 0; |
687 | opts->use_gid = 0; | 692 | opts->use_gid = 0; |
688 | opts->iocharset = NULL; | 693 | opts->iocharset = NULL; |
@@ -701,23 +706,29 @@ parse_options(char *options, befs_mount_options * opts) | |||
701 | case Opt_uid: | 706 | case Opt_uid: |
702 | if (match_int(&args[0], &option)) | 707 | if (match_int(&args[0], &option)) |
703 | return 0; | 708 | return 0; |
704 | if (option < 0) { | 709 | uid = INVALID_UID; |
710 | if (option >= 0) | ||
711 | uid = make_kuid(current_user_ns(), option); | ||
712 | if (!uid_valid(uid)) { | ||
705 | printk(KERN_ERR "BeFS: Invalid uid %d, " | 713 | printk(KERN_ERR "BeFS: Invalid uid %d, " |
706 | "using default\n", option); | 714 | "using default\n", option); |
707 | break; | 715 | break; |
708 | } | 716 | } |
709 | opts->uid = option; | 717 | opts->uid = uid; |
710 | opts->use_uid = 1; | 718 | opts->use_uid = 1; |
711 | break; | 719 | break; |
712 | case Opt_gid: | 720 | case Opt_gid: |
713 | if (match_int(&args[0], &option)) | 721 | if (match_int(&args[0], &option)) |
714 | return 0; | 722 | return 0; |
715 | if (option < 0) { | 723 | gid = INVALID_GID; |
724 | if (option >= 0) | ||
725 | gid = make_kgid(current_user_ns(), option); | ||
726 | if (!gid_valid(gid)) { | ||
716 | printk(KERN_ERR "BeFS: Invalid gid %d, " | 727 | printk(KERN_ERR "BeFS: Invalid gid %d, " |
717 | "using default\n", option); | 728 | "using default\n", option); |
718 | break; | 729 | break; |
719 | } | 730 | } |
720 | opts->gid = option; | 731 | opts->gid = gid; |
721 | opts->use_gid = 1; | 732 | opts->use_gid = 1; |
722 | break; | 733 | break; |
723 | case Opt_charset: | 734 | case Opt_charset: |
diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c index d5fc598d6e4a..737aaa3f7090 100644 --- a/fs/bfs/inode.c +++ b/fs/bfs/inode.c | |||
@@ -76,8 +76,8 @@ struct inode *bfs_iget(struct super_block *sb, unsigned long ino) | |||
76 | BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock); | 76 | BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock); |
77 | BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock); | 77 | BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock); |
78 | BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); | 78 | BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); |
79 | inode->i_uid = le32_to_cpu(di->i_uid); | 79 | i_uid_write(inode, le32_to_cpu(di->i_uid)); |
80 | inode->i_gid = le32_to_cpu(di->i_gid); | 80 | i_gid_write(inode, le32_to_cpu(di->i_gid)); |
81 | set_nlink(inode, le32_to_cpu(di->i_nlink)); | 81 | set_nlink(inode, le32_to_cpu(di->i_nlink)); |
82 | inode->i_size = BFS_FILESIZE(di); | 82 | inode->i_size = BFS_FILESIZE(di); |
83 | inode->i_blocks = BFS_FILEBLOCKS(di); | 83 | inode->i_blocks = BFS_FILEBLOCKS(di); |
@@ -139,8 +139,8 @@ static int bfs_write_inode(struct inode *inode, struct writeback_control *wbc) | |||
139 | 139 | ||
140 | di->i_ino = cpu_to_le16(ino); | 140 | di->i_ino = cpu_to_le16(ino); |
141 | di->i_mode = cpu_to_le32(inode->i_mode); | 141 | di->i_mode = cpu_to_le32(inode->i_mode); |
142 | di->i_uid = cpu_to_le32(inode->i_uid); | 142 | di->i_uid = cpu_to_le32(i_uid_read(inode)); |
143 | di->i_gid = cpu_to_le32(inode->i_gid); | 143 | di->i_gid = cpu_to_le32(i_gid_read(inode)); |
144 | di->i_nlink = cpu_to_le32(inode->i_nlink); | 144 | di->i_nlink = cpu_to_le32(inode->i_nlink); |
145 | di->i_atime = cpu_to_le32(inode->i_atime.tv_sec); | 145 | di->i_atime = cpu_to_le32(inode->i_atime.tv_sec); |
146 | di->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); | 146 | di->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); |
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 761e2cd8fed1..0c16e3dbfd56 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -61,7 +61,7 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int type) | |||
61 | size = __btrfs_getxattr(inode, name, value, size); | 61 | size = __btrfs_getxattr(inode, name, value, size); |
62 | } | 62 | } |
63 | if (size > 0) { | 63 | if (size > 0) { |
64 | acl = posix_acl_from_xattr(value, size); | 64 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
65 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { | 65 | } else if (size == -ENOENT || size == -ENODATA || size == 0) { |
66 | /* FIXME, who returns -ENOENT? I think nobody */ | 66 | /* FIXME, who returns -ENOENT? I think nobody */ |
67 | acl = NULL; | 67 | acl = NULL; |
@@ -91,7 +91,7 @@ static int btrfs_xattr_acl_get(struct dentry *dentry, const char *name, | |||
91 | return PTR_ERR(acl); | 91 | return PTR_ERR(acl); |
92 | if (acl == NULL) | 92 | if (acl == NULL) |
93 | return -ENODATA; | 93 | return -ENODATA; |
94 | ret = posix_acl_to_xattr(acl, value, size); | 94 | ret = posix_acl_to_xattr(&init_user_ns, acl, value, size); |
95 | posix_acl_release(acl); | 95 | posix_acl_release(acl); |
96 | 96 | ||
97 | return ret; | 97 | return ret; |
@@ -141,7 +141,7 @@ static int btrfs_set_acl(struct btrfs_trans_handle *trans, | |||
141 | goto out; | 141 | goto out; |
142 | } | 142 | } |
143 | 143 | ||
144 | ret = posix_acl_to_xattr(acl, value, size); | 144 | ret = posix_acl_to_xattr(&init_user_ns, acl, value, size); |
145 | if (ret < 0) | 145 | if (ret < 0) |
146 | goto out; | 146 | goto out; |
147 | } | 147 | } |
@@ -169,7 +169,7 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, | |||
169 | return -EOPNOTSUPP; | 169 | return -EOPNOTSUPP; |
170 | 170 | ||
171 | if (value) { | 171 | if (value) { |
172 | acl = posix_acl_from_xattr(value, size); | 172 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
173 | if (IS_ERR(acl)) | 173 | if (IS_ERR(acl)) |
174 | return PTR_ERR(acl); | 174 | return PTR_ERR(acl); |
175 | 175 | ||
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0d195b507660..9821b672f5a2 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -116,7 +116,7 @@ struct btrfs_ordered_sum; | |||
116 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL | 116 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL |
117 | 117 | ||
118 | /* | 118 | /* |
119 | * The inode number assigned to the special inode for sotring | 119 | * The inode number assigned to the special inode for storing |
120 | * free ino cache | 120 | * free ino cache |
121 | */ | 121 | */ |
122 | #define BTRFS_FREE_INO_OBJECTID -12ULL | 122 | #define BTRFS_FREE_INO_OBJECTID -12ULL |
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 07d5eeb1e6f1..52c85e2b95d0 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -1715,8 +1715,8 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans, | |||
1715 | struct btrfs_inode_item *inode_item, | 1715 | struct btrfs_inode_item *inode_item, |
1716 | struct inode *inode) | 1716 | struct inode *inode) |
1717 | { | 1717 | { |
1718 | btrfs_set_stack_inode_uid(inode_item, inode->i_uid); | 1718 | btrfs_set_stack_inode_uid(inode_item, i_uid_read(inode)); |
1719 | btrfs_set_stack_inode_gid(inode_item, inode->i_gid); | 1719 | btrfs_set_stack_inode_gid(inode_item, i_gid_read(inode)); |
1720 | btrfs_set_stack_inode_size(inode_item, BTRFS_I(inode)->disk_i_size); | 1720 | btrfs_set_stack_inode_size(inode_item, BTRFS_I(inode)->disk_i_size); |
1721 | btrfs_set_stack_inode_mode(inode_item, inode->i_mode); | 1721 | btrfs_set_stack_inode_mode(inode_item, inode->i_mode); |
1722 | btrfs_set_stack_inode_nlink(inode_item, inode->i_nlink); | 1722 | btrfs_set_stack_inode_nlink(inode_item, inode->i_nlink); |
@@ -1764,8 +1764,8 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev) | |||
1764 | 1764 | ||
1765 | inode_item = &delayed_node->inode_item; | 1765 | inode_item = &delayed_node->inode_item; |
1766 | 1766 | ||
1767 | inode->i_uid = btrfs_stack_inode_uid(inode_item); | 1767 | i_uid_write(inode, btrfs_stack_inode_uid(inode_item)); |
1768 | inode->i_gid = btrfs_stack_inode_gid(inode_item); | 1768 | i_gid_write(inode, btrfs_stack_inode_gid(inode_item)); |
1769 | btrfs_i_size_write(inode, btrfs_stack_inode_size(inode_item)); | 1769 | btrfs_i_size_write(inode, btrfs_stack_inode_size(inode_item)); |
1770 | inode->i_mode = btrfs_stack_inode_mode(inode_item); | 1770 | inode->i_mode = btrfs_stack_inode_mode(inode_item); |
1771 | set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); | 1771 | set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); |
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index ab5300595847..c9d703693df0 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h | |||
@@ -18,7 +18,7 @@ | |||
18 | #ifndef __DELAYED_REF__ | 18 | #ifndef __DELAYED_REF__ |
19 | #define __DELAYED_REF__ | 19 | #define __DELAYED_REF__ |
20 | 20 | ||
21 | /* these are the possible values of struct btrfs_delayed_ref->action */ | 21 | /* these are the possible values of struct btrfs_delayed_ref_node->action */ |
22 | #define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ | 22 | #define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ |
23 | #define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ | 23 | #define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ |
24 | #define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ | 24 | #define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cf03a91d806f..a6ed6944e50c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -1971,8 +1971,8 @@ out: | |||
1971 | ordered_extent->len - 1, NULL, GFP_NOFS); | 1971 | ordered_extent->len - 1, NULL, GFP_NOFS); |
1972 | 1972 | ||
1973 | /* | 1973 | /* |
1974 | * This needs to be dont to make sure anybody waiting knows we are done | 1974 | * This needs to be done to make sure anybody waiting knows we are done |
1975 | * upating everything for this ordered extent. | 1975 | * updating everything for this ordered extent. |
1976 | */ | 1976 | */ |
1977 | btrfs_remove_ordered_extent(inode, ordered_extent); | 1977 | btrfs_remove_ordered_extent(inode, ordered_extent); |
1978 | 1978 | ||
@@ -2572,8 +2572,8 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
2572 | struct btrfs_inode_item); | 2572 | struct btrfs_inode_item); |
2573 | inode->i_mode = btrfs_inode_mode(leaf, inode_item); | 2573 | inode->i_mode = btrfs_inode_mode(leaf, inode_item); |
2574 | set_nlink(inode, btrfs_inode_nlink(leaf, inode_item)); | 2574 | set_nlink(inode, btrfs_inode_nlink(leaf, inode_item)); |
2575 | inode->i_uid = btrfs_inode_uid(leaf, inode_item); | 2575 | i_uid_write(inode, btrfs_inode_uid(leaf, inode_item)); |
2576 | inode->i_gid = btrfs_inode_gid(leaf, inode_item); | 2576 | i_gid_write(inode, btrfs_inode_gid(leaf, inode_item)); |
2577 | btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item)); | 2577 | btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item)); |
2578 | 2578 | ||
2579 | tspec = btrfs_inode_atime(inode_item); | 2579 | tspec = btrfs_inode_atime(inode_item); |
@@ -2651,8 +2651,8 @@ static void fill_inode_item(struct btrfs_trans_handle *trans, | |||
2651 | struct btrfs_inode_item *item, | 2651 | struct btrfs_inode_item *item, |
2652 | struct inode *inode) | 2652 | struct inode *inode) |
2653 | { | 2653 | { |
2654 | btrfs_set_inode_uid(leaf, item, inode->i_uid); | 2654 | btrfs_set_inode_uid(leaf, item, i_uid_read(inode)); |
2655 | btrfs_set_inode_gid(leaf, item, inode->i_gid); | 2655 | btrfs_set_inode_gid(leaf, item, i_gid_read(inode)); |
2656 | btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size); | 2656 | btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size); |
2657 | btrfs_set_inode_mode(leaf, item, inode->i_mode); | 2657 | btrfs_set_inode_mode(leaf, item, inode->i_mode); |
2658 | btrfs_set_inode_nlink(leaf, item, inode->i_nlink); | 2658 | btrfs_set_inode_nlink(leaf, item, inode->i_nlink); |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0a4f0c8bc58f..47127c1bd290 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -575,13 +575,13 @@ fail: | |||
575 | */ | 575 | */ |
576 | static inline int btrfs_check_sticky(struct inode *dir, struct inode *inode) | 576 | static inline int btrfs_check_sticky(struct inode *dir, struct inode *inode) |
577 | { | 577 | { |
578 | uid_t fsuid = current_fsuid(); | 578 | kuid_t fsuid = current_fsuid(); |
579 | 579 | ||
580 | if (!(dir->i_mode & S_ISVTX)) | 580 | if (!(dir->i_mode & S_ISVTX)) |
581 | return 0; | 581 | return 0; |
582 | if (inode->i_uid == fsuid) | 582 | if (uid_eq(inode->i_uid, fsuid)) |
583 | return 0; | 583 | return 0; |
584 | if (dir->i_uid == fsuid) | 584 | if (uid_eq(dir->i_uid, fsuid)) |
585 | return 0; | 585 | return 0; |
586 | return !capable(CAP_FOWNER); | 586 | return !capable(CAP_FOWNER); |
587 | } | 587 | } |
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index a08306a8bec9..2075ddfffa73 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig | |||
@@ -9,13 +9,14 @@ config CIFS | |||
9 | select CRYPTO_ARC4 | 9 | select CRYPTO_ARC4 |
10 | select CRYPTO_ECB | 10 | select CRYPTO_ECB |
11 | select CRYPTO_DES | 11 | select CRYPTO_DES |
12 | select CRYPTO_SHA256 | ||
12 | help | 13 | help |
13 | This is the client VFS module for the Common Internet File System | 14 | This is the client VFS module for the Common Internet File System |
14 | (CIFS) protocol which is the successor to the Server Message Block | 15 | (CIFS) protocol which is the successor to the Server Message Block |
15 | (SMB) protocol, the native file sharing mechanism for most early | 16 | (SMB) protocol, the native file sharing mechanism for most early |
16 | PC operating systems. The CIFS protocol is fully supported by | 17 | PC operating systems. The CIFS protocol is fully supported by |
17 | file servers such as Windows 2000 (including Windows 2003, NT 4 | 18 | file servers such as Windows 2000 (including Windows 2003, Windows 2008, |
18 | and Windows XP) as well by Samba (which provides excellent CIFS | 19 | NT 4 and Windows XP) as well by Samba (which provides excellent CIFS |
19 | server support for Linux and many other operating systems). Limited | 20 | server support for Linux and many other operating systems). Limited |
20 | support for OS/2 and Windows ME and similar servers is provided as | 21 | support for OS/2 and Windows ME and similar servers is provided as |
21 | well. | 22 | well. |
@@ -114,6 +115,13 @@ config CIFS_POSIX | |||
114 | (such as Samba 3.10 and later) which can negotiate | 115 | (such as Samba 3.10 and later) which can negotiate |
115 | CIFS POSIX ACL support. If unsure, say N. | 116 | CIFS POSIX ACL support. If unsure, say N. |
116 | 117 | ||
118 | config CIFS_ACL | ||
119 | bool "Provide CIFS ACL support" | ||
120 | depends on CIFS_XATTR && KEYS | ||
121 | help | ||
122 | Allows fetching CIFS/NTFS ACL from the server. The DACL blob | ||
123 | is handed over to the application/caller. | ||
124 | |||
117 | config CIFS_DEBUG2 | 125 | config CIFS_DEBUG2 |
118 | bool "Enable additional CIFS debugging routines" | 126 | bool "Enable additional CIFS debugging routines" |
119 | depends on CIFS | 127 | depends on CIFS |
@@ -138,21 +146,6 @@ config CIFS_DFS_UPCALL | |||
138 | IP addresses) which is needed for implicit mounts of DFS junction | 146 | IP addresses) which is needed for implicit mounts of DFS junction |
139 | points. If unsure, say N. | 147 | points. If unsure, say N. |
140 | 148 | ||
141 | config CIFS_FSCACHE | ||
142 | bool "Provide CIFS client caching support" | ||
143 | depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y | ||
144 | help | ||
145 | Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data | ||
146 | to be cached locally on disk through the general filesystem cache | ||
147 | manager. If unsure, say N. | ||
148 | |||
149 | config CIFS_ACL | ||
150 | bool "Provide CIFS ACL support" | ||
151 | depends on CIFS_XATTR && KEYS | ||
152 | help | ||
153 | Allows to fetch CIFS/NTFS ACL from the server. The DACL blob | ||
154 | is handed over to the application/caller. | ||
155 | |||
156 | config CIFS_NFSD_EXPORT | 149 | config CIFS_NFSD_EXPORT |
157 | bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)" | 150 | bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)" |
158 | depends on CIFS && EXPERIMENTAL && BROKEN | 151 | depends on CIFS && EXPERIMENTAL && BROKEN |
@@ -161,7 +154,7 @@ config CIFS_NFSD_EXPORT | |||
161 | 154 | ||
162 | config CIFS_SMB2 | 155 | config CIFS_SMB2 |
163 | bool "SMB2 network file system support (EXPERIMENTAL)" | 156 | bool "SMB2 network file system support (EXPERIMENTAL)" |
164 | depends on EXPERIMENTAL && INET && BROKEN | 157 | depends on CIFS && EXPERIMENTAL && INET |
165 | select NLS | 158 | select NLS |
166 | select KEYS | 159 | select KEYS |
167 | select FSCACHE | 160 | select FSCACHE |
@@ -178,3 +171,12 @@ config CIFS_SMB2 | |||
178 | (compared to cifs) due to protocol improvements. | 171 | (compared to cifs) due to protocol improvements. |
179 | 172 | ||
180 | Unless you are a developer or tester, say N. | 173 | Unless you are a developer or tester, say N. |
174 | |||
175 | config CIFS_FSCACHE | ||
176 | bool "Provide CIFS client caching support" | ||
177 | depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y | ||
178 | help | ||
179 | Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data | ||
180 | to be cached locally on disk through the general filesystem cache | ||
181 | manager. If unsure, say N. | ||
182 | |||
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile index feee94309271..aa0d68b086eb 100644 --- a/fs/cifs/Makefile +++ b/fs/cifs/Makefile | |||
@@ -17,4 +17,4 @@ cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o | |||
17 | cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o | 17 | cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o |
18 | 18 | ||
19 | cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \ | 19 | cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \ |
20 | smb2misc.o smb2pdu.o smb2inode.o | 20 | smb2misc.o smb2pdu.o smb2inode.o smb2file.o |
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c index 05f4dc263a23..2ee5c54797fa 100644 --- a/fs/cifs/cifsacl.c +++ b/fs/cifs/cifsacl.c | |||
@@ -1222,7 +1222,7 @@ struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb, | |||
1222 | if (!open_file) | 1222 | if (!open_file) |
1223 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); | 1223 | return get_cifs_acl_by_path(cifs_sb, path, pacllen); |
1224 | 1224 | ||
1225 | pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen); | 1225 | pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->fid.netfid, pacllen); |
1226 | cifsFileInfo_put(open_file); | 1226 | cifsFileInfo_put(open_file); |
1227 | return pntsd; | 1227 | return pntsd; |
1228 | } | 1228 | } |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 6a0d741159f0..652f5051be09 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "ntlmssp.h" | 29 | #include "ntlmssp.h" |
30 | #include <linux/ctype.h> | 30 | #include <linux/ctype.h> |
31 | #include <linux/random.h> | 31 | #include <linux/random.h> |
32 | #include <linux/highmem.h> | ||
32 | 33 | ||
33 | /* | 34 | /* |
34 | * Calculate and return the CIFS signature based on the mac key and SMB PDU. | 35 | * Calculate and return the CIFS signature based on the mac key and SMB PDU. |
@@ -37,11 +38,13 @@ | |||
37 | * the sequence number before this function is called. Also, this function | 38 | * the sequence number before this function is called. Also, this function |
38 | * should be called with the server->srv_mutex held. | 39 | * should be called with the server->srv_mutex held. |
39 | */ | 40 | */ |
40 | static int cifs_calc_signature(const struct kvec *iov, int n_vec, | 41 | static int cifs_calc_signature(struct smb_rqst *rqst, |
41 | struct TCP_Server_Info *server, char *signature) | 42 | struct TCP_Server_Info *server, char *signature) |
42 | { | 43 | { |
43 | int i; | 44 | int i; |
44 | int rc; | 45 | int rc; |
46 | struct kvec *iov = rqst->rq_iov; | ||
47 | int n_vec = rqst->rq_nvec; | ||
45 | 48 | ||
46 | if (iov == NULL || signature == NULL || server == NULL) | 49 | if (iov == NULL || signature == NULL || server == NULL) |
47 | return -EINVAL; | 50 | return -EINVAL; |
@@ -91,6 +94,16 @@ static int cifs_calc_signature(const struct kvec *iov, int n_vec, | |||
91 | } | 94 | } |
92 | } | 95 | } |
93 | 96 | ||
97 | /* now hash over the rq_pages array */ | ||
98 | for (i = 0; i < rqst->rq_npages; i++) { | ||
99 | struct kvec p_iov; | ||
100 | |||
101 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
102 | crypto_shash_update(&server->secmech.sdescmd5->shash, | ||
103 | p_iov.iov_base, p_iov.iov_len); | ||
104 | kunmap(rqst->rq_pages[i]); | ||
105 | } | ||
106 | |||
94 | rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); | 107 | rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); |
95 | if (rc) | 108 | if (rc) |
96 | cERROR(1, "%s: Could not generate md5 hash", __func__); | 109 | cERROR(1, "%s: Could not generate md5 hash", __func__); |
@@ -99,12 +112,12 @@ static int cifs_calc_signature(const struct kvec *iov, int n_vec, | |||
99 | } | 112 | } |
100 | 113 | ||
101 | /* must be called with server->srv_mutex held */ | 114 | /* must be called with server->srv_mutex held */ |
102 | int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | 115 | int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, |
103 | __u32 *pexpected_response_sequence_number) | 116 | __u32 *pexpected_response_sequence_number) |
104 | { | 117 | { |
105 | int rc = 0; | 118 | int rc = 0; |
106 | char smb_signature[20]; | 119 | char smb_signature[20]; |
107 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0].iov_base; | 120 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
108 | 121 | ||
109 | if ((cifs_pdu == NULL) || (server == NULL)) | 122 | if ((cifs_pdu == NULL) || (server == NULL)) |
110 | return -EINVAL; | 123 | return -EINVAL; |
@@ -125,7 +138,7 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
125 | *pexpected_response_sequence_number = server->sequence_number++; | 138 | *pexpected_response_sequence_number = server->sequence_number++; |
126 | server->sequence_number++; | 139 | server->sequence_number++; |
127 | 140 | ||
128 | rc = cifs_calc_signature(iov, n_vec, server, smb_signature); | 141 | rc = cifs_calc_signature(rqst, server, smb_signature); |
129 | if (rc) | 142 | if (rc) |
130 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); | 143 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); |
131 | else | 144 | else |
@@ -134,6 +147,15 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
134 | return rc; | 147 | return rc; |
135 | } | 148 | } |
136 | 149 | ||
150 | int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | ||
151 | __u32 *pexpected_response_sequence) | ||
152 | { | ||
153 | struct smb_rqst rqst = { .rq_iov = iov, | ||
154 | .rq_nvec = n_vec }; | ||
155 | |||
156 | return cifs_sign_rqst(&rqst, server, pexpected_response_sequence); | ||
157 | } | ||
158 | |||
137 | /* must be called with server->srv_mutex held */ | 159 | /* must be called with server->srv_mutex held */ |
138 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | 160 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, |
139 | __u32 *pexpected_response_sequence_number) | 161 | __u32 *pexpected_response_sequence_number) |
@@ -147,14 +169,14 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | |||
147 | pexpected_response_sequence_number); | 169 | pexpected_response_sequence_number); |
148 | } | 170 | } |
149 | 171 | ||
150 | int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | 172 | int cifs_verify_signature(struct smb_rqst *rqst, |
151 | struct TCP_Server_Info *server, | 173 | struct TCP_Server_Info *server, |
152 | __u32 expected_sequence_number) | 174 | __u32 expected_sequence_number) |
153 | { | 175 | { |
154 | unsigned int rc; | 176 | unsigned int rc; |
155 | char server_response_sig[8]; | 177 | char server_response_sig[8]; |
156 | char what_we_think_sig_should_be[20]; | 178 | char what_we_think_sig_should_be[20]; |
157 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)iov[0].iov_base; | 179 | struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
158 | 180 | ||
159 | if (cifs_pdu == NULL || server == NULL) | 181 | if (cifs_pdu == NULL || server == NULL) |
160 | return -EINVAL; | 182 | return -EINVAL; |
@@ -186,8 +208,7 @@ int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | |||
186 | cifs_pdu->Signature.Sequence.Reserved = 0; | 208 | cifs_pdu->Signature.Sequence.Reserved = 0; |
187 | 209 | ||
188 | mutex_lock(&server->srv_mutex); | 210 | mutex_lock(&server->srv_mutex); |
189 | rc = cifs_calc_signature(iov, nr_iov, server, | 211 | rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be); |
190 | what_we_think_sig_should_be); | ||
191 | mutex_unlock(&server->srv_mutex); | 212 | mutex_unlock(&server->srv_mutex); |
192 | 213 | ||
193 | if (rc) | 214 | if (rc) |
@@ -686,12 +707,17 @@ calc_seckey(struct cifs_ses *ses) | |||
686 | void | 707 | void |
687 | cifs_crypto_shash_release(struct TCP_Server_Info *server) | 708 | cifs_crypto_shash_release(struct TCP_Server_Info *server) |
688 | { | 709 | { |
710 | if (server->secmech.hmacsha256) | ||
711 | crypto_free_shash(server->secmech.hmacsha256); | ||
712 | |||
689 | if (server->secmech.md5) | 713 | if (server->secmech.md5) |
690 | crypto_free_shash(server->secmech.md5); | 714 | crypto_free_shash(server->secmech.md5); |
691 | 715 | ||
692 | if (server->secmech.hmacmd5) | 716 | if (server->secmech.hmacmd5) |
693 | crypto_free_shash(server->secmech.hmacmd5); | 717 | crypto_free_shash(server->secmech.hmacmd5); |
694 | 718 | ||
719 | kfree(server->secmech.sdeschmacsha256); | ||
720 | |||
695 | kfree(server->secmech.sdeschmacmd5); | 721 | kfree(server->secmech.sdeschmacmd5); |
696 | 722 | ||
697 | kfree(server->secmech.sdescmd5); | 723 | kfree(server->secmech.sdescmd5); |
@@ -716,6 +742,13 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
716 | goto crypto_allocate_md5_fail; | 742 | goto crypto_allocate_md5_fail; |
717 | } | 743 | } |
718 | 744 | ||
745 | server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0); | ||
746 | if (IS_ERR(server->secmech.hmacsha256)) { | ||
747 | cERROR(1, "could not allocate crypto hmacsha256\n"); | ||
748 | rc = PTR_ERR(server->secmech.hmacsha256); | ||
749 | goto crypto_allocate_hmacsha256_fail; | ||
750 | } | ||
751 | |||
719 | size = sizeof(struct shash_desc) + | 752 | size = sizeof(struct shash_desc) + |
720 | crypto_shash_descsize(server->secmech.hmacmd5); | 753 | crypto_shash_descsize(server->secmech.hmacmd5); |
721 | server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); | 754 | server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); |
@@ -727,7 +760,6 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
727 | server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; | 760 | server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; |
728 | server->secmech.sdeschmacmd5->shash.flags = 0x0; | 761 | server->secmech.sdeschmacmd5->shash.flags = 0x0; |
729 | 762 | ||
730 | |||
731 | size = sizeof(struct shash_desc) + | 763 | size = sizeof(struct shash_desc) + |
732 | crypto_shash_descsize(server->secmech.md5); | 764 | crypto_shash_descsize(server->secmech.md5); |
733 | server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); | 765 | server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); |
@@ -739,12 +771,29 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
739 | server->secmech.sdescmd5->shash.tfm = server->secmech.md5; | 771 | server->secmech.sdescmd5->shash.tfm = server->secmech.md5; |
740 | server->secmech.sdescmd5->shash.flags = 0x0; | 772 | server->secmech.sdescmd5->shash.flags = 0x0; |
741 | 773 | ||
774 | size = sizeof(struct shash_desc) + | ||
775 | crypto_shash_descsize(server->secmech.hmacsha256); | ||
776 | server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL); | ||
777 | if (!server->secmech.sdeschmacsha256) { | ||
778 | cERROR(1, "%s: Can't alloc hmacsha256\n", __func__); | ||
779 | rc = -ENOMEM; | ||
780 | goto crypto_allocate_hmacsha256_sdesc_fail; | ||
781 | } | ||
782 | server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256; | ||
783 | server->secmech.sdeschmacsha256->shash.flags = 0x0; | ||
784 | |||
742 | return 0; | 785 | return 0; |
743 | 786 | ||
787 | crypto_allocate_hmacsha256_sdesc_fail: | ||
788 | kfree(server->secmech.sdescmd5); | ||
789 | |||
744 | crypto_allocate_md5_sdesc_fail: | 790 | crypto_allocate_md5_sdesc_fail: |
745 | kfree(server->secmech.sdeschmacmd5); | 791 | kfree(server->secmech.sdeschmacmd5); |
746 | 792 | ||
747 | crypto_allocate_hmacmd5_sdesc_fail: | 793 | crypto_allocate_hmacmd5_sdesc_fail: |
794 | crypto_free_shash(server->secmech.hmacsha256); | ||
795 | |||
796 | crypto_allocate_hmacsha256_fail: | ||
748 | crypto_free_shash(server->secmech.md5); | 797 | crypto_free_shash(server->secmech.md5); |
749 | 798 | ||
750 | crypto_allocate_md5_fail: | 799 | crypto_allocate_md5_fail: |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index d4ce77a02327..e7931cc55d0c 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/kthread.h> | 36 | #include <linux/kthread.h> |
37 | #include <linux/freezer.h> | 37 | #include <linux/freezer.h> |
38 | #include <linux/namei.h> | 38 | #include <linux/namei.h> |
39 | #include <linux/random.h> | ||
39 | #include <net/ipv6.h> | 40 | #include <net/ipv6.h> |
40 | #include "cifsfs.h" | 41 | #include "cifsfs.h" |
41 | #include "cifspdu.h" | 42 | #include "cifspdu.h" |
@@ -51,7 +52,6 @@ | |||
51 | #ifdef CONFIG_CIFS_SMB2 | 52 | #ifdef CONFIG_CIFS_SMB2 |
52 | #include "smb2pdu.h" | 53 | #include "smb2pdu.h" |
53 | #endif | 54 | #endif |
54 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ | ||
55 | 55 | ||
56 | int cifsFYI = 0; | 56 | int cifsFYI = 0; |
57 | int cifsERROR = 1; | 57 | int cifsERROR = 1; |
@@ -89,6 +89,10 @@ extern mempool_t *cifs_mid_poolp; | |||
89 | 89 | ||
90 | struct workqueue_struct *cifsiod_wq; | 90 | struct workqueue_struct *cifsiod_wq; |
91 | 91 | ||
92 | #ifdef CONFIG_CIFS_SMB2 | ||
93 | __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE]; | ||
94 | #endif | ||
95 | |||
92 | static int | 96 | static int |
93 | cifs_read_super(struct super_block *sb) | 97 | cifs_read_super(struct super_block *sb) |
94 | { | 98 | { |
@@ -160,13 +164,12 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
160 | struct super_block *sb = dentry->d_sb; | 164 | struct super_block *sb = dentry->d_sb; |
161 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 165 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
162 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); | 166 | struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); |
163 | int rc = -EOPNOTSUPP; | 167 | struct TCP_Server_Info *server = tcon->ses->server; |
164 | unsigned int xid; | 168 | unsigned int xid; |
169 | int rc = 0; | ||
165 | 170 | ||
166 | xid = get_xid(); | 171 | xid = get_xid(); |
167 | 172 | ||
168 | buf->f_type = CIFS_MAGIC_NUMBER; | ||
169 | |||
170 | /* | 173 | /* |
171 | * PATH_MAX may be too long - it would presumably be total path, | 174 | * PATH_MAX may be too long - it would presumably be total path, |
172 | * but note that some servers (includinng Samba 3) have a shorter | 175 | * but note that some servers (includinng Samba 3) have a shorter |
@@ -178,27 +181,8 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
178 | buf->f_files = 0; /* undefined */ | 181 | buf->f_files = 0; /* undefined */ |
179 | buf->f_ffree = 0; /* unlimited */ | 182 | buf->f_ffree = 0; /* unlimited */ |
180 | 183 | ||
181 | /* | 184 | if (server->ops->queryfs) |
182 | * We could add a second check for a QFS Unix capability bit | 185 | rc = server->ops->queryfs(xid, tcon, buf); |
183 | */ | ||
184 | if ((tcon->ses->capabilities & CAP_UNIX) && | ||
185 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) | ||
186 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); | ||
187 | |||
188 | /* | ||
189 | * Only need to call the old QFSInfo if failed on newer one, | ||
190 | * e.g. by OS/2. | ||
191 | **/ | ||
192 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) | ||
193 | rc = CIFSSMBQFSInfo(xid, tcon, buf); | ||
194 | |||
195 | /* | ||
196 | * Some old Windows servers also do not support level 103, retry with | ||
197 | * older level one if old server failed the previous call or we | ||
198 | * bypassed it because we detected that this was an older LANMAN sess | ||
199 | */ | ||
200 | if (rc) | ||
201 | rc = SMBOldQFSInfo(xid, tcon, buf); | ||
202 | 186 | ||
203 | free_xid(xid); | 187 | free_xid(xid); |
204 | return 0; | 188 | return 0; |
@@ -239,9 +223,10 @@ cifs_alloc_inode(struct super_block *sb) | |||
239 | return NULL; | 223 | return NULL; |
240 | cifs_inode->cifsAttrs = 0x20; /* default */ | 224 | cifs_inode->cifsAttrs = 0x20; /* default */ |
241 | cifs_inode->time = 0; | 225 | cifs_inode->time = 0; |
242 | /* Until the file is open and we have gotten oplock | 226 | /* |
243 | info back from the server, can not assume caching of | 227 | * Until the file is open and we have gotten oplock info back from the |
244 | file data or metadata */ | 228 | * server, can not assume caching of file data or metadata. |
229 | */ | ||
245 | cifs_set_oplock_level(cifs_inode, 0); | 230 | cifs_set_oplock_level(cifs_inode, 0); |
246 | cifs_inode->delete_pending = false; | 231 | cifs_inode->delete_pending = false; |
247 | cifs_inode->invalid_mapping = false; | 232 | cifs_inode->invalid_mapping = false; |
@@ -249,11 +234,16 @@ cifs_alloc_inode(struct super_block *sb) | |||
249 | cifs_inode->server_eof = 0; | 234 | cifs_inode->server_eof = 0; |
250 | cifs_inode->uniqueid = 0; | 235 | cifs_inode->uniqueid = 0; |
251 | cifs_inode->createtime = 0; | 236 | cifs_inode->createtime = 0; |
252 | 237 | #ifdef CONFIG_CIFS_SMB2 | |
253 | /* Can not set i_flags here - they get immediately overwritten | 238 | get_random_bytes(cifs_inode->lease_key, SMB2_LEASE_KEY_SIZE); |
254 | to zero by the VFS */ | 239 | #endif |
255 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ | 240 | /* |
241 | * Can not set i_flags here - they get immediately overwritten to zero | ||
242 | * by the VFS. | ||
243 | */ | ||
244 | /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */ | ||
256 | INIT_LIST_HEAD(&cifs_inode->openFileList); | 245 | INIT_LIST_HEAD(&cifs_inode->openFileList); |
246 | INIT_LIST_HEAD(&cifs_inode->llist); | ||
257 | return &cifs_inode->vfs_inode; | 247 | return &cifs_inode->vfs_inode; |
258 | } | 248 | } |
259 | 249 | ||
@@ -360,7 +350,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) | |||
360 | cifs_show_security(s, tcon->ses->server); | 350 | cifs_show_security(s, tcon->ses->server); |
361 | cifs_show_cache_flavor(s, cifs_sb); | 351 | cifs_show_cache_flavor(s, cifs_sb); |
362 | 352 | ||
363 | seq_printf(s, ",unc=%s", tcon->treeName); | 353 | seq_printf(s, ",unc="); |
354 | seq_escape(s, tcon->treeName, " \t\n\\"); | ||
364 | 355 | ||
365 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) | 356 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) |
366 | seq_printf(s, ",multiuser"); | 357 | seq_printf(s, ",multiuser"); |
@@ -957,7 +948,7 @@ cifs_init_once(void *inode) | |||
957 | struct cifsInodeInfo *cifsi = inode; | 948 | struct cifsInodeInfo *cifsi = inode; |
958 | 949 | ||
959 | inode_init_once(&cifsi->vfs_inode); | 950 | inode_init_once(&cifsi->vfs_inode); |
960 | mutex_init(&cifsi->lock_mutex); | 951 | init_rwsem(&cifsi->lock_sem); |
961 | } | 952 | } |
962 | 953 | ||
963 | static int | 954 | static int |
@@ -1132,6 +1123,10 @@ init_cifs(void) | |||
1132 | spin_lock_init(&cifs_file_list_lock); | 1123 | spin_lock_init(&cifs_file_list_lock); |
1133 | spin_lock_init(&GlobalMid_Lock); | 1124 | spin_lock_init(&GlobalMid_Lock); |
1134 | 1125 | ||
1126 | #ifdef CONFIG_CIFS_SMB2 | ||
1127 | get_random_bytes(cifs_client_guid, SMB2_CLIENT_GUID_SIZE); | ||
1128 | #endif | ||
1129 | |||
1135 | if (cifs_max_pending < 2) { | 1130 | if (cifs_max_pending < 2) { |
1136 | cifs_max_pending = 2; | 1131 | cifs_max_pending = 2; |
1137 | cFYI(1, "cifs_max_pending set to min of 2"); | 1132 | cFYI(1, "cifs_max_pending set to min of 2"); |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 1c49c5a9b27a..7163419cecd9 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -128,5 +128,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | |||
128 | extern const struct export_operations cifs_export_ops; | 128 | extern const struct export_operations cifs_export_ops; |
129 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ | 129 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ |
130 | 130 | ||
131 | #define CIFS_VERSION "1.78" | 131 | #define CIFS_VERSION "2.0" |
132 | #endif /* _CIFSFS_H */ | 132 | #endif /* _CIFSFS_H */ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 977dc0e85ccb..f5af2527fc69 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "smb2pdu.h" | 32 | #include "smb2pdu.h" |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ | ||
36 | |||
35 | /* | 37 | /* |
36 | * The sizes of various internal tables and strings | 38 | * The sizes of various internal tables and strings |
37 | */ | 39 | */ |
@@ -128,8 +130,10 @@ struct sdesc { | |||
128 | struct cifs_secmech { | 130 | struct cifs_secmech { |
129 | struct crypto_shash *hmacmd5; /* hmac-md5 hash function */ | 131 | struct crypto_shash *hmacmd5; /* hmac-md5 hash function */ |
130 | struct crypto_shash *md5; /* md5 hash function */ | 132 | struct crypto_shash *md5; /* md5 hash function */ |
133 | struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */ | ||
131 | struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */ | 134 | struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */ |
132 | struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */ | 135 | struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */ |
136 | struct sdesc *sdeschmacsha256; /* ctxt to generate smb2 signature */ | ||
133 | }; | 137 | }; |
134 | 138 | ||
135 | /* per smb session structure/fields */ | 139 | /* per smb session structure/fields */ |
@@ -158,9 +162,24 @@ struct cifs_cred { | |||
158 | ***************************************************************** | 162 | ***************************************************************** |
159 | */ | 163 | */ |
160 | 164 | ||
165 | /* | ||
166 | * A smb_rqst represents a complete request to be issued to a server. It's | ||
167 | * formed by a kvec array, followed by an array of pages. Page data is assumed | ||
168 | * to start at the beginning of the first page. | ||
169 | */ | ||
170 | struct smb_rqst { | ||
171 | struct kvec *rq_iov; /* array of kvecs */ | ||
172 | unsigned int rq_nvec; /* number of kvecs in array */ | ||
173 | struct page **rq_pages; /* pointer to array of page ptrs */ | ||
174 | unsigned int rq_npages; /* number pages in array */ | ||
175 | unsigned int rq_pagesz; /* page size to use */ | ||
176 | unsigned int rq_tailsz; /* length of last page */ | ||
177 | }; | ||
178 | |||
161 | enum smb_version { | 179 | enum smb_version { |
162 | Smb_1 = 1, | 180 | Smb_1 = 1, |
163 | Smb_21, | 181 | Smb_21, |
182 | Smb_30, | ||
164 | }; | 183 | }; |
165 | 184 | ||
166 | struct mid_q_entry; | 185 | struct mid_q_entry; |
@@ -171,17 +190,23 @@ struct cifs_tcon; | |||
171 | struct dfs_info3_param; | 190 | struct dfs_info3_param; |
172 | struct cifs_fattr; | 191 | struct cifs_fattr; |
173 | struct smb_vol; | 192 | struct smb_vol; |
193 | struct cifs_fid; | ||
194 | struct cifs_readdata; | ||
195 | struct cifs_writedata; | ||
196 | struct cifs_io_parms; | ||
197 | struct cifs_search_info; | ||
198 | struct cifsInodeInfo; | ||
174 | 199 | ||
175 | struct smb_version_operations { | 200 | struct smb_version_operations { |
176 | int (*send_cancel)(struct TCP_Server_Info *, void *, | 201 | int (*send_cancel)(struct TCP_Server_Info *, void *, |
177 | struct mid_q_entry *); | 202 | struct mid_q_entry *); |
178 | bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *); | 203 | bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *); |
179 | /* setup request: allocate mid, sign message */ | 204 | /* setup request: allocate mid, sign message */ |
180 | int (*setup_request)(struct cifs_ses *, struct kvec *, unsigned int, | 205 | struct mid_q_entry *(*setup_request)(struct cifs_ses *, |
181 | struct mid_q_entry **); | 206 | struct smb_rqst *); |
182 | /* setup async request: allocate mid, sign message */ | 207 | /* setup async request: allocate mid, sign message */ |
183 | int (*setup_async_request)(struct TCP_Server_Info *, struct kvec *, | 208 | struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *, |
184 | unsigned int, struct mid_q_entry **); | 209 | struct smb_rqst *); |
185 | /* check response: verify signature, map error */ | 210 | /* check response: verify signature, map error */ |
186 | int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, | 211 | int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *, |
187 | bool); | 212 | bool); |
@@ -212,6 +237,10 @@ struct smb_version_operations { | |||
212 | bool (*need_neg)(struct TCP_Server_Info *); | 237 | bool (*need_neg)(struct TCP_Server_Info *); |
213 | /* negotiate to the server */ | 238 | /* negotiate to the server */ |
214 | int (*negotiate)(const unsigned int, struct cifs_ses *); | 239 | int (*negotiate)(const unsigned int, struct cifs_ses *); |
240 | /* set negotiated write size */ | ||
241 | unsigned int (*negotiate_wsize)(struct cifs_tcon *, struct smb_vol *); | ||
242 | /* set negotiated read size */ | ||
243 | unsigned int (*negotiate_rsize)(struct cifs_tcon *, struct smb_vol *); | ||
215 | /* setup smb sessionn */ | 244 | /* setup smb sessionn */ |
216 | int (*sess_setup)(const unsigned int, struct cifs_ses *, | 245 | int (*sess_setup)(const unsigned int, struct cifs_ses *, |
217 | const struct nls_table *); | 246 | const struct nls_table *); |
@@ -235,10 +264,22 @@ struct smb_version_operations { | |||
235 | int (*query_path_info)(const unsigned int, struct cifs_tcon *, | 264 | int (*query_path_info)(const unsigned int, struct cifs_tcon *, |
236 | struct cifs_sb_info *, const char *, | 265 | struct cifs_sb_info *, const char *, |
237 | FILE_ALL_INFO *, bool *); | 266 | FILE_ALL_INFO *, bool *); |
267 | /* query file data from the server */ | ||
268 | int (*query_file_info)(const unsigned int, struct cifs_tcon *, | ||
269 | struct cifs_fid *, FILE_ALL_INFO *); | ||
238 | /* get server index number */ | 270 | /* get server index number */ |
239 | int (*get_srv_inum)(const unsigned int, struct cifs_tcon *, | 271 | int (*get_srv_inum)(const unsigned int, struct cifs_tcon *, |
240 | struct cifs_sb_info *, const char *, | 272 | struct cifs_sb_info *, const char *, |
241 | u64 *uniqueid, FILE_ALL_INFO *); | 273 | u64 *uniqueid, FILE_ALL_INFO *); |
274 | /* set size by path */ | ||
275 | int (*set_path_size)(const unsigned int, struct cifs_tcon *, | ||
276 | const char *, __u64, struct cifs_sb_info *, bool); | ||
277 | /* set size by file handle */ | ||
278 | int (*set_file_size)(const unsigned int, struct cifs_tcon *, | ||
279 | struct cifsFileInfo *, __u64, bool); | ||
280 | /* set attributes */ | ||
281 | int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *, | ||
282 | const unsigned int); | ||
242 | /* build a full path to the root of the mount */ | 283 | /* build a full path to the root of the mount */ |
243 | char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *, | 284 | char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *, |
244 | struct cifs_tcon *); | 285 | struct cifs_tcon *); |
@@ -256,10 +297,84 @@ struct smb_version_operations { | |||
256 | /* remove directory */ | 297 | /* remove directory */ |
257 | int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *, | 298 | int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *, |
258 | struct cifs_sb_info *); | 299 | struct cifs_sb_info *); |
300 | /* unlink file */ | ||
301 | int (*unlink)(const unsigned int, struct cifs_tcon *, const char *, | ||
302 | struct cifs_sb_info *); | ||
303 | /* open, rename and delete file */ | ||
304 | int (*rename_pending_delete)(const char *, struct dentry *, | ||
305 | const unsigned int); | ||
306 | /* send rename request */ | ||
307 | int (*rename)(const unsigned int, struct cifs_tcon *, const char *, | ||
308 | const char *, struct cifs_sb_info *); | ||
309 | /* send create hardlink request */ | ||
310 | int (*create_hardlink)(const unsigned int, struct cifs_tcon *, | ||
311 | const char *, const char *, | ||
312 | struct cifs_sb_info *); | ||
313 | /* open a file for non-posix mounts */ | ||
314 | int (*open)(const unsigned int, struct cifs_tcon *, const char *, int, | ||
315 | int, int, struct cifs_fid *, __u32 *, FILE_ALL_INFO *, | ||
316 | struct cifs_sb_info *); | ||
317 | /* set fid protocol-specific info */ | ||
318 | void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32); | ||
319 | /* close a file */ | ||
320 | void (*close)(const unsigned int, struct cifs_tcon *, | ||
321 | struct cifs_fid *); | ||
322 | /* send a flush request to the server */ | ||
323 | int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *); | ||
324 | /* async read from the server */ | ||
325 | int (*async_readv)(struct cifs_readdata *); | ||
326 | /* async write to the server */ | ||
327 | int (*async_writev)(struct cifs_writedata *); | ||
328 | /* sync read from the server */ | ||
329 | int (*sync_read)(const unsigned int, struct cifsFileInfo *, | ||
330 | struct cifs_io_parms *, unsigned int *, char **, | ||
331 | int *); | ||
332 | /* sync write to the server */ | ||
333 | int (*sync_write)(const unsigned int, struct cifsFileInfo *, | ||
334 | struct cifs_io_parms *, unsigned int *, struct kvec *, | ||
335 | unsigned long); | ||
336 | /* open dir, start readdir */ | ||
337 | int (*query_dir_first)(const unsigned int, struct cifs_tcon *, | ||
338 | const char *, struct cifs_sb_info *, | ||
339 | struct cifs_fid *, __u16, | ||
340 | struct cifs_search_info *); | ||
341 | /* continue readdir */ | ||
342 | int (*query_dir_next)(const unsigned int, struct cifs_tcon *, | ||
343 | struct cifs_fid *, | ||
344 | __u16, struct cifs_search_info *srch_inf); | ||
345 | /* close dir */ | ||
346 | int (*close_dir)(const unsigned int, struct cifs_tcon *, | ||
347 | struct cifs_fid *); | ||
348 | /* calculate a size of SMB message */ | ||
349 | unsigned int (*calc_smb_size)(void *); | ||
350 | /* check for STATUS_PENDING and process it in a positive case */ | ||
351 | bool (*is_status_pending)(char *, struct TCP_Server_Info *, int); | ||
352 | /* send oplock break response */ | ||
353 | int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *, | ||
354 | struct cifsInodeInfo *); | ||
355 | /* query remote filesystem */ | ||
356 | int (*queryfs)(const unsigned int, struct cifs_tcon *, | ||
357 | struct kstatfs *); | ||
358 | /* send mandatory brlock to the server */ | ||
359 | int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64, | ||
360 | __u64, __u32, int, int, bool); | ||
361 | /* unlock range of mandatory locks */ | ||
362 | int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *, | ||
363 | const unsigned int); | ||
364 | /* push brlocks from the cache to the server */ | ||
365 | int (*push_mand_locks)(struct cifsFileInfo *); | ||
366 | /* get lease key of the inode */ | ||
367 | void (*get_lease_key)(struct inode *, struct cifs_fid *fid); | ||
368 | /* set lease key of the inode */ | ||
369 | void (*set_lease_key)(struct inode *, struct cifs_fid *fid); | ||
370 | /* generate new lease key */ | ||
371 | void (*new_lease_key)(struct cifs_fid *fid); | ||
259 | }; | 372 | }; |
260 | 373 | ||
261 | struct smb_version_values { | 374 | struct smb_version_values { |
262 | char *version_string; | 375 | char *version_string; |
376 | __u16 protocol_id; | ||
377 | __u32 req_capabilities; | ||
263 | __u32 large_lock_type; | 378 | __u32 large_lock_type; |
264 | __u32 exclusive_lock_type; | 379 | __u32 exclusive_lock_type; |
265 | __u32 shared_lock_type; | 380 | __u32 shared_lock_type; |
@@ -496,6 +611,51 @@ get_next_mid(struct TCP_Server_Info *server) | |||
496 | } | 611 | } |
497 | 612 | ||
498 | /* | 613 | /* |
614 | * When the server supports very large reads and writes via POSIX extensions, | ||
615 | * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not | ||
616 | * including the RFC1001 length. | ||
617 | * | ||
618 | * Note that this might make for "interesting" allocation problems during | ||
619 | * writeback however as we have to allocate an array of pointers for the | ||
620 | * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096. | ||
621 | * | ||
622 | * For reads, there is a similar problem as we need to allocate an array | ||
623 | * of kvecs to handle the receive, though that should only need to be done | ||
624 | * once. | ||
625 | */ | ||
626 | #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) | ||
627 | #define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) | ||
628 | |||
629 | /* | ||
630 | * When the server doesn't allow large posix writes, only allow a rsize/wsize | ||
631 | * of 2^17-1 minus the size of the call header. That allows for a read or | ||
632 | * write up to the maximum size described by RFC1002. | ||
633 | */ | ||
634 | #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) | ||
635 | #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) | ||
636 | |||
637 | /* | ||
638 | * The default wsize is 1M. find_get_pages seems to return a maximum of 256 | ||
639 | * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill | ||
640 | * a single wsize request with a single call. | ||
641 | */ | ||
642 | #define CIFS_DEFAULT_IOSIZE (1024 * 1024) | ||
643 | |||
644 | /* | ||
645 | * Windows only supports a max of 60kb reads and 65535 byte writes. Default to | ||
646 | * those values when posix extensions aren't in force. In actuality here, we | ||
647 | * use 65536 to allow for a write that is a multiple of 4k. Most servers seem | ||
648 | * to be ok with the extra byte even though Windows doesn't send writes that | ||
649 | * are that large. | ||
650 | * | ||
651 | * Citation: | ||
652 | * | ||
653 | * http://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx | ||
654 | */ | ||
655 | #define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024) | ||
656 | #define CIFS_DEFAULT_NON_POSIX_WSIZE (65536) | ||
657 | |||
658 | /* | ||
499 | * Macros to allow the TCP_Server_Info->net field and related code to drop out | 659 | * Macros to allow the TCP_Server_Info->net field and related code to drop out |
500 | * when CONFIG_NET_NS isn't set. | 660 | * when CONFIG_NET_NS isn't set. |
501 | */ | 661 | */ |
@@ -559,6 +719,7 @@ struct cifs_ses { | |||
559 | __u16 session_flags; | 719 | __u16 session_flags; |
560 | #endif /* CONFIG_CIFS_SMB2 */ | 720 | #endif /* CONFIG_CIFS_SMB2 */ |
561 | }; | 721 | }; |
722 | |||
562 | /* no more than one of the following three session flags may be set */ | 723 | /* no more than one of the following three session flags may be set */ |
563 | #define CIFS_SES_NT4 1 | 724 | #define CIFS_SES_NT4 1 |
564 | #define CIFS_SES_OS2 2 | 725 | #define CIFS_SES_OS2 2 |
@@ -665,6 +826,7 @@ struct cifs_tcon { | |||
665 | u64 resource_id; /* server resource id */ | 826 | u64 resource_id; /* server resource id */ |
666 | struct fscache_cookie *fscache; /* cookie for share */ | 827 | struct fscache_cookie *fscache; /* cookie for share */ |
667 | #endif | 828 | #endif |
829 | struct list_head pending_opens; /* list of incomplete opens */ | ||
668 | /* BB add field for back pointer to sb struct(s)? */ | 830 | /* BB add field for back pointer to sb struct(s)? */ |
669 | }; | 831 | }; |
670 | 832 | ||
@@ -707,6 +869,15 @@ cifs_get_tlink(struct tcon_link *tlink) | |||
707 | /* This function is always expected to succeed */ | 869 | /* This function is always expected to succeed */ |
708 | extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); | 870 | extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); |
709 | 871 | ||
872 | #define CIFS_OPLOCK_NO_CHANGE 0xfe | ||
873 | |||
874 | struct cifs_pending_open { | ||
875 | struct list_head olist; | ||
876 | struct tcon_link *tlink; | ||
877 | __u8 lease_key[16]; | ||
878 | __u32 oplock; | ||
879 | }; | ||
880 | |||
710 | /* | 881 | /* |
711 | * This info hangs off the cifsFileInfo structure, pointed to by llist. | 882 | * This info hangs off the cifsFileInfo structure, pointed to by llist. |
712 | * This is used to track byte stream locks on the file | 883 | * This is used to track byte stream locks on the file |
@@ -740,16 +911,29 @@ struct cifs_search_info { | |||
740 | bool smallBuf:1; /* so we know which buf_release function to call */ | 911 | bool smallBuf:1; /* so we know which buf_release function to call */ |
741 | }; | 912 | }; |
742 | 913 | ||
914 | struct cifs_fid { | ||
915 | __u16 netfid; | ||
916 | #ifdef CONFIG_CIFS_SMB2 | ||
917 | __u64 persistent_fid; /* persist file id for smb2 */ | ||
918 | __u64 volatile_fid; /* volatile file id for smb2 */ | ||
919 | __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */ | ||
920 | #endif | ||
921 | struct cifs_pending_open *pending_open; | ||
922 | }; | ||
923 | |||
924 | struct cifs_fid_locks { | ||
925 | struct list_head llist; | ||
926 | struct cifsFileInfo *cfile; /* fid that owns locks */ | ||
927 | struct list_head locks; /* locks held by fid above */ | ||
928 | }; | ||
929 | |||
743 | struct cifsFileInfo { | 930 | struct cifsFileInfo { |
744 | struct list_head tlist; /* pointer to next fid owned by tcon */ | 931 | struct list_head tlist; /* pointer to next fid owned by tcon */ |
745 | struct list_head flist; /* next fid (file instance) for this inode */ | 932 | struct list_head flist; /* next fid (file instance) for this inode */ |
746 | struct list_head llist; /* | 933 | struct cifs_fid_locks *llist; /* brlocks held by this fid */ |
747 | * brlocks held by this fid, protected by | ||
748 | * lock_mutex from cifsInodeInfo structure | ||
749 | */ | ||
750 | unsigned int uid; /* allows finding which FileInfo structure */ | 934 | unsigned int uid; /* allows finding which FileInfo structure */ |
751 | __u32 pid; /* process id who opened file */ | 935 | __u32 pid; /* process id who opened file */ |
752 | __u16 netfid; /* file id from remote */ | 936 | struct cifs_fid fid; /* file id from remote */ |
753 | /* BB add lock scope info here if needed */ ; | 937 | /* BB add lock scope info here if needed */ ; |
754 | /* lock scope id (0 if none) */ | 938 | /* lock scope id (0 if none) */ |
755 | struct dentry *dentry; | 939 | struct dentry *dentry; |
@@ -765,12 +949,60 @@ struct cifsFileInfo { | |||
765 | 949 | ||
766 | struct cifs_io_parms { | 950 | struct cifs_io_parms { |
767 | __u16 netfid; | 951 | __u16 netfid; |
952 | #ifdef CONFIG_CIFS_SMB2 | ||
953 | __u64 persistent_fid; /* persist file id for smb2 */ | ||
954 | __u64 volatile_fid; /* volatile file id for smb2 */ | ||
955 | #endif | ||
768 | __u32 pid; | 956 | __u32 pid; |
769 | __u64 offset; | 957 | __u64 offset; |
770 | unsigned int length; | 958 | unsigned int length; |
771 | struct cifs_tcon *tcon; | 959 | struct cifs_tcon *tcon; |
772 | }; | 960 | }; |
773 | 961 | ||
962 | struct cifs_readdata; | ||
963 | |||
964 | /* asynchronous read support */ | ||
965 | struct cifs_readdata { | ||
966 | struct kref refcount; | ||
967 | struct list_head list; | ||
968 | struct completion done; | ||
969 | struct cifsFileInfo *cfile; | ||
970 | struct address_space *mapping; | ||
971 | __u64 offset; | ||
972 | unsigned int bytes; | ||
973 | pid_t pid; | ||
974 | int result; | ||
975 | struct work_struct work; | ||
976 | int (*read_into_pages)(struct TCP_Server_Info *server, | ||
977 | struct cifs_readdata *rdata, | ||
978 | unsigned int len); | ||
979 | struct kvec iov; | ||
980 | unsigned int pagesz; | ||
981 | unsigned int tailsz; | ||
982 | unsigned int nr_pages; | ||
983 | struct page *pages[]; | ||
984 | }; | ||
985 | |||
986 | struct cifs_writedata; | ||
987 | |||
988 | /* asynchronous write support */ | ||
989 | struct cifs_writedata { | ||
990 | struct kref refcount; | ||
991 | struct list_head list; | ||
992 | struct completion done; | ||
993 | enum writeback_sync_modes sync_mode; | ||
994 | struct work_struct work; | ||
995 | struct cifsFileInfo *cfile; | ||
996 | __u64 offset; | ||
997 | pid_t pid; | ||
998 | unsigned int bytes; | ||
999 | int result; | ||
1000 | unsigned int pagesz; | ||
1001 | unsigned int tailsz; | ||
1002 | unsigned int nr_pages; | ||
1003 | struct page *pages[1]; | ||
1004 | }; | ||
1005 | |||
774 | /* | 1006 | /* |
775 | * Take a reference on the file private data. Must be called with | 1007 | * Take a reference on the file private data. Must be called with |
776 | * cifs_file_list_lock held. | 1008 | * cifs_file_list_lock held. |
@@ -790,11 +1022,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file); | |||
790 | 1022 | ||
791 | struct cifsInodeInfo { | 1023 | struct cifsInodeInfo { |
792 | bool can_cache_brlcks; | 1024 | bool can_cache_brlcks; |
793 | struct mutex lock_mutex; /* | 1025 | struct list_head llist; /* locks helb by this inode */ |
794 | * protect the field above and llist | 1026 | struct rw_semaphore lock_sem; /* protect the fields above */ |
795 | * from every cifsFileInfo structure | ||
796 | * from openFileList | ||
797 | */ | ||
798 | /* BB add in lists for dirty pages i.e. write caching info for oplock */ | 1027 | /* BB add in lists for dirty pages i.e. write caching info for oplock */ |
799 | struct list_head openFileList; | 1028 | struct list_head openFileList; |
800 | __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ | 1029 | __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ |
@@ -806,6 +1035,9 @@ struct cifsInodeInfo { | |||
806 | u64 server_eof; /* current file size on server -- protected by i_lock */ | 1035 | u64 server_eof; /* current file size on server -- protected by i_lock */ |
807 | u64 uniqueid; /* server inode number */ | 1036 | u64 uniqueid; /* server inode number */ |
808 | u64 createtime; /* creation time on server */ | 1037 | u64 createtime; /* creation time on server */ |
1038 | #ifdef CONFIG_CIFS_SMB2 | ||
1039 | __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */ | ||
1040 | #endif | ||
809 | #ifdef CONFIG_CIFS_FSCACHE | 1041 | #ifdef CONFIG_CIFS_FSCACHE |
810 | struct fscache_cookie *fscache; | 1042 | struct fscache_cookie *fscache; |
811 | #endif | 1043 | #endif |
@@ -1130,7 +1362,7 @@ require use of the stronger protocol */ | |||
1130 | #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ | 1362 | #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ |
1131 | #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ | 1363 | #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ |
1132 | 1364 | ||
1133 | #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2) | 1365 | #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_NTLMSSP) |
1134 | #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2) | 1366 | #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2) |
1135 | #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) | 1367 | #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) |
1136 | /* | 1368 | /* |
@@ -1267,7 +1499,13 @@ extern mempool_t *cifs_mid_poolp; | |||
1267 | #define SMB1_VERSION_STRING "1.0" | 1499 | #define SMB1_VERSION_STRING "1.0" |
1268 | extern struct smb_version_operations smb1_operations; | 1500 | extern struct smb_version_operations smb1_operations; |
1269 | extern struct smb_version_values smb1_values; | 1501 | extern struct smb_version_values smb1_values; |
1502 | #define SMB20_VERSION_STRING "2.0" | ||
1503 | /*extern struct smb_version_operations smb20_operations; */ /* not needed yet */ | ||
1504 | extern struct smb_version_values smb20_values; | ||
1270 | #define SMB21_VERSION_STRING "2.1" | 1505 | #define SMB21_VERSION_STRING "2.1" |
1271 | extern struct smb_version_operations smb21_operations; | 1506 | extern struct smb_version_operations smb21_operations; |
1272 | extern struct smb_version_values smb21_values; | 1507 | extern struct smb_version_values smb21_values; |
1508 | #define SMB30_VERSION_STRING "3.0" | ||
1509 | /*extern struct smb_version_operations smb30_operations; */ /* not needed yet */ | ||
1510 | extern struct smb_version_values smb30_values; | ||
1273 | #endif /* _CIFS_GLOB_H */ | 1511 | #endif /* _CIFS_GLOB_H */ |
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index 3fb03e2c8e86..b9d59a948a2c 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h | |||
@@ -2210,7 +2210,7 @@ typedef struct { /* data block encoding of response to level 263 QPathInfo */ | |||
2210 | __u8 DeletePending; | 2210 | __u8 DeletePending; |
2211 | __u8 Directory; | 2211 | __u8 Directory; |
2212 | __u16 Pad2; | 2212 | __u16 Pad2; |
2213 | __u64 IndexNumber; | 2213 | __le64 IndexNumber; |
2214 | __le32 EASize; | 2214 | __le32 EASize; |
2215 | __le32 AccessFlags; | 2215 | __le32 AccessFlags; |
2216 | __u64 IndexNumber1; | 2216 | __u64 IndexNumber1; |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index f1bbf8305d3a..5144e9fbeb8c 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | struct statfs; | 25 | struct statfs; |
26 | struct smb_vol; | 26 | struct smb_vol; |
27 | struct smb_rqst; | ||
27 | 28 | ||
28 | /* | 29 | /* |
29 | ***************************************************************** | 30 | ***************************************************************** |
@@ -35,6 +36,8 @@ extern struct smb_hdr *cifs_buf_get(void); | |||
35 | extern void cifs_buf_release(void *); | 36 | extern void cifs_buf_release(void *); |
36 | extern struct smb_hdr *cifs_small_buf_get(void); | 37 | extern struct smb_hdr *cifs_small_buf_get(void); |
37 | extern void cifs_small_buf_release(void *); | 38 | extern void cifs_small_buf_release(void *); |
39 | extern void cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx, | ||
40 | struct kvec *iov); | ||
38 | extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, | 41 | extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, |
39 | unsigned int /* length */); | 42 | unsigned int /* length */); |
40 | extern unsigned int _get_xid(void); | 43 | extern unsigned int _get_xid(void); |
@@ -65,21 +68,22 @@ extern char *cifs_compose_mount_options(const char *sb_mountdata, | |||
65 | extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer, | 68 | extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer, |
66 | struct TCP_Server_Info *server); | 69 | struct TCP_Server_Info *server); |
67 | extern void DeleteMidQEntry(struct mid_q_entry *midEntry); | 70 | extern void DeleteMidQEntry(struct mid_q_entry *midEntry); |
71 | extern void cifs_delete_mid(struct mid_q_entry *mid); | ||
68 | extern void cifs_wake_up_task(struct mid_q_entry *mid); | 72 | extern void cifs_wake_up_task(struct mid_q_entry *mid); |
69 | extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | 73 | extern int cifs_call_async(struct TCP_Server_Info *server, |
70 | unsigned int nvec, mid_receive_t *receive, | 74 | struct smb_rqst *rqst, |
71 | mid_callback_t *callback, void *cbdata, | 75 | mid_receive_t *receive, mid_callback_t *callback, |
72 | const int flags); | 76 | void *cbdata, const int flags); |
73 | extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, | 77 | extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, |
74 | struct smb_hdr * /* input */ , | 78 | struct smb_hdr * /* input */ , |
75 | struct smb_hdr * /* out */ , | 79 | struct smb_hdr * /* out */ , |
76 | int * /* bytes returned */ , const int); | 80 | int * /* bytes returned */ , const int); |
77 | extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, | 81 | extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, |
78 | char *in_buf, int flags); | 82 | char *in_buf, int flags); |
79 | extern int cifs_setup_request(struct cifs_ses *, struct kvec *, unsigned int, | 83 | extern struct mid_q_entry *cifs_setup_request(struct cifs_ses *, |
80 | struct mid_q_entry **); | 84 | struct smb_rqst *); |
81 | extern int cifs_setup_async_request(struct TCP_Server_Info *, struct kvec *, | 85 | extern struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *, |
82 | unsigned int, struct mid_q_entry **); | 86 | struct smb_rqst *); |
83 | extern int cifs_check_receive(struct mid_q_entry *mid, | 87 | extern int cifs_check_receive(struct mid_q_entry *mid, |
84 | struct TCP_Server_Info *server, bool log_error); | 88 | struct TCP_Server_Info *server, bool log_error); |
85 | extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, | 89 | extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, |
@@ -99,7 +103,7 @@ extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | |||
99 | unsigned int bytes_written); | 103 | unsigned int bytes_written); |
100 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); | 104 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); |
101 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); | 105 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); |
102 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); | 106 | extern unsigned int smbCalcSize(void *buf); |
103 | extern int decode_negTokenInit(unsigned char *security_blob, int length, | 107 | extern int decode_negTokenInit(unsigned char *security_blob, int length, |
104 | struct TCP_Server_Info *server); | 108 | struct TCP_Server_Info *server); |
105 | extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); | 109 | extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); |
@@ -120,10 +124,14 @@ extern u64 cifs_UnixTimeToNT(struct timespec); | |||
120 | extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, | 124 | extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, |
121 | int offset); | 125 | int offset); |
122 | extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); | 126 | extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); |
123 | 127 | extern int cifs_unlock_range(struct cifsFileInfo *cfile, | |
124 | extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle, | 128 | struct file_lock *flock, const unsigned int xid); |
125 | struct file *file, struct tcon_link *tlink, | 129 | extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile); |
126 | __u32 oplock); | 130 | |
131 | extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, | ||
132 | struct file *file, | ||
133 | struct tcon_link *tlink, | ||
134 | __u32 oplock); | ||
127 | extern int cifs_posix_open(char *full_path, struct inode **inode, | 135 | extern int cifs_posix_open(char *full_path, struct inode **inode, |
128 | struct super_block *sb, int mode, | 136 | struct super_block *sb, int mode, |
129 | unsigned int f_flags, __u32 *oplock, __u16 *netfid, | 137 | unsigned int f_flags, __u32 *oplock, __u16 *netfid, |
@@ -132,18 +140,23 @@ void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); | |||
132 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, | 140 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, |
133 | FILE_UNIX_BASIC_INFO *info, | 141 | FILE_UNIX_BASIC_INFO *info, |
134 | struct cifs_sb_info *cifs_sb); | 142 | struct cifs_sb_info *cifs_sb); |
143 | extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *, | ||
144 | struct cifs_sb_info *); | ||
135 | extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); | 145 | extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); |
136 | extern struct inode *cifs_iget(struct super_block *sb, | 146 | extern struct inode *cifs_iget(struct super_block *sb, |
137 | struct cifs_fattr *fattr); | 147 | struct cifs_fattr *fattr); |
138 | 148 | ||
139 | extern int cifs_get_file_info(struct file *filp); | ||
140 | extern int cifs_get_inode_info(struct inode **inode, const char *full_path, | 149 | extern int cifs_get_inode_info(struct inode **inode, const char *full_path, |
141 | FILE_ALL_INFO *data, struct super_block *sb, | 150 | FILE_ALL_INFO *data, struct super_block *sb, |
142 | int xid, const __u16 *fid); | 151 | int xid, const __u16 *fid); |
143 | extern int cifs_get_file_info_unix(struct file *filp); | ||
144 | extern int cifs_get_inode_info_unix(struct inode **pinode, | 152 | extern int cifs_get_inode_info_unix(struct inode **pinode, |
145 | const unsigned char *search_path, | 153 | const unsigned char *search_path, |
146 | struct super_block *sb, unsigned int xid); | 154 | struct super_block *sb, unsigned int xid); |
155 | extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, | ||
156 | unsigned int xid, char *full_path, __u32 dosattr); | ||
157 | extern int cifs_rename_pending_delete(const char *full_path, | ||
158 | struct dentry *dentry, | ||
159 | const unsigned int xid); | ||
147 | extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, | 160 | extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, |
148 | struct cifs_fattr *fattr, struct inode *inode, | 161 | struct cifs_fattr *fattr, struct inode *inode, |
149 | const char *path, const __u16 *pfid); | 162 | const char *path, const __u16 *pfid); |
@@ -169,6 +182,17 @@ extern struct smb_vol *cifs_get_volume_info(char *mount_data, | |||
169 | extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *); | 182 | extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *); |
170 | extern void cifs_umount(struct cifs_sb_info *); | 183 | extern void cifs_umount(struct cifs_sb_info *); |
171 | extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); | 184 | extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); |
185 | extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, | ||
186 | __u64 length, __u8 type, | ||
187 | struct cifsLockInfo **conf_lock, | ||
188 | bool rw_check); | ||
189 | extern void cifs_add_pending_open(struct cifs_fid *fid, | ||
190 | struct tcon_link *tlink, | ||
191 | struct cifs_pending_open *open); | ||
192 | extern void cifs_add_pending_open_locked(struct cifs_fid *fid, | ||
193 | struct tcon_link *tlink, | ||
194 | struct cifs_pending_open *open); | ||
195 | extern void cifs_del_pending_open(struct cifs_pending_open *open); | ||
172 | 196 | ||
173 | #if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) | 197 | #if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) |
174 | extern void cifs_dfs_release_automount_timer(void); | 198 | extern void cifs_dfs_release_automount_timer(void); |
@@ -179,6 +203,10 @@ extern void cifs_dfs_release_automount_timer(void); | |||
179 | void cifs_proc_init(void); | 203 | void cifs_proc_init(void); |
180 | void cifs_proc_clean(void); | 204 | void cifs_proc_clean(void); |
181 | 205 | ||
206 | extern void cifs_move_llist(struct list_head *source, struct list_head *dest); | ||
207 | extern void cifs_free_llist(struct list_head *llist); | ||
208 | extern void cifs_del_lock_waiters(struct cifsLockInfo *lock); | ||
209 | |||
182 | extern int cifs_negotiate_protocol(const unsigned int xid, | 210 | extern int cifs_negotiate_protocol(const unsigned int xid, |
183 | struct cifs_ses *ses); | 211 | struct cifs_ses *ses); |
184 | extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, | 212 | extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, |
@@ -190,10 +218,10 @@ extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses, | |||
190 | const struct nls_table *); | 218 | const struct nls_table *); |
191 | 219 | ||
192 | extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | 220 | extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
193 | const char *searchName, const struct nls_table *nls_codepage, | 221 | const char *searchName, struct cifs_sb_info *cifs_sb, |
194 | __u16 *searchHandle, __u16 search_flags, | 222 | __u16 *searchHandle, __u16 search_flags, |
195 | struct cifs_search_info *psrch_inf, | 223 | struct cifs_search_info *psrch_inf, |
196 | int map, const char dirsep); | 224 | bool msearch); |
197 | 225 | ||
198 | extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, | 226 | extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, |
199 | __u16 searchHandle, __u16 search_flags, | 227 | __u16 searchHandle, __u16 search_flags, |
@@ -265,13 +293,11 @@ extern int CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, | |||
265 | const struct nls_table *nls_codepage); | 293 | const struct nls_table *nls_codepage); |
266 | #endif /* possibly unneeded function */ | 294 | #endif /* possibly unneeded function */ |
267 | extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | 295 | extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
268 | const char *fileName, __u64 size, | 296 | const char *file_name, __u64 size, |
269 | bool setAllocationSizeFlag, | 297 | struct cifs_sb_info *cifs_sb, bool set_allocation); |
270 | const struct nls_table *nls_codepage, | ||
271 | int remap_special_chars); | ||
272 | extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, | 298 | extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
273 | __u64 size, __u16 fileHandle, __u32 opener_pid, | 299 | struct cifsFileInfo *cfile, __u64 size, |
274 | bool AllocSizeFlag); | 300 | bool set_allocation); |
275 | 301 | ||
276 | struct cifs_unix_set_info_args { | 302 | struct cifs_unix_set_info_args { |
277 | __u64 ctime; | 303 | __u64 ctime; |
@@ -303,22 +329,17 @@ extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, | |||
303 | const struct nls_table *nls_codepage, | 329 | const struct nls_table *nls_codepage, |
304 | int remap_special_chars); | 330 | int remap_special_chars); |
305 | extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, | 331 | extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, |
306 | const char *name, | 332 | const char *name, struct cifs_sb_info *cifs_sb); |
307 | const struct nls_table *nls_codepage, | ||
308 | int remap_special_chars); | ||
309 | extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | 333 | extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
310 | const char *fromName, const char *toName, | 334 | const char *from_name, const char *to_name, |
311 | const struct nls_table *nls_codepage, | 335 | struct cifs_sb_info *cifs_sb); |
312 | int remap_special_chars); | ||
313 | extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, | 336 | extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, |
314 | int netfid, const char *target_name, | 337 | int netfid, const char *target_name, |
315 | const struct nls_table *nls_codepage, | 338 | const struct nls_table *nls_codepage, |
316 | int remap_special_chars); | 339 | int remap_special_chars); |
317 | extern int CIFSCreateHardLink(const unsigned int xid, | 340 | extern int CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
318 | struct cifs_tcon *tcon, | 341 | const char *from_name, const char *to_name, |
319 | const char *fromName, const char *toName, | 342 | struct cifs_sb_info *cifs_sb); |
320 | const struct nls_table *nls_codepage, | ||
321 | int remap_special_chars); | ||
322 | extern int CIFSUnixCreateHardLink(const unsigned int xid, | 343 | extern int CIFSUnixCreateHardLink(const unsigned int xid, |
323 | struct cifs_tcon *tcon, | 344 | struct cifs_tcon *tcon, |
324 | const char *fromName, const char *toName, | 345 | const char *fromName, const char *toName, |
@@ -367,8 +388,7 @@ extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, | |||
367 | unsigned int *nbytes, const char *buf, | 388 | unsigned int *nbytes, const char *buf, |
368 | const char __user *ubuf, const int long_op); | 389 | const char __user *ubuf, const int long_op); |
369 | extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | 390 | extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
370 | unsigned int *nbytes, struct kvec *iov, const int nvec, | 391 | unsigned int *nbytes, struct kvec *iov, const int nvec); |
371 | const int long_op); | ||
372 | extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, | 392 | extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, |
373 | const char *search_name, __u64 *inode_number, | 393 | const char *search_name, __u64 *inode_number, |
374 | const struct nls_table *nls_codepage, | 394 | const struct nls_table *nls_codepage, |
@@ -397,10 +417,12 @@ extern void sesInfoFree(struct cifs_ses *); | |||
397 | extern struct cifs_tcon *tconInfoAlloc(void); | 417 | extern struct cifs_tcon *tconInfoAlloc(void); |
398 | extern void tconInfoFree(struct cifs_tcon *); | 418 | extern void tconInfoFree(struct cifs_tcon *); |
399 | 419 | ||
400 | extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); | 420 | extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, |
421 | __u32 *pexpected_response_sequence_number); | ||
401 | extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *, | 422 | extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *, |
402 | __u32 *); | 423 | __u32 *); |
403 | extern int cifs_verify_signature(struct kvec *iov, unsigned int nr_iov, | 424 | extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); |
425 | extern int cifs_verify_signature(struct smb_rqst *rqst, | ||
404 | struct TCP_Server_Info *server, | 426 | struct TCP_Server_Info *server, |
405 | __u32 expected_sequence_number); | 427 | __u32 expected_sequence_number); |
406 | extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, | 428 | extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, |
@@ -462,45 +484,9 @@ extern int E_md4hash(const unsigned char *passwd, unsigned char *p16, | |||
462 | extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8, | 484 | extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8, |
463 | unsigned char *p24); | 485 | unsigned char *p24); |
464 | 486 | ||
465 | /* asynchronous read support */ | ||
466 | struct cifs_readdata { | ||
467 | struct kref refcount; | ||
468 | struct list_head list; | ||
469 | struct completion done; | ||
470 | struct cifsFileInfo *cfile; | ||
471 | struct address_space *mapping; | ||
472 | __u64 offset; | ||
473 | unsigned int bytes; | ||
474 | pid_t pid; | ||
475 | int result; | ||
476 | struct list_head pages; | ||
477 | struct work_struct work; | ||
478 | int (*marshal_iov) (struct cifs_readdata *rdata, | ||
479 | unsigned int remaining); | ||
480 | unsigned int nr_iov; | ||
481 | struct kvec iov[1]; | ||
482 | }; | ||
483 | |||
484 | void cifs_readdata_release(struct kref *refcount); | 487 | void cifs_readdata_release(struct kref *refcount); |
485 | int cifs_async_readv(struct cifs_readdata *rdata); | 488 | int cifs_async_readv(struct cifs_readdata *rdata); |
486 | 489 | int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); | |
487 | /* asynchronous write support */ | ||
488 | struct cifs_writedata { | ||
489 | struct kref refcount; | ||
490 | struct list_head list; | ||
491 | struct completion done; | ||
492 | enum writeback_sync_modes sync_mode; | ||
493 | struct work_struct work; | ||
494 | struct cifsFileInfo *cfile; | ||
495 | __u64 offset; | ||
496 | pid_t pid; | ||
497 | unsigned int bytes; | ||
498 | int result; | ||
499 | void (*marshal_iov) (struct kvec *iov, | ||
500 | struct cifs_writedata *wdata); | ||
501 | unsigned int nr_pages; | ||
502 | struct page *pages[1]; | ||
503 | }; | ||
504 | 490 | ||
505 | int cifs_async_writev(struct cifs_writedata *wdata); | 491 | int cifs_async_writev(struct cifs_writedata *wdata); |
506 | void cifs_writev_complete(struct work_struct *work); | 492 | void cifs_writev_complete(struct work_struct *work); |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index f0cf934ba877..76d0d2998850 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -86,32 +86,6 @@ static struct { | |||
86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ | 86 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
87 | #endif /* CIFS_POSIX */ | 87 | #endif /* CIFS_POSIX */ |
88 | 88 | ||
89 | #ifdef CONFIG_HIGHMEM | ||
90 | /* | ||
91 | * On arches that have high memory, kmap address space is limited. By | ||
92 | * serializing the kmap operations on those arches, we ensure that we don't | ||
93 | * end up with a bunch of threads in writeback with partially mapped page | ||
94 | * arrays, stuck waiting for kmap to come back. That situation prevents | ||
95 | * progress and can deadlock. | ||
96 | */ | ||
97 | static DEFINE_MUTEX(cifs_kmap_mutex); | ||
98 | |||
99 | static inline void | ||
100 | cifs_kmap_lock(void) | ||
101 | { | ||
102 | mutex_lock(&cifs_kmap_mutex); | ||
103 | } | ||
104 | |||
105 | static inline void | ||
106 | cifs_kmap_unlock(void) | ||
107 | { | ||
108 | mutex_unlock(&cifs_kmap_mutex); | ||
109 | } | ||
110 | #else /* !CONFIG_HIGHMEM */ | ||
111 | #define cifs_kmap_lock() do { ; } while(0) | ||
112 | #define cifs_kmap_unlock() do { ; } while(0) | ||
113 | #endif /* CONFIG_HIGHMEM */ | ||
114 | |||
115 | /* | 89 | /* |
116 | * Mark as invalid, all open files on tree connections since they | 90 | * Mark as invalid, all open files on tree connections since they |
117 | * were closed when session to server was lost. | 91 | * were closed when session to server was lost. |
@@ -751,6 +725,8 @@ CIFSSMBEcho(struct TCP_Server_Info *server) | |||
751 | ECHO_REQ *smb; | 725 | ECHO_REQ *smb; |
752 | int rc = 0; | 726 | int rc = 0; |
753 | struct kvec iov; | 727 | struct kvec iov; |
728 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
729 | .rq_nvec = 1 }; | ||
754 | 730 | ||
755 | cFYI(1, "In echo request"); | 731 | cFYI(1, "In echo request"); |
756 | 732 | ||
@@ -768,7 +744,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) | |||
768 | iov.iov_base = smb; | 744 | iov.iov_base = smb; |
769 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; | 745 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
770 | 746 | ||
771 | rc = cifs_call_async(server, &iov, 1, NULL, cifs_echo_callback, | 747 | rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, |
772 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); | 748 | server, CIFS_ASYNC_OP | CIFS_ECHO_OP); |
773 | if (rc) | 749 | if (rc) |
774 | cFYI(1, "Echo request failed: %d", rc); | 750 | cFYI(1, "Echo request failed: %d", rc); |
@@ -902,15 +878,15 @@ PsxDelete: | |||
902 | } | 878 | } |
903 | 879 | ||
904 | int | 880 | int |
905 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, | 881 | CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
906 | const char *fileName, const struct nls_table *nls_codepage, | 882 | struct cifs_sb_info *cifs_sb) |
907 | int remap) | ||
908 | { | 883 | { |
909 | DELETE_FILE_REQ *pSMB = NULL; | 884 | DELETE_FILE_REQ *pSMB = NULL; |
910 | DELETE_FILE_RSP *pSMBr = NULL; | 885 | DELETE_FILE_RSP *pSMBr = NULL; |
911 | int rc = 0; | 886 | int rc = 0; |
912 | int bytes_returned; | 887 | int bytes_returned; |
913 | int name_len; | 888 | int name_len; |
889 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
914 | 890 | ||
915 | DelFileRetry: | 891 | DelFileRetry: |
916 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, | 892 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
@@ -919,15 +895,15 @@ DelFileRetry: | |||
919 | return rc; | 895 | return rc; |
920 | 896 | ||
921 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 897 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
922 | name_len = | 898 | name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, |
923 | cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName, | 899 | PATH_MAX, cifs_sb->local_nls, |
924 | PATH_MAX, nls_codepage, remap); | 900 | remap); |
925 | name_len++; /* trailing null */ | 901 | name_len++; /* trailing null */ |
926 | name_len *= 2; | 902 | name_len *= 2; |
927 | } else { /* BB improve check for buffer overruns BB */ | 903 | } else { /* BB improve check for buffer overruns BB */ |
928 | name_len = strnlen(fileName, PATH_MAX); | 904 | name_len = strnlen(name, PATH_MAX); |
929 | name_len++; /* trailing null */ | 905 | name_len++; /* trailing null */ |
930 | strncpy(pSMB->fileName, fileName, name_len); | 906 | strncpy(pSMB->fileName, name, name_len); |
931 | } | 907 | } |
932 | pSMB->SearchAttributes = | 908 | pSMB->SearchAttributes = |
933 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); | 909 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
@@ -1440,7 +1416,7 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1440 | return 0; | 1416 | return 0; |
1441 | } | 1417 | } |
1442 | 1418 | ||
1443 | static int | 1419 | int |
1444 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | 1420 | cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) |
1445 | { | 1421 | { |
1446 | int length, len; | 1422 | int length, len; |
@@ -1460,10 +1436,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1460 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - | 1436 | len = min_t(unsigned int, buflen, server->vals->read_rsp_size) - |
1461 | HEADER_SIZE(server) + 1; | 1437 | HEADER_SIZE(server) + 1; |
1462 | 1438 | ||
1463 | rdata->iov[0].iov_base = buf + HEADER_SIZE(server) - 1; | 1439 | rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1; |
1464 | rdata->iov[0].iov_len = len; | 1440 | rdata->iov.iov_len = len; |
1465 | 1441 | ||
1466 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); | 1442 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
1467 | if (length < 0) | 1443 | if (length < 0) |
1468 | return length; | 1444 | return length; |
1469 | server->total_read += length; | 1445 | server->total_read += length; |
@@ -1509,19 +1485,19 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1509 | len = data_offset - server->total_read; | 1485 | len = data_offset - server->total_read; |
1510 | if (len > 0) { | 1486 | if (len > 0) { |
1511 | /* read any junk before data into the rest of smallbuf */ | 1487 | /* read any junk before data into the rest of smallbuf */ |
1512 | rdata->iov[0].iov_base = buf + server->total_read; | 1488 | rdata->iov.iov_base = buf + server->total_read; |
1513 | rdata->iov[0].iov_len = len; | 1489 | rdata->iov.iov_len = len; |
1514 | length = cifs_readv_from_socket(server, rdata->iov, 1, len); | 1490 | length = cifs_readv_from_socket(server, &rdata->iov, 1, len); |
1515 | if (length < 0) | 1491 | if (length < 0) |
1516 | return length; | 1492 | return length; |
1517 | server->total_read += length; | 1493 | server->total_read += length; |
1518 | } | 1494 | } |
1519 | 1495 | ||
1520 | /* set up first iov for signature check */ | 1496 | /* set up first iov for signature check */ |
1521 | rdata->iov[0].iov_base = buf; | 1497 | rdata->iov.iov_base = buf; |
1522 | rdata->iov[0].iov_len = server->total_read; | 1498 | rdata->iov.iov_len = server->total_read; |
1523 | cFYI(1, "0: iov_base=%p iov_len=%zu", | 1499 | cFYI(1, "0: iov_base=%p iov_len=%zu", |
1524 | rdata->iov[0].iov_base, rdata->iov[0].iov_len); | 1500 | rdata->iov.iov_base, rdata->iov.iov_len); |
1525 | 1501 | ||
1526 | /* how much data is in the response? */ | 1502 | /* how much data is in the response? */ |
1527 | data_len = server->ops->read_data_length(buf); | 1503 | data_len = server->ops->read_data_length(buf); |
@@ -1531,23 +1507,11 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
1531 | return cifs_readv_discard(server, mid); | 1507 | return cifs_readv_discard(server, mid); |
1532 | } | 1508 | } |
1533 | 1509 | ||
1534 | /* marshal up the page array */ | 1510 | length = rdata->read_into_pages(server, rdata, data_len); |
1535 | cifs_kmap_lock(); | 1511 | if (length < 0) |
1536 | len = rdata->marshal_iov(rdata, data_len); | 1512 | return length; |
1537 | cifs_kmap_unlock(); | ||
1538 | data_len -= len; | ||
1539 | |||
1540 | /* issue the read if we have any iovecs left to fill */ | ||
1541 | if (rdata->nr_iov > 1) { | ||
1542 | length = cifs_readv_from_socket(server, &rdata->iov[1], | ||
1543 | rdata->nr_iov - 1, len); | ||
1544 | if (length < 0) | ||
1545 | return length; | ||
1546 | server->total_read += length; | ||
1547 | } else { | ||
1548 | length = 0; | ||
1549 | } | ||
1550 | 1513 | ||
1514 | server->total_read += length; | ||
1551 | rdata->bytes = length; | 1515 | rdata->bytes = length; |
1552 | 1516 | ||
1553 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, | 1517 | cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read, |
@@ -1567,6 +1531,12 @@ cifs_readv_callback(struct mid_q_entry *mid) | |||
1567 | struct cifs_readdata *rdata = mid->callback_data; | 1531 | struct cifs_readdata *rdata = mid->callback_data; |
1568 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | 1532 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
1569 | struct TCP_Server_Info *server = tcon->ses->server; | 1533 | struct TCP_Server_Info *server = tcon->ses->server; |
1534 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1535 | .rq_nvec = 1, | ||
1536 | .rq_pages = rdata->pages, | ||
1537 | .rq_npages = rdata->nr_pages, | ||
1538 | .rq_pagesz = rdata->pagesz, | ||
1539 | .rq_tailsz = rdata->tailsz }; | ||
1570 | 1540 | ||
1571 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, | 1541 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, |
1572 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); | 1542 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); |
@@ -1578,9 +1548,8 @@ cifs_readv_callback(struct mid_q_entry *mid) | |||
1578 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | 1548 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
1579 | int rc = 0; | 1549 | int rc = 0; |
1580 | 1550 | ||
1581 | rc = cifs_verify_signature(rdata->iov, rdata->nr_iov, | 1551 | rc = cifs_verify_signature(&rqst, server, |
1582 | server, | 1552 | mid->sequence_number + 1); |
1583 | mid->sequence_number + 1); | ||
1584 | if (rc) | 1553 | if (rc) |
1585 | cERROR(1, "SMB signature verification returned " | 1554 | cERROR(1, "SMB signature verification returned " |
1586 | "error = %d", rc); | 1555 | "error = %d", rc); |
@@ -1610,6 +1579,8 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1610 | READ_REQ *smb = NULL; | 1579 | READ_REQ *smb = NULL; |
1611 | int wct; | 1580 | int wct; |
1612 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | 1581 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); |
1582 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1583 | .rq_nvec = 1 }; | ||
1613 | 1584 | ||
1614 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, | 1585 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, |
1615 | rdata->offset, rdata->bytes); | 1586 | rdata->offset, rdata->bytes); |
@@ -1632,7 +1603,7 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1632 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); | 1603 | smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16)); |
1633 | 1604 | ||
1634 | smb->AndXCommand = 0xFF; /* none */ | 1605 | smb->AndXCommand = 0xFF; /* none */ |
1635 | smb->Fid = rdata->cfile->netfid; | 1606 | smb->Fid = rdata->cfile->fid.netfid; |
1636 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); | 1607 | smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF); |
1637 | if (wct == 12) | 1608 | if (wct == 12) |
1638 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); | 1609 | smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32); |
@@ -1649,13 +1620,12 @@ cifs_async_readv(struct cifs_readdata *rdata) | |||
1649 | } | 1620 | } |
1650 | 1621 | ||
1651 | /* 4 for RFC1001 length + 1 for BCC */ | 1622 | /* 4 for RFC1001 length + 1 for BCC */ |
1652 | rdata->iov[0].iov_base = smb; | 1623 | rdata->iov.iov_base = smb; |
1653 | rdata->iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; | 1624 | rdata->iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
1654 | 1625 | ||
1655 | kref_get(&rdata->refcount); | 1626 | kref_get(&rdata->refcount); |
1656 | rc = cifs_call_async(tcon->ses->server, rdata->iov, 1, | 1627 | rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive, |
1657 | cifs_readv_receive, cifs_readv_callback, | 1628 | cifs_readv_callback, rdata, 0); |
1658 | rdata, 0); | ||
1659 | 1629 | ||
1660 | if (rc == 0) | 1630 | if (rc == 0) |
1661 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); | 1631 | cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); |
@@ -1926,6 +1896,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata) | |||
1926 | { | 1896 | { |
1927 | int i, rc; | 1897 | int i, rc; |
1928 | struct inode *inode = wdata->cfile->dentry->d_inode; | 1898 | struct inode *inode = wdata->cfile->dentry->d_inode; |
1899 | struct TCP_Server_Info *server; | ||
1929 | 1900 | ||
1930 | for (i = 0; i < wdata->nr_pages; i++) { | 1901 | for (i = 0; i < wdata->nr_pages; i++) { |
1931 | lock_page(wdata->pages[i]); | 1902 | lock_page(wdata->pages[i]); |
@@ -1933,7 +1904,8 @@ cifs_writev_requeue(struct cifs_writedata *wdata) | |||
1933 | } | 1904 | } |
1934 | 1905 | ||
1935 | do { | 1906 | do { |
1936 | rc = cifs_async_writev(wdata); | 1907 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
1908 | rc = server->ops->async_writev(wdata); | ||
1937 | } while (rc == -EAGAIN); | 1909 | } while (rc == -EAGAIN); |
1938 | 1910 | ||
1939 | for (i = 0; i < wdata->nr_pages; i++) { | 1911 | for (i = 0; i < wdata->nr_pages; i++) { |
@@ -2053,11 +2025,12 @@ cifs_writev_callback(struct mid_q_entry *mid) | |||
2053 | int | 2025 | int |
2054 | cifs_async_writev(struct cifs_writedata *wdata) | 2026 | cifs_async_writev(struct cifs_writedata *wdata) |
2055 | { | 2027 | { |
2056 | int i, rc = -EACCES; | 2028 | int rc = -EACCES; |
2057 | WRITE_REQ *smb = NULL; | 2029 | WRITE_REQ *smb = NULL; |
2058 | int wct; | 2030 | int wct; |
2059 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | 2031 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); |
2060 | struct kvec *iov = NULL; | 2032 | struct kvec iov; |
2033 | struct smb_rqst rqst = { }; | ||
2061 | 2034 | ||
2062 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { | 2035 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
2063 | wct = 14; | 2036 | wct = 14; |
@@ -2073,18 +2046,11 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2073 | if (rc) | 2046 | if (rc) |
2074 | goto async_writev_out; | 2047 | goto async_writev_out; |
2075 | 2048 | ||
2076 | /* 1 iov per page + 1 for header */ | ||
2077 | iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS); | ||
2078 | if (iov == NULL) { | ||
2079 | rc = -ENOMEM; | ||
2080 | goto async_writev_out; | ||
2081 | } | ||
2082 | |||
2083 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); | 2049 | smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); |
2084 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); | 2050 | smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); |
2085 | 2051 | ||
2086 | smb->AndXCommand = 0xFF; /* none */ | 2052 | smb->AndXCommand = 0xFF; /* none */ |
2087 | smb->Fid = wdata->cfile->netfid; | 2053 | smb->Fid = wdata->cfile->fid.netfid; |
2088 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); | 2054 | smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); |
2089 | if (wct == 14) | 2055 | if (wct == 14) |
2090 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); | 2056 | smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); |
@@ -2096,18 +2062,15 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2096 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); | 2062 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
2097 | 2063 | ||
2098 | /* 4 for RFC1001 length + 1 for BCC */ | 2064 | /* 4 for RFC1001 length + 1 for BCC */ |
2099 | iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; | 2065 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; |
2100 | iov[0].iov_base = smb; | 2066 | iov.iov_base = smb; |
2101 | 2067 | ||
2102 | /* | 2068 | rqst.rq_iov = &iov; |
2103 | * This function should marshal up the page array into the kvec | 2069 | rqst.rq_nvec = 1; |
2104 | * array, reserving [0] for the header. It should kmap the pages | 2070 | rqst.rq_pages = wdata->pages; |
2105 | * and set the iov_len properly for each one. It may also set | 2071 | rqst.rq_npages = wdata->nr_pages; |
2106 | * wdata->bytes too. | 2072 | rqst.rq_pagesz = wdata->pagesz; |
2107 | */ | 2073 | rqst.rq_tailsz = wdata->tailsz; |
2108 | cifs_kmap_lock(); | ||
2109 | wdata->marshal_iov(iov, wdata); | ||
2110 | cifs_kmap_unlock(); | ||
2111 | 2074 | ||
2112 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); | 2075 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); |
2113 | 2076 | ||
@@ -2123,32 +2086,26 @@ cifs_async_writev(struct cifs_writedata *wdata) | |||
2123 | (struct smb_com_writex_req *)smb; | 2086 | (struct smb_com_writex_req *)smb; |
2124 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); | 2087 | inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); |
2125 | put_bcc(wdata->bytes + 5, &smbw->hdr); | 2088 | put_bcc(wdata->bytes + 5, &smbw->hdr); |
2126 | iov[0].iov_len += 4; /* pad bigger by four bytes */ | 2089 | iov.iov_len += 4; /* pad bigger by four bytes */ |
2127 | } | 2090 | } |
2128 | 2091 | ||
2129 | kref_get(&wdata->refcount); | 2092 | kref_get(&wdata->refcount); |
2130 | rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1, | 2093 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, |
2131 | NULL, cifs_writev_callback, wdata, 0); | 2094 | cifs_writev_callback, wdata, 0); |
2132 | 2095 | ||
2133 | if (rc == 0) | 2096 | if (rc == 0) |
2134 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); | 2097 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
2135 | else | 2098 | else |
2136 | kref_put(&wdata->refcount, cifs_writedata_release); | 2099 | kref_put(&wdata->refcount, cifs_writedata_release); |
2137 | 2100 | ||
2138 | /* send is done, unmap pages */ | ||
2139 | for (i = 0; i < wdata->nr_pages; i++) | ||
2140 | kunmap(wdata->pages[i]); | ||
2141 | |||
2142 | async_writev_out: | 2101 | async_writev_out: |
2143 | cifs_small_buf_release(smb); | 2102 | cifs_small_buf_release(smb); |
2144 | kfree(iov); | ||
2145 | return rc; | 2103 | return rc; |
2146 | } | 2104 | } |
2147 | 2105 | ||
2148 | int | 2106 | int |
2149 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | 2107 | CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, |
2150 | unsigned int *nbytes, struct kvec *iov, int n_vec, | 2108 | unsigned int *nbytes, struct kvec *iov, int n_vec) |
2151 | const int long_op) | ||
2152 | { | 2109 | { |
2153 | int rc = -EACCES; | 2110 | int rc = -EACCES; |
2154 | WRITE_REQ *pSMB = NULL; | 2111 | WRITE_REQ *pSMB = NULL; |
@@ -2219,8 +2176,7 @@ CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, | |||
2219 | iov[0].iov_len = smb_hdr_len + 8; | 2176 | iov[0].iov_len = smb_hdr_len + 8; |
2220 | 2177 | ||
2221 | 2178 | ||
2222 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, | 2179 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0); |
2223 | long_op); | ||
2224 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); | 2180 | cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); |
2225 | if (rc) { | 2181 | if (rc) { |
2226 | cFYI(1, "Send error Write2 = %d", rc); | 2182 | cFYI(1, "Send error Write2 = %d", rc); |
@@ -2557,8 +2513,8 @@ CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) | |||
2557 | 2513 | ||
2558 | int | 2514 | int |
2559 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | 2515 | CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, |
2560 | const char *fromName, const char *toName, | 2516 | const char *from_name, const char *to_name, |
2561 | const struct nls_table *nls_codepage, int remap) | 2517 | struct cifs_sb_info *cifs_sb) |
2562 | { | 2518 | { |
2563 | int rc = 0; | 2519 | int rc = 0; |
2564 | RENAME_REQ *pSMB = NULL; | 2520 | RENAME_REQ *pSMB = NULL; |
@@ -2566,6 +2522,7 @@ CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, | |||
2566 | int bytes_returned; | 2522 | int bytes_returned; |
2567 | int name_len, name_len2; | 2523 | int name_len, name_len2; |
2568 | __u16 count; | 2524 | __u16 count; |
2525 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
2569 | 2526 | ||
2570 | cFYI(1, "In CIFSSMBRename"); | 2527 | cFYI(1, "In CIFSSMBRename"); |
2571 | renameRetry: | 2528 | renameRetry: |
@@ -2580,9 +2537,9 @@ renameRetry: | |||
2580 | ATTR_DIRECTORY); | 2537 | ATTR_DIRECTORY); |
2581 | 2538 | ||
2582 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2539 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2583 | name_len = | 2540 | name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, |
2584 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, | 2541 | from_name, PATH_MAX, |
2585 | PATH_MAX, nls_codepage, remap); | 2542 | cifs_sb->local_nls, remap); |
2586 | name_len++; /* trailing null */ | 2543 | name_len++; /* trailing null */ |
2587 | name_len *= 2; | 2544 | name_len *= 2; |
2588 | pSMB->OldFileName[name_len] = 0x04; /* pad */ | 2545 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
@@ -2590,17 +2547,18 @@ renameRetry: | |||
2590 | pSMB->OldFileName[name_len + 1] = 0x00; | 2547 | pSMB->OldFileName[name_len + 1] = 0x00; |
2591 | name_len2 = | 2548 | name_len2 = |
2592 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], | 2549 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
2593 | toName, PATH_MAX, nls_codepage, remap); | 2550 | to_name, PATH_MAX, cifs_sb->local_nls, |
2551 | remap); | ||
2594 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2552 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2595 | name_len2 *= 2; /* convert to bytes */ | 2553 | name_len2 *= 2; /* convert to bytes */ |
2596 | } else { /* BB improve the check for buffer overruns BB */ | 2554 | } else { /* BB improve the check for buffer overruns BB */ |
2597 | name_len = strnlen(fromName, PATH_MAX); | 2555 | name_len = strnlen(from_name, PATH_MAX); |
2598 | name_len++; /* trailing null */ | 2556 | name_len++; /* trailing null */ |
2599 | strncpy(pSMB->OldFileName, fromName, name_len); | 2557 | strncpy(pSMB->OldFileName, from_name, name_len); |
2600 | name_len2 = strnlen(toName, PATH_MAX); | 2558 | name_len2 = strnlen(to_name, PATH_MAX); |
2601 | name_len2++; /* trailing null */ | 2559 | name_len2++; /* trailing null */ |
2602 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ | 2560 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
2603 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); | 2561 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
2604 | name_len2++; /* trailing null */ | 2562 | name_len2++; /* trailing null */ |
2605 | name_len2++; /* signature byte */ | 2563 | name_len2++; /* signature byte */ |
2606 | } | 2564 | } |
@@ -2948,8 +2906,8 @@ createHardLinkRetry: | |||
2948 | 2906 | ||
2949 | int | 2907 | int |
2950 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, | 2908 | CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, |
2951 | const char *fromName, const char *toName, | 2909 | const char *from_name, const char *to_name, |
2952 | const struct nls_table *nls_codepage, int remap) | 2910 | struct cifs_sb_info *cifs_sb) |
2953 | { | 2911 | { |
2954 | int rc = 0; | 2912 | int rc = 0; |
2955 | NT_RENAME_REQ *pSMB = NULL; | 2913 | NT_RENAME_REQ *pSMB = NULL; |
@@ -2957,6 +2915,7 @@ CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, | |||
2957 | int bytes_returned; | 2915 | int bytes_returned; |
2958 | int name_len, name_len2; | 2916 | int name_len, name_len2; |
2959 | __u16 count; | 2917 | __u16 count; |
2918 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
2960 | 2919 | ||
2961 | cFYI(1, "In CIFSCreateHardLink"); | 2920 | cFYI(1, "In CIFSCreateHardLink"); |
2962 | winCreateHardLinkRetry: | 2921 | winCreateHardLinkRetry: |
@@ -2976,8 +2935,8 @@ winCreateHardLinkRetry: | |||
2976 | 2935 | ||
2977 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2936 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2978 | name_len = | 2937 | name_len = |
2979 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName, | 2938 | cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, |
2980 | PATH_MAX, nls_codepage, remap); | 2939 | PATH_MAX, cifs_sb->local_nls, remap); |
2981 | name_len++; /* trailing null */ | 2940 | name_len++; /* trailing null */ |
2982 | name_len *= 2; | 2941 | name_len *= 2; |
2983 | 2942 | ||
@@ -2986,17 +2945,18 @@ winCreateHardLinkRetry: | |||
2986 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ | 2945 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
2987 | name_len2 = | 2946 | name_len2 = |
2988 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], | 2947 | cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], |
2989 | toName, PATH_MAX, nls_codepage, remap); | 2948 | to_name, PATH_MAX, cifs_sb->local_nls, |
2949 | remap); | ||
2990 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2950 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2991 | name_len2 *= 2; /* convert to bytes */ | 2951 | name_len2 *= 2; /* convert to bytes */ |
2992 | } else { /* BB improve the check for buffer overruns BB */ | 2952 | } else { /* BB improve the check for buffer overruns BB */ |
2993 | name_len = strnlen(fromName, PATH_MAX); | 2953 | name_len = strnlen(from_name, PATH_MAX); |
2994 | name_len++; /* trailing null */ | 2954 | name_len++; /* trailing null */ |
2995 | strncpy(pSMB->OldFileName, fromName, name_len); | 2955 | strncpy(pSMB->OldFileName, from_name, name_len); |
2996 | name_len2 = strnlen(toName, PATH_MAX); | 2956 | name_len2 = strnlen(to_name, PATH_MAX); |
2997 | name_len2++; /* trailing null */ | 2957 | name_len2++; /* trailing null */ |
2998 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ | 2958 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
2999 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); | 2959 | strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); |
3000 | name_len2++; /* trailing null */ | 2960 | name_len2++; /* trailing null */ |
3001 | name_len2++; /* signature byte */ | 2961 | name_len2++; /* signature byte */ |
3002 | } | 2962 | } |
@@ -4254,10 +4214,9 @@ UnixQPathInfoRetry: | |||
4254 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ | 4214 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
4255 | int | 4215 | int |
4256 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | 4216 | CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, |
4257 | const char *searchName, | 4217 | const char *searchName, struct cifs_sb_info *cifs_sb, |
4258 | const struct nls_table *nls_codepage, | ||
4259 | __u16 *pnetfid, __u16 search_flags, | 4218 | __u16 *pnetfid, __u16 search_flags, |
4260 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) | 4219 | struct cifs_search_info *psrch_inf, bool msearch) |
4261 | { | 4220 | { |
4262 | /* level 257 SMB_ */ | 4221 | /* level 257 SMB_ */ |
4263 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; | 4222 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
@@ -4265,8 +4224,9 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, | |||
4265 | T2_FFIRST_RSP_PARMS *parms; | 4224 | T2_FFIRST_RSP_PARMS *parms; |
4266 | int rc = 0; | 4225 | int rc = 0; |
4267 | int bytes_returned = 0; | 4226 | int bytes_returned = 0; |
4268 | int name_len; | 4227 | int name_len, remap; |
4269 | __u16 params, byte_count; | 4228 | __u16 params, byte_count; |
4229 | struct nls_table *nls_codepage; | ||
4270 | 4230 | ||
4271 | cFYI(1, "In FindFirst for %s", searchName); | 4231 | cFYI(1, "In FindFirst for %s", searchName); |
4272 | 4232 | ||
@@ -4276,6 +4236,9 @@ findFirstRetry: | |||
4276 | if (rc) | 4236 | if (rc) |
4277 | return rc; | 4237 | return rc; |
4278 | 4238 | ||
4239 | nls_codepage = cifs_sb->local_nls; | ||
4240 | remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
4241 | |||
4279 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 4242 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
4280 | name_len = | 4243 | name_len = |
4281 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, | 4244 | cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, |
@@ -4284,24 +4247,29 @@ findFirstRetry: | |||
4284 | it got remapped to 0xF03A as if it were part of the | 4247 | it got remapped to 0xF03A as if it were part of the |
4285 | directory name instead of a wildcard */ | 4248 | directory name instead of a wildcard */ |
4286 | name_len *= 2; | 4249 | name_len *= 2; |
4287 | pSMB->FileName[name_len] = dirsep; | 4250 | if (msearch) { |
4288 | pSMB->FileName[name_len+1] = 0; | 4251 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
4289 | pSMB->FileName[name_len+2] = '*'; | 4252 | pSMB->FileName[name_len+1] = 0; |
4290 | pSMB->FileName[name_len+3] = 0; | 4253 | pSMB->FileName[name_len+2] = '*'; |
4291 | name_len += 4; /* now the trailing null */ | 4254 | pSMB->FileName[name_len+3] = 0; |
4292 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ | 4255 | name_len += 4; /* now the trailing null */ |
4293 | pSMB->FileName[name_len+1] = 0; | 4256 | /* null terminate just in case */ |
4294 | name_len += 2; | 4257 | pSMB->FileName[name_len] = 0; |
4258 | pSMB->FileName[name_len+1] = 0; | ||
4259 | name_len += 2; | ||
4260 | } | ||
4295 | } else { /* BB add check for overrun of SMB buf BB */ | 4261 | } else { /* BB add check for overrun of SMB buf BB */ |
4296 | name_len = strnlen(searchName, PATH_MAX); | 4262 | name_len = strnlen(searchName, PATH_MAX); |
4297 | /* BB fix here and in unicode clause above ie | 4263 | /* BB fix here and in unicode clause above ie |
4298 | if (name_len > buffersize-header) | 4264 | if (name_len > buffersize-header) |
4299 | free buffer exit; BB */ | 4265 | free buffer exit; BB */ |
4300 | strncpy(pSMB->FileName, searchName, name_len); | 4266 | strncpy(pSMB->FileName, searchName, name_len); |
4301 | pSMB->FileName[name_len] = dirsep; | 4267 | if (msearch) { |
4302 | pSMB->FileName[name_len+1] = '*'; | 4268 | pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); |
4303 | pSMB->FileName[name_len+2] = 0; | 4269 | pSMB->FileName[name_len+1] = '*'; |
4304 | name_len += 3; | 4270 | pSMB->FileName[name_len+2] = 0; |
4271 | name_len += 3; | ||
4272 | } | ||
4305 | } | 4273 | } |
4306 | 4274 | ||
4307 | params = 12 + name_len /* includes null */ ; | 4275 | params = 12 + name_len /* includes null */ ; |
@@ -4389,7 +4357,8 @@ findFirstRetry: | |||
4389 | psrch_inf->last_entry = psrch_inf->srch_entries_start + | 4357 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
4390 | lnoff; | 4358 | lnoff; |
4391 | 4359 | ||
4392 | *pnetfid = parms->SearchHandle; | 4360 | if (pnetfid) |
4361 | *pnetfid = parms->SearchHandle; | ||
4393 | } else { | 4362 | } else { |
4394 | cifs_buf_release(pSMB); | 4363 | cifs_buf_release(pSMB); |
4395 | } | 4364 | } |
@@ -5417,16 +5386,16 @@ QFSPosixRetry: | |||
5417 | } | 5386 | } |
5418 | 5387 | ||
5419 | 5388 | ||
5420 | /* We can not use write of zero bytes trick to | 5389 | /* |
5421 | set file size due to need for large file support. Also note that | 5390 | * We can not use write of zero bytes trick to set file size due to need for |
5422 | this SetPathInfo is preferred to SetFileInfo based method in next | 5391 | * large file support. Also note that this SetPathInfo is preferred to |
5423 | routine which is only needed to work around a sharing violation bug | 5392 | * SetFileInfo based method in next routine which is only needed to work around |
5424 | in Samba which this routine can run into */ | 5393 | * a sharing violation bugin Samba which this routine can run into. |
5425 | 5394 | */ | |
5426 | int | 5395 | int |
5427 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | 5396 | CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, |
5428 | const char *fileName, __u64 size, bool SetAllocation, | 5397 | const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, |
5429 | const struct nls_table *nls_codepage, int remap) | 5398 | bool set_allocation) |
5430 | { | 5399 | { |
5431 | struct smb_com_transaction2_spi_req *pSMB = NULL; | 5400 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
5432 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; | 5401 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
@@ -5434,6 +5403,8 @@ CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, | |||
5434 | int name_len; | 5403 | int name_len; |
5435 | int rc = 0; | 5404 | int rc = 0; |
5436 | int bytes_returned = 0; | 5405 | int bytes_returned = 0; |
5406 | int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR; | ||
5407 | |||
5437 | __u16 params, byte_count, data_count, param_offset, offset; | 5408 | __u16 params, byte_count, data_count, param_offset, offset; |
5438 | 5409 | ||
5439 | cFYI(1, "In SetEOF"); | 5410 | cFYI(1, "In SetEOF"); |
@@ -5445,14 +5416,14 @@ SetEOFRetry: | |||
5445 | 5416 | ||
5446 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5417 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5447 | name_len = | 5418 | name_len = |
5448 | cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, | 5419 | cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, |
5449 | PATH_MAX, nls_codepage, remap); | 5420 | PATH_MAX, cifs_sb->local_nls, remap); |
5450 | name_len++; /* trailing null */ | 5421 | name_len++; /* trailing null */ |
5451 | name_len *= 2; | 5422 | name_len *= 2; |
5452 | } else { /* BB improve the check for buffer overruns BB */ | 5423 | } else { /* BB improve the check for buffer overruns BB */ |
5453 | name_len = strnlen(fileName, PATH_MAX); | 5424 | name_len = strnlen(file_name, PATH_MAX); |
5454 | name_len++; /* trailing null */ | 5425 | name_len++; /* trailing null */ |
5455 | strncpy(pSMB->FileName, fileName, name_len); | 5426 | strncpy(pSMB->FileName, file_name, name_len); |
5456 | } | 5427 | } |
5457 | params = 6 + name_len; | 5428 | params = 6 + name_len; |
5458 | data_count = sizeof(struct file_end_of_file_info); | 5429 | data_count = sizeof(struct file_end_of_file_info); |
@@ -5466,7 +5437,7 @@ SetEOFRetry: | |||
5466 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 5437 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
5467 | InformationLevel) - 4; | 5438 | InformationLevel) - 4; |
5468 | offset = param_offset + params; | 5439 | offset = param_offset + params; |
5469 | if (SetAllocation) { | 5440 | if (set_allocation) { |
5470 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 5441 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
5471 | pSMB->InformationLevel = | 5442 | pSMB->InformationLevel = |
5472 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 5443 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
@@ -5513,8 +5484,8 @@ SetEOFRetry: | |||
5513 | } | 5484 | } |
5514 | 5485 | ||
5515 | int | 5486 | int |
5516 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | 5487 | CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, |
5517 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) | 5488 | struct cifsFileInfo *cfile, __u64 size, bool set_allocation) |
5518 | { | 5489 | { |
5519 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 5490 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
5520 | struct file_end_of_file_info *parm_data; | 5491 | struct file_end_of_file_info *parm_data; |
@@ -5528,8 +5499,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | |||
5528 | if (rc) | 5499 | if (rc) |
5529 | return rc; | 5500 | return rc; |
5530 | 5501 | ||
5531 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); | 5502 | pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); |
5532 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); | 5503 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); |
5533 | 5504 | ||
5534 | params = 6; | 5505 | params = 6; |
5535 | pSMB->MaxSetupCount = 0; | 5506 | pSMB->MaxSetupCount = 0; |
@@ -5558,8 +5529,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, __u64 size, | |||
5558 | + offset); | 5529 | + offset); |
5559 | pSMB->DataOffset = cpu_to_le16(offset); | 5530 | pSMB->DataOffset = cpu_to_le16(offset); |
5560 | parm_data->FileSize = cpu_to_le64(size); | 5531 | parm_data->FileSize = cpu_to_le64(size); |
5561 | pSMB->Fid = fid; | 5532 | pSMB->Fid = cfile->fid.netfid; |
5562 | if (SetAllocation) { | 5533 | if (set_allocation) { |
5563 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 5534 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
5564 | pSMB->InformationLevel = | 5535 | pSMB->InformationLevel = |
5565 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 5536 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 6df6fa14cba8..2fdbe08a7a23 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -82,8 +82,7 @@ enum { | |||
82 | Opt_serverino, Opt_noserverino, | 82 | Opt_serverino, Opt_noserverino, |
83 | Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl, | 83 | Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl, |
84 | Opt_acl, Opt_noacl, Opt_locallease, | 84 | Opt_acl, Opt_noacl, Opt_locallease, |
85 | Opt_sign, Opt_seal, Opt_direct, | 85 | Opt_sign, Opt_seal, Opt_noac, |
86 | Opt_strictcache, Opt_noac, | ||
87 | Opt_fsc, Opt_mfsymlinks, | 86 | Opt_fsc, Opt_mfsymlinks, |
88 | Opt_multiuser, Opt_sloppy, | 87 | Opt_multiuser, Opt_sloppy, |
89 | 88 | ||
@@ -160,10 +159,6 @@ static const match_table_t cifs_mount_option_tokens = { | |||
160 | { Opt_locallease, "locallease" }, | 159 | { Opt_locallease, "locallease" }, |
161 | { Opt_sign, "sign" }, | 160 | { Opt_sign, "sign" }, |
162 | { Opt_seal, "seal" }, | 161 | { Opt_seal, "seal" }, |
163 | { Opt_direct, "direct" }, | ||
164 | { Opt_direct, "directio" }, | ||
165 | { Opt_direct, "forcedirectio" }, | ||
166 | { Opt_strictcache, "strictcache" }, | ||
167 | { Opt_noac, "noac" }, | 162 | { Opt_noac, "noac" }, |
168 | { Opt_fsc, "fsc" }, | 163 | { Opt_fsc, "fsc" }, |
169 | { Opt_mfsymlinks, "mfsymlinks" }, | 164 | { Opt_mfsymlinks, "mfsymlinks" }, |
@@ -277,6 +272,7 @@ static const match_table_t cifs_cacheflavor_tokens = { | |||
277 | static const match_table_t cifs_smb_version_tokens = { | 272 | static const match_table_t cifs_smb_version_tokens = { |
278 | { Smb_1, SMB1_VERSION_STRING }, | 273 | { Smb_1, SMB1_VERSION_STRING }, |
279 | { Smb_21, SMB21_VERSION_STRING }, | 274 | { Smb_21, SMB21_VERSION_STRING }, |
275 | { Smb_30, SMB30_VERSION_STRING }, | ||
280 | }; | 276 | }; |
281 | 277 | ||
282 | static int ip_connect(struct TCP_Server_Info *server); | 278 | static int ip_connect(struct TCP_Server_Info *server); |
@@ -819,6 +815,10 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
819 | cifs_dump_mem("Bad SMB: ", buf, | 815 | cifs_dump_mem("Bad SMB: ", buf, |
820 | min_t(unsigned int, server->total_read, 48)); | 816 | min_t(unsigned int, server->total_read, 48)); |
821 | 817 | ||
818 | if (server->ops->is_status_pending && | ||
819 | server->ops->is_status_pending(buf, server, length)) | ||
820 | return -1; | ||
821 | |||
822 | if (!mid) | 822 | if (!mid) |
823 | return length; | 823 | return length; |
824 | 824 | ||
@@ -1075,6 +1075,10 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol) | |||
1075 | vol->ops = &smb21_operations; | 1075 | vol->ops = &smb21_operations; |
1076 | vol->vals = &smb21_values; | 1076 | vol->vals = &smb21_values; |
1077 | break; | 1077 | break; |
1078 | case Smb_30: | ||
1079 | vol->ops = &smb21_operations; /* currently identical with 2.1 */ | ||
1080 | vol->vals = &smb30_values; | ||
1081 | break; | ||
1078 | #endif | 1082 | #endif |
1079 | default: | 1083 | default: |
1080 | cERROR(1, "Unknown vers= option specified: %s", value); | 1084 | cERROR(1, "Unknown vers= option specified: %s", value); |
@@ -1101,8 +1105,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1101 | char *string = NULL; | 1105 | char *string = NULL; |
1102 | char *tmp_end, *value; | 1106 | char *tmp_end, *value; |
1103 | char delim; | 1107 | char delim; |
1104 | bool cache_specified = false; | ||
1105 | static bool cache_warned = false; | ||
1106 | 1108 | ||
1107 | separator[0] = ','; | 1109 | separator[0] = ','; |
1108 | separator[1] = 0; | 1110 | separator[1] = 0; |
@@ -1134,6 +1136,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1134 | /* default to using server inode numbers where available */ | 1136 | /* default to using server inode numbers where available */ |
1135 | vol->server_ino = 1; | 1137 | vol->server_ino = 1; |
1136 | 1138 | ||
1139 | /* default is to use strict cifs caching semantics */ | ||
1140 | vol->strict_io = true; | ||
1141 | |||
1137 | vol->actimeo = CIFS_DEF_ACTIMEO; | 1142 | vol->actimeo = CIFS_DEF_ACTIMEO; |
1138 | 1143 | ||
1139 | /* FIXME: add autonegotiation -- for now, SMB1 is default */ | 1144 | /* FIXME: add autonegotiation -- for now, SMB1 is default */ |
@@ -1317,22 +1322,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1317 | */ | 1322 | */ |
1318 | vol->seal = 1; | 1323 | vol->seal = 1; |
1319 | break; | 1324 | break; |
1320 | case Opt_direct: | ||
1321 | cache_specified = true; | ||
1322 | vol->direct_io = true; | ||
1323 | vol->strict_io = false; | ||
1324 | cERROR(1, "The \"directio\" option will be removed in " | ||
1325 | "3.7. Please switch to the \"cache=none\" " | ||
1326 | "option."); | ||
1327 | break; | ||
1328 | case Opt_strictcache: | ||
1329 | cache_specified = true; | ||
1330 | vol->direct_io = false; | ||
1331 | vol->strict_io = true; | ||
1332 | cERROR(1, "The \"strictcache\" option will be removed " | ||
1333 | "in 3.7. Please switch to the \"cache=strict\" " | ||
1334 | "option."); | ||
1335 | break; | ||
1336 | case Opt_noac: | 1325 | case Opt_noac: |
1337 | printk(KERN_WARNING "CIFS: Mount option noac not " | 1326 | printk(KERN_WARNING "CIFS: Mount option noac not " |
1338 | "supported. Instead set " | 1327 | "supported. Instead set " |
@@ -1676,8 +1665,13 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1676 | if (string == NULL) | 1665 | if (string == NULL) |
1677 | goto out_nomem; | 1666 | goto out_nomem; |
1678 | 1667 | ||
1679 | if (strnicmp(string, "TCP_NODELAY", 11) == 0) | 1668 | if (strnicmp(string, "TCP_NODELAY", 11) == 0) { |
1669 | printk(KERN_WARNING "CIFS: the " | ||
1670 | "sockopt=TCP_NODELAY option has been " | ||
1671 | "deprecated and will be removed " | ||
1672 | "in 3.9\n"); | ||
1680 | vol->sockopt_tcp_nodelay = 1; | 1673 | vol->sockopt_tcp_nodelay = 1; |
1674 | } | ||
1681 | break; | 1675 | break; |
1682 | case Opt_netbiosname: | 1676 | case Opt_netbiosname: |
1683 | string = match_strdup(args); | 1677 | string = match_strdup(args); |
@@ -1762,7 +1756,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1762 | goto cifs_parse_mount_err; | 1756 | goto cifs_parse_mount_err; |
1763 | break; | 1757 | break; |
1764 | case Opt_cache: | 1758 | case Opt_cache: |
1765 | cache_specified = true; | ||
1766 | string = match_strdup(args); | 1759 | string = match_strdup(args); |
1767 | if (string == NULL) | 1760 | if (string == NULL) |
1768 | goto out_nomem; | 1761 | goto out_nomem; |
@@ -1813,14 +1806,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1813 | printk(KERN_NOTICE "CIFS: ignoring forcegid mount option " | 1806 | printk(KERN_NOTICE "CIFS: ignoring forcegid mount option " |
1814 | "specified with no gid= option.\n"); | 1807 | "specified with no gid= option.\n"); |
1815 | 1808 | ||
1816 | /* FIXME: remove this block in 3.7 */ | ||
1817 | if (!cache_specified && !cache_warned) { | ||
1818 | cache_warned = true; | ||
1819 | printk(KERN_NOTICE "CIFS: no cache= option specified, using " | ||
1820 | "\"cache=loose\". This default will change " | ||
1821 | "to \"cache=strict\" in 3.7.\n"); | ||
1822 | } | ||
1823 | |||
1824 | kfree(mountdata_copy); | 1809 | kfree(mountdata_copy); |
1825 | return 0; | 1810 | return 0; |
1826 | 1811 | ||
@@ -2636,6 +2621,7 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) | |||
2636 | tcon->retry = volume_info->retry; | 2621 | tcon->retry = volume_info->retry; |
2637 | tcon->nocase = volume_info->nocase; | 2622 | tcon->nocase = volume_info->nocase; |
2638 | tcon->local_lease = volume_info->local_lease; | 2623 | tcon->local_lease = volume_info->local_lease; |
2624 | INIT_LIST_HEAD(&tcon->pending_opens); | ||
2639 | 2625 | ||
2640 | spin_lock(&cifs_tcp_ses_lock); | 2626 | spin_lock(&cifs_tcp_ses_lock); |
2641 | list_add(&tcon->tcon_list, &ses->tcon_list); | 2627 | list_add(&tcon->tcon_list, &ses->tcon_list); |
@@ -3261,146 +3247,6 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, | |||
3261 | "mount option supported"); | 3247 | "mount option supported"); |
3262 | } | 3248 | } |
3263 | 3249 | ||
3264 | /* | ||
3265 | * When the server supports very large reads and writes via POSIX extensions, | ||
3266 | * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not | ||
3267 | * including the RFC1001 length. | ||
3268 | * | ||
3269 | * Note that this might make for "interesting" allocation problems during | ||
3270 | * writeback however as we have to allocate an array of pointers for the | ||
3271 | * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096. | ||
3272 | * | ||
3273 | * For reads, there is a similar problem as we need to allocate an array | ||
3274 | * of kvecs to handle the receive, though that should only need to be done | ||
3275 | * once. | ||
3276 | */ | ||
3277 | #define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4) | ||
3278 | #define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4) | ||
3279 | |||
3280 | /* | ||
3281 | * When the server doesn't allow large posix writes, only allow a rsize/wsize | ||
3282 | * of 2^17-1 minus the size of the call header. That allows for a read or | ||
3283 | * write up to the maximum size described by RFC1002. | ||
3284 | */ | ||
3285 | #define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4) | ||
3286 | #define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4) | ||
3287 | |||
3288 | /* | ||
3289 | * The default wsize is 1M. find_get_pages seems to return a maximum of 256 | ||
3290 | * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill | ||
3291 | * a single wsize request with a single call. | ||
3292 | */ | ||
3293 | #define CIFS_DEFAULT_IOSIZE (1024 * 1024) | ||
3294 | |||
3295 | /* | ||
3296 | * Windows only supports a max of 60kb reads and 65535 byte writes. Default to | ||
3297 | * those values when posix extensions aren't in force. In actuality here, we | ||
3298 | * use 65536 to allow for a write that is a multiple of 4k. Most servers seem | ||
3299 | * to be ok with the extra byte even though Windows doesn't send writes that | ||
3300 | * are that large. | ||
3301 | * | ||
3302 | * Citation: | ||
3303 | * | ||
3304 | * http://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx | ||
3305 | */ | ||
3306 | #define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024) | ||
3307 | #define CIFS_DEFAULT_NON_POSIX_WSIZE (65536) | ||
3308 | |||
3309 | /* | ||
3310 | * On hosts with high memory, we can't currently support wsize/rsize that are | ||
3311 | * larger than we can kmap at once. Cap the rsize/wsize at | ||
3312 | * LAST_PKMAP * PAGE_SIZE. We'll never be able to fill a read or write request | ||
3313 | * larger than that anyway. | ||
3314 | */ | ||
3315 | #ifdef CONFIG_HIGHMEM | ||
3316 | #define CIFS_KMAP_SIZE_LIMIT (LAST_PKMAP * PAGE_CACHE_SIZE) | ||
3317 | #else /* CONFIG_HIGHMEM */ | ||
3318 | #define CIFS_KMAP_SIZE_LIMIT (1<<24) | ||
3319 | #endif /* CONFIG_HIGHMEM */ | ||
3320 | |||
3321 | static unsigned int | ||
3322 | cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info) | ||
3323 | { | ||
3324 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
3325 | struct TCP_Server_Info *server = tcon->ses->server; | ||
3326 | unsigned int wsize; | ||
3327 | |||
3328 | /* start with specified wsize, or default */ | ||
3329 | if (pvolume_info->wsize) | ||
3330 | wsize = pvolume_info->wsize; | ||
3331 | else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
3332 | wsize = CIFS_DEFAULT_IOSIZE; | ||
3333 | else | ||
3334 | wsize = CIFS_DEFAULT_NON_POSIX_WSIZE; | ||
3335 | |||
3336 | /* can server support 24-bit write sizes? (via UNIX extensions) */ | ||
3337 | if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
3338 | wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE); | ||
3339 | |||
3340 | /* | ||
3341 | * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set? | ||
3342 | * Limit it to max buffer offered by the server, minus the size of the | ||
3343 | * WRITEX header, not including the 4 byte RFC1001 length. | ||
3344 | */ | ||
3345 | if (!(server->capabilities & CAP_LARGE_WRITE_X) || | ||
3346 | (!(server->capabilities & CAP_UNIX) && | ||
3347 | (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)))) | ||
3348 | wsize = min_t(unsigned int, wsize, | ||
3349 | server->maxBuf - sizeof(WRITE_REQ) + 4); | ||
3350 | |||
3351 | /* limit to the amount that we can kmap at once */ | ||
3352 | wsize = min_t(unsigned int, wsize, CIFS_KMAP_SIZE_LIMIT); | ||
3353 | |||
3354 | /* hard limit of CIFS_MAX_WSIZE */ | ||
3355 | wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE); | ||
3356 | |||
3357 | return wsize; | ||
3358 | } | ||
3359 | |||
3360 | static unsigned int | ||
3361 | cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info) | ||
3362 | { | ||
3363 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
3364 | struct TCP_Server_Info *server = tcon->ses->server; | ||
3365 | unsigned int rsize, defsize; | ||
3366 | |||
3367 | /* | ||
3368 | * Set default value... | ||
3369 | * | ||
3370 | * HACK alert! Ancient servers have very small buffers. Even though | ||
3371 | * MS-CIFS indicates that servers are only limited by the client's | ||
3372 | * bufsize for reads, testing against win98se shows that it throws | ||
3373 | * INVALID_PARAMETER errors if you try to request too large a read. | ||
3374 | * OS/2 just sends back short reads. | ||
3375 | * | ||
3376 | * If the server doesn't advertise CAP_LARGE_READ_X, then assume that | ||
3377 | * it can't handle a read request larger than its MaxBufferSize either. | ||
3378 | */ | ||
3379 | if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) | ||
3380 | defsize = CIFS_DEFAULT_IOSIZE; | ||
3381 | else if (server->capabilities & CAP_LARGE_READ_X) | ||
3382 | defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; | ||
3383 | else | ||
3384 | defsize = server->maxBuf - sizeof(READ_RSP); | ||
3385 | |||
3386 | rsize = pvolume_info->rsize ? pvolume_info->rsize : defsize; | ||
3387 | |||
3388 | /* | ||
3389 | * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to | ||
3390 | * the client's MaxBufferSize. | ||
3391 | */ | ||
3392 | if (!(server->capabilities & CAP_LARGE_READ_X)) | ||
3393 | rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); | ||
3394 | |||
3395 | /* limit to the amount that we can kmap at once */ | ||
3396 | rsize = min_t(unsigned int, rsize, CIFS_KMAP_SIZE_LIMIT); | ||
3397 | |||
3398 | /* hard limit of CIFS_MAX_RSIZE */ | ||
3399 | rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); | ||
3400 | |||
3401 | return rsize; | ||
3402 | } | ||
3403 | |||
3404 | static void | 3250 | static void |
3405 | cleanup_volume_info_contents(struct smb_vol *volume_info) | 3251 | cleanup_volume_info_contents(struct smb_vol *volume_info) |
3406 | { | 3252 | { |
@@ -3651,8 +3497,8 @@ try_mount_again: | |||
3651 | if (!tcon->ipc && server->ops->qfs_tcon) | 3497 | if (!tcon->ipc && server->ops->qfs_tcon) |
3652 | server->ops->qfs_tcon(xid, tcon); | 3498 | server->ops->qfs_tcon(xid, tcon); |
3653 | 3499 | ||
3654 | cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info); | 3500 | cifs_sb->wsize = server->ops->negotiate_wsize(tcon, volume_info); |
3655 | cifs_sb->rsize = cifs_negotiate_rsize(tcon, volume_info); | 3501 | cifs_sb->rsize = server->ops->negotiate_rsize(tcon, volume_info); |
3656 | 3502 | ||
3657 | /* tune readahead according to rsize */ | 3503 | /* tune readahead according to rsize */ |
3658 | cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE; | 3504 | cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE; |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 781025be48bc..7c0a81283645 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -160,17 +160,18 @@ check_name(struct dentry *direntry) | |||
160 | static int | 160 | static int |
161 | cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | 161 | cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, |
162 | struct tcon_link *tlink, unsigned oflags, umode_t mode, | 162 | struct tcon_link *tlink, unsigned oflags, umode_t mode, |
163 | __u32 *oplock, __u16 *fileHandle, int *created) | 163 | __u32 *oplock, struct cifs_fid *fid, int *created) |
164 | { | 164 | { |
165 | int rc = -ENOENT; | 165 | int rc = -ENOENT; |
166 | int create_options = CREATE_NOT_DIR; | 166 | int create_options = CREATE_NOT_DIR; |
167 | int desiredAccess; | 167 | int desired_access; |
168 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 168 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
169 | struct cifs_tcon *tcon = tlink_tcon(tlink); | 169 | struct cifs_tcon *tcon = tlink_tcon(tlink); |
170 | char *full_path = NULL; | 170 | char *full_path = NULL; |
171 | FILE_ALL_INFO *buf = NULL; | 171 | FILE_ALL_INFO *buf = NULL; |
172 | struct inode *newinode = NULL; | 172 | struct inode *newinode = NULL; |
173 | int disposition; | 173 | int disposition; |
174 | struct TCP_Server_Info *server = tcon->ses->server; | ||
174 | 175 | ||
175 | *oplock = 0; | 176 | *oplock = 0; |
176 | if (tcon->ses->server->oplocks) | 177 | if (tcon->ses->server->oplocks) |
@@ -185,8 +186,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
185 | if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && | 186 | if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && |
186 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & | 187 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
187 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { | 188 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
188 | rc = cifs_posix_open(full_path, &newinode, | 189 | rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode, |
189 | inode->i_sb, mode, oflags, oplock, fileHandle, xid); | 190 | oflags, oplock, &fid->netfid, xid); |
190 | switch (rc) { | 191 | switch (rc) { |
191 | case 0: | 192 | case 0: |
192 | if (newinode == NULL) { | 193 | if (newinode == NULL) { |
@@ -202,7 +203,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
202 | * close it and proceed as if it were a normal | 203 | * close it and proceed as if it were a normal |
203 | * lookup. | 204 | * lookup. |
204 | */ | 205 | */ |
205 | CIFSSMBClose(xid, tcon, *fileHandle); | 206 | CIFSSMBClose(xid, tcon, fid->netfid); |
206 | goto cifs_create_get_file_info; | 207 | goto cifs_create_get_file_info; |
207 | } | 208 | } |
208 | /* success, no need to query */ | 209 | /* success, no need to query */ |
@@ -244,11 +245,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
244 | */ | 245 | */ |
245 | } | 246 | } |
246 | 247 | ||
247 | desiredAccess = 0; | 248 | desired_access = 0; |
248 | if (OPEN_FMODE(oflags) & FMODE_READ) | 249 | if (OPEN_FMODE(oflags) & FMODE_READ) |
249 | desiredAccess |= GENERIC_READ; /* is this too little? */ | 250 | desired_access |= GENERIC_READ; /* is this too little? */ |
250 | if (OPEN_FMODE(oflags) & FMODE_WRITE) | 251 | if (OPEN_FMODE(oflags) & FMODE_WRITE) |
251 | desiredAccess |= GENERIC_WRITE; | 252 | desired_access |= GENERIC_WRITE; |
252 | 253 | ||
253 | disposition = FILE_OVERWRITE_IF; | 254 | disposition = FILE_OVERWRITE_IF; |
254 | if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) | 255 | if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) |
@@ -260,8 +261,15 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
260 | else | 261 | else |
261 | cFYI(1, "Create flag not set in create function"); | 262 | cFYI(1, "Create flag not set in create function"); |
262 | 263 | ||
263 | /* BB add processing to set equivalent of mode - e.g. via CreateX with | 264 | /* |
264 | ACLs */ | 265 | * BB add processing to set equivalent of mode - e.g. via CreateX with |
266 | * ACLs | ||
267 | */ | ||
268 | |||
269 | if (!server->ops->open) { | ||
270 | rc = -ENOSYS; | ||
271 | goto out; | ||
272 | } | ||
265 | 273 | ||
266 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 274 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
267 | if (buf == NULL) { | 275 | if (buf == NULL) { |
@@ -279,28 +287,18 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
279 | if (backup_cred(cifs_sb)) | 287 | if (backup_cred(cifs_sb)) |
280 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 288 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
281 | 289 | ||
282 | if (tcon->ses->capabilities & CAP_NT_SMBS) | 290 | rc = server->ops->open(xid, tcon, full_path, disposition, |
283 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, | 291 | desired_access, create_options, fid, oplock, |
284 | desiredAccess, create_options, | 292 | buf, cifs_sb); |
285 | fileHandle, oplock, buf, cifs_sb->local_nls, | ||
286 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
287 | else | ||
288 | rc = -EIO; /* no NT SMB support fall into legacy open below */ | ||
289 | |||
290 | if (rc == -EIO) { | ||
291 | /* old server, retry the open legacy style */ | ||
292 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, | ||
293 | desiredAccess, create_options, | ||
294 | fileHandle, oplock, buf, cifs_sb->local_nls, | ||
295 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
296 | } | ||
297 | if (rc) { | 293 | if (rc) { |
298 | cFYI(1, "cifs_create returned 0x%x", rc); | 294 | cFYI(1, "cifs_create returned 0x%x", rc); |
299 | goto out; | 295 | goto out; |
300 | } | 296 | } |
301 | 297 | ||
302 | /* If Open reported that we actually created a file | 298 | /* |
303 | then we now have to set the mode if possible */ | 299 | * If Open reported that we actually created a file then we now have to |
300 | * set the mode if possible. | ||
301 | */ | ||
304 | if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) { | 302 | if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) { |
305 | struct cifs_unix_set_info_args args = { | 303 | struct cifs_unix_set_info_args args = { |
306 | .mode = mode, | 304 | .mode = mode, |
@@ -321,11 +319,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
321 | args.uid = NO_CHANGE_64; | 319 | args.uid = NO_CHANGE_64; |
322 | args.gid = NO_CHANGE_64; | 320 | args.gid = NO_CHANGE_64; |
323 | } | 321 | } |
324 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, *fileHandle, | 322 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid, |
325 | current->tgid); | 323 | current->tgid); |
326 | } else { | 324 | } else { |
327 | /* BB implement mode setting via Windows security | 325 | /* |
328 | descriptors e.g. */ | 326 | * BB implement mode setting via Windows security |
327 | * descriptors e.g. | ||
328 | */ | ||
329 | /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ | 329 | /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ |
330 | 330 | ||
331 | /* Could set r/o dos attribute if mode & 0222 == 0 */ | 331 | /* Could set r/o dos attribute if mode & 0222 == 0 */ |
@@ -334,12 +334,14 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, | |||
334 | cifs_create_get_file_info: | 334 | cifs_create_get_file_info: |
335 | /* server might mask mode so we have to query for it */ | 335 | /* server might mask mode so we have to query for it */ |
336 | if (tcon->unix_ext) | 336 | if (tcon->unix_ext) |
337 | rc = cifs_get_inode_info_unix(&newinode, full_path, | 337 | rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, |
338 | inode->i_sb, xid); | 338 | xid); |
339 | else { | 339 | else { |
340 | rc = cifs_get_inode_info(&newinode, full_path, buf, | 340 | rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, |
341 | inode->i_sb, xid, fileHandle); | 341 | xid, &fid->netfid); |
342 | if (newinode) { | 342 | if (newinode) { |
343 | if (server->ops->set_lease_key) | ||
344 | server->ops->set_lease_key(newinode, fid); | ||
343 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) | 345 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) |
344 | newinode->i_mode = mode; | 346 | newinode->i_mode = mode; |
345 | if ((*oplock & CIFS_CREATE_ACTION) && | 347 | if ((*oplock & CIFS_CREATE_ACTION) && |
@@ -356,7 +358,8 @@ cifs_create_get_file_info: | |||
356 | cifs_create_set_dentry: | 358 | cifs_create_set_dentry: |
357 | if (rc != 0) { | 359 | if (rc != 0) { |
358 | cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); | 360 | cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); |
359 | CIFSSMBClose(xid, tcon, *fileHandle); | 361 | if (server->ops->close) |
362 | server->ops->close(xid, tcon, fid); | ||
360 | goto out; | 363 | goto out; |
361 | } | 364 | } |
362 | d_drop(direntry); | 365 | d_drop(direntry); |
@@ -377,11 +380,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, | |||
377 | unsigned int xid; | 380 | unsigned int xid; |
378 | struct tcon_link *tlink; | 381 | struct tcon_link *tlink; |
379 | struct cifs_tcon *tcon; | 382 | struct cifs_tcon *tcon; |
380 | __u16 fileHandle; | 383 | struct TCP_Server_Info *server; |
384 | struct cifs_fid fid; | ||
385 | struct cifs_pending_open open; | ||
381 | __u32 oplock; | 386 | __u32 oplock; |
382 | struct cifsFileInfo *pfile_info; | 387 | struct cifsFileInfo *file_info; |
383 | 388 | ||
384 | /* Posix open is only called (at lookup time) for file create now. For | 389 | /* |
390 | * Posix open is only called (at lookup time) for file create now. For | ||
385 | * opens (rather than creates), because we do not know if it is a file | 391 | * opens (rather than creates), because we do not know if it is a file |
386 | * or directory yet, and current Samba no longer allows us to do posix | 392 | * or directory yet, and current Samba no longer allows us to do posix |
387 | * open on dirs, we could end up wasting an open call on what turns out | 393 | * open on dirs, we could end up wasting an open call on what turns out |
@@ -413,22 +419,34 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, | |||
413 | goto out_free_xid; | 419 | goto out_free_xid; |
414 | 420 | ||
415 | tcon = tlink_tcon(tlink); | 421 | tcon = tlink_tcon(tlink); |
422 | server = tcon->ses->server; | ||
423 | |||
424 | if (server->ops->new_lease_key) | ||
425 | server->ops->new_lease_key(&fid); | ||
426 | |||
427 | cifs_add_pending_open(&fid, tlink, &open); | ||
416 | 428 | ||
417 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, | 429 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, |
418 | &oplock, &fileHandle, opened); | 430 | &oplock, &fid, opened); |
419 | 431 | ||
420 | if (rc) | 432 | if (rc) { |
433 | cifs_del_pending_open(&open); | ||
421 | goto out; | 434 | goto out; |
435 | } | ||
422 | 436 | ||
423 | rc = finish_open(file, direntry, generic_file_open, opened); | 437 | rc = finish_open(file, direntry, generic_file_open, opened); |
424 | if (rc) { | 438 | if (rc) { |
425 | CIFSSMBClose(xid, tcon, fileHandle); | 439 | if (server->ops->close) |
440 | server->ops->close(xid, tcon, &fid); | ||
441 | cifs_del_pending_open(&open); | ||
426 | goto out; | 442 | goto out; |
427 | } | 443 | } |
428 | 444 | ||
429 | pfile_info = cifs_new_fileinfo(fileHandle, file, tlink, oplock); | 445 | file_info = cifs_new_fileinfo(&fid, file, tlink, oplock); |
430 | if (pfile_info == NULL) { | 446 | if (file_info == NULL) { |
431 | CIFSSMBClose(xid, tcon, fileHandle); | 447 | if (server->ops->close) |
448 | server->ops->close(xid, tcon, &fid); | ||
449 | cifs_del_pending_open(&open); | ||
432 | rc = -ENOMEM; | 450 | rc = -ENOMEM; |
433 | } | 451 | } |
434 | 452 | ||
@@ -453,7 +471,9 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode, | |||
453 | */ | 471 | */ |
454 | unsigned oflags = O_EXCL | O_CREAT | O_RDWR; | 472 | unsigned oflags = O_EXCL | O_CREAT | O_RDWR; |
455 | struct tcon_link *tlink; | 473 | struct tcon_link *tlink; |
456 | __u16 fileHandle; | 474 | struct cifs_tcon *tcon; |
475 | struct TCP_Server_Info *server; | ||
476 | struct cifs_fid fid; | ||
457 | __u32 oplock; | 477 | __u32 oplock; |
458 | int created = FILE_CREATED; | 478 | int created = FILE_CREATED; |
459 | 479 | ||
@@ -465,10 +485,16 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode, | |||
465 | if (IS_ERR(tlink)) | 485 | if (IS_ERR(tlink)) |
466 | goto out_free_xid; | 486 | goto out_free_xid; |
467 | 487 | ||
488 | tcon = tlink_tcon(tlink); | ||
489 | server = tcon->ses->server; | ||
490 | |||
491 | if (server->ops->new_lease_key) | ||
492 | server->ops->new_lease_key(&fid); | ||
493 | |||
468 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, | 494 | rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, |
469 | &oplock, &fileHandle, &created); | 495 | &oplock, &fid, &created); |
470 | if (!rc) | 496 | if (!rc && server->ops->close) |
471 | CIFSSMBClose(xid, tlink_tcon(tlink), fileHandle); | 497 | server->ops->close(xid, tcon, &fid); |
472 | 498 | ||
473 | cifs_put_tlink(tlink); | 499 | cifs_put_tlink(tlink); |
474 | out_free_xid: | 500 | out_free_xid: |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 71e9ad9f5961..7d7bbdc4c8e7 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -169,16 +169,20 @@ posix_open_ret: | |||
169 | 169 | ||
170 | static int | 170 | static int |
171 | cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | 171 | cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, |
172 | struct cifs_tcon *tcon, unsigned int f_flags, __u32 *poplock, | 172 | struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock, |
173 | __u16 *pnetfid, unsigned int xid) | 173 | struct cifs_fid *fid, unsigned int xid) |
174 | { | 174 | { |
175 | int rc; | 175 | int rc; |
176 | int desiredAccess; | 176 | int desired_access; |
177 | int disposition; | 177 | int disposition; |
178 | int create_options = CREATE_NOT_DIR; | 178 | int create_options = CREATE_NOT_DIR; |
179 | FILE_ALL_INFO *buf; | 179 | FILE_ALL_INFO *buf; |
180 | struct TCP_Server_Info *server = tcon->ses->server; | ||
181 | |||
182 | if (!server->ops->open) | ||
183 | return -ENOSYS; | ||
180 | 184 | ||
181 | desiredAccess = cifs_convert_flags(f_flags); | 185 | desired_access = cifs_convert_flags(f_flags); |
182 | 186 | ||
183 | /********************************************************************* | 187 | /********************************************************************* |
184 | * open flag mapping table: | 188 | * open flag mapping table: |
@@ -215,16 +219,9 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | |||
215 | if (backup_cred(cifs_sb)) | 219 | if (backup_cred(cifs_sb)) |
216 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 220 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
217 | 221 | ||
218 | if (tcon->ses->capabilities & CAP_NT_SMBS) | 222 | rc = server->ops->open(xid, tcon, full_path, disposition, |
219 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, | 223 | desired_access, create_options, fid, oplock, buf, |
220 | desiredAccess, create_options, pnetfid, poplock, buf, | 224 | cifs_sb); |
221 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
222 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
223 | else | ||
224 | rc = SMBLegacyOpen(xid, tcon, full_path, disposition, | ||
225 | desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf, | ||
226 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
227 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
228 | 225 | ||
229 | if (rc) | 226 | if (rc) |
230 | goto out; | 227 | goto out; |
@@ -234,7 +231,7 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, | |||
234 | xid); | 231 | xid); |
235 | else | 232 | else |
236 | rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, | 233 | rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, |
237 | xid, pnetfid); | 234 | xid, &fid->netfid); |
238 | 235 | ||
239 | out: | 236 | out: |
240 | kfree(buf); | 237 | kfree(buf); |
@@ -242,48 +239,62 @@ out: | |||
242 | } | 239 | } |
243 | 240 | ||
244 | struct cifsFileInfo * | 241 | struct cifsFileInfo * |
245 | cifs_new_fileinfo(__u16 fileHandle, struct file *file, | 242 | cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, |
246 | struct tcon_link *tlink, __u32 oplock) | 243 | struct tcon_link *tlink, __u32 oplock) |
247 | { | 244 | { |
248 | struct dentry *dentry = file->f_path.dentry; | 245 | struct dentry *dentry = file->f_path.dentry; |
249 | struct inode *inode = dentry->d_inode; | 246 | struct inode *inode = dentry->d_inode; |
250 | struct cifsInodeInfo *pCifsInode = CIFS_I(inode); | 247 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
251 | struct cifsFileInfo *pCifsFile; | 248 | struct cifsFileInfo *cfile; |
252 | 249 | struct cifs_fid_locks *fdlocks; | |
253 | pCifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); | 250 | struct cifs_tcon *tcon = tlink_tcon(tlink); |
254 | if (pCifsFile == NULL) | 251 | |
255 | return pCifsFile; | 252 | cfile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); |
256 | 253 | if (cfile == NULL) | |
257 | pCifsFile->count = 1; | 254 | return cfile; |
258 | pCifsFile->netfid = fileHandle; | 255 | |
259 | pCifsFile->pid = current->tgid; | 256 | fdlocks = kzalloc(sizeof(struct cifs_fid_locks), GFP_KERNEL); |
260 | pCifsFile->uid = current_fsuid(); | 257 | if (!fdlocks) { |
261 | pCifsFile->dentry = dget(dentry); | 258 | kfree(cfile); |
262 | pCifsFile->f_flags = file->f_flags; | 259 | return NULL; |
263 | pCifsFile->invalidHandle = false; | 260 | } |
264 | pCifsFile->tlink = cifs_get_tlink(tlink); | 261 | |
265 | mutex_init(&pCifsFile->fh_mutex); | 262 | INIT_LIST_HEAD(&fdlocks->locks); |
266 | INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break); | 263 | fdlocks->cfile = cfile; |
267 | INIT_LIST_HEAD(&pCifsFile->llist); | 264 | cfile->llist = fdlocks; |
265 | down_write(&cinode->lock_sem); | ||
266 | list_add(&fdlocks->llist, &cinode->llist); | ||
267 | up_write(&cinode->lock_sem); | ||
268 | |||
269 | cfile->count = 1; | ||
270 | cfile->pid = current->tgid; | ||
271 | cfile->uid = current_fsuid(); | ||
272 | cfile->dentry = dget(dentry); | ||
273 | cfile->f_flags = file->f_flags; | ||
274 | cfile->invalidHandle = false; | ||
275 | cfile->tlink = cifs_get_tlink(tlink); | ||
276 | INIT_WORK(&cfile->oplock_break, cifs_oplock_break); | ||
277 | mutex_init(&cfile->fh_mutex); | ||
268 | 278 | ||
269 | spin_lock(&cifs_file_list_lock); | 279 | spin_lock(&cifs_file_list_lock); |
270 | list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList)); | 280 | if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE) |
281 | oplock = fid->pending_open->oplock; | ||
282 | list_del(&fid->pending_open->olist); | ||
283 | |||
284 | tlink_tcon(tlink)->ses->server->ops->set_fid(cfile, fid, oplock); | ||
285 | |||
286 | list_add(&cfile->tlist, &tcon->openFileList); | ||
271 | /* if readable file instance put first in list*/ | 287 | /* if readable file instance put first in list*/ |
272 | if (file->f_mode & FMODE_READ) | 288 | if (file->f_mode & FMODE_READ) |
273 | list_add(&pCifsFile->flist, &pCifsInode->openFileList); | 289 | list_add(&cfile->flist, &cinode->openFileList); |
274 | else | 290 | else |
275 | list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList); | 291 | list_add_tail(&cfile->flist, &cinode->openFileList); |
276 | spin_unlock(&cifs_file_list_lock); | 292 | spin_unlock(&cifs_file_list_lock); |
277 | 293 | ||
278 | cifs_set_oplock_level(pCifsInode, oplock); | 294 | file->private_data = cfile; |
279 | pCifsInode->can_cache_brlcks = pCifsInode->clientCanCacheAll; | 295 | return cfile; |
280 | |||
281 | file->private_data = pCifsFile; | ||
282 | return pCifsFile; | ||
283 | } | 296 | } |
284 | 297 | ||
285 | static void cifs_del_lock_waiters(struct cifsLockInfo *lock); | ||
286 | |||
287 | struct cifsFileInfo * | 298 | struct cifsFileInfo * |
288 | cifsFileInfo_get(struct cifsFileInfo *cifs_file) | 299 | cifsFileInfo_get(struct cifsFileInfo *cifs_file) |
289 | { | 300 | { |
@@ -302,9 +313,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
302 | { | 313 | { |
303 | struct inode *inode = cifs_file->dentry->d_inode; | 314 | struct inode *inode = cifs_file->dentry->d_inode; |
304 | struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); | 315 | struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); |
316 | struct TCP_Server_Info *server = tcon->ses->server; | ||
305 | struct cifsInodeInfo *cifsi = CIFS_I(inode); | 317 | struct cifsInodeInfo *cifsi = CIFS_I(inode); |
306 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 318 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
307 | struct cifsLockInfo *li, *tmp; | 319 | struct cifsLockInfo *li, *tmp; |
320 | struct cifs_fid fid; | ||
321 | struct cifs_pending_open open; | ||
308 | 322 | ||
309 | spin_lock(&cifs_file_list_lock); | 323 | spin_lock(&cifs_file_list_lock); |
310 | if (--cifs_file->count > 0) { | 324 | if (--cifs_file->count > 0) { |
@@ -312,6 +326,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
312 | return; | 326 | return; |
313 | } | 327 | } |
314 | 328 | ||
329 | if (server->ops->get_lease_key) | ||
330 | server->ops->get_lease_key(inode, &fid); | ||
331 | |||
332 | /* store open in pending opens to make sure we don't miss lease break */ | ||
333 | cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open); | ||
334 | |||
315 | /* remove it from the lists */ | 335 | /* remove it from the lists */ |
316 | list_del(&cifs_file->flist); | 336 | list_del(&cifs_file->flist); |
317 | list_del(&cifs_file->tlist); | 337 | list_del(&cifs_file->tlist); |
@@ -319,13 +339,13 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
319 | if (list_empty(&cifsi->openFileList)) { | 339 | if (list_empty(&cifsi->openFileList)) { |
320 | cFYI(1, "closing last open instance for inode %p", | 340 | cFYI(1, "closing last open instance for inode %p", |
321 | cifs_file->dentry->d_inode); | 341 | cifs_file->dentry->d_inode); |
322 | 342 | /* | |
323 | /* in strict cache mode we need invalidate mapping on the last | 343 | * In strict cache mode we need invalidate mapping on the last |
324 | close because it may cause a error when we open this file | 344 | * close because it may cause a error when we open this file |
325 | again and get at least level II oplock */ | 345 | * again and get at least level II oplock. |
346 | */ | ||
326 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) | 347 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) |
327 | CIFS_I(inode)->invalid_mapping = true; | 348 | CIFS_I(inode)->invalid_mapping = true; |
328 | |||
329 | cifs_set_oplock_level(cifsi, 0); | 349 | cifs_set_oplock_level(cifsi, 0); |
330 | } | 350 | } |
331 | spin_unlock(&cifs_file_list_lock); | 351 | spin_unlock(&cifs_file_list_lock); |
@@ -333,23 +353,30 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
333 | cancel_work_sync(&cifs_file->oplock_break); | 353 | cancel_work_sync(&cifs_file->oplock_break); |
334 | 354 | ||
335 | if (!tcon->need_reconnect && !cifs_file->invalidHandle) { | 355 | if (!tcon->need_reconnect && !cifs_file->invalidHandle) { |
356 | struct TCP_Server_Info *server = tcon->ses->server; | ||
336 | unsigned int xid; | 357 | unsigned int xid; |
337 | int rc; | 358 | |
338 | xid = get_xid(); | 359 | xid = get_xid(); |
339 | rc = CIFSSMBClose(xid, tcon, cifs_file->netfid); | 360 | if (server->ops->close) |
340 | free_xid(xid); | 361 | server->ops->close(xid, tcon, &cifs_file->fid); |
362 | _free_xid(xid); | ||
341 | } | 363 | } |
342 | 364 | ||
343 | /* Delete any outstanding lock records. We'll lose them when the file | 365 | cifs_del_pending_open(&open); |
366 | |||
367 | /* | ||
368 | * Delete any outstanding lock records. We'll lose them when the file | ||
344 | * is closed anyway. | 369 | * is closed anyway. |
345 | */ | 370 | */ |
346 | mutex_lock(&cifsi->lock_mutex); | 371 | down_write(&cifsi->lock_sem); |
347 | list_for_each_entry_safe(li, tmp, &cifs_file->llist, llist) { | 372 | list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) { |
348 | list_del(&li->llist); | 373 | list_del(&li->llist); |
349 | cifs_del_lock_waiters(li); | 374 | cifs_del_lock_waiters(li); |
350 | kfree(li); | 375 | kfree(li); |
351 | } | 376 | } |
352 | mutex_unlock(&cifsi->lock_mutex); | 377 | list_del(&cifs_file->llist->llist); |
378 | kfree(cifs_file->llist); | ||
379 | up_write(&cifsi->lock_sem); | ||
353 | 380 | ||
354 | cifs_put_tlink(cifs_file->tlink); | 381 | cifs_put_tlink(cifs_file->tlink); |
355 | dput(cifs_file->dentry); | 382 | dput(cifs_file->dentry); |
@@ -357,17 +384,20 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
357 | } | 384 | } |
358 | 385 | ||
359 | int cifs_open(struct inode *inode, struct file *file) | 386 | int cifs_open(struct inode *inode, struct file *file) |
387 | |||
360 | { | 388 | { |
361 | int rc = -EACCES; | 389 | int rc = -EACCES; |
362 | unsigned int xid; | 390 | unsigned int xid; |
363 | __u32 oplock; | 391 | __u32 oplock; |
364 | struct cifs_sb_info *cifs_sb; | 392 | struct cifs_sb_info *cifs_sb; |
393 | struct TCP_Server_Info *server; | ||
365 | struct cifs_tcon *tcon; | 394 | struct cifs_tcon *tcon; |
366 | struct tcon_link *tlink; | 395 | struct tcon_link *tlink; |
367 | struct cifsFileInfo *pCifsFile = NULL; | 396 | struct cifsFileInfo *cfile = NULL; |
368 | char *full_path = NULL; | 397 | char *full_path = NULL; |
369 | bool posix_open_ok = false; | 398 | bool posix_open_ok = false; |
370 | __u16 netfid; | 399 | struct cifs_fid fid; |
400 | struct cifs_pending_open open; | ||
371 | 401 | ||
372 | xid = get_xid(); | 402 | xid = get_xid(); |
373 | 403 | ||
@@ -378,6 +408,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
378 | return PTR_ERR(tlink); | 408 | return PTR_ERR(tlink); |
379 | } | 409 | } |
380 | tcon = tlink_tcon(tlink); | 410 | tcon = tlink_tcon(tlink); |
411 | server = tcon->ses->server; | ||
381 | 412 | ||
382 | full_path = build_path_from_dentry(file->f_path.dentry); | 413 | full_path = build_path_from_dentry(file->f_path.dentry); |
383 | if (full_path == NULL) { | 414 | if (full_path == NULL) { |
@@ -388,7 +419,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
388 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", | 419 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", |
389 | inode, file->f_flags, full_path); | 420 | inode, file->f_flags, full_path); |
390 | 421 | ||
391 | if (tcon->ses->server->oplocks) | 422 | if (server->oplocks) |
392 | oplock = REQ_OPLOCK; | 423 | oplock = REQ_OPLOCK; |
393 | else | 424 | else |
394 | oplock = 0; | 425 | oplock = 0; |
@@ -399,7 +430,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
399 | /* can not refresh inode info since size could be stale */ | 430 | /* can not refresh inode info since size could be stale */ |
400 | rc = cifs_posix_open(full_path, &inode, inode->i_sb, | 431 | rc = cifs_posix_open(full_path, &inode, inode->i_sb, |
401 | cifs_sb->mnt_file_mode /* ignored */, | 432 | cifs_sb->mnt_file_mode /* ignored */, |
402 | file->f_flags, &oplock, &netfid, xid); | 433 | file->f_flags, &oplock, &fid.netfid, xid); |
403 | if (rc == 0) { | 434 | if (rc == 0) { |
404 | cFYI(1, "posix open succeeded"); | 435 | cFYI(1, "posix open succeeded"); |
405 | posix_open_ok = true; | 436 | posix_open_ok = true; |
@@ -415,20 +446,34 @@ int cifs_open(struct inode *inode, struct file *file) | |||
415 | } else if ((rc != -EIO) && (rc != -EREMOTE) && | 446 | } else if ((rc != -EIO) && (rc != -EREMOTE) && |
416 | (rc != -EOPNOTSUPP)) /* path not found or net err */ | 447 | (rc != -EOPNOTSUPP)) /* path not found or net err */ |
417 | goto out; | 448 | goto out; |
418 | /* else fallthrough to retry open the old way on network i/o | 449 | /* |
419 | or DFS errors */ | 450 | * Else fallthrough to retry open the old way on network i/o |
451 | * or DFS errors. | ||
452 | */ | ||
420 | } | 453 | } |
421 | 454 | ||
455 | if (server->ops->get_lease_key) | ||
456 | server->ops->get_lease_key(inode, &fid); | ||
457 | |||
458 | cifs_add_pending_open(&fid, tlink, &open); | ||
459 | |||
422 | if (!posix_open_ok) { | 460 | if (!posix_open_ok) { |
461 | if (server->ops->get_lease_key) | ||
462 | server->ops->get_lease_key(inode, &fid); | ||
463 | |||
423 | rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, | 464 | rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, |
424 | file->f_flags, &oplock, &netfid, xid); | 465 | file->f_flags, &oplock, &fid, xid); |
425 | if (rc) | 466 | if (rc) { |
467 | cifs_del_pending_open(&open); | ||
426 | goto out; | 468 | goto out; |
469 | } | ||
427 | } | 470 | } |
428 | 471 | ||
429 | pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock); | 472 | cfile = cifs_new_fileinfo(&fid, file, tlink, oplock); |
430 | if (pCifsFile == NULL) { | 473 | if (cfile == NULL) { |
431 | CIFSSMBClose(xid, tcon, netfid); | 474 | if (server->ops->close) |
475 | server->ops->close(xid, tcon, &fid); | ||
476 | cifs_del_pending_open(&open); | ||
432 | rc = -ENOMEM; | 477 | rc = -ENOMEM; |
433 | goto out; | 478 | goto out; |
434 | } | 479 | } |
@@ -436,8 +481,10 @@ int cifs_open(struct inode *inode, struct file *file) | |||
436 | cifs_fscache_set_inode_cookie(inode, file); | 481 | cifs_fscache_set_inode_cookie(inode, file); |
437 | 482 | ||
438 | if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { | 483 | if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { |
439 | /* time to set mode which we can not set earlier due to | 484 | /* |
440 | problems creating new read-only files */ | 485 | * Time to set mode which we can not set earlier due to |
486 | * problems creating new read-only files. | ||
487 | */ | ||
441 | struct cifs_unix_set_info_args args = { | 488 | struct cifs_unix_set_info_args args = { |
442 | .mode = inode->i_mode, | 489 | .mode = inode->i_mode, |
443 | .uid = NO_CHANGE_64, | 490 | .uid = NO_CHANGE_64, |
@@ -447,8 +494,8 @@ int cifs_open(struct inode *inode, struct file *file) | |||
447 | .mtime = NO_CHANGE_64, | 494 | .mtime = NO_CHANGE_64, |
448 | .device = 0, | 495 | .device = 0, |
449 | }; | 496 | }; |
450 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid, | 497 | CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid, |
451 | pCifsFile->pid); | 498 | cfile->pid); |
452 | } | 499 | } |
453 | 500 | ||
454 | out: | 501 | out: |
@@ -458,59 +505,66 @@ out: | |||
458 | return rc; | 505 | return rc; |
459 | } | 506 | } |
460 | 507 | ||
461 | /* Try to reacquire byte range locks that were released when session */ | 508 | /* |
462 | /* to server was lost */ | 509 | * Try to reacquire byte range locks that were released when session |
510 | * to server was lost | ||
511 | */ | ||
463 | static int cifs_relock_file(struct cifsFileInfo *cifsFile) | 512 | static int cifs_relock_file(struct cifsFileInfo *cifsFile) |
464 | { | 513 | { |
465 | int rc = 0; | 514 | int rc = 0; |
466 | 515 | ||
467 | /* BB list all locks open on this file and relock */ | 516 | /* BB list all locks open on this file and relock */ |
468 | 517 | ||
469 | return rc; | 518 | return rc; |
470 | } | 519 | } |
471 | 520 | ||
472 | static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) | 521 | static int |
522 | cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) | ||
473 | { | 523 | { |
474 | int rc = -EACCES; | 524 | int rc = -EACCES; |
475 | unsigned int xid; | 525 | unsigned int xid; |
476 | __u32 oplock; | 526 | __u32 oplock; |
477 | struct cifs_sb_info *cifs_sb; | 527 | struct cifs_sb_info *cifs_sb; |
478 | struct cifs_tcon *tcon; | 528 | struct cifs_tcon *tcon; |
479 | struct cifsInodeInfo *pCifsInode; | 529 | struct TCP_Server_Info *server; |
530 | struct cifsInodeInfo *cinode; | ||
480 | struct inode *inode; | 531 | struct inode *inode; |
481 | char *full_path = NULL; | 532 | char *full_path = NULL; |
482 | int desiredAccess; | 533 | int desired_access; |
483 | int disposition = FILE_OPEN; | 534 | int disposition = FILE_OPEN; |
484 | int create_options = CREATE_NOT_DIR; | 535 | int create_options = CREATE_NOT_DIR; |
485 | __u16 netfid; | 536 | struct cifs_fid fid; |
486 | 537 | ||
487 | xid = get_xid(); | 538 | xid = get_xid(); |
488 | mutex_lock(&pCifsFile->fh_mutex); | 539 | mutex_lock(&cfile->fh_mutex); |
489 | if (!pCifsFile->invalidHandle) { | 540 | if (!cfile->invalidHandle) { |
490 | mutex_unlock(&pCifsFile->fh_mutex); | 541 | mutex_unlock(&cfile->fh_mutex); |
491 | rc = 0; | 542 | rc = 0; |
492 | free_xid(xid); | 543 | free_xid(xid); |
493 | return rc; | 544 | return rc; |
494 | } | 545 | } |
495 | 546 | ||
496 | inode = pCifsFile->dentry->d_inode; | 547 | inode = cfile->dentry->d_inode; |
497 | cifs_sb = CIFS_SB(inode->i_sb); | 548 | cifs_sb = CIFS_SB(inode->i_sb); |
498 | tcon = tlink_tcon(pCifsFile->tlink); | 549 | tcon = tlink_tcon(cfile->tlink); |
550 | server = tcon->ses->server; | ||
499 | 551 | ||
500 | /* can not grab rename sem here because various ops, including | 552 | /* |
501 | those that already have the rename sem can end up causing writepage | 553 | * Can not grab rename sem here because various ops, including those |
502 | to get called and if the server was down that means we end up here, | 554 | * that already have the rename sem can end up causing writepage to get |
503 | and we can never tell if the caller already has the rename_sem */ | 555 | * called and if the server was down that means we end up here, and we |
504 | full_path = build_path_from_dentry(pCifsFile->dentry); | 556 | * can never tell if the caller already has the rename_sem. |
557 | */ | ||
558 | full_path = build_path_from_dentry(cfile->dentry); | ||
505 | if (full_path == NULL) { | 559 | if (full_path == NULL) { |
506 | rc = -ENOMEM; | 560 | rc = -ENOMEM; |
507 | mutex_unlock(&pCifsFile->fh_mutex); | 561 | mutex_unlock(&cfile->fh_mutex); |
508 | free_xid(xid); | 562 | free_xid(xid); |
509 | return rc; | 563 | return rc; |
510 | } | 564 | } |
511 | 565 | ||
512 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", | 566 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", inode, cfile->f_flags, |
513 | inode, pCifsFile->f_flags, full_path); | 567 | full_path); |
514 | 568 | ||
515 | if (tcon->ses->server->oplocks) | 569 | if (tcon->ses->server->oplocks) |
516 | oplock = REQ_OPLOCK; | 570 | oplock = REQ_OPLOCK; |
@@ -524,69 +578,72 @@ static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) | |||
524 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the | 578 | * O_CREAT, O_EXCL and O_TRUNC already had their effect on the |
525 | * original open. Must mask them off for a reopen. | 579 | * original open. Must mask them off for a reopen. |
526 | */ | 580 | */ |
527 | unsigned int oflags = pCifsFile->f_flags & | 581 | unsigned int oflags = cfile->f_flags & |
528 | ~(O_CREAT | O_EXCL | O_TRUNC); | 582 | ~(O_CREAT | O_EXCL | O_TRUNC); |
529 | 583 | ||
530 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, | 584 | rc = cifs_posix_open(full_path, NULL, inode->i_sb, |
531 | cifs_sb->mnt_file_mode /* ignored */, | 585 | cifs_sb->mnt_file_mode /* ignored */, |
532 | oflags, &oplock, &netfid, xid); | 586 | oflags, &oplock, &fid.netfid, xid); |
533 | if (rc == 0) { | 587 | if (rc == 0) { |
534 | cFYI(1, "posix reopen succeeded"); | 588 | cFYI(1, "posix reopen succeeded"); |
535 | goto reopen_success; | 589 | goto reopen_success; |
536 | } | 590 | } |
537 | /* fallthrough to retry open the old way on errors, especially | 591 | /* |
538 | in the reconnect path it is important to retry hard */ | 592 | * fallthrough to retry open the old way on errors, especially |
593 | * in the reconnect path it is important to retry hard | ||
594 | */ | ||
539 | } | 595 | } |
540 | 596 | ||
541 | desiredAccess = cifs_convert_flags(pCifsFile->f_flags); | 597 | desired_access = cifs_convert_flags(cfile->f_flags); |
542 | 598 | ||
543 | if (backup_cred(cifs_sb)) | 599 | if (backup_cred(cifs_sb)) |
544 | create_options |= CREATE_OPEN_BACKUP_INTENT; | 600 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
545 | 601 | ||
546 | /* Can not refresh inode by passing in file_info buf to be returned | 602 | if (server->ops->get_lease_key) |
547 | by SMBOpen and then calling get_inode_info with returned buf | 603 | server->ops->get_lease_key(inode, &fid); |
548 | since file might have write behind data that needs to be flushed | ||
549 | and server version of file size can be stale. If we knew for sure | ||
550 | that inode was not dirty locally we could do this */ | ||
551 | 604 | ||
552 | rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess, | 605 | /* |
553 | create_options, &netfid, &oplock, NULL, | 606 | * Can not refresh inode by passing in file_info buf to be returned by |
554 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 607 | * CIFSSMBOpen and then calling get_inode_info with returned buf since |
555 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 608 | * file might have write behind data that needs to be flushed and server |
609 | * version of file size can be stale. If we knew for sure that inode was | ||
610 | * not dirty locally we could do this. | ||
611 | */ | ||
612 | rc = server->ops->open(xid, tcon, full_path, disposition, | ||
613 | desired_access, create_options, &fid, &oplock, | ||
614 | NULL, cifs_sb); | ||
556 | if (rc) { | 615 | if (rc) { |
557 | mutex_unlock(&pCifsFile->fh_mutex); | 616 | mutex_unlock(&cfile->fh_mutex); |
558 | cFYI(1, "cifs_open returned 0x%x", rc); | 617 | cFYI(1, "cifs_reopen returned 0x%x", rc); |
559 | cFYI(1, "oplock: %d", oplock); | 618 | cFYI(1, "oplock: %d", oplock); |
560 | goto reopen_error_exit; | 619 | goto reopen_error_exit; |
561 | } | 620 | } |
562 | 621 | ||
563 | reopen_success: | 622 | reopen_success: |
564 | pCifsFile->netfid = netfid; | 623 | cfile->invalidHandle = false; |
565 | pCifsFile->invalidHandle = false; | 624 | mutex_unlock(&cfile->fh_mutex); |
566 | mutex_unlock(&pCifsFile->fh_mutex); | 625 | cinode = CIFS_I(inode); |
567 | pCifsInode = CIFS_I(inode); | ||
568 | 626 | ||
569 | if (can_flush) { | 627 | if (can_flush) { |
570 | rc = filemap_write_and_wait(inode->i_mapping); | 628 | rc = filemap_write_and_wait(inode->i_mapping); |
571 | mapping_set_error(inode->i_mapping, rc); | 629 | mapping_set_error(inode->i_mapping, rc); |
572 | 630 | ||
573 | if (tcon->unix_ext) | 631 | if (tcon->unix_ext) |
574 | rc = cifs_get_inode_info_unix(&inode, | 632 | rc = cifs_get_inode_info_unix(&inode, full_path, |
575 | full_path, inode->i_sb, xid); | 633 | inode->i_sb, xid); |
576 | else | 634 | else |
577 | rc = cifs_get_inode_info(&inode, | 635 | rc = cifs_get_inode_info(&inode, full_path, NULL, |
578 | full_path, NULL, inode->i_sb, | 636 | inode->i_sb, xid, NULL); |
579 | xid, NULL); | 637 | } |
580 | } /* else we are writing out data to server already | 638 | /* |
581 | and could deadlock if we tried to flush data, and | 639 | * Else we are writing out data to server already and could deadlock if |
582 | since we do not know if we have data that would | 640 | * we tried to flush data, and since we do not know if we have data that |
583 | invalidate the current end of file on the server | 641 | * would invalidate the current end of file on the server we can not go |
584 | we can not go to the server to get the new inod | 642 | * to the server to get the new inode info. |
585 | info */ | 643 | */ |
586 | |||
587 | cifs_set_oplock_level(pCifsInode, oplock); | ||
588 | 644 | ||
589 | cifs_relock_file(pCifsFile); | 645 | server->ops->set_fid(cfile, &fid, oplock); |
646 | cifs_relock_file(cfile); | ||
590 | 647 | ||
591 | reopen_error_exit: | 648 | reopen_error_exit: |
592 | kfree(full_path); | 649 | kfree(full_path); |
@@ -609,42 +666,48 @@ int cifs_closedir(struct inode *inode, struct file *file) | |||
609 | { | 666 | { |
610 | int rc = 0; | 667 | int rc = 0; |
611 | unsigned int xid; | 668 | unsigned int xid; |
612 | struct cifsFileInfo *pCFileStruct = file->private_data; | 669 | struct cifsFileInfo *cfile = file->private_data; |
613 | char *ptmp; | 670 | struct cifs_tcon *tcon; |
671 | struct TCP_Server_Info *server; | ||
672 | char *buf; | ||
614 | 673 | ||
615 | cFYI(1, "Closedir inode = 0x%p", inode); | 674 | cFYI(1, "Closedir inode = 0x%p", inode); |
616 | 675 | ||
676 | if (cfile == NULL) | ||
677 | return rc; | ||
678 | |||
617 | xid = get_xid(); | 679 | xid = get_xid(); |
680 | tcon = tlink_tcon(cfile->tlink); | ||
681 | server = tcon->ses->server; | ||
618 | 682 | ||
619 | if (pCFileStruct) { | 683 | cFYI(1, "Freeing private data in close dir"); |
620 | struct cifs_tcon *pTcon = tlink_tcon(pCFileStruct->tlink); | 684 | spin_lock(&cifs_file_list_lock); |
685 | if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) { | ||
686 | cfile->invalidHandle = true; | ||
687 | spin_unlock(&cifs_file_list_lock); | ||
688 | if (server->ops->close_dir) | ||
689 | rc = server->ops->close_dir(xid, tcon, &cfile->fid); | ||
690 | else | ||
691 | rc = -ENOSYS; | ||
692 | cFYI(1, "Closing uncompleted readdir with rc %d", rc); | ||
693 | /* not much we can do if it fails anyway, ignore rc */ | ||
694 | rc = 0; | ||
695 | } else | ||
696 | spin_unlock(&cifs_file_list_lock); | ||
621 | 697 | ||
622 | cFYI(1, "Freeing private data in close dir"); | 698 | buf = cfile->srch_inf.ntwrk_buf_start; |
623 | spin_lock(&cifs_file_list_lock); | 699 | if (buf) { |
624 | if (!pCFileStruct->srch_inf.endOfSearch && | 700 | cFYI(1, "closedir free smb buf in srch struct"); |
625 | !pCFileStruct->invalidHandle) { | 701 | cfile->srch_inf.ntwrk_buf_start = NULL; |
626 | pCFileStruct->invalidHandle = true; | 702 | if (cfile->srch_inf.smallBuf) |
627 | spin_unlock(&cifs_file_list_lock); | 703 | cifs_small_buf_release(buf); |
628 | rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid); | 704 | else |
629 | cFYI(1, "Closing uncompleted readdir with rc %d", | 705 | cifs_buf_release(buf); |
630 | rc); | ||
631 | /* not much we can do if it fails anyway, ignore rc */ | ||
632 | rc = 0; | ||
633 | } else | ||
634 | spin_unlock(&cifs_file_list_lock); | ||
635 | ptmp = pCFileStruct->srch_inf.ntwrk_buf_start; | ||
636 | if (ptmp) { | ||
637 | cFYI(1, "closedir free smb buf in srch struct"); | ||
638 | pCFileStruct->srch_inf.ntwrk_buf_start = NULL; | ||
639 | if (pCFileStruct->srch_inf.smallBuf) | ||
640 | cifs_small_buf_release(ptmp); | ||
641 | else | ||
642 | cifs_buf_release(ptmp); | ||
643 | } | ||
644 | cifs_put_tlink(pCFileStruct->tlink); | ||
645 | kfree(file->private_data); | ||
646 | file->private_data = NULL; | ||
647 | } | 706 | } |
707 | |||
708 | cifs_put_tlink(cfile->tlink); | ||
709 | kfree(file->private_data); | ||
710 | file->private_data = NULL; | ||
648 | /* BB can we lock the filestruct while this is going on? */ | 711 | /* BB can we lock the filestruct while this is going on? */ |
649 | free_xid(xid); | 712 | free_xid(xid); |
650 | return rc; | 713 | return rc; |
@@ -666,7 +729,7 @@ cifs_lock_init(__u64 offset, __u64 length, __u8 type) | |||
666 | return lock; | 729 | return lock; |
667 | } | 730 | } |
668 | 731 | ||
669 | static void | 732 | void |
670 | cifs_del_lock_waiters(struct cifsLockInfo *lock) | 733 | cifs_del_lock_waiters(struct cifsLockInfo *lock) |
671 | { | 734 | { |
672 | struct cifsLockInfo *li, *tmp; | 735 | struct cifsLockInfo *li, *tmp; |
@@ -677,45 +740,47 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock) | |||
677 | } | 740 | } |
678 | 741 | ||
679 | static bool | 742 | static bool |
680 | cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, | 743 | cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset, |
681 | __u64 length, __u8 type, struct cifsFileInfo *cur, | 744 | __u64 length, __u8 type, struct cifsFileInfo *cfile, |
682 | struct cifsLockInfo **conf_lock) | 745 | struct cifsLockInfo **conf_lock, bool rw_check) |
683 | { | 746 | { |
684 | struct cifsLockInfo *li; | 747 | struct cifsLockInfo *li; |
748 | struct cifsFileInfo *cur_cfile = fdlocks->cfile; | ||
685 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | 749 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
686 | 750 | ||
687 | list_for_each_entry(li, &cfile->llist, llist) { | 751 | list_for_each_entry(li, &fdlocks->locks, llist) { |
688 | if (offset + length <= li->offset || | 752 | if (offset + length <= li->offset || |
689 | offset >= li->offset + li->length) | 753 | offset >= li->offset + li->length) |
690 | continue; | 754 | continue; |
691 | else if ((type & server->vals->shared_lock_type) && | 755 | if (rw_check && server->ops->compare_fids(cfile, cur_cfile) && |
692 | ((server->ops->compare_fids(cur, cfile) && | 756 | current->tgid == li->pid) |
693 | current->tgid == li->pid) || type == li->type)) | ||
694 | continue; | 757 | continue; |
695 | else { | 758 | if ((type & server->vals->shared_lock_type) && |
759 | ((server->ops->compare_fids(cfile, cur_cfile) && | ||
760 | current->tgid == li->pid) || type == li->type)) | ||
761 | continue; | ||
762 | if (conf_lock) | ||
696 | *conf_lock = li; | 763 | *conf_lock = li; |
697 | return true; | 764 | return true; |
698 | } | ||
699 | } | 765 | } |
700 | return false; | 766 | return false; |
701 | } | 767 | } |
702 | 768 | ||
703 | static bool | 769 | bool |
704 | cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | 770 | cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, |
705 | __u8 type, struct cifsLockInfo **conf_lock) | 771 | __u8 type, struct cifsLockInfo **conf_lock, |
772 | bool rw_check) | ||
706 | { | 773 | { |
707 | bool rc = false; | 774 | bool rc = false; |
708 | struct cifsFileInfo *fid, *tmp; | 775 | struct cifs_fid_locks *cur; |
709 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | 776 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
710 | 777 | ||
711 | spin_lock(&cifs_file_list_lock); | 778 | list_for_each_entry(cur, &cinode->llist, llist) { |
712 | list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) { | 779 | rc = cifs_find_fid_lock_conflict(cur, offset, length, type, |
713 | rc = cifs_find_fid_lock_conflict(fid, offset, length, type, | 780 | cfile, conf_lock, rw_check); |
714 | cfile, conf_lock); | ||
715 | if (rc) | 781 | if (rc) |
716 | break; | 782 | break; |
717 | } | 783 | } |
718 | spin_unlock(&cifs_file_list_lock); | ||
719 | 784 | ||
720 | return rc; | 785 | return rc; |
721 | } | 786 | } |
@@ -737,10 +802,10 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | |||
737 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | 802 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; |
738 | bool exist; | 803 | bool exist; |
739 | 804 | ||
740 | mutex_lock(&cinode->lock_mutex); | 805 | down_read(&cinode->lock_sem); |
741 | 806 | ||
742 | exist = cifs_find_lock_conflict(cfile, offset, length, type, | 807 | exist = cifs_find_lock_conflict(cfile, offset, length, type, |
743 | &conf_lock); | 808 | &conf_lock, false); |
744 | if (exist) { | 809 | if (exist) { |
745 | flock->fl_start = conf_lock->offset; | 810 | flock->fl_start = conf_lock->offset; |
746 | flock->fl_end = conf_lock->offset + conf_lock->length - 1; | 811 | flock->fl_end = conf_lock->offset + conf_lock->length - 1; |
@@ -754,7 +819,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, | |||
754 | else | 819 | else |
755 | flock->fl_type = F_UNLCK; | 820 | flock->fl_type = F_UNLCK; |
756 | 821 | ||
757 | mutex_unlock(&cinode->lock_mutex); | 822 | up_read(&cinode->lock_sem); |
758 | return rc; | 823 | return rc; |
759 | } | 824 | } |
760 | 825 | ||
@@ -762,9 +827,9 @@ static void | |||
762 | cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) | 827 | cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) |
763 | { | 828 | { |
764 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | 829 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); |
765 | mutex_lock(&cinode->lock_mutex); | 830 | down_write(&cinode->lock_sem); |
766 | list_add_tail(&lock->llist, &cfile->llist); | 831 | list_add_tail(&lock->llist, &cfile->llist->locks); |
767 | mutex_unlock(&cinode->lock_mutex); | 832 | up_write(&cinode->lock_sem); |
768 | } | 833 | } |
769 | 834 | ||
770 | /* | 835 | /* |
@@ -784,13 +849,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, | |||
784 | 849 | ||
785 | try_again: | 850 | try_again: |
786 | exist = false; | 851 | exist = false; |
787 | mutex_lock(&cinode->lock_mutex); | 852 | down_write(&cinode->lock_sem); |
788 | 853 | ||
789 | exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, | 854 | exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, |
790 | lock->type, &conf_lock); | 855 | lock->type, &conf_lock, false); |
791 | if (!exist && cinode->can_cache_brlcks) { | 856 | if (!exist && cinode->can_cache_brlcks) { |
792 | list_add_tail(&lock->llist, &cfile->llist); | 857 | list_add_tail(&lock->llist, &cfile->llist->locks); |
793 | mutex_unlock(&cinode->lock_mutex); | 858 | up_write(&cinode->lock_sem); |
794 | return rc; | 859 | return rc; |
795 | } | 860 | } |
796 | 861 | ||
@@ -800,17 +865,17 @@ try_again: | |||
800 | rc = -EACCES; | 865 | rc = -EACCES; |
801 | else { | 866 | else { |
802 | list_add_tail(&lock->blist, &conf_lock->blist); | 867 | list_add_tail(&lock->blist, &conf_lock->blist); |
803 | mutex_unlock(&cinode->lock_mutex); | 868 | up_write(&cinode->lock_sem); |
804 | rc = wait_event_interruptible(lock->block_q, | 869 | rc = wait_event_interruptible(lock->block_q, |
805 | (lock->blist.prev == &lock->blist) && | 870 | (lock->blist.prev == &lock->blist) && |
806 | (lock->blist.next == &lock->blist)); | 871 | (lock->blist.next == &lock->blist)); |
807 | if (!rc) | 872 | if (!rc) |
808 | goto try_again; | 873 | goto try_again; |
809 | mutex_lock(&cinode->lock_mutex); | 874 | down_write(&cinode->lock_sem); |
810 | list_del_init(&lock->blist); | 875 | list_del_init(&lock->blist); |
811 | } | 876 | } |
812 | 877 | ||
813 | mutex_unlock(&cinode->lock_mutex); | 878 | up_write(&cinode->lock_sem); |
814 | return rc; | 879 | return rc; |
815 | } | 880 | } |
816 | 881 | ||
@@ -831,7 +896,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) | |||
831 | if ((flock->fl_flags & FL_POSIX) == 0) | 896 | if ((flock->fl_flags & FL_POSIX) == 0) |
832 | return 1; | 897 | return 1; |
833 | 898 | ||
834 | mutex_lock(&cinode->lock_mutex); | 899 | down_read(&cinode->lock_sem); |
835 | posix_test_lock(file, flock); | 900 | posix_test_lock(file, flock); |
836 | 901 | ||
837 | if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { | 902 | if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { |
@@ -839,7 +904,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) | |||
839 | rc = 1; | 904 | rc = 1; |
840 | } | 905 | } |
841 | 906 | ||
842 | mutex_unlock(&cinode->lock_mutex); | 907 | up_read(&cinode->lock_sem); |
843 | return rc; | 908 | return rc; |
844 | } | 909 | } |
845 | 910 | ||
@@ -859,14 +924,14 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock) | |||
859 | return rc; | 924 | return rc; |
860 | 925 | ||
861 | try_again: | 926 | try_again: |
862 | mutex_lock(&cinode->lock_mutex); | 927 | down_write(&cinode->lock_sem); |
863 | if (!cinode->can_cache_brlcks) { | 928 | if (!cinode->can_cache_brlcks) { |
864 | mutex_unlock(&cinode->lock_mutex); | 929 | up_write(&cinode->lock_sem); |
865 | return rc; | 930 | return rc; |
866 | } | 931 | } |
867 | 932 | ||
868 | rc = posix_lock_file(file, flock, NULL); | 933 | rc = posix_lock_file(file, flock, NULL); |
869 | mutex_unlock(&cinode->lock_mutex); | 934 | up_write(&cinode->lock_sem); |
870 | if (rc == FILE_LOCK_DEFERRED) { | 935 | if (rc == FILE_LOCK_DEFERRED) { |
871 | rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next); | 936 | rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next); |
872 | if (!rc) | 937 | if (!rc) |
@@ -876,7 +941,7 @@ try_again: | |||
876 | return rc; | 941 | return rc; |
877 | } | 942 | } |
878 | 943 | ||
879 | static int | 944 | int |
880 | cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | 945 | cifs_push_mandatory_locks(struct cifsFileInfo *cfile) |
881 | { | 946 | { |
882 | unsigned int xid; | 947 | unsigned int xid; |
@@ -893,9 +958,10 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
893 | xid = get_xid(); | 958 | xid = get_xid(); |
894 | tcon = tlink_tcon(cfile->tlink); | 959 | tcon = tlink_tcon(cfile->tlink); |
895 | 960 | ||
896 | mutex_lock(&cinode->lock_mutex); | 961 | /* we are going to update can_cache_brlcks here - need a write access */ |
962 | down_write(&cinode->lock_sem); | ||
897 | if (!cinode->can_cache_brlcks) { | 963 | if (!cinode->can_cache_brlcks) { |
898 | mutex_unlock(&cinode->lock_mutex); | 964 | up_write(&cinode->lock_sem); |
899 | free_xid(xid); | 965 | free_xid(xid); |
900 | return rc; | 966 | return rc; |
901 | } | 967 | } |
@@ -906,7 +972,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
906 | */ | 972 | */ |
907 | max_buf = tcon->ses->server->maxBuf; | 973 | max_buf = tcon->ses->server->maxBuf; |
908 | if (!max_buf) { | 974 | if (!max_buf) { |
909 | mutex_unlock(&cinode->lock_mutex); | 975 | up_write(&cinode->lock_sem); |
910 | free_xid(xid); | 976 | free_xid(xid); |
911 | return -EINVAL; | 977 | return -EINVAL; |
912 | } | 978 | } |
@@ -915,7 +981,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
915 | sizeof(LOCKING_ANDX_RANGE); | 981 | sizeof(LOCKING_ANDX_RANGE); |
916 | buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); | 982 | buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); |
917 | if (!buf) { | 983 | if (!buf) { |
918 | mutex_unlock(&cinode->lock_mutex); | 984 | up_write(&cinode->lock_sem); |
919 | free_xid(xid); | 985 | free_xid(xid); |
920 | return -ENOMEM; | 986 | return -ENOMEM; |
921 | } | 987 | } |
@@ -923,7 +989,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
923 | for (i = 0; i < 2; i++) { | 989 | for (i = 0; i < 2; i++) { |
924 | cur = buf; | 990 | cur = buf; |
925 | num = 0; | 991 | num = 0; |
926 | list_for_each_entry_safe(li, tmp, &cfile->llist, llist) { | 992 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { |
927 | if (li->type != types[i]) | 993 | if (li->type != types[i]) |
928 | continue; | 994 | continue; |
929 | cur->Pid = cpu_to_le16(li->pid); | 995 | cur->Pid = cpu_to_le16(li->pid); |
@@ -932,7 +998,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
932 | cur->OffsetLow = cpu_to_le32((u32)li->offset); | 998 | cur->OffsetLow = cpu_to_le32((u32)li->offset); |
933 | cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); | 999 | cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32)); |
934 | if (++num == max_num) { | 1000 | if (++num == max_num) { |
935 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1001 | stored_rc = cifs_lockv(xid, tcon, |
1002 | cfile->fid.netfid, | ||
936 | (__u8)li->type, 0, num, | 1003 | (__u8)li->type, 0, num, |
937 | buf); | 1004 | buf); |
938 | if (stored_rc) | 1005 | if (stored_rc) |
@@ -944,7 +1011,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
944 | } | 1011 | } |
945 | 1012 | ||
946 | if (num) { | 1013 | if (num) { |
947 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1014 | stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, |
948 | (__u8)types[i], 0, num, buf); | 1015 | (__u8)types[i], 0, num, buf); |
949 | if (stored_rc) | 1016 | if (stored_rc) |
950 | rc = stored_rc; | 1017 | rc = stored_rc; |
@@ -952,7 +1019,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) | |||
952 | } | 1019 | } |
953 | 1020 | ||
954 | cinode->can_cache_brlcks = false; | 1021 | cinode->can_cache_brlcks = false; |
955 | mutex_unlock(&cinode->lock_mutex); | 1022 | up_write(&cinode->lock_sem); |
956 | 1023 | ||
957 | kfree(buf); | 1024 | kfree(buf); |
958 | free_xid(xid); | 1025 | free_xid(xid); |
@@ -987,9 +1054,10 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
987 | 1054 | ||
988 | xid = get_xid(); | 1055 | xid = get_xid(); |
989 | 1056 | ||
990 | mutex_lock(&cinode->lock_mutex); | 1057 | /* we are going to update can_cache_brlcks here - need a write access */ |
1058 | down_write(&cinode->lock_sem); | ||
991 | if (!cinode->can_cache_brlcks) { | 1059 | if (!cinode->can_cache_brlcks) { |
992 | mutex_unlock(&cinode->lock_mutex); | 1060 | up_write(&cinode->lock_sem); |
993 | free_xid(xid); | 1061 | free_xid(xid); |
994 | return rc; | 1062 | return rc; |
995 | } | 1063 | } |
@@ -1005,7 +1073,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1005 | 1073 | ||
1006 | /* | 1074 | /* |
1007 | * Allocating count locks is enough because no FL_POSIX locks can be | 1075 | * Allocating count locks is enough because no FL_POSIX locks can be |
1008 | * added to the list while we are holding cinode->lock_mutex that | 1076 | * added to the list while we are holding cinode->lock_sem that |
1009 | * protects locking operations of this inode. | 1077 | * protects locking operations of this inode. |
1010 | */ | 1078 | */ |
1011 | for (; i < count; i++) { | 1079 | for (; i < count; i++) { |
@@ -1038,7 +1106,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1038 | type = CIFS_WRLCK; | 1106 | type = CIFS_WRLCK; |
1039 | lck = list_entry(el, struct lock_to_push, llist); | 1107 | lck = list_entry(el, struct lock_to_push, llist); |
1040 | lck->pid = flock->fl_pid; | 1108 | lck->pid = flock->fl_pid; |
1041 | lck->netfid = cfile->netfid; | 1109 | lck->netfid = cfile->fid.netfid; |
1042 | lck->length = length; | 1110 | lck->length = length; |
1043 | lck->type = type; | 1111 | lck->type = type; |
1044 | lck->offset = flock->fl_start; | 1112 | lck->offset = flock->fl_start; |
@@ -1060,7 +1128,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) | |||
1060 | 1128 | ||
1061 | out: | 1129 | out: |
1062 | cinode->can_cache_brlcks = false; | 1130 | cinode->can_cache_brlcks = false; |
1063 | mutex_unlock(&cinode->lock_mutex); | 1131 | up_write(&cinode->lock_sem); |
1064 | 1132 | ||
1065 | free_xid(xid); | 1133 | free_xid(xid); |
1066 | return rc; | 1134 | return rc; |
@@ -1083,7 +1151,7 @@ cifs_push_locks(struct cifsFileInfo *cfile) | |||
1083 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | 1151 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) |
1084 | return cifs_push_posix_locks(cfile); | 1152 | return cifs_push_posix_locks(cfile); |
1085 | 1153 | ||
1086 | return cifs_push_mandatory_locks(cfile); | 1154 | return tcon->ses->server->ops->push_mand_locks(cfile); |
1087 | } | 1155 | } |
1088 | 1156 | ||
1089 | static void | 1157 | static void |
@@ -1104,7 +1172,8 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, | |||
1104 | if (flock->fl_flags & FL_LEASE) | 1172 | if (flock->fl_flags & FL_LEASE) |
1105 | cFYI(1, "Lease on file - not implemented yet"); | 1173 | cFYI(1, "Lease on file - not implemented yet"); |
1106 | if (flock->fl_flags & | 1174 | if (flock->fl_flags & |
1107 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE))) | 1175 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | |
1176 | FL_ACCESS | FL_LEASE | FL_CLOSE))) | ||
1108 | cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags); | 1177 | cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags); |
1109 | 1178 | ||
1110 | *type = server->vals->large_lock_type; | 1179 | *type = server->vals->large_lock_type; |
@@ -1134,15 +1203,6 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, | |||
1134 | } | 1203 | } |
1135 | 1204 | ||
1136 | static int | 1205 | static int |
1137 | cifs_mandatory_lock(unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
1138 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
1139 | { | ||
1140 | return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->netfid, | ||
1141 | current->tgid, length, offset, unlock, lock, | ||
1142 | (__u8)type, wait, 0); | ||
1143 | } | ||
1144 | |||
1145 | static int | ||
1146 | cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | 1206 | cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, |
1147 | bool wait_flag, bool posix_lck, unsigned int xid) | 1207 | bool wait_flag, bool posix_lck, unsigned int xid) |
1148 | { | 1208 | { |
@@ -1151,7 +1211,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1151 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | 1211 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
1152 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 1212 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
1153 | struct TCP_Server_Info *server = tcon->ses->server; | 1213 | struct TCP_Server_Info *server = tcon->ses->server; |
1154 | __u16 netfid = cfile->netfid; | 1214 | __u16 netfid = cfile->fid.netfid; |
1155 | 1215 | ||
1156 | if (posix_lck) { | 1216 | if (posix_lck) { |
1157 | int posix_lock_type; | 1217 | int posix_lock_type; |
@@ -1175,11 +1235,11 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1175 | return rc; | 1235 | return rc; |
1176 | 1236 | ||
1177 | /* BB we could chain these into one lock request BB */ | 1237 | /* BB we could chain these into one lock request BB */ |
1178 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, type, | 1238 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type, |
1179 | 1, 0, false); | 1239 | 1, 0, false); |
1180 | if (rc == 0) { | 1240 | if (rc == 0) { |
1181 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1241 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1182 | type, 0, 1, false); | 1242 | type, 0, 1, false); |
1183 | flock->fl_type = F_UNLCK; | 1243 | flock->fl_type = F_UNLCK; |
1184 | if (rc != 0) | 1244 | if (rc != 0) |
1185 | cERROR(1, "Error unlocking previously locked " | 1245 | cERROR(1, "Error unlocking previously locked " |
@@ -1192,13 +1252,14 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1192 | return 0; | 1252 | return 0; |
1193 | } | 1253 | } |
1194 | 1254 | ||
1195 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1255 | type &= ~server->vals->exclusive_lock_type; |
1196 | type | server->vals->shared_lock_type, 1, 0, | 1256 | |
1197 | false); | 1257 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1258 | type | server->vals->shared_lock_type, | ||
1259 | 1, 0, false); | ||
1198 | if (rc == 0) { | 1260 | if (rc == 0) { |
1199 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1261 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1200 | type | server->vals->shared_lock_type, | 1262 | type | server->vals->shared_lock_type, 0, 1, false); |
1201 | 0, 1, false); | ||
1202 | flock->fl_type = F_RDLCK; | 1263 | flock->fl_type = F_RDLCK; |
1203 | if (rc != 0) | 1264 | if (rc != 0) |
1204 | cERROR(1, "Error unlocking previously locked " | 1265 | cERROR(1, "Error unlocking previously locked " |
@@ -1209,7 +1270,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1209 | return 0; | 1270 | return 0; |
1210 | } | 1271 | } |
1211 | 1272 | ||
1212 | static void | 1273 | void |
1213 | cifs_move_llist(struct list_head *source, struct list_head *dest) | 1274 | cifs_move_llist(struct list_head *source, struct list_head *dest) |
1214 | { | 1275 | { |
1215 | struct list_head *li, *tmp; | 1276 | struct list_head *li, *tmp; |
@@ -1217,7 +1278,7 @@ cifs_move_llist(struct list_head *source, struct list_head *dest) | |||
1217 | list_move(li, dest); | 1278 | list_move(li, dest); |
1218 | } | 1279 | } |
1219 | 1280 | ||
1220 | static void | 1281 | void |
1221 | cifs_free_llist(struct list_head *llist) | 1282 | cifs_free_llist(struct list_head *llist) |
1222 | { | 1283 | { |
1223 | struct cifsLockInfo *li, *tmp; | 1284 | struct cifsLockInfo *li, *tmp; |
@@ -1228,7 +1289,7 @@ cifs_free_llist(struct list_head *llist) | |||
1228 | } | 1289 | } |
1229 | } | 1290 | } |
1230 | 1291 | ||
1231 | static int | 1292 | int |
1232 | cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | 1293 | cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, |
1233 | unsigned int xid) | 1294 | unsigned int xid) |
1234 | { | 1295 | { |
@@ -1260,11 +1321,11 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1260 | if (!buf) | 1321 | if (!buf) |
1261 | return -ENOMEM; | 1322 | return -ENOMEM; |
1262 | 1323 | ||
1263 | mutex_lock(&cinode->lock_mutex); | 1324 | down_write(&cinode->lock_sem); |
1264 | for (i = 0; i < 2; i++) { | 1325 | for (i = 0; i < 2; i++) { |
1265 | cur = buf; | 1326 | cur = buf; |
1266 | num = 0; | 1327 | num = 0; |
1267 | list_for_each_entry_safe(li, tmp, &cfile->llist, llist) { | 1328 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { |
1268 | if (flock->fl_start > li->offset || | 1329 | if (flock->fl_start > li->offset || |
1269 | (flock->fl_start + length) < | 1330 | (flock->fl_start + length) < |
1270 | (li->offset + li->length)) | 1331 | (li->offset + li->length)) |
@@ -1295,7 +1356,8 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1295 | */ | 1356 | */ |
1296 | list_move(&li->llist, &tmp_llist); | 1357 | list_move(&li->llist, &tmp_llist); |
1297 | if (++num == max_num) { | 1358 | if (++num == max_num) { |
1298 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1359 | stored_rc = cifs_lockv(xid, tcon, |
1360 | cfile->fid.netfid, | ||
1299 | li->type, num, 0, buf); | 1361 | li->type, num, 0, buf); |
1300 | if (stored_rc) { | 1362 | if (stored_rc) { |
1301 | /* | 1363 | /* |
@@ -1304,7 +1366,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1304 | * list to the head of the file's list. | 1366 | * list to the head of the file's list. |
1305 | */ | 1367 | */ |
1306 | cifs_move_llist(&tmp_llist, | 1368 | cifs_move_llist(&tmp_llist, |
1307 | &cfile->llist); | 1369 | &cfile->llist->locks); |
1308 | rc = stored_rc; | 1370 | rc = stored_rc; |
1309 | } else | 1371 | } else |
1310 | /* | 1372 | /* |
@@ -1318,23 +1380,24 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | |||
1318 | cur++; | 1380 | cur++; |
1319 | } | 1381 | } |
1320 | if (num) { | 1382 | if (num) { |
1321 | stored_rc = cifs_lockv(xid, tcon, cfile->netfid, | 1383 | stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, |
1322 | types[i], num, 0, buf); | 1384 | types[i], num, 0, buf); |
1323 | if (stored_rc) { | 1385 | if (stored_rc) { |
1324 | cifs_move_llist(&tmp_llist, &cfile->llist); | 1386 | cifs_move_llist(&tmp_llist, |
1387 | &cfile->llist->locks); | ||
1325 | rc = stored_rc; | 1388 | rc = stored_rc; |
1326 | } else | 1389 | } else |
1327 | cifs_free_llist(&tmp_llist); | 1390 | cifs_free_llist(&tmp_llist); |
1328 | } | 1391 | } |
1329 | } | 1392 | } |
1330 | 1393 | ||
1331 | mutex_unlock(&cinode->lock_mutex); | 1394 | up_write(&cinode->lock_sem); |
1332 | kfree(buf); | 1395 | kfree(buf); |
1333 | return rc; | 1396 | return rc; |
1334 | } | 1397 | } |
1335 | 1398 | ||
1336 | static int | 1399 | static int |
1337 | cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | 1400 | cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, |
1338 | bool wait_flag, bool posix_lck, int lock, int unlock, | 1401 | bool wait_flag, bool posix_lck, int lock, int unlock, |
1339 | unsigned int xid) | 1402 | unsigned int xid) |
1340 | { | 1403 | { |
@@ -1343,7 +1406,6 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1343 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | 1406 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; |
1344 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 1407 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
1345 | struct TCP_Server_Info *server = tcon->ses->server; | 1408 | struct TCP_Server_Info *server = tcon->ses->server; |
1346 | __u16 netfid = cfile->netfid; | ||
1347 | 1409 | ||
1348 | if (posix_lck) { | 1410 | if (posix_lck) { |
1349 | int posix_lock_type; | 1411 | int posix_lock_type; |
@@ -1360,9 +1422,9 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1360 | if (unlock == 1) | 1422 | if (unlock == 1) |
1361 | posix_lock_type = CIFS_UNLCK; | 1423 | posix_lock_type = CIFS_UNLCK; |
1362 | 1424 | ||
1363 | rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid, | 1425 | rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, |
1364 | flock->fl_start, length, NULL, | 1426 | current->tgid, flock->fl_start, length, |
1365 | posix_lock_type, wait_flag); | 1427 | NULL, posix_lock_type, wait_flag); |
1366 | goto out; | 1428 | goto out; |
1367 | } | 1429 | } |
1368 | 1430 | ||
@@ -1379,8 +1441,8 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1379 | if (rc <= 0) | 1441 | if (rc <= 0) |
1380 | goto out; | 1442 | goto out; |
1381 | 1443 | ||
1382 | rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, | 1444 | rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, |
1383 | type, 1, 0, wait_flag); | 1445 | type, 1, 0, wait_flag); |
1384 | if (rc) { | 1446 | if (rc) { |
1385 | kfree(lock); | 1447 | kfree(lock); |
1386 | goto out; | 1448 | goto out; |
@@ -1388,7 +1450,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, | |||
1388 | 1450 | ||
1389 | cifs_lock_add(cfile, lock); | 1451 | cifs_lock_add(cfile, lock); |
1390 | } else if (unlock) | 1452 | } else if (unlock) |
1391 | rc = cifs_unlock_range(cfile, flock, xid); | 1453 | rc = server->ops->mand_unlock_range(cfile, flock, xid); |
1392 | 1454 | ||
1393 | out: | 1455 | out: |
1394 | if (flock->fl_flags & FL_POSIX) | 1456 | if (flock->fl_flags & FL_POSIX) |
@@ -1423,7 +1485,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) | |||
1423 | tcon->ses->server); | 1485 | tcon->ses->server); |
1424 | 1486 | ||
1425 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 1487 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
1426 | netfid = cfile->netfid; | 1488 | netfid = cfile->fid.netfid; |
1427 | cinode = CIFS_I(file->f_path.dentry->d_inode); | 1489 | cinode = CIFS_I(file->f_path.dentry->d_inode); |
1428 | 1490 | ||
1429 | if (cap_unix(tcon->ses) && | 1491 | if (cap_unix(tcon->ses) && |
@@ -1469,15 +1531,16 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | |||
1469 | cifsi->server_eof = end_of_write; | 1531 | cifsi->server_eof = end_of_write; |
1470 | } | 1532 | } |
1471 | 1533 | ||
1472 | static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | 1534 | static ssize_t |
1473 | const char *write_data, size_t write_size, | 1535 | cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data, |
1474 | loff_t *poffset) | 1536 | size_t write_size, loff_t *offset) |
1475 | { | 1537 | { |
1476 | int rc = 0; | 1538 | int rc = 0; |
1477 | unsigned int bytes_written = 0; | 1539 | unsigned int bytes_written = 0; |
1478 | unsigned int total_written; | 1540 | unsigned int total_written; |
1479 | struct cifs_sb_info *cifs_sb; | 1541 | struct cifs_sb_info *cifs_sb; |
1480 | struct cifs_tcon *pTcon; | 1542 | struct cifs_tcon *tcon; |
1543 | struct TCP_Server_Info *server; | ||
1481 | unsigned int xid; | 1544 | unsigned int xid; |
1482 | struct dentry *dentry = open_file->dentry; | 1545 | struct dentry *dentry = open_file->dentry; |
1483 | struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); | 1546 | struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); |
@@ -1486,9 +1549,13 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1486 | cifs_sb = CIFS_SB(dentry->d_sb); | 1549 | cifs_sb = CIFS_SB(dentry->d_sb); |
1487 | 1550 | ||
1488 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, | 1551 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, |
1489 | *poffset, dentry->d_name.name); | 1552 | *offset, dentry->d_name.name); |
1490 | 1553 | ||
1491 | pTcon = tlink_tcon(open_file->tlink); | 1554 | tcon = tlink_tcon(open_file->tlink); |
1555 | server = tcon->ses->server; | ||
1556 | |||
1557 | if (!server->ops->sync_write) | ||
1558 | return -ENOSYS; | ||
1492 | 1559 | ||
1493 | xid = get_xid(); | 1560 | xid = get_xid(); |
1494 | 1561 | ||
@@ -1514,13 +1581,12 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1514 | /* iov[0] is reserved for smb header */ | 1581 | /* iov[0] is reserved for smb header */ |
1515 | iov[1].iov_base = (char *)write_data + total_written; | 1582 | iov[1].iov_base = (char *)write_data + total_written; |
1516 | iov[1].iov_len = len; | 1583 | iov[1].iov_len = len; |
1517 | io_parms.netfid = open_file->netfid; | ||
1518 | io_parms.pid = pid; | 1584 | io_parms.pid = pid; |
1519 | io_parms.tcon = pTcon; | 1585 | io_parms.tcon = tcon; |
1520 | io_parms.offset = *poffset; | 1586 | io_parms.offset = *offset; |
1521 | io_parms.length = len; | 1587 | io_parms.length = len; |
1522 | rc = CIFSSMBWrite2(xid, &io_parms, &bytes_written, iov, | 1588 | rc = server->ops->sync_write(xid, open_file, &io_parms, |
1523 | 1, 0); | 1589 | &bytes_written, iov, 1); |
1524 | } | 1590 | } |
1525 | if (rc || (bytes_written == 0)) { | 1591 | if (rc || (bytes_written == 0)) { |
1526 | if (total_written) | 1592 | if (total_written) |
@@ -1531,18 +1597,18 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid, | |||
1531 | } | 1597 | } |
1532 | } else { | 1598 | } else { |
1533 | spin_lock(&dentry->d_inode->i_lock); | 1599 | spin_lock(&dentry->d_inode->i_lock); |
1534 | cifs_update_eof(cifsi, *poffset, bytes_written); | 1600 | cifs_update_eof(cifsi, *offset, bytes_written); |
1535 | spin_unlock(&dentry->d_inode->i_lock); | 1601 | spin_unlock(&dentry->d_inode->i_lock); |
1536 | *poffset += bytes_written; | 1602 | *offset += bytes_written; |
1537 | } | 1603 | } |
1538 | } | 1604 | } |
1539 | 1605 | ||
1540 | cifs_stats_bytes_written(pTcon, total_written); | 1606 | cifs_stats_bytes_written(tcon, total_written); |
1541 | 1607 | ||
1542 | if (total_written > 0) { | 1608 | if (total_written > 0) { |
1543 | spin_lock(&dentry->d_inode->i_lock); | 1609 | spin_lock(&dentry->d_inode->i_lock); |
1544 | if (*poffset > dentry->d_inode->i_size) | 1610 | if (*offset > dentry->d_inode->i_size) |
1545 | i_size_write(dentry->d_inode, *poffset); | 1611 | i_size_write(dentry->d_inode, *offset); |
1546 | spin_unlock(&dentry->d_inode->i_lock); | 1612 | spin_unlock(&dentry->d_inode->i_lock); |
1547 | } | 1613 | } |
1548 | mark_inode_dirty_sync(dentry->d_inode); | 1614 | mark_inode_dirty_sync(dentry->d_inode); |
@@ -1718,27 +1784,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) | |||
1718 | return rc; | 1784 | return rc; |
1719 | } | 1785 | } |
1720 | 1786 | ||
1721 | /* | ||
1722 | * Marshal up the iov array, reserving the first one for the header. Also, | ||
1723 | * set wdata->bytes. | ||
1724 | */ | ||
1725 | static void | ||
1726 | cifs_writepages_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata) | ||
1727 | { | ||
1728 | int i; | ||
1729 | struct inode *inode = wdata->cfile->dentry->d_inode; | ||
1730 | loff_t size = i_size_read(inode); | ||
1731 | |||
1732 | /* marshal up the pages into iov array */ | ||
1733 | wdata->bytes = 0; | ||
1734 | for (i = 0; i < wdata->nr_pages; i++) { | ||
1735 | iov[i + 1].iov_len = min(size - page_offset(wdata->pages[i]), | ||
1736 | (loff_t)PAGE_CACHE_SIZE); | ||
1737 | iov[i + 1].iov_base = kmap(wdata->pages[i]); | ||
1738 | wdata->bytes += iov[i + 1].iov_len; | ||
1739 | } | ||
1740 | } | ||
1741 | |||
1742 | static int cifs_writepages(struct address_space *mapping, | 1787 | static int cifs_writepages(struct address_space *mapping, |
1743 | struct writeback_control *wbc) | 1788 | struct writeback_control *wbc) |
1744 | { | 1789 | { |
@@ -1746,8 +1791,10 @@ static int cifs_writepages(struct address_space *mapping, | |||
1746 | bool done = false, scanned = false, range_whole = false; | 1791 | bool done = false, scanned = false, range_whole = false; |
1747 | pgoff_t end, index; | 1792 | pgoff_t end, index; |
1748 | struct cifs_writedata *wdata; | 1793 | struct cifs_writedata *wdata; |
1794 | struct TCP_Server_Info *server; | ||
1749 | struct page *page; | 1795 | struct page *page; |
1750 | int rc = 0; | 1796 | int rc = 0; |
1797 | loff_t isize = i_size_read(mapping->host); | ||
1751 | 1798 | ||
1752 | /* | 1799 | /* |
1753 | * If wsize is smaller than the page cache size, default to writing | 1800 | * If wsize is smaller than the page cache size, default to writing |
@@ -1852,7 +1899,7 @@ retry: | |||
1852 | */ | 1899 | */ |
1853 | set_page_writeback(page); | 1900 | set_page_writeback(page); |
1854 | 1901 | ||
1855 | if (page_offset(page) >= mapping->host->i_size) { | 1902 | if (page_offset(page) >= isize) { |
1856 | done = true; | 1903 | done = true; |
1857 | unlock_page(page); | 1904 | unlock_page(page); |
1858 | end_page_writeback(page); | 1905 | end_page_writeback(page); |
@@ -1883,7 +1930,12 @@ retry: | |||
1883 | wdata->sync_mode = wbc->sync_mode; | 1930 | wdata->sync_mode = wbc->sync_mode; |
1884 | wdata->nr_pages = nr_pages; | 1931 | wdata->nr_pages = nr_pages; |
1885 | wdata->offset = page_offset(wdata->pages[0]); | 1932 | wdata->offset = page_offset(wdata->pages[0]); |
1886 | wdata->marshal_iov = cifs_writepages_marshal_iov; | 1933 | wdata->pagesz = PAGE_CACHE_SIZE; |
1934 | wdata->tailsz = | ||
1935 | min(isize - page_offset(wdata->pages[nr_pages - 1]), | ||
1936 | (loff_t)PAGE_CACHE_SIZE); | ||
1937 | wdata->bytes = ((nr_pages - 1) * PAGE_CACHE_SIZE) + | ||
1938 | wdata->tailsz; | ||
1887 | 1939 | ||
1888 | do { | 1940 | do { |
1889 | if (wdata->cfile != NULL) | 1941 | if (wdata->cfile != NULL) |
@@ -1896,7 +1948,8 @@ retry: | |||
1896 | break; | 1948 | break; |
1897 | } | 1949 | } |
1898 | wdata->pid = wdata->cfile->pid; | 1950 | wdata->pid = wdata->cfile->pid; |
1899 | rc = cifs_async_writev(wdata); | 1951 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; |
1952 | rc = server->ops->async_writev(wdata); | ||
1900 | } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); | 1953 | } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); |
1901 | 1954 | ||
1902 | for (i = 0; i < nr_pages; ++i) | 1955 | for (i = 0; i < nr_pages; ++i) |
@@ -2054,6 +2107,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, | |||
2054 | unsigned int xid; | 2107 | unsigned int xid; |
2055 | int rc = 0; | 2108 | int rc = 0; |
2056 | struct cifs_tcon *tcon; | 2109 | struct cifs_tcon *tcon; |
2110 | struct TCP_Server_Info *server; | ||
2057 | struct cifsFileInfo *smbfile = file->private_data; | 2111 | struct cifsFileInfo *smbfile = file->private_data; |
2058 | struct inode *inode = file->f_path.dentry->d_inode; | 2112 | struct inode *inode = file->f_path.dentry->d_inode; |
2059 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 2113 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
@@ -2077,8 +2131,13 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, | |||
2077 | } | 2131 | } |
2078 | 2132 | ||
2079 | tcon = tlink_tcon(smbfile->tlink); | 2133 | tcon = tlink_tcon(smbfile->tlink); |
2080 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) | 2134 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { |
2081 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); | 2135 | server = tcon->ses->server; |
2136 | if (server->ops->flush) | ||
2137 | rc = server->ops->flush(xid, tcon, &smbfile->fid); | ||
2138 | else | ||
2139 | rc = -ENOSYS; | ||
2140 | } | ||
2082 | 2141 | ||
2083 | free_xid(xid); | 2142 | free_xid(xid); |
2084 | mutex_unlock(&inode->i_mutex); | 2143 | mutex_unlock(&inode->i_mutex); |
@@ -2090,6 +2149,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
2090 | unsigned int xid; | 2149 | unsigned int xid; |
2091 | int rc = 0; | 2150 | int rc = 0; |
2092 | struct cifs_tcon *tcon; | 2151 | struct cifs_tcon *tcon; |
2152 | struct TCP_Server_Info *server; | ||
2093 | struct cifsFileInfo *smbfile = file->private_data; | 2153 | struct cifsFileInfo *smbfile = file->private_data; |
2094 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2154 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2095 | struct inode *inode = file->f_mapping->host; | 2155 | struct inode *inode = file->f_mapping->host; |
@@ -2105,8 +2165,13 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
2105 | file->f_path.dentry->d_name.name, datasync); | 2165 | file->f_path.dentry->d_name.name, datasync); |
2106 | 2166 | ||
2107 | tcon = tlink_tcon(smbfile->tlink); | 2167 | tcon = tlink_tcon(smbfile->tlink); |
2108 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) | 2168 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { |
2109 | rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); | 2169 | server = tcon->ses->server; |
2170 | if (server->ops->flush) | ||
2171 | rc = server->ops->flush(xid, tcon, &smbfile->fid); | ||
2172 | else | ||
2173 | rc = -ENOSYS; | ||
2174 | } | ||
2110 | 2175 | ||
2111 | free_xid(xid); | 2176 | free_xid(xid); |
2112 | mutex_unlock(&inode->i_mutex); | 2177 | mutex_unlock(&inode->i_mutex); |
@@ -2172,20 +2237,6 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len) | |||
2172 | } | 2237 | } |
2173 | 2238 | ||
2174 | static void | 2239 | static void |
2175 | cifs_uncached_marshal_iov(struct kvec *iov, struct cifs_writedata *wdata) | ||
2176 | { | ||
2177 | int i; | ||
2178 | size_t bytes = wdata->bytes; | ||
2179 | |||
2180 | /* marshal up the pages into iov array */ | ||
2181 | for (i = 0; i < wdata->nr_pages; i++) { | ||
2182 | iov[i + 1].iov_len = min_t(size_t, bytes, PAGE_SIZE); | ||
2183 | iov[i + 1].iov_base = kmap(wdata->pages[i]); | ||
2184 | bytes -= iov[i + 1].iov_len; | ||
2185 | } | ||
2186 | } | ||
2187 | |||
2188 | static void | ||
2189 | cifs_uncached_writev_complete(struct work_struct *work) | 2240 | cifs_uncached_writev_complete(struct work_struct *work) |
2190 | { | 2241 | { |
2191 | int i; | 2242 | int i; |
@@ -2215,6 +2266,9 @@ static int | |||
2215 | cifs_uncached_retry_writev(struct cifs_writedata *wdata) | 2266 | cifs_uncached_retry_writev(struct cifs_writedata *wdata) |
2216 | { | 2267 | { |
2217 | int rc; | 2268 | int rc; |
2269 | struct TCP_Server_Info *server; | ||
2270 | |||
2271 | server = tlink_tcon(wdata->cfile->tlink)->ses->server; | ||
2218 | 2272 | ||
2219 | do { | 2273 | do { |
2220 | if (wdata->cfile->invalidHandle) { | 2274 | if (wdata->cfile->invalidHandle) { |
@@ -2222,7 +2276,7 @@ cifs_uncached_retry_writev(struct cifs_writedata *wdata) | |||
2222 | if (rc != 0) | 2276 | if (rc != 0) |
2223 | continue; | 2277 | continue; |
2224 | } | 2278 | } |
2225 | rc = cifs_async_writev(wdata); | 2279 | rc = server->ops->async_writev(wdata); |
2226 | } while (rc == -EAGAIN); | 2280 | } while (rc == -EAGAIN); |
2227 | 2281 | ||
2228 | return rc; | 2282 | return rc; |
@@ -2257,6 +2311,10 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2257 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2311 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2258 | open_file = file->private_data; | 2312 | open_file = file->private_data; |
2259 | tcon = tlink_tcon(open_file->tlink); | 2313 | tcon = tlink_tcon(open_file->tlink); |
2314 | |||
2315 | if (!tcon->ses->server->ops->async_writev) | ||
2316 | return -ENOSYS; | ||
2317 | |||
2260 | offset = *poffset; | 2318 | offset = *poffset; |
2261 | 2319 | ||
2262 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2320 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
@@ -2298,7 +2356,8 @@ cifs_iovec_write(struct file *file, const struct iovec *iov, | |||
2298 | wdata->cfile = cifsFileInfo_get(open_file); | 2356 | wdata->cfile = cifsFileInfo_get(open_file); |
2299 | wdata->pid = pid; | 2357 | wdata->pid = pid; |
2300 | wdata->bytes = cur_len; | 2358 | wdata->bytes = cur_len; |
2301 | wdata->marshal_iov = cifs_uncached_marshal_iov; | 2359 | wdata->pagesz = PAGE_SIZE; |
2360 | wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); | ||
2302 | rc = cifs_uncached_retry_writev(wdata); | 2361 | rc = cifs_uncached_retry_writev(wdata); |
2303 | if (rc) { | 2362 | if (rc) { |
2304 | kref_put(&wdata->refcount, cifs_writedata_release); | 2363 | kref_put(&wdata->refcount, cifs_writedata_release); |
@@ -2376,40 +2435,110 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | |||
2376 | return written; | 2435 | return written; |
2377 | } | 2436 | } |
2378 | 2437 | ||
2379 | ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | 2438 | static ssize_t |
2380 | unsigned long nr_segs, loff_t pos) | 2439 | cifs_writev(struct kiocb *iocb, const struct iovec *iov, |
2440 | unsigned long nr_segs, loff_t pos) | ||
2381 | { | 2441 | { |
2382 | struct inode *inode; | 2442 | struct file *file = iocb->ki_filp; |
2443 | struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; | ||
2444 | struct inode *inode = file->f_mapping->host; | ||
2445 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
2446 | struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; | ||
2447 | ssize_t rc = -EACCES; | ||
2383 | 2448 | ||
2384 | inode = iocb->ki_filp->f_path.dentry->d_inode; | 2449 | BUG_ON(iocb->ki_pos != pos); |
2385 | 2450 | ||
2386 | if (CIFS_I(inode)->clientCanCacheAll) | 2451 | sb_start_write(inode->i_sb); |
2387 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | 2452 | |
2453 | /* | ||
2454 | * We need to hold the sem to be sure nobody modifies lock list | ||
2455 | * with a brlock that prevents writing. | ||
2456 | */ | ||
2457 | down_read(&cinode->lock_sem); | ||
2458 | if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), | ||
2459 | server->vals->exclusive_lock_type, NULL, | ||
2460 | true)) { | ||
2461 | mutex_lock(&inode->i_mutex); | ||
2462 | rc = __generic_file_aio_write(iocb, iov, nr_segs, | ||
2463 | &iocb->ki_pos); | ||
2464 | mutex_unlock(&inode->i_mutex); | ||
2465 | } | ||
2466 | |||
2467 | if (rc > 0 || rc == -EIOCBQUEUED) { | ||
2468 | ssize_t err; | ||
2469 | |||
2470 | err = generic_write_sync(file, pos, rc); | ||
2471 | if (err < 0 && rc > 0) | ||
2472 | rc = err; | ||
2473 | } | ||
2474 | |||
2475 | up_read(&cinode->lock_sem); | ||
2476 | sb_end_write(inode->i_sb); | ||
2477 | return rc; | ||
2478 | } | ||
2479 | |||
2480 | ssize_t | ||
2481 | cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | ||
2482 | unsigned long nr_segs, loff_t pos) | ||
2483 | { | ||
2484 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; | ||
2485 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
2486 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
2487 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) | ||
2488 | iocb->ki_filp->private_data; | ||
2489 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
2388 | 2490 | ||
2491 | #ifdef CONFIG_CIFS_SMB2 | ||
2389 | /* | 2492 | /* |
2390 | * In strict cache mode we need to write the data to the server exactly | 2493 | * If we have an oplock for read and want to write a data to the file |
2391 | * from the pos to pos+len-1 rather than flush all affected pages | 2494 | * we need to store it in the page cache and then push it to the server |
2392 | * because it may cause a error with mandatory locks on these pages but | 2495 | * to be sure the next read will get a valid data. |
2393 | * not on the region from pos to ppos+len-1. | ||
2394 | */ | 2496 | */ |
2497 | if (!cinode->clientCanCacheAll && cinode->clientCanCacheRead) { | ||
2498 | ssize_t written; | ||
2499 | int rc; | ||
2395 | 2500 | ||
2396 | return cifs_user_writev(iocb, iov, nr_segs, pos); | 2501 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
2502 | rc = filemap_fdatawrite(inode->i_mapping); | ||
2503 | if (rc) | ||
2504 | return (ssize_t)rc; | ||
2505 | |||
2506 | return written; | ||
2507 | } | ||
2508 | #endif | ||
2509 | |||
2510 | /* | ||
2511 | * For non-oplocked files in strict cache mode we need to write the data | ||
2512 | * to the server exactly from the pos to pos+len-1 rather than flush all | ||
2513 | * affected pages because it may cause a error with mandatory locks on | ||
2514 | * these pages but not on the region from pos to ppos+len-1. | ||
2515 | */ | ||
2516 | |||
2517 | if (!cinode->clientCanCacheAll) | ||
2518 | return cifs_user_writev(iocb, iov, nr_segs, pos); | ||
2519 | |||
2520 | if (cap_unix(tcon->ses) && | ||
2521 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && | ||
2522 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | ||
2523 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | ||
2524 | |||
2525 | return cifs_writev(iocb, iov, nr_segs, pos); | ||
2397 | } | 2526 | } |
2398 | 2527 | ||
2399 | static struct cifs_readdata * | 2528 | static struct cifs_readdata * |
2400 | cifs_readdata_alloc(unsigned int nr_vecs, work_func_t complete) | 2529 | cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete) |
2401 | { | 2530 | { |
2402 | struct cifs_readdata *rdata; | 2531 | struct cifs_readdata *rdata; |
2403 | 2532 | ||
2404 | rdata = kzalloc(sizeof(*rdata) + | 2533 | rdata = kzalloc(sizeof(*rdata) + (sizeof(struct page *) * nr_pages), |
2405 | sizeof(struct kvec) * nr_vecs, GFP_KERNEL); | 2534 | GFP_KERNEL); |
2406 | if (rdata != NULL) { | 2535 | if (rdata != NULL) { |
2407 | kref_init(&rdata->refcount); | 2536 | kref_init(&rdata->refcount); |
2408 | INIT_LIST_HEAD(&rdata->list); | 2537 | INIT_LIST_HEAD(&rdata->list); |
2409 | init_completion(&rdata->done); | 2538 | init_completion(&rdata->done); |
2410 | INIT_WORK(&rdata->work, complete); | 2539 | INIT_WORK(&rdata->work, complete); |
2411 | INIT_LIST_HEAD(&rdata->pages); | ||
2412 | } | 2540 | } |
2541 | |||
2413 | return rdata; | 2542 | return rdata; |
2414 | } | 2543 | } |
2415 | 2544 | ||
@@ -2426,25 +2555,25 @@ cifs_readdata_release(struct kref *refcount) | |||
2426 | } | 2555 | } |
2427 | 2556 | ||
2428 | static int | 2557 | static int |
2429 | cifs_read_allocate_pages(struct list_head *list, unsigned int npages) | 2558 | cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages) |
2430 | { | 2559 | { |
2431 | int rc = 0; | 2560 | int rc = 0; |
2432 | struct page *page, *tpage; | 2561 | struct page *page; |
2433 | unsigned int i; | 2562 | unsigned int i; |
2434 | 2563 | ||
2435 | for (i = 0; i < npages; i++) { | 2564 | for (i = 0; i < nr_pages; i++) { |
2436 | page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); | 2565 | page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); |
2437 | if (!page) { | 2566 | if (!page) { |
2438 | rc = -ENOMEM; | 2567 | rc = -ENOMEM; |
2439 | break; | 2568 | break; |
2440 | } | 2569 | } |
2441 | list_add(&page->lru, list); | 2570 | rdata->pages[i] = page; |
2442 | } | 2571 | } |
2443 | 2572 | ||
2444 | if (rc) { | 2573 | if (rc) { |
2445 | list_for_each_entry_safe(page, tpage, list, lru) { | 2574 | for (i = 0; i < nr_pages; i++) { |
2446 | list_del(&page->lru); | 2575 | put_page(rdata->pages[i]); |
2447 | put_page(page); | 2576 | rdata->pages[i] = NULL; |
2448 | } | 2577 | } |
2449 | } | 2578 | } |
2450 | return rc; | 2579 | return rc; |
@@ -2453,13 +2582,13 @@ cifs_read_allocate_pages(struct list_head *list, unsigned int npages) | |||
2453 | static void | 2582 | static void |
2454 | cifs_uncached_readdata_release(struct kref *refcount) | 2583 | cifs_uncached_readdata_release(struct kref *refcount) |
2455 | { | 2584 | { |
2456 | struct page *page, *tpage; | ||
2457 | struct cifs_readdata *rdata = container_of(refcount, | 2585 | struct cifs_readdata *rdata = container_of(refcount, |
2458 | struct cifs_readdata, refcount); | 2586 | struct cifs_readdata, refcount); |
2587 | unsigned int i; | ||
2459 | 2588 | ||
2460 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 2589 | for (i = 0; i < rdata->nr_pages; i++) { |
2461 | list_del(&page->lru); | 2590 | put_page(rdata->pages[i]); |
2462 | put_page(page); | 2591 | rdata->pages[i] = NULL; |
2463 | } | 2592 | } |
2464 | cifs_readdata_release(refcount); | 2593 | cifs_readdata_release(refcount); |
2465 | } | 2594 | } |
@@ -2468,6 +2597,9 @@ static int | |||
2468 | cifs_retry_async_readv(struct cifs_readdata *rdata) | 2597 | cifs_retry_async_readv(struct cifs_readdata *rdata) |
2469 | { | 2598 | { |
2470 | int rc; | 2599 | int rc; |
2600 | struct TCP_Server_Info *server; | ||
2601 | |||
2602 | server = tlink_tcon(rdata->cfile->tlink)->ses->server; | ||
2471 | 2603 | ||
2472 | do { | 2604 | do { |
2473 | if (rdata->cfile->invalidHandle) { | 2605 | if (rdata->cfile->invalidHandle) { |
@@ -2475,7 +2607,7 @@ cifs_retry_async_readv(struct cifs_readdata *rdata) | |||
2475 | if (rc != 0) | 2607 | if (rc != 0) |
2476 | continue; | 2608 | continue; |
2477 | } | 2609 | } |
2478 | rc = cifs_async_readv(rdata); | 2610 | rc = server->ops->async_readv(rdata); |
2479 | } while (rc == -EAGAIN); | 2611 | } while (rc == -EAGAIN); |
2480 | 2612 | ||
2481 | return rc; | 2613 | return rc; |
@@ -2500,17 +2632,18 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, const struct iovec *iov, | |||
2500 | int rc = 0; | 2632 | int rc = 0; |
2501 | struct iov_iter ii; | 2633 | struct iov_iter ii; |
2502 | size_t pos = rdata->offset - offset; | 2634 | size_t pos = rdata->offset - offset; |
2503 | struct page *page, *tpage; | ||
2504 | ssize_t remaining = rdata->bytes; | 2635 | ssize_t remaining = rdata->bytes; |
2505 | unsigned char *pdata; | 2636 | unsigned char *pdata; |
2637 | unsigned int i; | ||
2506 | 2638 | ||
2507 | /* set up iov_iter and advance to the correct offset */ | 2639 | /* set up iov_iter and advance to the correct offset */ |
2508 | iov_iter_init(&ii, iov, nr_segs, iov_length(iov, nr_segs), 0); | 2640 | iov_iter_init(&ii, iov, nr_segs, iov_length(iov, nr_segs), 0); |
2509 | iov_iter_advance(&ii, pos); | 2641 | iov_iter_advance(&ii, pos); |
2510 | 2642 | ||
2511 | *copied = 0; | 2643 | *copied = 0; |
2512 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 2644 | for (i = 0; i < rdata->nr_pages; i++) { |
2513 | ssize_t copy; | 2645 | ssize_t copy; |
2646 | struct page *page = rdata->pages[i]; | ||
2514 | 2647 | ||
2515 | /* copy a whole page or whatever's left */ | 2648 | /* copy a whole page or whatever's left */ |
2516 | copy = min_t(ssize_t, remaining, PAGE_SIZE); | 2649 | copy = min_t(ssize_t, remaining, PAGE_SIZE); |
@@ -2530,9 +2663,6 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, const struct iovec *iov, | |||
2530 | iov_iter_advance(&ii, copy); | 2663 | iov_iter_advance(&ii, copy); |
2531 | } | 2664 | } |
2532 | } | 2665 | } |
2533 | |||
2534 | list_del(&page->lru); | ||
2535 | put_page(page); | ||
2536 | } | 2666 | } |
2537 | 2667 | ||
2538 | return rc; | 2668 | return rc; |
@@ -2544,59 +2674,56 @@ cifs_uncached_readv_complete(struct work_struct *work) | |||
2544 | struct cifs_readdata *rdata = container_of(work, | 2674 | struct cifs_readdata *rdata = container_of(work, |
2545 | struct cifs_readdata, work); | 2675 | struct cifs_readdata, work); |
2546 | 2676 | ||
2547 | /* if the result is non-zero then the pages weren't kmapped */ | ||
2548 | if (rdata->result == 0) { | ||
2549 | struct page *page; | ||
2550 | |||
2551 | list_for_each_entry(page, &rdata->pages, lru) | ||
2552 | kunmap(page); | ||
2553 | } | ||
2554 | |||
2555 | complete(&rdata->done); | 2677 | complete(&rdata->done); |
2556 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); | 2678 | kref_put(&rdata->refcount, cifs_uncached_readdata_release); |
2557 | } | 2679 | } |
2558 | 2680 | ||
2559 | static int | 2681 | static int |
2560 | cifs_uncached_read_marshal_iov(struct cifs_readdata *rdata, | 2682 | cifs_uncached_read_into_pages(struct TCP_Server_Info *server, |
2561 | unsigned int remaining) | 2683 | struct cifs_readdata *rdata, unsigned int len) |
2562 | { | 2684 | { |
2563 | int len = 0; | 2685 | int total_read = 0, result = 0; |
2564 | struct page *page, *tpage; | 2686 | unsigned int i; |
2687 | unsigned int nr_pages = rdata->nr_pages; | ||
2688 | struct kvec iov; | ||
2689 | |||
2690 | rdata->tailsz = PAGE_SIZE; | ||
2691 | for (i = 0; i < nr_pages; i++) { | ||
2692 | struct page *page = rdata->pages[i]; | ||
2565 | 2693 | ||
2566 | rdata->nr_iov = 1; | 2694 | if (len >= PAGE_SIZE) { |
2567 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | ||
2568 | if (remaining >= PAGE_SIZE) { | ||
2569 | /* enough data to fill the page */ | 2695 | /* enough data to fill the page */ |
2570 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 2696 | iov.iov_base = kmap(page); |
2571 | rdata->iov[rdata->nr_iov].iov_len = PAGE_SIZE; | 2697 | iov.iov_len = PAGE_SIZE; |
2572 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 2698 | cFYI(1, "%u: iov_base=%p iov_len=%zu", |
2573 | rdata->nr_iov, page->index, | 2699 | i, iov.iov_base, iov.iov_len); |
2574 | rdata->iov[rdata->nr_iov].iov_base, | 2700 | len -= PAGE_SIZE; |
2575 | rdata->iov[rdata->nr_iov].iov_len); | 2701 | } else if (len > 0) { |
2576 | ++rdata->nr_iov; | ||
2577 | len += PAGE_SIZE; | ||
2578 | remaining -= PAGE_SIZE; | ||
2579 | } else if (remaining > 0) { | ||
2580 | /* enough for partial page, fill and zero the rest */ | 2702 | /* enough for partial page, fill and zero the rest */ |
2581 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 2703 | iov.iov_base = kmap(page); |
2582 | rdata->iov[rdata->nr_iov].iov_len = remaining; | 2704 | iov.iov_len = len; |
2583 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 2705 | cFYI(1, "%u: iov_base=%p iov_len=%zu", |
2584 | rdata->nr_iov, page->index, | 2706 | i, iov.iov_base, iov.iov_len); |
2585 | rdata->iov[rdata->nr_iov].iov_base, | 2707 | memset(iov.iov_base + len, '\0', PAGE_SIZE - len); |
2586 | rdata->iov[rdata->nr_iov].iov_len); | 2708 | rdata->tailsz = len; |
2587 | memset(rdata->iov[rdata->nr_iov].iov_base + remaining, | 2709 | len = 0; |
2588 | '\0', PAGE_SIZE - remaining); | ||
2589 | ++rdata->nr_iov; | ||
2590 | len += remaining; | ||
2591 | remaining = 0; | ||
2592 | } else { | 2710 | } else { |
2593 | /* no need to hold page hostage */ | 2711 | /* no need to hold page hostage */ |
2594 | list_del(&page->lru); | 2712 | rdata->pages[i] = NULL; |
2713 | rdata->nr_pages--; | ||
2595 | put_page(page); | 2714 | put_page(page); |
2715 | continue; | ||
2596 | } | 2716 | } |
2717 | |||
2718 | result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len); | ||
2719 | kunmap(page); | ||
2720 | if (result < 0) | ||
2721 | break; | ||
2722 | |||
2723 | total_read += result; | ||
2597 | } | 2724 | } |
2598 | 2725 | ||
2599 | return len; | 2726 | return total_read > 0 ? total_read : result; |
2600 | } | 2727 | } |
2601 | 2728 | ||
2602 | static ssize_t | 2729 | static ssize_t |
@@ -2627,6 +2754,9 @@ cifs_iovec_read(struct file *file, const struct iovec *iov, | |||
2627 | open_file = file->private_data; | 2754 | open_file = file->private_data; |
2628 | tcon = tlink_tcon(open_file->tlink); | 2755 | tcon = tlink_tcon(open_file->tlink); |
2629 | 2756 | ||
2757 | if (!tcon->ses->server->ops->async_readv) | ||
2758 | return -ENOSYS; | ||
2759 | |||
2630 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2760 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
2631 | pid = open_file->pid; | 2761 | pid = open_file->pid; |
2632 | else | 2762 | else |
@@ -2647,15 +2777,17 @@ cifs_iovec_read(struct file *file, const struct iovec *iov, | |||
2647 | goto error; | 2777 | goto error; |
2648 | } | 2778 | } |
2649 | 2779 | ||
2650 | rc = cifs_read_allocate_pages(&rdata->pages, npages); | 2780 | rc = cifs_read_allocate_pages(rdata, npages); |
2651 | if (rc) | 2781 | if (rc) |
2652 | goto error; | 2782 | goto error; |
2653 | 2783 | ||
2654 | rdata->cfile = cifsFileInfo_get(open_file); | 2784 | rdata->cfile = cifsFileInfo_get(open_file); |
2785 | rdata->nr_pages = npages; | ||
2655 | rdata->offset = offset; | 2786 | rdata->offset = offset; |
2656 | rdata->bytes = cur_len; | 2787 | rdata->bytes = cur_len; |
2657 | rdata->pid = pid; | 2788 | rdata->pid = pid; |
2658 | rdata->marshal_iov = cifs_uncached_read_marshal_iov; | 2789 | rdata->pagesz = PAGE_SIZE; |
2790 | rdata->read_into_pages = cifs_uncached_read_into_pages; | ||
2659 | 2791 | ||
2660 | rc = cifs_retry_async_readv(rdata); | 2792 | rc = cifs_retry_async_readv(rdata); |
2661 | error: | 2793 | error: |
@@ -2706,6 +2838,10 @@ restart_loop: | |||
2706 | cifs_stats_bytes_read(tcon, total_read); | 2838 | cifs_stats_bytes_read(tcon, total_read); |
2707 | *poffset += total_read; | 2839 | *poffset += total_read; |
2708 | 2840 | ||
2841 | /* mask nodata case */ | ||
2842 | if (rc == -ENODATA) | ||
2843 | rc = 0; | ||
2844 | |||
2709 | return total_read ? total_read : rc; | 2845 | return total_read ? total_read : rc; |
2710 | } | 2846 | } |
2711 | 2847 | ||
@@ -2721,15 +2857,17 @@ ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, | |||
2721 | return read; | 2857 | return read; |
2722 | } | 2858 | } |
2723 | 2859 | ||
2724 | ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | 2860 | ssize_t |
2725 | unsigned long nr_segs, loff_t pos) | 2861 | cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, |
2862 | unsigned long nr_segs, loff_t pos) | ||
2726 | { | 2863 | { |
2727 | struct inode *inode; | 2864 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
2728 | 2865 | struct cifsInodeInfo *cinode = CIFS_I(inode); | |
2729 | inode = iocb->ki_filp->f_path.dentry->d_inode; | 2866 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
2730 | 2867 | struct cifsFileInfo *cfile = (struct cifsFileInfo *) | |
2731 | if (CIFS_I(inode)->clientCanCacheRead) | 2868 | iocb->ki_filp->private_data; |
2732 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | 2869 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
2870 | int rc = -EACCES; | ||
2733 | 2871 | ||
2734 | /* | 2872 | /* |
2735 | * In strict cache mode we need to read from the server all the time | 2873 | * In strict cache mode we need to read from the server all the time |
@@ -2739,12 +2877,29 @@ ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | |||
2739 | * on pages affected by this read but not on the region from pos to | 2877 | * on pages affected by this read but not on the region from pos to |
2740 | * pos+len-1. | 2878 | * pos+len-1. |
2741 | */ | 2879 | */ |
2880 | if (!cinode->clientCanCacheRead) | ||
2881 | return cifs_user_readv(iocb, iov, nr_segs, pos); | ||
2882 | |||
2883 | if (cap_unix(tcon->ses) && | ||
2884 | (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && | ||
2885 | ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) | ||
2886 | return generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
2742 | 2887 | ||
2743 | return cifs_user_readv(iocb, iov, nr_segs, pos); | 2888 | /* |
2889 | * We need to hold the sem to be sure nobody modifies lock list | ||
2890 | * with a brlock that prevents reading. | ||
2891 | */ | ||
2892 | down_read(&cinode->lock_sem); | ||
2893 | if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), | ||
2894 | tcon->ses->server->vals->shared_lock_type, | ||
2895 | NULL, true)) | ||
2896 | rc = generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
2897 | up_read(&cinode->lock_sem); | ||
2898 | return rc; | ||
2744 | } | 2899 | } |
2745 | 2900 | ||
2746 | static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | 2901 | static ssize_t |
2747 | loff_t *poffset) | 2902 | cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) |
2748 | { | 2903 | { |
2749 | int rc = -EACCES; | 2904 | int rc = -EACCES; |
2750 | unsigned int bytes_read = 0; | 2905 | unsigned int bytes_read = 0; |
@@ -2753,8 +2908,9 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2753 | unsigned int rsize; | 2908 | unsigned int rsize; |
2754 | struct cifs_sb_info *cifs_sb; | 2909 | struct cifs_sb_info *cifs_sb; |
2755 | struct cifs_tcon *tcon; | 2910 | struct cifs_tcon *tcon; |
2911 | struct TCP_Server_Info *server; | ||
2756 | unsigned int xid; | 2912 | unsigned int xid; |
2757 | char *current_offset; | 2913 | char *cur_offset; |
2758 | struct cifsFileInfo *open_file; | 2914 | struct cifsFileInfo *open_file; |
2759 | struct cifs_io_parms io_parms; | 2915 | struct cifs_io_parms io_parms; |
2760 | int buf_type = CIFS_NO_BUFFER; | 2916 | int buf_type = CIFS_NO_BUFFER; |
@@ -2773,6 +2929,12 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2773 | } | 2929 | } |
2774 | open_file = file->private_data; | 2930 | open_file = file->private_data; |
2775 | tcon = tlink_tcon(open_file->tlink); | 2931 | tcon = tlink_tcon(open_file->tlink); |
2932 | server = tcon->ses->server; | ||
2933 | |||
2934 | if (!server->ops->sync_read) { | ||
2935 | free_xid(xid); | ||
2936 | return -ENOSYS; | ||
2937 | } | ||
2776 | 2938 | ||
2777 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) | 2939 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) |
2778 | pid = open_file->pid; | 2940 | pid = open_file->pid; |
@@ -2782,9 +2944,8 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2782 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) | 2944 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
2783 | cFYI(1, "attempting read on write only file instance"); | 2945 | cFYI(1, "attempting read on write only file instance"); |
2784 | 2946 | ||
2785 | for (total_read = 0, current_offset = read_data; | 2947 | for (total_read = 0, cur_offset = read_data; read_size > total_read; |
2786 | read_size > total_read; | 2948 | total_read += bytes_read, cur_offset += bytes_read) { |
2787 | total_read += bytes_read, current_offset += bytes_read) { | ||
2788 | current_read_size = min_t(uint, read_size - total_read, rsize); | 2949 | current_read_size = min_t(uint, read_size - total_read, rsize); |
2789 | /* | 2950 | /* |
2790 | * For windows me and 9x we do not want to request more than it | 2951 | * For windows me and 9x we do not want to request more than it |
@@ -2802,13 +2963,13 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2802 | if (rc != 0) | 2963 | if (rc != 0) |
2803 | break; | 2964 | break; |
2804 | } | 2965 | } |
2805 | io_parms.netfid = open_file->netfid; | ||
2806 | io_parms.pid = pid; | 2966 | io_parms.pid = pid; |
2807 | io_parms.tcon = tcon; | 2967 | io_parms.tcon = tcon; |
2808 | io_parms.offset = *poffset; | 2968 | io_parms.offset = *offset; |
2809 | io_parms.length = current_read_size; | 2969 | io_parms.length = current_read_size; |
2810 | rc = CIFSSMBRead(xid, &io_parms, &bytes_read, | 2970 | rc = server->ops->sync_read(xid, open_file, &io_parms, |
2811 | ¤t_offset, &buf_type); | 2971 | &bytes_read, &cur_offset, |
2972 | &buf_type); | ||
2812 | } | 2973 | } |
2813 | if (rc || (bytes_read == 0)) { | 2974 | if (rc || (bytes_read == 0)) { |
2814 | if (total_read) { | 2975 | if (total_read) { |
@@ -2819,7 +2980,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
2819 | } | 2980 | } |
2820 | } else { | 2981 | } else { |
2821 | cifs_stats_bytes_read(tcon, total_read); | 2982 | cifs_stats_bytes_read(tcon, total_read); |
2822 | *poffset += bytes_read; | 2983 | *offset += bytes_read; |
2823 | } | 2984 | } |
2824 | } | 2985 | } |
2825 | free_xid(xid); | 2986 | free_xid(xid); |
@@ -2885,16 +3046,16 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
2885 | static void | 3046 | static void |
2886 | cifs_readv_complete(struct work_struct *work) | 3047 | cifs_readv_complete(struct work_struct *work) |
2887 | { | 3048 | { |
3049 | unsigned int i; | ||
2888 | struct cifs_readdata *rdata = container_of(work, | 3050 | struct cifs_readdata *rdata = container_of(work, |
2889 | struct cifs_readdata, work); | 3051 | struct cifs_readdata, work); |
2890 | struct page *page, *tpage; | ||
2891 | 3052 | ||
2892 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 3053 | for (i = 0; i < rdata->nr_pages; i++) { |
2893 | list_del(&page->lru); | 3054 | struct page *page = rdata->pages[i]; |
3055 | |||
2894 | lru_cache_add_file(page); | 3056 | lru_cache_add_file(page); |
2895 | 3057 | ||
2896 | if (rdata->result == 0) { | 3058 | if (rdata->result == 0) { |
2897 | kunmap(page); | ||
2898 | flush_dcache_page(page); | 3059 | flush_dcache_page(page); |
2899 | SetPageUptodate(page); | 3060 | SetPageUptodate(page); |
2900 | } | 3061 | } |
@@ -2905,49 +3066,48 @@ cifs_readv_complete(struct work_struct *work) | |||
2905 | cifs_readpage_to_fscache(rdata->mapping->host, page); | 3066 | cifs_readpage_to_fscache(rdata->mapping->host, page); |
2906 | 3067 | ||
2907 | page_cache_release(page); | 3068 | page_cache_release(page); |
3069 | rdata->pages[i] = NULL; | ||
2908 | } | 3070 | } |
2909 | kref_put(&rdata->refcount, cifs_readdata_release); | 3071 | kref_put(&rdata->refcount, cifs_readdata_release); |
2910 | } | 3072 | } |
2911 | 3073 | ||
2912 | static int | 3074 | static int |
2913 | cifs_readpages_marshal_iov(struct cifs_readdata *rdata, unsigned int remaining) | 3075 | cifs_readpages_read_into_pages(struct TCP_Server_Info *server, |
3076 | struct cifs_readdata *rdata, unsigned int len) | ||
2914 | { | 3077 | { |
2915 | int len = 0; | 3078 | int total_read = 0, result = 0; |
2916 | struct page *page, *tpage; | 3079 | unsigned int i; |
2917 | u64 eof; | 3080 | u64 eof; |
2918 | pgoff_t eof_index; | 3081 | pgoff_t eof_index; |
3082 | unsigned int nr_pages = rdata->nr_pages; | ||
3083 | struct kvec iov; | ||
2919 | 3084 | ||
2920 | /* determine the eof that the server (probably) has */ | 3085 | /* determine the eof that the server (probably) has */ |
2921 | eof = CIFS_I(rdata->mapping->host)->server_eof; | 3086 | eof = CIFS_I(rdata->mapping->host)->server_eof; |
2922 | eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0; | 3087 | eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0; |
2923 | cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index); | 3088 | cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index); |
2924 | 3089 | ||
2925 | rdata->nr_iov = 1; | 3090 | rdata->tailsz = PAGE_CACHE_SIZE; |
2926 | list_for_each_entry_safe(page, tpage, &rdata->pages, lru) { | 3091 | for (i = 0; i < nr_pages; i++) { |
2927 | if (remaining >= PAGE_CACHE_SIZE) { | 3092 | struct page *page = rdata->pages[i]; |
3093 | |||
3094 | if (len >= PAGE_CACHE_SIZE) { | ||
2928 | /* enough data to fill the page */ | 3095 | /* enough data to fill the page */ |
2929 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 3096 | iov.iov_base = kmap(page); |
2930 | rdata->iov[rdata->nr_iov].iov_len = PAGE_CACHE_SIZE; | 3097 | iov.iov_len = PAGE_CACHE_SIZE; |
2931 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 3098 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
2932 | rdata->nr_iov, page->index, | 3099 | i, page->index, iov.iov_base, iov.iov_len); |
2933 | rdata->iov[rdata->nr_iov].iov_base, | 3100 | len -= PAGE_CACHE_SIZE; |
2934 | rdata->iov[rdata->nr_iov].iov_len); | 3101 | } else if (len > 0) { |
2935 | ++rdata->nr_iov; | ||
2936 | len += PAGE_CACHE_SIZE; | ||
2937 | remaining -= PAGE_CACHE_SIZE; | ||
2938 | } else if (remaining > 0) { | ||
2939 | /* enough for partial page, fill and zero the rest */ | 3102 | /* enough for partial page, fill and zero the rest */ |
2940 | rdata->iov[rdata->nr_iov].iov_base = kmap(page); | 3103 | iov.iov_base = kmap(page); |
2941 | rdata->iov[rdata->nr_iov].iov_len = remaining; | 3104 | iov.iov_len = len; |
2942 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", | 3105 | cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu", |
2943 | rdata->nr_iov, page->index, | 3106 | i, page->index, iov.iov_base, iov.iov_len); |
2944 | rdata->iov[rdata->nr_iov].iov_base, | 3107 | memset(iov.iov_base + len, |
2945 | rdata->iov[rdata->nr_iov].iov_len); | 3108 | '\0', PAGE_CACHE_SIZE - len); |
2946 | memset(rdata->iov[rdata->nr_iov].iov_base + remaining, | 3109 | rdata->tailsz = len; |
2947 | '\0', PAGE_CACHE_SIZE - remaining); | 3110 | len = 0; |
2948 | ++rdata->nr_iov; | ||
2949 | len += remaining; | ||
2950 | remaining = 0; | ||
2951 | } else if (page->index > eof_index) { | 3111 | } else if (page->index > eof_index) { |
2952 | /* | 3112 | /* |
2953 | * The VFS will not try to do readahead past the | 3113 | * The VFS will not try to do readahead past the |
@@ -2958,22 +3118,33 @@ cifs_readpages_marshal_iov(struct cifs_readdata *rdata, unsigned int remaining) | |||
2958 | * fill them until the writes are flushed. | 3118 | * fill them until the writes are flushed. |
2959 | */ | 3119 | */ |
2960 | zero_user(page, 0, PAGE_CACHE_SIZE); | 3120 | zero_user(page, 0, PAGE_CACHE_SIZE); |
2961 | list_del(&page->lru); | ||
2962 | lru_cache_add_file(page); | 3121 | lru_cache_add_file(page); |
2963 | flush_dcache_page(page); | 3122 | flush_dcache_page(page); |
2964 | SetPageUptodate(page); | 3123 | SetPageUptodate(page); |
2965 | unlock_page(page); | 3124 | unlock_page(page); |
2966 | page_cache_release(page); | 3125 | page_cache_release(page); |
3126 | rdata->pages[i] = NULL; | ||
3127 | rdata->nr_pages--; | ||
3128 | continue; | ||
2967 | } else { | 3129 | } else { |
2968 | /* no need to hold page hostage */ | 3130 | /* no need to hold page hostage */ |
2969 | list_del(&page->lru); | ||
2970 | lru_cache_add_file(page); | 3131 | lru_cache_add_file(page); |
2971 | unlock_page(page); | 3132 | unlock_page(page); |
2972 | page_cache_release(page); | 3133 | page_cache_release(page); |
3134 | rdata->pages[i] = NULL; | ||
3135 | rdata->nr_pages--; | ||
3136 | continue; | ||
2973 | } | 3137 | } |
3138 | |||
3139 | result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len); | ||
3140 | kunmap(page); | ||
3141 | if (result < 0) | ||
3142 | break; | ||
3143 | |||
3144 | total_read += result; | ||
2974 | } | 3145 | } |
2975 | 3146 | ||
2976 | return len; | 3147 | return total_read > 0 ? total_read : result; |
2977 | } | 3148 | } |
2978 | 3149 | ||
2979 | static int cifs_readpages(struct file *file, struct address_space *mapping, | 3150 | static int cifs_readpages(struct file *file, struct address_space *mapping, |
@@ -3027,6 +3198,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
3027 | * the rdata->pages, then we want them in increasing order. | 3198 | * the rdata->pages, then we want them in increasing order. |
3028 | */ | 3199 | */ |
3029 | while (!list_empty(page_list)) { | 3200 | while (!list_empty(page_list)) { |
3201 | unsigned int i; | ||
3030 | unsigned int bytes = PAGE_CACHE_SIZE; | 3202 | unsigned int bytes = PAGE_CACHE_SIZE; |
3031 | unsigned int expected_index; | 3203 | unsigned int expected_index; |
3032 | unsigned int nr_pages = 1; | 3204 | unsigned int nr_pages = 1; |
@@ -3096,14 +3268,18 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
3096 | rdata->offset = offset; | 3268 | rdata->offset = offset; |
3097 | rdata->bytes = bytes; | 3269 | rdata->bytes = bytes; |
3098 | rdata->pid = pid; | 3270 | rdata->pid = pid; |
3099 | rdata->marshal_iov = cifs_readpages_marshal_iov; | 3271 | rdata->pagesz = PAGE_CACHE_SIZE; |
3100 | list_splice_init(&tmplist, &rdata->pages); | 3272 | rdata->read_into_pages = cifs_readpages_read_into_pages; |
3273 | |||
3274 | list_for_each_entry_safe(page, tpage, &tmplist, lru) { | ||
3275 | list_del(&page->lru); | ||
3276 | rdata->pages[rdata->nr_pages++] = page; | ||
3277 | } | ||
3101 | 3278 | ||
3102 | rc = cifs_retry_async_readv(rdata); | 3279 | rc = cifs_retry_async_readv(rdata); |
3103 | if (rc != 0) { | 3280 | if (rc != 0) { |
3104 | list_for_each_entry_safe(page, tpage, &rdata->pages, | 3281 | for (i = 0; i < rdata->nr_pages; i++) { |
3105 | lru) { | 3282 | page = rdata->pages[i]; |
3106 | list_del(&page->lru); | ||
3107 | lru_cache_add_file(page); | 3283 | lru_cache_add_file(page); |
3108 | unlock_page(page); | 3284 | unlock_page(page); |
3109 | page_cache_release(page); | 3285 | page_cache_release(page); |
@@ -3347,6 +3523,7 @@ void cifs_oplock_break(struct work_struct *work) | |||
3347 | oplock_break); | 3523 | oplock_break); |
3348 | struct inode *inode = cfile->dentry->d_inode; | 3524 | struct inode *inode = cfile->dentry->d_inode; |
3349 | struct cifsInodeInfo *cinode = CIFS_I(inode); | 3525 | struct cifsInodeInfo *cinode = CIFS_I(inode); |
3526 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
3350 | int rc = 0; | 3527 | int rc = 0; |
3351 | 3528 | ||
3352 | if (inode && S_ISREG(inode->i_mode)) { | 3529 | if (inode && S_ISREG(inode->i_mode)) { |
@@ -3374,10 +3551,8 @@ void cifs_oplock_break(struct work_struct *work) | |||
3374 | * disconnected since oplock already released by the server | 3551 | * disconnected since oplock already released by the server |
3375 | */ | 3552 | */ |
3376 | if (!cfile->oplock_break_cancelled) { | 3553 | if (!cfile->oplock_break_cancelled) { |
3377 | rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, | 3554 | rc = tcon->ses->server->ops->oplock_response(tcon, &cfile->fid, |
3378 | current->tgid, 0, 0, 0, 0, | 3555 | cinode); |
3379 | LOCKING_ANDX_OPLOCK_RELEASE, false, | ||
3380 | cinode->clientCanCacheRead ? 1 : 0); | ||
3381 | cFYI(1, "Oplock release rc = %d", rc); | 3556 | cFYI(1, "Oplock release rc = %d", rc); |
3382 | } | 3557 | } |
3383 | } | 3558 | } |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index cb79c7edecb0..afdff79651f1 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -282,7 +282,8 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) | |||
282 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; | 282 | fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; |
283 | } | 283 | } |
284 | 284 | ||
285 | int cifs_get_file_info_unix(struct file *filp) | 285 | static int |
286 | cifs_get_file_info_unix(struct file *filp) | ||
286 | { | 287 | { |
287 | int rc; | 288 | int rc; |
288 | unsigned int xid; | 289 | unsigned int xid; |
@@ -294,7 +295,7 @@ int cifs_get_file_info_unix(struct file *filp) | |||
294 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 295 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
295 | 296 | ||
296 | xid = get_xid(); | 297 | xid = get_xid(); |
297 | rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data); | 298 | rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->fid.netfid, &find_data); |
298 | if (!rc) { | 299 | if (!rc) { |
299 | cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); | 300 | cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); |
300 | } else if (rc == -EREMOTE) { | 301 | } else if (rc == -EREMOTE) { |
@@ -550,7 +551,8 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info, | |||
550 | fattr->cf_gid = cifs_sb->mnt_gid; | 551 | fattr->cf_gid = cifs_sb->mnt_gid; |
551 | } | 552 | } |
552 | 553 | ||
553 | int cifs_get_file_info(struct file *filp) | 554 | static int |
555 | cifs_get_file_info(struct file *filp) | ||
554 | { | 556 | { |
555 | int rc; | 557 | int rc; |
556 | unsigned int xid; | 558 | unsigned int xid; |
@@ -560,9 +562,13 @@ int cifs_get_file_info(struct file *filp) | |||
560 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 562 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
561 | struct cifsFileInfo *cfile = filp->private_data; | 563 | struct cifsFileInfo *cfile = filp->private_data; |
562 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | 564 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); |
565 | struct TCP_Server_Info *server = tcon->ses->server; | ||
566 | |||
567 | if (!server->ops->query_file_info) | ||
568 | return -ENOSYS; | ||
563 | 569 | ||
564 | xid = get_xid(); | 570 | xid = get_xid(); |
565 | rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data); | 571 | rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data); |
566 | switch (rc) { | 572 | switch (rc) { |
567 | case 0: | 573 | case 0: |
568 | cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); | 574 | cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); |
@@ -601,7 +607,9 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
601 | FILE_ALL_INFO *data, struct super_block *sb, int xid, | 607 | FILE_ALL_INFO *data, struct super_block *sb, int xid, |
602 | const __u16 *fid) | 608 | const __u16 *fid) |
603 | { | 609 | { |
604 | int rc = 0, tmprc; | 610 | bool validinum = false; |
611 | __u16 srchflgs; | ||
612 | int rc = 0, tmprc = ENOSYS; | ||
605 | struct cifs_tcon *tcon; | 613 | struct cifs_tcon *tcon; |
606 | struct TCP_Server_Info *server; | 614 | struct TCP_Server_Info *server; |
607 | struct tcon_link *tlink; | 615 | struct tcon_link *tlink; |
@@ -609,6 +617,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
609 | char *buf = NULL; | 617 | char *buf = NULL; |
610 | bool adjust_tz = false; | 618 | bool adjust_tz = false; |
611 | struct cifs_fattr fattr; | 619 | struct cifs_fattr fattr; |
620 | struct cifs_search_info *srchinf = NULL; | ||
612 | 621 | ||
613 | tlink = cifs_sb_tlink(cifs_sb); | 622 | tlink = cifs_sb_tlink(cifs_sb); |
614 | if (IS_ERR(tlink)) | 623 | if (IS_ERR(tlink)) |
@@ -647,9 +656,38 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
647 | } else if (rc == -EREMOTE) { | 656 | } else if (rc == -EREMOTE) { |
648 | cifs_create_dfs_fattr(&fattr, sb); | 657 | cifs_create_dfs_fattr(&fattr, sb); |
649 | rc = 0; | 658 | rc = 0; |
650 | } else { | 659 | } else if (rc == -EACCES && backup_cred(cifs_sb)) { |
660 | srchinf = kzalloc(sizeof(struct cifs_search_info), | ||
661 | GFP_KERNEL); | ||
662 | if (srchinf == NULL) { | ||
663 | rc = -ENOMEM; | ||
664 | goto cgii_exit; | ||
665 | } | ||
666 | |||
667 | srchinf->endOfSearch = false; | ||
668 | srchinf->info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO; | ||
669 | |||
670 | srchflgs = CIFS_SEARCH_CLOSE_ALWAYS | | ||
671 | CIFS_SEARCH_CLOSE_AT_END | | ||
672 | CIFS_SEARCH_BACKUP_SEARCH; | ||
673 | |||
674 | rc = CIFSFindFirst(xid, tcon, full_path, | ||
675 | cifs_sb, NULL, srchflgs, srchinf, false); | ||
676 | if (!rc) { | ||
677 | data = | ||
678 | (FILE_ALL_INFO *)srchinf->srch_entries_start; | ||
679 | |||
680 | cifs_dir_info_to_fattr(&fattr, | ||
681 | (FILE_DIRECTORY_INFO *)data, cifs_sb); | ||
682 | fattr.cf_uniqueid = le64_to_cpu( | ||
683 | ((SEARCH_ID_FULL_DIR_INFO *)data)->UniqueId); | ||
684 | validinum = true; | ||
685 | |||
686 | cifs_buf_release(srchinf->ntwrk_buf_start); | ||
687 | } | ||
688 | kfree(srchinf); | ||
689 | } else | ||
651 | goto cgii_exit; | 690 | goto cgii_exit; |
652 | } | ||
653 | 691 | ||
654 | /* | 692 | /* |
655 | * If an inode wasn't passed in, then get the inode number | 693 | * If an inode wasn't passed in, then get the inode number |
@@ -660,23 +698,21 @@ cifs_get_inode_info(struct inode **inode, const char *full_path, | |||
660 | */ | 698 | */ |
661 | if (*inode == NULL) { | 699 | if (*inode == NULL) { |
662 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | 700 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
663 | if (server->ops->get_srv_inum) | 701 | if (validinum == false) { |
664 | tmprc = server->ops->get_srv_inum(xid, tcon, | 702 | if (server->ops->get_srv_inum) |
665 | cifs_sb, full_path, &fattr.cf_uniqueid, | 703 | tmprc = server->ops->get_srv_inum(xid, |
666 | data); | 704 | tcon, cifs_sb, full_path, |
667 | else | 705 | &fattr.cf_uniqueid, data); |
668 | tmprc = -ENOSYS; | 706 | if (tmprc) { |
669 | if (tmprc || !fattr.cf_uniqueid) { | 707 | cFYI(1, "GetSrvInodeNum rc %d", tmprc); |
670 | cFYI(1, "GetSrvInodeNum rc %d", tmprc); | 708 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
671 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 709 | cifs_autodisable_serverino(cifs_sb); |
672 | cifs_autodisable_serverino(cifs_sb); | 710 | } |
673 | } | 711 | } |
674 | } else { | 712 | } else |
675 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 713 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
676 | } | 714 | } else |
677 | } else { | ||
678 | fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; | 715 | fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; |
679 | } | ||
680 | 716 | ||
681 | /* query for SFU type info if supported and needed */ | 717 | /* query for SFU type info if supported and needed */ |
682 | if (fattr.cf_cifsattrs & ATTR_SYSTEM && | 718 | if (fattr.cf_cifsattrs & ATTR_SYSTEM && |
@@ -876,25 +912,22 @@ out: | |||
876 | return inode; | 912 | return inode; |
877 | } | 913 | } |
878 | 914 | ||
879 | static int | 915 | int |
880 | cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, | 916 | cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, |
881 | char *full_path, __u32 dosattr) | 917 | char *full_path, __u32 dosattr) |
882 | { | 918 | { |
883 | int rc; | ||
884 | int oplock = 0; | ||
885 | __u16 netfid; | ||
886 | __u32 netpid; | ||
887 | bool set_time = false; | 919 | bool set_time = false; |
888 | struct cifsFileInfo *open_file; | ||
889 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); | ||
890 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 920 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
891 | struct tcon_link *tlink = NULL; | 921 | struct TCP_Server_Info *server; |
892 | struct cifs_tcon *pTcon; | ||
893 | FILE_BASIC_INFO info_buf; | 922 | FILE_BASIC_INFO info_buf; |
894 | 923 | ||
895 | if (attrs == NULL) | 924 | if (attrs == NULL) |
896 | return -EINVAL; | 925 | return -EINVAL; |
897 | 926 | ||
927 | server = cifs_sb_master_tcon(cifs_sb)->ses->server; | ||
928 | if (!server->ops->set_file_info) | ||
929 | return -ENOSYS; | ||
930 | |||
898 | if (attrs->ia_valid & ATTR_ATIME) { | 931 | if (attrs->ia_valid & ATTR_ATIME) { |
899 | set_time = true; | 932 | set_time = true; |
900 | info_buf.LastAccessTime = | 933 | info_buf.LastAccessTime = |
@@ -925,81 +958,17 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, | |||
925 | info_buf.CreationTime = 0; /* don't change */ | 958 | info_buf.CreationTime = 0; /* don't change */ |
926 | info_buf.Attributes = cpu_to_le32(dosattr); | 959 | info_buf.Attributes = cpu_to_le32(dosattr); |
927 | 960 | ||
928 | /* | 961 | return server->ops->set_file_info(inode, full_path, &info_buf, xid); |
929 | * If the file is already open for write, just use that fileid | ||
930 | */ | ||
931 | open_file = find_writable_file(cifsInode, true); | ||
932 | if (open_file) { | ||
933 | netfid = open_file->netfid; | ||
934 | netpid = open_file->pid; | ||
935 | pTcon = tlink_tcon(open_file->tlink); | ||
936 | goto set_via_filehandle; | ||
937 | } | ||
938 | |||
939 | tlink = cifs_sb_tlink(cifs_sb); | ||
940 | if (IS_ERR(tlink)) { | ||
941 | rc = PTR_ERR(tlink); | ||
942 | tlink = NULL; | ||
943 | goto out; | ||
944 | } | ||
945 | pTcon = tlink_tcon(tlink); | ||
946 | |||
947 | /* | ||
948 | * NT4 apparently returns success on this call, but it doesn't | ||
949 | * really work. | ||
950 | */ | ||
951 | if (!(pTcon->ses->flags & CIFS_SES_NT4)) { | ||
952 | rc = CIFSSMBSetPathInfo(xid, pTcon, full_path, | ||
953 | &info_buf, cifs_sb->local_nls, | ||
954 | cifs_sb->mnt_cifs_flags & | ||
955 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
956 | if (rc == 0) { | ||
957 | cifsInode->cifsAttrs = dosattr; | ||
958 | goto out; | ||
959 | } else if (rc != -EOPNOTSUPP && rc != -EINVAL) | ||
960 | goto out; | ||
961 | } | ||
962 | |||
963 | cFYI(1, "calling SetFileInfo since SetPathInfo for " | ||
964 | "times not supported by this server"); | ||
965 | rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, | ||
966 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, | ||
967 | CREATE_NOT_DIR, &netfid, &oplock, | ||
968 | NULL, cifs_sb->local_nls, | ||
969 | cifs_sb->mnt_cifs_flags & | ||
970 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
971 | |||
972 | if (rc != 0) { | ||
973 | if (rc == -EIO) | ||
974 | rc = -EINVAL; | ||
975 | goto out; | ||
976 | } | ||
977 | |||
978 | netpid = current->tgid; | ||
979 | |||
980 | set_via_filehandle: | ||
981 | rc = CIFSSMBSetFileInfo(xid, pTcon, &info_buf, netfid, netpid); | ||
982 | if (!rc) | ||
983 | cifsInode->cifsAttrs = dosattr; | ||
984 | |||
985 | if (open_file == NULL) | ||
986 | CIFSSMBClose(xid, pTcon, netfid); | ||
987 | else | ||
988 | cifsFileInfo_put(open_file); | ||
989 | out: | ||
990 | if (tlink != NULL) | ||
991 | cifs_put_tlink(tlink); | ||
992 | return rc; | ||
993 | } | 962 | } |
994 | 963 | ||
995 | /* | 964 | /* |
996 | * open the given file (if it isn't already), set the DELETE_ON_CLOSE bit | 965 | * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit |
997 | * and rename it to a random name that hopefully won't conflict with | 966 | * and rename it to a random name that hopefully won't conflict with |
998 | * anything else. | 967 | * anything else. |
999 | */ | 968 | */ |
1000 | static int | 969 | int |
1001 | cifs_rename_pending_delete(char *full_path, struct dentry *dentry, | 970 | cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, |
1002 | unsigned int xid) | 971 | const unsigned int xid) |
1003 | { | 972 | { |
1004 | int oplock = 0; | 973 | int oplock = 0; |
1005 | int rc; | 974 | int rc; |
@@ -1136,6 +1105,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1136 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 1105 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
1137 | struct tcon_link *tlink; | 1106 | struct tcon_link *tlink; |
1138 | struct cifs_tcon *tcon; | 1107 | struct cifs_tcon *tcon; |
1108 | struct TCP_Server_Info *server; | ||
1139 | struct iattr *attrs = NULL; | 1109 | struct iattr *attrs = NULL; |
1140 | __u32 dosattr = 0, origattr = 0; | 1110 | __u32 dosattr = 0, origattr = 0; |
1141 | 1111 | ||
@@ -1145,6 +1115,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1145 | if (IS_ERR(tlink)) | 1115 | if (IS_ERR(tlink)) |
1146 | return PTR_ERR(tlink); | 1116 | return PTR_ERR(tlink); |
1147 | tcon = tlink_tcon(tlink); | 1117 | tcon = tlink_tcon(tlink); |
1118 | server = tcon->ses->server; | ||
1148 | 1119 | ||
1149 | xid = get_xid(); | 1120 | xid = get_xid(); |
1150 | 1121 | ||
@@ -1167,8 +1138,12 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1167 | } | 1138 | } |
1168 | 1139 | ||
1169 | retry_std_delete: | 1140 | retry_std_delete: |
1170 | rc = CIFSSMBDelFile(xid, tcon, full_path, cifs_sb->local_nls, | 1141 | if (!server->ops->unlink) { |
1171 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 1142 | rc = -ENOSYS; |
1143 | goto psx_del_no_retry; | ||
1144 | } | ||
1145 | |||
1146 | rc = server->ops->unlink(xid, tcon, full_path, cifs_sb); | ||
1172 | 1147 | ||
1173 | psx_del_no_retry: | 1148 | psx_del_no_retry: |
1174 | if (!rc) { | 1149 | if (!rc) { |
@@ -1177,9 +1152,14 @@ psx_del_no_retry: | |||
1177 | } else if (rc == -ENOENT) { | 1152 | } else if (rc == -ENOENT) { |
1178 | d_drop(dentry); | 1153 | d_drop(dentry); |
1179 | } else if (rc == -ETXTBSY) { | 1154 | } else if (rc == -ETXTBSY) { |
1180 | rc = cifs_rename_pending_delete(full_path, dentry, xid); | 1155 | if (server->ops->rename_pending_delete) { |
1181 | if (rc == 0) | 1156 | rc = server->ops->rename_pending_delete(full_path, |
1182 | cifs_drop_nlink(inode); | 1157 | dentry, xid); |
1158 | if (rc == 0) | ||
1159 | cifs_drop_nlink(inode); | ||
1160 | } | ||
1161 | if (rc == -ETXTBSY) | ||
1162 | rc = -EBUSY; | ||
1183 | } else if ((rc == -EACCES) && (dosattr == 0) && inode) { | 1163 | } else if ((rc == -EACCES) && (dosattr == 0) && inode) { |
1184 | attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); | 1164 | attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); |
1185 | if (attrs == NULL) { | 1165 | if (attrs == NULL) { |
@@ -1227,34 +1207,33 @@ unlink_out: | |||
1227 | } | 1207 | } |
1228 | 1208 | ||
1229 | static int | 1209 | static int |
1230 | cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | 1210 | cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, |
1231 | const char *full_path, struct cifs_sb_info *cifs_sb, | 1211 | const char *full_path, struct cifs_sb_info *cifs_sb, |
1232 | struct cifs_tcon *tcon, const unsigned int xid) | 1212 | struct cifs_tcon *tcon, const unsigned int xid) |
1233 | { | 1213 | { |
1234 | int rc = 0; | 1214 | int rc = 0; |
1235 | struct inode *newinode = NULL; | 1215 | struct inode *inode = NULL; |
1236 | 1216 | ||
1237 | if (tcon->unix_ext) | 1217 | if (tcon->unix_ext) |
1238 | rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, | 1218 | rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb, |
1239 | xid); | 1219 | xid); |
1240 | else | 1220 | else |
1241 | rc = cifs_get_inode_info(&newinode, full_path, NULL, | 1221 | rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb, |
1242 | inode->i_sb, xid, NULL); | 1222 | xid, NULL); |
1223 | |||
1243 | if (rc) | 1224 | if (rc) |
1244 | return rc; | 1225 | return rc; |
1245 | 1226 | ||
1246 | d_instantiate(dentry, newinode); | ||
1247 | /* | 1227 | /* |
1248 | * setting nlink not necessary except in cases where we failed to get it | 1228 | * setting nlink not necessary except in cases where we failed to get it |
1249 | * from the server or was set bogus | 1229 | * from the server or was set bogus. Also, since this is a brand new |
1230 | * inode, no need to grab the i_lock before setting the i_nlink. | ||
1250 | */ | 1231 | */ |
1251 | spin_lock(&dentry->d_inode->i_lock); | 1232 | if (inode->i_nlink < 2) |
1252 | if ((dentry->d_inode) && (dentry->d_inode->i_nlink < 2)) | 1233 | set_nlink(inode, 2); |
1253 | set_nlink(dentry->d_inode, 2); | ||
1254 | spin_unlock(&dentry->d_inode->i_lock); | ||
1255 | mode &= ~current_umask(); | 1234 | mode &= ~current_umask(); |
1256 | /* must turn on setgid bit if parent dir has it */ | 1235 | /* must turn on setgid bit if parent dir has it */ |
1257 | if (inode->i_mode & S_ISGID) | 1236 | if (parent->i_mode & S_ISGID) |
1258 | mode |= S_ISGID; | 1237 | mode |= S_ISGID; |
1259 | 1238 | ||
1260 | if (tcon->unix_ext) { | 1239 | if (tcon->unix_ext) { |
@@ -1267,8 +1246,8 @@ cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | |||
1267 | }; | 1246 | }; |
1268 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | 1247 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { |
1269 | args.uid = (__u64)current_fsuid(); | 1248 | args.uid = (__u64)current_fsuid(); |
1270 | if (inode->i_mode & S_ISGID) | 1249 | if (parent->i_mode & S_ISGID) |
1271 | args.gid = (__u64)inode->i_gid; | 1250 | args.gid = (__u64)parent->i_gid; |
1272 | else | 1251 | else |
1273 | args.gid = (__u64)current_fsgid(); | 1252 | args.gid = (__u64)current_fsgid(); |
1274 | } else { | 1253 | } else { |
@@ -1283,22 +1262,20 @@ cifs_mkdir_qinfo(struct inode *inode, struct dentry *dentry, umode_t mode, | |||
1283 | struct TCP_Server_Info *server = tcon->ses->server; | 1262 | struct TCP_Server_Info *server = tcon->ses->server; |
1284 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) && | 1263 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) && |
1285 | (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo) | 1264 | (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo) |
1286 | server->ops->mkdir_setinfo(newinode, full_path, cifs_sb, | 1265 | server->ops->mkdir_setinfo(inode, full_path, cifs_sb, |
1287 | tcon, xid); | 1266 | tcon, xid); |
1288 | if (dentry->d_inode) { | 1267 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) |
1289 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) | 1268 | inode->i_mode = (mode | S_IFDIR); |
1290 | dentry->d_inode->i_mode = (mode | S_IFDIR); | 1269 | |
1291 | 1270 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | |
1292 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { | 1271 | inode->i_uid = current_fsuid(); |
1293 | dentry->d_inode->i_uid = current_fsuid(); | 1272 | if (inode->i_mode & S_ISGID) |
1294 | if (inode->i_mode & S_ISGID) | 1273 | inode->i_gid = parent->i_gid; |
1295 | dentry->d_inode->i_gid = inode->i_gid; | 1274 | else |
1296 | else | 1275 | inode->i_gid = current_fsgid(); |
1297 | dentry->d_inode->i_gid = | ||
1298 | current_fsgid(); | ||
1299 | } | ||
1300 | } | 1276 | } |
1301 | } | 1277 | } |
1278 | d_instantiate(dentry, inode); | ||
1302 | return rc; | 1279 | return rc; |
1303 | } | 1280 | } |
1304 | 1281 | ||
@@ -1495,29 +1472,32 @@ rmdir_exit: | |||
1495 | } | 1472 | } |
1496 | 1473 | ||
1497 | static int | 1474 | static int |
1498 | cifs_do_rename(unsigned int xid, struct dentry *from_dentry, | 1475 | cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, |
1499 | const char *fromPath, struct dentry *to_dentry, | 1476 | const char *from_path, struct dentry *to_dentry, |
1500 | const char *toPath) | 1477 | const char *to_path) |
1501 | { | 1478 | { |
1502 | struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb); | 1479 | struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb); |
1503 | struct tcon_link *tlink; | 1480 | struct tcon_link *tlink; |
1504 | struct cifs_tcon *pTcon; | 1481 | struct cifs_tcon *tcon; |
1482 | struct TCP_Server_Info *server; | ||
1505 | __u16 srcfid; | 1483 | __u16 srcfid; |
1506 | int oplock, rc; | 1484 | int oplock, rc; |
1507 | 1485 | ||
1508 | tlink = cifs_sb_tlink(cifs_sb); | 1486 | tlink = cifs_sb_tlink(cifs_sb); |
1509 | if (IS_ERR(tlink)) | 1487 | if (IS_ERR(tlink)) |
1510 | return PTR_ERR(tlink); | 1488 | return PTR_ERR(tlink); |
1511 | pTcon = tlink_tcon(tlink); | 1489 | tcon = tlink_tcon(tlink); |
1490 | server = tcon->ses->server; | ||
1491 | |||
1492 | if (!server->ops->rename) | ||
1493 | return -ENOSYS; | ||
1512 | 1494 | ||
1513 | /* try path-based rename first */ | 1495 | /* try path-based rename first */ |
1514 | rc = CIFSSMBRename(xid, pTcon, fromPath, toPath, cifs_sb->local_nls, | 1496 | rc = server->ops->rename(xid, tcon, from_path, to_path, cifs_sb); |
1515 | cifs_sb->mnt_cifs_flags & | ||
1516 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
1517 | 1497 | ||
1518 | /* | 1498 | /* |
1519 | * don't bother with rename by filehandle unless file is busy and | 1499 | * Don't bother with rename by filehandle unless file is busy and |
1520 | * source Note that cross directory moves do not work with | 1500 | * source. Note that cross directory moves do not work with |
1521 | * rename by filehandle to various Windows servers. | 1501 | * rename by filehandle to various Windows servers. |
1522 | */ | 1502 | */ |
1523 | if (rc == 0 || rc != -ETXTBSY) | 1503 | if (rc == 0 || rc != -ETXTBSY) |
@@ -1528,29 +1508,28 @@ cifs_do_rename(unsigned int xid, struct dentry *from_dentry, | |||
1528 | goto do_rename_exit; | 1508 | goto do_rename_exit; |
1529 | 1509 | ||
1530 | /* open the file to be renamed -- we need DELETE perms */ | 1510 | /* open the file to be renamed -- we need DELETE perms */ |
1531 | rc = CIFSSMBOpen(xid, pTcon, fromPath, FILE_OPEN, DELETE, | 1511 | rc = CIFSSMBOpen(xid, tcon, from_path, FILE_OPEN, DELETE, |
1532 | CREATE_NOT_DIR, &srcfid, &oplock, NULL, | 1512 | CREATE_NOT_DIR, &srcfid, &oplock, NULL, |
1533 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 1513 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
1534 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1514 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1535 | |||
1536 | if (rc == 0) { | 1515 | if (rc == 0) { |
1537 | rc = CIFSSMBRenameOpenFile(xid, pTcon, srcfid, | 1516 | rc = CIFSSMBRenameOpenFile(xid, tcon, srcfid, |
1538 | (const char *) to_dentry->d_name.name, | 1517 | (const char *) to_dentry->d_name.name, |
1539 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | 1518 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & |
1540 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1519 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1541 | 1520 | CIFSSMBClose(xid, tcon, srcfid); | |
1542 | CIFSSMBClose(xid, pTcon, srcfid); | ||
1543 | } | 1521 | } |
1544 | do_rename_exit: | 1522 | do_rename_exit: |
1545 | cifs_put_tlink(tlink); | 1523 | cifs_put_tlink(tlink); |
1546 | return rc; | 1524 | return rc; |
1547 | } | 1525 | } |
1548 | 1526 | ||
1549 | int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | 1527 | int |
1550 | struct inode *target_dir, struct dentry *target_dentry) | 1528 | cifs_rename(struct inode *source_dir, struct dentry *source_dentry, |
1529 | struct inode *target_dir, struct dentry *target_dentry) | ||
1551 | { | 1530 | { |
1552 | char *fromName = NULL; | 1531 | char *from_name = NULL; |
1553 | char *toName = NULL; | 1532 | char *to_name = NULL; |
1554 | struct cifs_sb_info *cifs_sb; | 1533 | struct cifs_sb_info *cifs_sb; |
1555 | struct tcon_link *tlink; | 1534 | struct tcon_link *tlink; |
1556 | struct cifs_tcon *tcon; | 1535 | struct cifs_tcon *tcon; |
@@ -1571,25 +1550,25 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1571 | * we already have the rename sem so we do not need to | 1550 | * we already have the rename sem so we do not need to |
1572 | * grab it again here to protect the path integrity | 1551 | * grab it again here to protect the path integrity |
1573 | */ | 1552 | */ |
1574 | fromName = build_path_from_dentry(source_dentry); | 1553 | from_name = build_path_from_dentry(source_dentry); |
1575 | if (fromName == NULL) { | 1554 | if (from_name == NULL) { |
1576 | rc = -ENOMEM; | 1555 | rc = -ENOMEM; |
1577 | goto cifs_rename_exit; | 1556 | goto cifs_rename_exit; |
1578 | } | 1557 | } |
1579 | 1558 | ||
1580 | toName = build_path_from_dentry(target_dentry); | 1559 | to_name = build_path_from_dentry(target_dentry); |
1581 | if (toName == NULL) { | 1560 | if (to_name == NULL) { |
1582 | rc = -ENOMEM; | 1561 | rc = -ENOMEM; |
1583 | goto cifs_rename_exit; | 1562 | goto cifs_rename_exit; |
1584 | } | 1563 | } |
1585 | 1564 | ||
1586 | rc = cifs_do_rename(xid, source_dentry, fromName, | 1565 | rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry, |
1587 | target_dentry, toName); | 1566 | to_name); |
1588 | 1567 | ||
1589 | if (rc == -EEXIST && tcon->unix_ext) { | 1568 | if (rc == -EEXIST && tcon->unix_ext) { |
1590 | /* | 1569 | /* |
1591 | * Are src and dst hardlinks of same inode? We can | 1570 | * Are src and dst hardlinks of same inode? We can only tell |
1592 | * only tell with unix extensions enabled | 1571 | * with unix extensions enabled. |
1593 | */ | 1572 | */ |
1594 | info_buf_source = | 1573 | info_buf_source = |
1595 | kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), | 1574 | kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), |
@@ -1600,19 +1579,19 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1600 | } | 1579 | } |
1601 | 1580 | ||
1602 | info_buf_target = info_buf_source + 1; | 1581 | info_buf_target = info_buf_source + 1; |
1603 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, fromName, | 1582 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, from_name, |
1604 | info_buf_source, | 1583 | info_buf_source, |
1605 | cifs_sb->local_nls, | 1584 | cifs_sb->local_nls, |
1606 | cifs_sb->mnt_cifs_flags & | 1585 | cifs_sb->mnt_cifs_flags & |
1607 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1586 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1608 | if (tmprc != 0) | 1587 | if (tmprc != 0) |
1609 | goto unlink_target; | 1588 | goto unlink_target; |
1610 | 1589 | ||
1611 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, toName, | 1590 | tmprc = CIFSSMBUnixQPathInfo(xid, tcon, to_name, |
1612 | info_buf_target, | 1591 | info_buf_target, |
1613 | cifs_sb->local_nls, | 1592 | cifs_sb->local_nls, |
1614 | cifs_sb->mnt_cifs_flags & | 1593 | cifs_sb->mnt_cifs_flags & |
1615 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1594 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1616 | 1595 | ||
1617 | if (tmprc == 0 && (info_buf_source->UniqueId == | 1596 | if (tmprc == 0 && (info_buf_source->UniqueId == |
1618 | info_buf_target->UniqueId)) { | 1597 | info_buf_target->UniqueId)) { |
@@ -1620,8 +1599,11 @@ int cifs_rename(struct inode *source_dir, struct dentry *source_dentry, | |||
1620 | rc = 0; | 1599 | rc = 0; |
1621 | goto cifs_rename_exit; | 1600 | goto cifs_rename_exit; |
1622 | } | 1601 | } |
1623 | } /* else ... BB we could add the same check for Windows by | 1602 | } |
1624 | checking the UniqueId via FILE_INTERNAL_INFO */ | 1603 | /* |
1604 | * else ... BB we could add the same check for Windows by | ||
1605 | * checking the UniqueId via FILE_INTERNAL_INFO | ||
1606 | */ | ||
1625 | 1607 | ||
1626 | unlink_target: | 1608 | unlink_target: |
1627 | /* Try unlinking the target dentry if it's not negative */ | 1609 | /* Try unlinking the target dentry if it's not negative */ |
@@ -1629,15 +1611,14 @@ unlink_target: | |||
1629 | tmprc = cifs_unlink(target_dir, target_dentry); | 1611 | tmprc = cifs_unlink(target_dir, target_dentry); |
1630 | if (tmprc) | 1612 | if (tmprc) |
1631 | goto cifs_rename_exit; | 1613 | goto cifs_rename_exit; |
1632 | 1614 | rc = cifs_do_rename(xid, source_dentry, from_name, | |
1633 | rc = cifs_do_rename(xid, source_dentry, fromName, | 1615 | target_dentry, to_name); |
1634 | target_dentry, toName); | ||
1635 | } | 1616 | } |
1636 | 1617 | ||
1637 | cifs_rename_exit: | 1618 | cifs_rename_exit: |
1638 | kfree(info_buf_source); | 1619 | kfree(info_buf_source); |
1639 | kfree(fromName); | 1620 | kfree(from_name); |
1640 | kfree(toName); | 1621 | kfree(to_name); |
1641 | free_xid(xid); | 1622 | free_xid(xid); |
1642 | cifs_put_tlink(tlink); | 1623 | cifs_put_tlink(tlink); |
1643 | return rc; | 1624 | return rc; |
@@ -1862,7 +1843,8 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1862 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); | 1843 | struct cifsInodeInfo *cifsInode = CIFS_I(inode); |
1863 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 1844 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
1864 | struct tcon_link *tlink = NULL; | 1845 | struct tcon_link *tlink = NULL; |
1865 | struct cifs_tcon *pTcon = NULL; | 1846 | struct cifs_tcon *tcon = NULL; |
1847 | struct TCP_Server_Info *server; | ||
1866 | struct cifs_io_parms io_parms; | 1848 | struct cifs_io_parms io_parms; |
1867 | 1849 | ||
1868 | /* | 1850 | /* |
@@ -1876,19 +1858,21 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1876 | */ | 1858 | */ |
1877 | open_file = find_writable_file(cifsInode, true); | 1859 | open_file = find_writable_file(cifsInode, true); |
1878 | if (open_file) { | 1860 | if (open_file) { |
1879 | __u16 nfid = open_file->netfid; | 1861 | tcon = tlink_tcon(open_file->tlink); |
1880 | __u32 npid = open_file->pid; | 1862 | server = tcon->ses->server; |
1881 | pTcon = tlink_tcon(open_file->tlink); | 1863 | if (server->ops->set_file_size) |
1882 | rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid, | 1864 | rc = server->ops->set_file_size(xid, tcon, open_file, |
1883 | npid, false); | 1865 | attrs->ia_size, false); |
1866 | else | ||
1867 | rc = -ENOSYS; | ||
1884 | cifsFileInfo_put(open_file); | 1868 | cifsFileInfo_put(open_file); |
1885 | cFYI(1, "SetFSize for attrs rc = %d", rc); | 1869 | cFYI(1, "SetFSize for attrs rc = %d", rc); |
1886 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1870 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
1887 | unsigned int bytes_written; | 1871 | unsigned int bytes_written; |
1888 | 1872 | ||
1889 | io_parms.netfid = nfid; | 1873 | io_parms.netfid = open_file->fid.netfid; |
1890 | io_parms.pid = npid; | 1874 | io_parms.pid = open_file->pid; |
1891 | io_parms.tcon = pTcon; | 1875 | io_parms.tcon = tcon; |
1892 | io_parms.offset = 0; | 1876 | io_parms.offset = 0; |
1893 | io_parms.length = attrs->ia_size; | 1877 | io_parms.length = attrs->ia_size; |
1894 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, | 1878 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, |
@@ -1898,52 +1882,55 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1898 | } else | 1882 | } else |
1899 | rc = -EINVAL; | 1883 | rc = -EINVAL; |
1900 | 1884 | ||
1901 | if (rc != 0) { | 1885 | if (!rc) |
1902 | if (pTcon == NULL) { | 1886 | goto set_size_out; |
1903 | tlink = cifs_sb_tlink(cifs_sb); | ||
1904 | if (IS_ERR(tlink)) | ||
1905 | return PTR_ERR(tlink); | ||
1906 | pTcon = tlink_tcon(tlink); | ||
1907 | } | ||
1908 | 1887 | ||
1909 | /* Set file size by pathname rather than by handle | 1888 | if (tcon == NULL) { |
1910 | either because no valid, writeable file handle for | 1889 | tlink = cifs_sb_tlink(cifs_sb); |
1911 | it was found or because there was an error setting | 1890 | if (IS_ERR(tlink)) |
1912 | it by handle */ | 1891 | return PTR_ERR(tlink); |
1913 | rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, | 1892 | tcon = tlink_tcon(tlink); |
1914 | false, cifs_sb->local_nls, | 1893 | server = tcon->ses->server; |
1894 | } | ||
1895 | |||
1896 | /* | ||
1897 | * Set file size by pathname rather than by handle either because no | ||
1898 | * valid, writeable file handle for it was found or because there was | ||
1899 | * an error setting it by handle. | ||
1900 | */ | ||
1901 | if (server->ops->set_path_size) | ||
1902 | rc = server->ops->set_path_size(xid, tcon, full_path, | ||
1903 | attrs->ia_size, cifs_sb, false); | ||
1904 | else | ||
1905 | rc = -ENOSYS; | ||
1906 | cFYI(1, "SetEOF by path (setattrs) rc = %d", rc); | ||
1907 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | ||
1908 | __u16 netfid; | ||
1909 | int oplock = 0; | ||
1910 | |||
1911 | rc = SMBLegacyOpen(xid, tcon, full_path, FILE_OPEN, | ||
1912 | GENERIC_WRITE, CREATE_NOT_DIR, &netfid, | ||
1913 | &oplock, NULL, cifs_sb->local_nls, | ||
1915 | cifs_sb->mnt_cifs_flags & | 1914 | cifs_sb->mnt_cifs_flags & |
1916 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1915 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1917 | cFYI(1, "SetEOF by path (setattrs) rc = %d", rc); | 1916 | if (rc == 0) { |
1918 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1917 | unsigned int bytes_written; |
1919 | __u16 netfid; | 1918 | |
1920 | int oplock = 0; | 1919 | io_parms.netfid = netfid; |
1921 | 1920 | io_parms.pid = current->tgid; | |
1922 | rc = SMBLegacyOpen(xid, pTcon, full_path, | 1921 | io_parms.tcon = tcon; |
1923 | FILE_OPEN, GENERIC_WRITE, | 1922 | io_parms.offset = 0; |
1924 | CREATE_NOT_DIR, &netfid, &oplock, NULL, | 1923 | io_parms.length = attrs->ia_size; |
1925 | cifs_sb->local_nls, | 1924 | rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, NULL, |
1926 | cifs_sb->mnt_cifs_flags & | 1925 | NULL, 1); |
1927 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1926 | cFYI(1, "wrt seteof rc %d", rc); |
1928 | if (rc == 0) { | 1927 | CIFSSMBClose(xid, tcon, netfid); |
1929 | unsigned int bytes_written; | ||
1930 | |||
1931 | io_parms.netfid = netfid; | ||
1932 | io_parms.pid = current->tgid; | ||
1933 | io_parms.tcon = pTcon; | ||
1934 | io_parms.offset = 0; | ||
1935 | io_parms.length = attrs->ia_size; | ||
1936 | rc = CIFSSMBWrite(xid, &io_parms, | ||
1937 | &bytes_written, | ||
1938 | NULL, NULL, 1); | ||
1939 | cFYI(1, "wrt seteof rc %d", rc); | ||
1940 | CIFSSMBClose(xid, pTcon, netfid); | ||
1941 | } | ||
1942 | } | 1928 | } |
1943 | if (tlink) | ||
1944 | cifs_put_tlink(tlink); | ||
1945 | } | 1929 | } |
1930 | if (tlink) | ||
1931 | cifs_put_tlink(tlink); | ||
1946 | 1932 | ||
1933 | set_size_out: | ||
1947 | if (rc == 0) { | 1934 | if (rc == 0) { |
1948 | cifsInode->server_eof = attrs->ia_size; | 1935 | cifsInode->server_eof = attrs->ia_size; |
1949 | cifs_setsize(inode, attrs->ia_size); | 1936 | cifs_setsize(inode, attrs->ia_size); |
@@ -2050,7 +2037,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) | |||
2050 | args->device = 0; | 2037 | args->device = 0; |
2051 | open_file = find_writable_file(cifsInode, true); | 2038 | open_file = find_writable_file(cifsInode, true); |
2052 | if (open_file) { | 2039 | if (open_file) { |
2053 | u16 nfid = open_file->netfid; | 2040 | u16 nfid = open_file->fid.netfid; |
2054 | u32 npid = open_file->pid; | 2041 | u32 npid = open_file->pid; |
2055 | pTcon = tlink_tcon(open_file->tlink); | 2042 | pTcon = tlink_tcon(open_file->tlink); |
2056 | rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid); | 2043 | rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid); |
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index ae082a66de2f..fd5009d56f9f 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c | |||
@@ -28,8 +28,6 @@ | |||
28 | #include "cifs_debug.h" | 28 | #include "cifs_debug.h" |
29 | #include "cifsfs.h" | 29 | #include "cifsfs.h" |
30 | 30 | ||
31 | #define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2) | ||
32 | |||
33 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | 31 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) |
34 | { | 32 | { |
35 | struct inode *inode = filep->f_dentry->d_inode; | 33 | struct inode *inode = filep->f_dentry->d_inode; |
@@ -51,23 +49,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
51 | cifs_sb = CIFS_SB(inode->i_sb); | 49 | cifs_sb = CIFS_SB(inode->i_sb); |
52 | 50 | ||
53 | switch (command) { | 51 | switch (command) { |
54 | static bool warned = false; | ||
55 | case CIFS_IOC_CHECKUMOUNT: | ||
56 | if (!warned) { | ||
57 | warned = true; | ||
58 | cERROR(1, "the CIFS_IOC_CHECKMOUNT ioctl will " | ||
59 | "be deprecated in 3.7. Please " | ||
60 | "migrate away from the use of " | ||
61 | "umount.cifs"); | ||
62 | } | ||
63 | cFYI(1, "User unmount attempted"); | ||
64 | if (cifs_sb->mnt_uid == current_uid()) | ||
65 | rc = 0; | ||
66 | else { | ||
67 | rc = -EACCES; | ||
68 | cFYI(1, "uids do not match"); | ||
69 | } | ||
70 | break; | ||
71 | #ifdef CONFIG_CIFS_POSIX | 52 | #ifdef CONFIG_CIFS_POSIX |
72 | case FS_IOC_GETFLAGS: | 53 | case FS_IOC_GETFLAGS: |
73 | if (pSMBFile == NULL) | 54 | if (pSMBFile == NULL) |
@@ -75,8 +56,9 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
75 | tcon = tlink_tcon(pSMBFile->tlink); | 56 | tcon = tlink_tcon(pSMBFile->tlink); |
76 | caps = le64_to_cpu(tcon->fsUnixInfo.Capability); | 57 | caps = le64_to_cpu(tcon->fsUnixInfo.Capability); |
77 | if (CIFS_UNIX_EXTATTR_CAP & caps) { | 58 | if (CIFS_UNIX_EXTATTR_CAP & caps) { |
78 | rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, | 59 | rc = CIFSGetExtAttr(xid, tcon, |
79 | &ExtAttrBits, &ExtAttrMask); | 60 | pSMBFile->fid.netfid, |
61 | &ExtAttrBits, &ExtAttrMask); | ||
80 | if (rc == 0) | 62 | if (rc == 0) |
81 | rc = put_user(ExtAttrBits & | 63 | rc = put_user(ExtAttrBits & |
82 | FS_FL_USER_VISIBLE, | 64 | FS_FL_USER_VISIBLE, |
@@ -94,8 +76,12 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
94 | rc = -EFAULT; | 76 | rc = -EFAULT; |
95 | break; | 77 | break; |
96 | } | 78 | } |
97 | /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, | 79 | /* |
98 | extAttrBits, &ExtAttrMask);*/ | 80 | * rc = CIFSGetExtAttr(xid, tcon, |
81 | * pSMBFile->fid.netfid, | ||
82 | * extAttrBits, | ||
83 | * &ExtAttrMask); | ||
84 | */ | ||
99 | } | 85 | } |
100 | cFYI(1, "set flags not implemented yet"); | 86 | cFYI(1, "set flags not implemented yet"); |
101 | break; | 87 | break; |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index e6ce3b112875..51dc2fb6e854 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -391,72 +391,86 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode, | |||
391 | { | 391 | { |
392 | int rc = -EACCES; | 392 | int rc = -EACCES; |
393 | unsigned int xid; | 393 | unsigned int xid; |
394 | char *fromName = NULL; | 394 | char *from_name = NULL; |
395 | char *toName = NULL; | 395 | char *to_name = NULL; |
396 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | 396 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
397 | struct tcon_link *tlink; | 397 | struct tcon_link *tlink; |
398 | struct cifs_tcon *pTcon; | 398 | struct cifs_tcon *tcon; |
399 | struct TCP_Server_Info *server; | ||
399 | struct cifsInodeInfo *cifsInode; | 400 | struct cifsInodeInfo *cifsInode; |
400 | 401 | ||
401 | tlink = cifs_sb_tlink(cifs_sb); | 402 | tlink = cifs_sb_tlink(cifs_sb); |
402 | if (IS_ERR(tlink)) | 403 | if (IS_ERR(tlink)) |
403 | return PTR_ERR(tlink); | 404 | return PTR_ERR(tlink); |
404 | pTcon = tlink_tcon(tlink); | 405 | tcon = tlink_tcon(tlink); |
405 | 406 | ||
406 | xid = get_xid(); | 407 | xid = get_xid(); |
407 | 408 | ||
408 | fromName = build_path_from_dentry(old_file); | 409 | from_name = build_path_from_dentry(old_file); |
409 | toName = build_path_from_dentry(direntry); | 410 | to_name = build_path_from_dentry(direntry); |
410 | if ((fromName == NULL) || (toName == NULL)) { | 411 | if ((from_name == NULL) || (to_name == NULL)) { |
411 | rc = -ENOMEM; | 412 | rc = -ENOMEM; |
412 | goto cifs_hl_exit; | 413 | goto cifs_hl_exit; |
413 | } | 414 | } |
414 | 415 | ||
415 | if (pTcon->unix_ext) | 416 | if (tcon->unix_ext) |
416 | rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName, | 417 | rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name, |
417 | cifs_sb->local_nls, | 418 | cifs_sb->local_nls, |
418 | cifs_sb->mnt_cifs_flags & | 419 | cifs_sb->mnt_cifs_flags & |
419 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 420 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
420 | else { | 421 | else { |
421 | rc = CIFSCreateHardLink(xid, pTcon, fromName, toName, | 422 | server = tcon->ses->server; |
422 | cifs_sb->local_nls, | 423 | if (!server->ops->create_hardlink) |
423 | cifs_sb->mnt_cifs_flags & | 424 | return -ENOSYS; |
424 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 425 | rc = server->ops->create_hardlink(xid, tcon, from_name, to_name, |
426 | cifs_sb); | ||
425 | if ((rc == -EIO) || (rc == -EINVAL)) | 427 | if ((rc == -EIO) || (rc == -EINVAL)) |
426 | rc = -EOPNOTSUPP; | 428 | rc = -EOPNOTSUPP; |
427 | } | 429 | } |
428 | 430 | ||
429 | d_drop(direntry); /* force new lookup from server of target */ | 431 | d_drop(direntry); /* force new lookup from server of target */ |
430 | 432 | ||
431 | /* if source file is cached (oplocked) revalidate will not go to server | 433 | /* |
432 | until the file is closed or oplock broken so update nlinks locally */ | 434 | * if source file is cached (oplocked) revalidate will not go to server |
435 | * until the file is closed or oplock broken so update nlinks locally | ||
436 | */ | ||
433 | if (old_file->d_inode) { | 437 | if (old_file->d_inode) { |
434 | cifsInode = CIFS_I(old_file->d_inode); | 438 | cifsInode = CIFS_I(old_file->d_inode); |
435 | if (rc == 0) { | 439 | if (rc == 0) { |
436 | spin_lock(&old_file->d_inode->i_lock); | 440 | spin_lock(&old_file->d_inode->i_lock); |
437 | inc_nlink(old_file->d_inode); | 441 | inc_nlink(old_file->d_inode); |
438 | spin_unlock(&old_file->d_inode->i_lock); | 442 | spin_unlock(&old_file->d_inode->i_lock); |
439 | /* BB should we make this contingent on superblock flag NOATIME? */ | 443 | /* |
440 | /* old_file->d_inode->i_ctime = CURRENT_TIME;*/ | 444 | * BB should we make this contingent on superblock flag |
441 | /* parent dir timestamps will update from srv | 445 | * NOATIME? |
442 | within a second, would it really be worth it | 446 | */ |
443 | to set the parent dir cifs inode time to zero | 447 | /* old_file->d_inode->i_ctime = CURRENT_TIME; */ |
444 | to force revalidate (faster) for it too? */ | 448 | /* |
449 | * parent dir timestamps will update from srv within a | ||
450 | * second, would it really be worth it to set the parent | ||
451 | * dir cifs inode time to zero to force revalidate | ||
452 | * (faster) for it too? | ||
453 | */ | ||
445 | } | 454 | } |
446 | /* if not oplocked will force revalidate to get info | 455 | /* |
447 | on source file from srv */ | 456 | * if not oplocked will force revalidate to get info on source |
457 | * file from srv | ||
458 | */ | ||
448 | cifsInode->time = 0; | 459 | cifsInode->time = 0; |
449 | 460 | ||
450 | /* Will update parent dir timestamps from srv within a second. | 461 | /* |
451 | Would it really be worth it to set the parent dir (cifs | 462 | * Will update parent dir timestamps from srv within a second. |
452 | inode) time field to zero to force revalidate on parent | 463 | * Would it really be worth it to set the parent dir (cifs |
453 | directory faster ie | 464 | * inode) time field to zero to force revalidate on parent |
454 | CIFS_I(inode)->time = 0; */ | 465 | * directory faster ie |
466 | * | ||
467 | * CIFS_I(inode)->time = 0; | ||
468 | */ | ||
455 | } | 469 | } |
456 | 470 | ||
457 | cifs_hl_exit: | 471 | cifs_hl_exit: |
458 | kfree(fromName); | 472 | kfree(from_name); |
459 | kfree(toName); | 473 | kfree(to_name); |
460 | free_xid(xid); | 474 | free_xid(xid); |
461 | cifs_put_tlink(tlink); | 475 | cifs_put_tlink(tlink); |
462 | return rc; | 476 | return rc; |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index ce41fee07e5b..3a00c0d0cead 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -466,7 +466,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) | |||
466 | list_for_each(tmp2, &tcon->openFileList) { | 466 | list_for_each(tmp2, &tcon->openFileList) { |
467 | netfile = list_entry(tmp2, struct cifsFileInfo, | 467 | netfile = list_entry(tmp2, struct cifsFileInfo, |
468 | tlist); | 468 | tlist); |
469 | if (pSMB->Fid != netfile->netfid) | 469 | if (pSMB->Fid != netfile->fid.netfid) |
470 | continue; | 470 | continue; |
471 | 471 | ||
472 | cFYI(1, "file id match, oplock break"); | 472 | cFYI(1, "file id match, oplock break"); |
@@ -579,3 +579,33 @@ backup_cred(struct cifs_sb_info *cifs_sb) | |||
579 | 579 | ||
580 | return false; | 580 | return false; |
581 | } | 581 | } |
582 | |||
583 | void | ||
584 | cifs_del_pending_open(struct cifs_pending_open *open) | ||
585 | { | ||
586 | spin_lock(&cifs_file_list_lock); | ||
587 | list_del(&open->olist); | ||
588 | spin_unlock(&cifs_file_list_lock); | ||
589 | } | ||
590 | |||
591 | void | ||
592 | cifs_add_pending_open_locked(struct cifs_fid *fid, struct tcon_link *tlink, | ||
593 | struct cifs_pending_open *open) | ||
594 | { | ||
595 | #ifdef CONFIG_CIFS_SMB2 | ||
596 | memcpy(open->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
597 | #endif | ||
598 | open->oplock = CIFS_OPLOCK_NO_CHANGE; | ||
599 | open->tlink = tlink; | ||
600 | fid->pending_open = open; | ||
601 | list_add_tail(&open->olist, &tlink_tcon(tlink)->pending_opens); | ||
602 | } | ||
603 | |||
604 | void | ||
605 | cifs_add_pending_open(struct cifs_fid *fid, struct tcon_link *tlink, | ||
606 | struct cifs_pending_open *open) | ||
607 | { | ||
608 | spin_lock(&cifs_file_list_lock); | ||
609 | cifs_add_pending_open_locked(fid, tlink, open); | ||
610 | spin_unlock(&cifs_file_list_lock); | ||
611 | } | ||
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 581c225f7f50..d5ce9e26696c 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -110,7 +110,7 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = { | |||
110 | {ERRnoroom, -ENOSPC}, | 110 | {ERRnoroom, -ENOSPC}, |
111 | {ERRrmuns, -EUSERS}, | 111 | {ERRrmuns, -EUSERS}, |
112 | {ERRtimeout, -ETIME}, | 112 | {ERRtimeout, -ETIME}, |
113 | {ERRnoresource, -ENOBUFS}, | 113 | {ERRnoresource, -EREMOTEIO}, |
114 | {ERRtoomanyuids, -EUSERS}, | 114 | {ERRtoomanyuids, -EUSERS}, |
115 | {ERRbaduid, -EACCES}, | 115 | {ERRbaduid, -EACCES}, |
116 | {ERRusempx, -EIO}, | 116 | {ERRusempx, -EIO}, |
@@ -412,7 +412,7 @@ static const struct { | |||
412 | from NT_STATUS_INSUFFICIENT_RESOURCES to | 412 | from NT_STATUS_INSUFFICIENT_RESOURCES to |
413 | NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */ | 413 | NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */ |
414 | { | 414 | { |
415 | ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES}, { | 415 | ERRDOS, ERRnoresource, NT_STATUS_INSUFFICIENT_RESOURCES}, { |
416 | ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, { | 416 | ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, { |
417 | ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, { | 417 | ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, { |
418 | ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, { | 418 | ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, { |
@@ -682,7 +682,7 @@ static const struct { | |||
682 | ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, { | 682 | ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, { |
683 | ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, { | 683 | ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, { |
684 | ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, { | 684 | ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, { |
685 | ERRDOS, ERRnomem, NT_STATUS_INSUFF_SERVER_RESOURCES}, { | 685 | ERRDOS, ERRnoresource, NT_STATUS_INSUFF_SERVER_RESOURCES}, { |
686 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, { | 686 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, { |
687 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, { | 687 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, { |
688 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, { | 688 | ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, { |
@@ -913,8 +913,9 @@ map_smb_to_linux_error(char *buf, bool logErr) | |||
913 | * portion, the number of word parameters and the data portion of the message | 913 | * portion, the number of word parameters and the data portion of the message |
914 | */ | 914 | */ |
915 | unsigned int | 915 | unsigned int |
916 | smbCalcSize(struct smb_hdr *ptr) | 916 | smbCalcSize(void *buf) |
917 | { | 917 | { |
918 | struct smb_hdr *ptr = (struct smb_hdr *)buf; | ||
918 | return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + | 919 | return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + |
919 | 2 /* size of the bcc field */ + get_bcc(ptr)); | 920 | 2 /* size of the bcc field */ + get_bcc(ptr)); |
920 | } | 921 | } |
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index d87f82678bc7..f9b5d3d6cf33 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -151,7 +151,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb) | |||
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | static void | 154 | void |
155 | cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, | 155 | cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, |
156 | struct cifs_sb_info *cifs_sb) | 156 | struct cifs_sb_info *cifs_sb) |
157 | { | 157 | { |
@@ -220,7 +220,8 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb, | |||
220 | } | 220 | } |
221 | */ | 221 | */ |
222 | 222 | ||
223 | static int initiate_cifs_search(const unsigned int xid, struct file *file) | 223 | static int |
224 | initiate_cifs_search(const unsigned int xid, struct file *file) | ||
224 | { | 225 | { |
225 | __u16 search_flags; | 226 | __u16 search_flags; |
226 | int rc = 0; | 227 | int rc = 0; |
@@ -229,6 +230,7 @@ static int initiate_cifs_search(const unsigned int xid, struct file *file) | |||
229 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 230 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
230 | struct tcon_link *tlink = NULL; | 231 | struct tcon_link *tlink = NULL; |
231 | struct cifs_tcon *tcon; | 232 | struct cifs_tcon *tcon; |
233 | struct TCP_Server_Info *server; | ||
232 | 234 | ||
233 | if (file->private_data == NULL) { | 235 | if (file->private_data == NULL) { |
234 | tlink = cifs_sb_tlink(cifs_sb); | 236 | tlink = cifs_sb_tlink(cifs_sb); |
@@ -248,6 +250,13 @@ static int initiate_cifs_search(const unsigned int xid, struct file *file) | |||
248 | tcon = tlink_tcon(cifsFile->tlink); | 250 | tcon = tlink_tcon(cifsFile->tlink); |
249 | } | 251 | } |
250 | 252 | ||
253 | server = tcon->ses->server; | ||
254 | |||
255 | if (!server->ops->query_dir_first) { | ||
256 | rc = -ENOSYS; | ||
257 | goto error_exit; | ||
258 | } | ||
259 | |||
251 | cifsFile->invalidHandle = true; | 260 | cifsFile->invalidHandle = true; |
252 | cifsFile->srch_inf.endOfSearch = false; | 261 | cifsFile->srch_inf.endOfSearch = false; |
253 | 262 | ||
@@ -278,10 +287,10 @@ ffirst_retry: | |||
278 | if (backup_cred(cifs_sb)) | 287 | if (backup_cred(cifs_sb)) |
279 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; | 288 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; |
280 | 289 | ||
281 | rc = CIFSFindFirst(xid, tcon, full_path, cifs_sb->local_nls, | 290 | rc = server->ops->query_dir_first(xid, tcon, full_path, cifs_sb, |
282 | &cifsFile->netfid, search_flags, &cifsFile->srch_inf, | 291 | &cifsFile->fid, search_flags, |
283 | cifs_sb->mnt_cifs_flags & | 292 | &cifsFile->srch_inf); |
284 | CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb)); | 293 | |
285 | if (rc == 0) | 294 | if (rc == 0) |
286 | cifsFile->invalidHandle = false; | 295 | cifsFile->invalidHandle = false; |
287 | /* BB add following call to handle readdir on new NTFS symlink errors | 296 | /* BB add following call to handle readdir on new NTFS symlink errors |
@@ -501,62 +510,67 @@ static int cifs_save_resume_key(const char *current_entry, | |||
501 | return rc; | 510 | return rc; |
502 | } | 511 | } |
503 | 512 | ||
504 | /* find the corresponding entry in the search */ | 513 | /* |
505 | /* Note that the SMB server returns search entries for . and .. which | 514 | * Find the corresponding entry in the search. Note that the SMB server returns |
506 | complicates logic here if we choose to parse for them and we do not | 515 | * search entries for . and .. which complicates logic here if we choose to |
507 | assume that they are located in the findfirst return buffer.*/ | 516 | * parse for them and we do not assume that they are located in the findfirst |
508 | /* We start counting in the buffer with entry 2 and increment for every | 517 | * return buffer. We start counting in the buffer with entry 2 and increment for |
509 | entry (do not increment for . or .. entry) */ | 518 | * every entry (do not increment for . or .. entry). |
510 | static int find_cifs_entry(const unsigned int xid, struct cifs_tcon *pTcon, | 519 | */ |
511 | struct file *file, char **ppCurrentEntry, int *num_to_ret) | 520 | static int |
521 | find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, | ||
522 | struct file *file, char **current_entry, int *num_to_ret) | ||
512 | { | 523 | { |
513 | __u16 search_flags; | 524 | __u16 search_flags; |
514 | int rc = 0; | 525 | int rc = 0; |
515 | int pos_in_buf = 0; | 526 | int pos_in_buf = 0; |
516 | loff_t first_entry_in_buffer; | 527 | loff_t first_entry_in_buffer; |
517 | loff_t index_to_find = file->f_pos; | 528 | loff_t index_to_find = file->f_pos; |
518 | struct cifsFileInfo *cifsFile = file->private_data; | 529 | struct cifsFileInfo *cfile = file->private_data; |
519 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 530 | struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
531 | struct TCP_Server_Info *server = tcon->ses->server; | ||
520 | /* check if index in the buffer */ | 532 | /* check if index in the buffer */ |
521 | 533 | ||
522 | if ((cifsFile == NULL) || (ppCurrentEntry == NULL) || | 534 | if (!server->ops->query_dir_first || !server->ops->query_dir_next) |
523 | (num_to_ret == NULL)) | 535 | return -ENOSYS; |
536 | |||
537 | if ((cfile == NULL) || (current_entry == NULL) || (num_to_ret == NULL)) | ||
524 | return -ENOENT; | 538 | return -ENOENT; |
525 | 539 | ||
526 | *ppCurrentEntry = NULL; | 540 | *current_entry = NULL; |
527 | first_entry_in_buffer = | 541 | first_entry_in_buffer = cfile->srch_inf.index_of_last_entry - |
528 | cifsFile->srch_inf.index_of_last_entry - | 542 | cfile->srch_inf.entries_in_buffer; |
529 | cifsFile->srch_inf.entries_in_buffer; | ||
530 | 543 | ||
531 | /* if first entry in buf is zero then is first buffer | 544 | /* |
532 | in search response data which means it is likely . and .. | 545 | * If first entry in buf is zero then is first buffer |
533 | will be in this buffer, although some servers do not return | 546 | * in search response data which means it is likely . and .. |
534 | . and .. for the root of a drive and for those we need | 547 | * will be in this buffer, although some servers do not return |
535 | to start two entries earlier */ | 548 | * . and .. for the root of a drive and for those we need |
549 | * to start two entries earlier. | ||
550 | */ | ||
536 | 551 | ||
537 | dump_cifs_file_struct(file, "In fce "); | 552 | dump_cifs_file_struct(file, "In fce "); |
538 | if (((index_to_find < cifsFile->srch_inf.index_of_last_entry) && | 553 | if (((index_to_find < cfile->srch_inf.index_of_last_entry) && |
539 | is_dir_changed(file)) || | 554 | is_dir_changed(file)) || (index_to_find < first_entry_in_buffer)) { |
540 | (index_to_find < first_entry_in_buffer)) { | ||
541 | /* close and restart search */ | 555 | /* close and restart search */ |
542 | cFYI(1, "search backing up - close and restart search"); | 556 | cFYI(1, "search backing up - close and restart search"); |
543 | spin_lock(&cifs_file_list_lock); | 557 | spin_lock(&cifs_file_list_lock); |
544 | if (!cifsFile->srch_inf.endOfSearch && | 558 | if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) { |
545 | !cifsFile->invalidHandle) { | 559 | cfile->invalidHandle = true; |
546 | cifsFile->invalidHandle = true; | ||
547 | spin_unlock(&cifs_file_list_lock); | 560 | spin_unlock(&cifs_file_list_lock); |
548 | CIFSFindClose(xid, pTcon, cifsFile->netfid); | 561 | if (server->ops->close) |
562 | server->ops->close(xid, tcon, &cfile->fid); | ||
549 | } else | 563 | } else |
550 | spin_unlock(&cifs_file_list_lock); | 564 | spin_unlock(&cifs_file_list_lock); |
551 | if (cifsFile->srch_inf.ntwrk_buf_start) { | 565 | if (cfile->srch_inf.ntwrk_buf_start) { |
552 | cFYI(1, "freeing SMB ff cache buf on search rewind"); | 566 | cFYI(1, "freeing SMB ff cache buf on search rewind"); |
553 | if (cifsFile->srch_inf.smallBuf) | 567 | if (cfile->srch_inf.smallBuf) |
554 | cifs_small_buf_release(cifsFile->srch_inf. | 568 | cifs_small_buf_release(cfile->srch_inf. |
555 | ntwrk_buf_start); | 569 | ntwrk_buf_start); |
556 | else | 570 | else |
557 | cifs_buf_release(cifsFile->srch_inf. | 571 | cifs_buf_release(cfile->srch_inf. |
558 | ntwrk_buf_start); | 572 | ntwrk_buf_start); |
559 | cifsFile->srch_inf.ntwrk_buf_start = NULL; | 573 | cfile->srch_inf.ntwrk_buf_start = NULL; |
560 | } | 574 | } |
561 | rc = initiate_cifs_search(xid, file); | 575 | rc = initiate_cifs_search(xid, file); |
562 | if (rc) { | 576 | if (rc) { |
@@ -565,65 +579,64 @@ static int find_cifs_entry(const unsigned int xid, struct cifs_tcon *pTcon, | |||
565 | return rc; | 579 | return rc; |
566 | } | 580 | } |
567 | /* FindFirst/Next set last_entry to NULL on malformed reply */ | 581 | /* FindFirst/Next set last_entry to NULL on malformed reply */ |
568 | if (cifsFile->srch_inf.last_entry) | 582 | if (cfile->srch_inf.last_entry) |
569 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, | 583 | cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); |
570 | cifsFile); | ||
571 | } | 584 | } |
572 | 585 | ||
573 | search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; | 586 | search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; |
574 | if (backup_cred(cifs_sb)) | 587 | if (backup_cred(cifs_sb)) |
575 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; | 588 | search_flags |= CIFS_SEARCH_BACKUP_SEARCH; |
576 | 589 | ||
577 | while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && | 590 | while ((index_to_find >= cfile->srch_inf.index_of_last_entry) && |
578 | (rc == 0) && !cifsFile->srch_inf.endOfSearch) { | 591 | (rc == 0) && !cfile->srch_inf.endOfSearch) { |
579 | cFYI(1, "calling findnext2"); | 592 | cFYI(1, "calling findnext2"); |
580 | rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, search_flags, | 593 | rc = server->ops->query_dir_next(xid, tcon, &cfile->fid, |
581 | &cifsFile->srch_inf); | 594 | search_flags, |
595 | &cfile->srch_inf); | ||
582 | /* FindFirst/Next set last_entry to NULL on malformed reply */ | 596 | /* FindFirst/Next set last_entry to NULL on malformed reply */ |
583 | if (cifsFile->srch_inf.last_entry) | 597 | if (cfile->srch_inf.last_entry) |
584 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, | 598 | cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); |
585 | cifsFile); | ||
586 | if (rc) | 599 | if (rc) |
587 | return -ENOENT; | 600 | return -ENOENT; |
588 | } | 601 | } |
589 | if (index_to_find < cifsFile->srch_inf.index_of_last_entry) { | 602 | if (index_to_find < cfile->srch_inf.index_of_last_entry) { |
590 | /* we found the buffer that contains the entry */ | 603 | /* we found the buffer that contains the entry */ |
591 | /* scan and find it */ | 604 | /* scan and find it */ |
592 | int i; | 605 | int i; |
593 | char *current_entry; | 606 | char *cur_ent; |
594 | char *end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + | 607 | char *end_of_smb = cfile->srch_inf.ntwrk_buf_start + |
595 | smbCalcSize((struct smb_hdr *) | 608 | server->ops->calc_smb_size( |
596 | cifsFile->srch_inf.ntwrk_buf_start); | 609 | cfile->srch_inf.ntwrk_buf_start); |
597 | 610 | ||
598 | current_entry = cifsFile->srch_inf.srch_entries_start; | 611 | cur_ent = cfile->srch_inf.srch_entries_start; |
599 | first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry | 612 | first_entry_in_buffer = cfile->srch_inf.index_of_last_entry |
600 | - cifsFile->srch_inf.entries_in_buffer; | 613 | - cfile->srch_inf.entries_in_buffer; |
601 | pos_in_buf = index_to_find - first_entry_in_buffer; | 614 | pos_in_buf = index_to_find - first_entry_in_buffer; |
602 | cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); | 615 | cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); |
603 | 616 | ||
604 | for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) { | 617 | for (i = 0; (i < (pos_in_buf)) && (cur_ent != NULL); i++) { |
605 | /* go entry by entry figuring out which is first */ | 618 | /* go entry by entry figuring out which is first */ |
606 | current_entry = nxt_dir_entry(current_entry, end_of_smb, | 619 | cur_ent = nxt_dir_entry(cur_ent, end_of_smb, |
607 | cifsFile->srch_inf.info_level); | 620 | cfile->srch_inf.info_level); |
608 | } | 621 | } |
609 | if ((current_entry == NULL) && (i < pos_in_buf)) { | 622 | if ((cur_ent == NULL) && (i < pos_in_buf)) { |
610 | /* BB fixme - check if we should flag this error */ | 623 | /* BB fixme - check if we should flag this error */ |
611 | cERROR(1, "reached end of buf searching for pos in buf" | 624 | cERROR(1, "reached end of buf searching for pos in buf" |
612 | " %d index to find %lld rc %d", | 625 | " %d index to find %lld rc %d", pos_in_buf, |
613 | pos_in_buf, index_to_find, rc); | 626 | index_to_find, rc); |
614 | } | 627 | } |
615 | rc = 0; | 628 | rc = 0; |
616 | *ppCurrentEntry = current_entry; | 629 | *current_entry = cur_ent; |
617 | } else { | 630 | } else { |
618 | cFYI(1, "index not in buffer - could not findnext into it"); | 631 | cFYI(1, "index not in buffer - could not findnext into it"); |
619 | return 0; | 632 | return 0; |
620 | } | 633 | } |
621 | 634 | ||
622 | if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) { | 635 | if (pos_in_buf >= cfile->srch_inf.entries_in_buffer) { |
623 | cFYI(1, "can not return entries pos_in_buf beyond last"); | 636 | cFYI(1, "can not return entries pos_in_buf beyond last"); |
624 | *num_to_ret = 0; | 637 | *num_to_ret = 0; |
625 | } else | 638 | } else |
626 | *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf; | 639 | *num_to_ret = cfile->srch_inf.entries_in_buffer - pos_in_buf; |
627 | 640 | ||
628 | return rc; | 641 | return rc; |
629 | } | 642 | } |
@@ -723,7 +736,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
723 | int rc = 0; | 736 | int rc = 0; |
724 | unsigned int xid; | 737 | unsigned int xid; |
725 | int i; | 738 | int i; |
726 | struct cifs_tcon *pTcon; | 739 | struct cifs_tcon *tcon; |
727 | struct cifsFileInfo *cifsFile = NULL; | 740 | struct cifsFileInfo *cifsFile = NULL; |
728 | char *current_entry; | 741 | char *current_entry; |
729 | int num_to_fill = 0; | 742 | int num_to_fill = 0; |
@@ -781,12 +794,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
781 | } | 794 | } |
782 | } /* else { | 795 | } /* else { |
783 | cifsFile->invalidHandle = true; | 796 | cifsFile->invalidHandle = true; |
784 | CIFSFindClose(xid, pTcon, cifsFile->netfid); | 797 | tcon->ses->server->close(xid, tcon, &cifsFile->fid); |
785 | } */ | 798 | } */ |
786 | 799 | ||
787 | pTcon = tlink_tcon(cifsFile->tlink); | 800 | tcon = tlink_tcon(cifsFile->tlink); |
788 | rc = find_cifs_entry(xid, pTcon, file, | 801 | rc = find_cifs_entry(xid, tcon, file, ¤t_entry, |
789 | ¤t_entry, &num_to_fill); | 802 | &num_to_fill); |
790 | if (rc) { | 803 | if (rc) { |
791 | cFYI(1, "fce error %d", rc); | 804 | cFYI(1, "fce error %d", rc); |
792 | goto rddir2_exit; | 805 | goto rddir2_exit; |
@@ -798,7 +811,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
798 | } | 811 | } |
799 | cFYI(1, "loop through %d times filling dir for net buf %p", | 812 | cFYI(1, "loop through %d times filling dir for net buf %p", |
800 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); | 813 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); |
801 | max_len = smbCalcSize((struct smb_hdr *) | 814 | max_len = tcon->ses->server->ops->calc_smb_size( |
802 | cifsFile->srch_inf.ntwrk_buf_start); | 815 | cifsFile->srch_inf.ntwrk_buf_start); |
803 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; | 816 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; |
804 | 817 | ||
@@ -815,10 +828,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
815 | num_to_fill, i); | 828 | num_to_fill, i); |
816 | break; | 829 | break; |
817 | } | 830 | } |
818 | /* if buggy server returns . and .. late do | 831 | /* |
819 | we want to check for that here? */ | 832 | * if buggy server returns . and .. late do we want to |
820 | rc = cifs_filldir(current_entry, file, | 833 | * check for that here? |
821 | filldir, direntry, tmp_buf, max_len); | 834 | */ |
835 | rc = cifs_filldir(current_entry, file, filldir, | ||
836 | direntry, tmp_buf, max_len); | ||
822 | if (rc == -EOVERFLOW) { | 837 | if (rc == -EOVERFLOW) { |
823 | rc = 0; | 838 | rc = 0; |
824 | break; | 839 | break; |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 382c06d01b38..76809f4d3428 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -876,7 +876,8 @@ ssetup_ntlmssp_authenticate: | |||
876 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; | 876 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; |
877 | smb_buf = (struct smb_hdr *)iov[0].iov_base; | 877 | smb_buf = (struct smb_hdr *)iov[0].iov_base; |
878 | 878 | ||
879 | if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError == | 879 | if ((type == RawNTLMSSP) && (resp_buf_type != CIFS_NO_BUFFER) && |
880 | (smb_buf->Status.CifsError == | ||
880 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { | 881 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { |
881 | if (phase != NtLmNegotiate) { | 882 | if (phase != NtLmNegotiate) { |
882 | cERROR(1, "Unexpected more processing error"); | 883 | cERROR(1, "Unexpected more processing error"); |
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index 3129ac74b819..56cc4be87807 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c | |||
@@ -17,6 +17,8 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/pagemap.h> | ||
21 | #include <linux/vfs.h> | ||
20 | #include "cifsglob.h" | 22 | #include "cifsglob.h" |
21 | #include "cifsproto.h" | 23 | #include "cifsproto.h" |
22 | #include "cifs_debug.h" | 24 | #include "cifs_debug.h" |
@@ -63,7 +65,7 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf, | |||
63 | static bool | 65 | static bool |
64 | cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | 66 | cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) |
65 | { | 67 | { |
66 | return ob1->netfid == ob2->netfid; | 68 | return ob1->fid.netfid == ob2->fid.netfid; |
67 | } | 69 | } |
68 | 70 | ||
69 | static unsigned int | 71 | static unsigned int |
@@ -410,6 +412,83 @@ cifs_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
410 | return rc; | 412 | return rc; |
411 | } | 413 | } |
412 | 414 | ||
415 | static unsigned int | ||
416 | cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
417 | { | ||
418 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
419 | struct TCP_Server_Info *server = tcon->ses->server; | ||
420 | unsigned int wsize; | ||
421 | |||
422 | /* start with specified wsize, or default */ | ||
423 | if (volume_info->wsize) | ||
424 | wsize = volume_info->wsize; | ||
425 | else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
426 | wsize = CIFS_DEFAULT_IOSIZE; | ||
427 | else | ||
428 | wsize = CIFS_DEFAULT_NON_POSIX_WSIZE; | ||
429 | |||
430 | /* can server support 24-bit write sizes? (via UNIX extensions) */ | ||
431 | if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP)) | ||
432 | wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE); | ||
433 | |||
434 | /* | ||
435 | * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set? | ||
436 | * Limit it to max buffer offered by the server, minus the size of the | ||
437 | * WRITEX header, not including the 4 byte RFC1001 length. | ||
438 | */ | ||
439 | if (!(server->capabilities & CAP_LARGE_WRITE_X) || | ||
440 | (!(server->capabilities & CAP_UNIX) && | ||
441 | (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)))) | ||
442 | wsize = min_t(unsigned int, wsize, | ||
443 | server->maxBuf - sizeof(WRITE_REQ) + 4); | ||
444 | |||
445 | /* hard limit of CIFS_MAX_WSIZE */ | ||
446 | wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE); | ||
447 | |||
448 | return wsize; | ||
449 | } | ||
450 | |||
451 | static unsigned int | ||
452 | cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
453 | { | ||
454 | __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); | ||
455 | struct TCP_Server_Info *server = tcon->ses->server; | ||
456 | unsigned int rsize, defsize; | ||
457 | |||
458 | /* | ||
459 | * Set default value... | ||
460 | * | ||
461 | * HACK alert! Ancient servers have very small buffers. Even though | ||
462 | * MS-CIFS indicates that servers are only limited by the client's | ||
463 | * bufsize for reads, testing against win98se shows that it throws | ||
464 | * INVALID_PARAMETER errors if you try to request too large a read. | ||
465 | * OS/2 just sends back short reads. | ||
466 | * | ||
467 | * If the server doesn't advertise CAP_LARGE_READ_X, then assume that | ||
468 | * it can't handle a read request larger than its MaxBufferSize either. | ||
469 | */ | ||
470 | if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP)) | ||
471 | defsize = CIFS_DEFAULT_IOSIZE; | ||
472 | else if (server->capabilities & CAP_LARGE_READ_X) | ||
473 | defsize = CIFS_DEFAULT_NON_POSIX_RSIZE; | ||
474 | else | ||
475 | defsize = server->maxBuf - sizeof(READ_RSP); | ||
476 | |||
477 | rsize = volume_info->rsize ? volume_info->rsize : defsize; | ||
478 | |||
479 | /* | ||
480 | * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to | ||
481 | * the client's MaxBufferSize. | ||
482 | */ | ||
483 | if (!(server->capabilities & CAP_LARGE_READ_X)) | ||
484 | rsize = min_t(unsigned int, CIFSMaxBufSize, rsize); | ||
485 | |||
486 | /* hard limit of CIFS_MAX_RSIZE */ | ||
487 | rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE); | ||
488 | |||
489 | return rsize; | ||
490 | } | ||
491 | |||
413 | static void | 492 | static void |
414 | cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) | 493 | cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon) |
415 | { | 494 | { |
@@ -489,6 +568,13 @@ cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |||
489 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 568 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
490 | } | 569 | } |
491 | 570 | ||
571 | static int | ||
572 | cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
573 | struct cifs_fid *fid, FILE_ALL_INFO *data) | ||
574 | { | ||
575 | return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data); | ||
576 | } | ||
577 | |||
492 | static char * | 578 | static char * |
493 | cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, | 579 | cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, |
494 | struct cifs_tcon *tcon) | 580 | struct cifs_tcon *tcon) |
@@ -607,6 +693,219 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path, | |||
607 | cifsInode->cifsAttrs = dosattrs; | 693 | cifsInode->cifsAttrs = dosattrs; |
608 | } | 694 | } |
609 | 695 | ||
696 | static int | ||
697 | cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, | ||
698 | int disposition, int desired_access, int create_options, | ||
699 | struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf, | ||
700 | struct cifs_sb_info *cifs_sb) | ||
701 | { | ||
702 | if (!(tcon->ses->capabilities & CAP_NT_SMBS)) | ||
703 | return SMBLegacyOpen(xid, tcon, path, disposition, | ||
704 | desired_access, create_options, | ||
705 | &fid->netfid, oplock, buf, | ||
706 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags | ||
707 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
708 | return CIFSSMBOpen(xid, tcon, path, disposition, desired_access, | ||
709 | create_options, &fid->netfid, oplock, buf, | ||
710 | cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & | ||
711 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
712 | } | ||
713 | |||
714 | static void | ||
715 | cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | ||
716 | { | ||
717 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
718 | cfile->fid.netfid = fid->netfid; | ||
719 | cifs_set_oplock_level(cinode, oplock); | ||
720 | cinode->can_cache_brlcks = cinode->clientCanCacheAll; | ||
721 | } | ||
722 | |||
723 | static void | ||
724 | cifs_close_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
725 | struct cifs_fid *fid) | ||
726 | { | ||
727 | CIFSSMBClose(xid, tcon, fid->netfid); | ||
728 | } | ||
729 | |||
730 | static int | ||
731 | cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
732 | struct cifs_fid *fid) | ||
733 | { | ||
734 | return CIFSSMBFlush(xid, tcon, fid->netfid); | ||
735 | } | ||
736 | |||
737 | static int | ||
738 | cifs_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, | ||
739 | struct cifs_io_parms *parms, unsigned int *bytes_read, | ||
740 | char **buf, int *buf_type) | ||
741 | { | ||
742 | parms->netfid = cfile->fid.netfid; | ||
743 | return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type); | ||
744 | } | ||
745 | |||
746 | static int | ||
747 | cifs_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, | ||
748 | struct cifs_io_parms *parms, unsigned int *written, | ||
749 | struct kvec *iov, unsigned long nr_segs) | ||
750 | { | ||
751 | |||
752 | parms->netfid = cfile->fid.netfid; | ||
753 | return CIFSSMBWrite2(xid, parms, written, iov, nr_segs); | ||
754 | } | ||
755 | |||
756 | static int | ||
757 | smb_set_file_info(struct inode *inode, const char *full_path, | ||
758 | FILE_BASIC_INFO *buf, const unsigned int xid) | ||
759 | { | ||
760 | int oplock = 0; | ||
761 | int rc; | ||
762 | __u16 netfid; | ||
763 | __u32 netpid; | ||
764 | struct cifsFileInfo *open_file; | ||
765 | struct cifsInodeInfo *cinode = CIFS_I(inode); | ||
766 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
767 | struct tcon_link *tlink = NULL; | ||
768 | struct cifs_tcon *tcon; | ||
769 | FILE_BASIC_INFO info_buf; | ||
770 | |||
771 | /* if the file is already open for write, just use that fileid */ | ||
772 | open_file = find_writable_file(cinode, true); | ||
773 | if (open_file) { | ||
774 | netfid = open_file->fid.netfid; | ||
775 | netpid = open_file->pid; | ||
776 | tcon = tlink_tcon(open_file->tlink); | ||
777 | goto set_via_filehandle; | ||
778 | } | ||
779 | |||
780 | tlink = cifs_sb_tlink(cifs_sb); | ||
781 | if (IS_ERR(tlink)) { | ||
782 | rc = PTR_ERR(tlink); | ||
783 | tlink = NULL; | ||
784 | goto out; | ||
785 | } | ||
786 | tcon = tlink_tcon(tlink); | ||
787 | |||
788 | /* | ||
789 | * NT4 apparently returns success on this call, but it doesn't really | ||
790 | * work. | ||
791 | */ | ||
792 | if (!(tcon->ses->flags & CIFS_SES_NT4)) { | ||
793 | rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf, | ||
794 | cifs_sb->local_nls, | ||
795 | cifs_sb->mnt_cifs_flags & | ||
796 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
797 | if (rc == 0) { | ||
798 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); | ||
799 | goto out; | ||
800 | } else if (rc != -EOPNOTSUPP && rc != -EINVAL) | ||
801 | goto out; | ||
802 | } | ||
803 | |||
804 | cFYI(1, "calling SetFileInfo since SetPathInfo for times not supported " | ||
805 | "by this server"); | ||
806 | rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN, | ||
807 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR, | ||
808 | &netfid, &oplock, NULL, cifs_sb->local_nls, | ||
809 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
810 | |||
811 | if (rc != 0) { | ||
812 | if (rc == -EIO) | ||
813 | rc = -EINVAL; | ||
814 | goto out; | ||
815 | } | ||
816 | |||
817 | netpid = current->tgid; | ||
818 | |||
819 | set_via_filehandle: | ||
820 | rc = CIFSSMBSetFileInfo(xid, tcon, &info_buf, netfid, netpid); | ||
821 | if (!rc) | ||
822 | cinode->cifsAttrs = le32_to_cpu(buf->Attributes); | ||
823 | |||
824 | if (open_file == NULL) | ||
825 | CIFSSMBClose(xid, tcon, netfid); | ||
826 | else | ||
827 | cifsFileInfo_put(open_file); | ||
828 | out: | ||
829 | if (tlink != NULL) | ||
830 | cifs_put_tlink(tlink); | ||
831 | return rc; | ||
832 | } | ||
833 | |||
834 | static int | ||
835 | cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | ||
836 | const char *path, struct cifs_sb_info *cifs_sb, | ||
837 | struct cifs_fid *fid, __u16 search_flags, | ||
838 | struct cifs_search_info *srch_inf) | ||
839 | { | ||
840 | return CIFSFindFirst(xid, tcon, path, cifs_sb, | ||
841 | &fid->netfid, search_flags, srch_inf, true); | ||
842 | } | ||
843 | |||
844 | static int | ||
845 | cifs_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | ||
846 | struct cifs_fid *fid, __u16 search_flags, | ||
847 | struct cifs_search_info *srch_inf) | ||
848 | { | ||
849 | return CIFSFindNext(xid, tcon, fid->netfid, search_flags, srch_inf); | ||
850 | } | ||
851 | |||
852 | static int | ||
853 | cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | ||
854 | struct cifs_fid *fid) | ||
855 | { | ||
856 | return CIFSFindClose(xid, tcon, fid->netfid); | ||
857 | } | ||
858 | |||
859 | static int | ||
860 | cifs_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | ||
861 | struct cifsInodeInfo *cinode) | ||
862 | { | ||
863 | return CIFSSMBLock(0, tcon, fid->netfid, current->tgid, 0, 0, 0, 0, | ||
864 | LOCKING_ANDX_OPLOCK_RELEASE, false, | ||
865 | cinode->clientCanCacheRead ? 1 : 0); | ||
866 | } | ||
867 | |||
868 | static int | ||
869 | cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | ||
870 | struct kstatfs *buf) | ||
871 | { | ||
872 | int rc = -EOPNOTSUPP; | ||
873 | |||
874 | buf->f_type = CIFS_MAGIC_NUMBER; | ||
875 | |||
876 | /* | ||
877 | * We could add a second check for a QFS Unix capability bit | ||
878 | */ | ||
879 | if ((tcon->ses->capabilities & CAP_UNIX) && | ||
880 | (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability))) | ||
881 | rc = CIFSSMBQFSPosixInfo(xid, tcon, buf); | ||
882 | |||
883 | /* | ||
884 | * Only need to call the old QFSInfo if failed on newer one, | ||
885 | * e.g. by OS/2. | ||
886 | **/ | ||
887 | if (rc && (tcon->ses->capabilities & CAP_NT_SMBS)) | ||
888 | rc = CIFSSMBQFSInfo(xid, tcon, buf); | ||
889 | |||
890 | /* | ||
891 | * Some old Windows servers also do not support level 103, retry with | ||
892 | * older level one if old server failed the previous call or we | ||
893 | * bypassed it because we detected that this was an older LANMAN sess | ||
894 | */ | ||
895 | if (rc) | ||
896 | rc = SMBOldQFSInfo(xid, tcon, buf); | ||
897 | return rc; | ||
898 | } | ||
899 | |||
900 | static int | ||
901 | cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
902 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
903 | { | ||
904 | return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid, | ||
905 | current->tgid, length, offset, unlock, lock, | ||
906 | (__u8)type, wait, 0); | ||
907 | } | ||
908 | |||
610 | struct smb_version_operations smb1_operations = { | 909 | struct smb_version_operations smb1_operations = { |
611 | .send_cancel = send_nt_cancel, | 910 | .send_cancel = send_nt_cancel, |
612 | .compare_fids = cifs_compare_fids, | 911 | .compare_fids = cifs_compare_fids, |
@@ -630,6 +929,8 @@ struct smb_version_operations smb1_operations = { | |||
630 | .check_trans2 = cifs_check_trans2, | 929 | .check_trans2 = cifs_check_trans2, |
631 | .need_neg = cifs_need_neg, | 930 | .need_neg = cifs_need_neg, |
632 | .negotiate = cifs_negotiate, | 931 | .negotiate = cifs_negotiate, |
932 | .negotiate_wsize = cifs_negotiate_wsize, | ||
933 | .negotiate_rsize = cifs_negotiate_rsize, | ||
633 | .sess_setup = CIFS_SessSetup, | 934 | .sess_setup = CIFS_SessSetup, |
634 | .logoff = CIFSSMBLogoff, | 935 | .logoff = CIFSSMBLogoff, |
635 | .tree_connect = CIFSTCon, | 936 | .tree_connect = CIFSTCon, |
@@ -638,12 +939,37 @@ struct smb_version_operations smb1_operations = { | |||
638 | .qfs_tcon = cifs_qfs_tcon, | 939 | .qfs_tcon = cifs_qfs_tcon, |
639 | .is_path_accessible = cifs_is_path_accessible, | 940 | .is_path_accessible = cifs_is_path_accessible, |
640 | .query_path_info = cifs_query_path_info, | 941 | .query_path_info = cifs_query_path_info, |
942 | .query_file_info = cifs_query_file_info, | ||
641 | .get_srv_inum = cifs_get_srv_inum, | 943 | .get_srv_inum = cifs_get_srv_inum, |
944 | .set_path_size = CIFSSMBSetEOF, | ||
945 | .set_file_size = CIFSSMBSetFileSize, | ||
946 | .set_file_info = smb_set_file_info, | ||
642 | .build_path_to_root = cifs_build_path_to_root, | 947 | .build_path_to_root = cifs_build_path_to_root, |
643 | .echo = CIFSSMBEcho, | 948 | .echo = CIFSSMBEcho, |
644 | .mkdir = CIFSSMBMkDir, | 949 | .mkdir = CIFSSMBMkDir, |
645 | .mkdir_setinfo = cifs_mkdir_setinfo, | 950 | .mkdir_setinfo = cifs_mkdir_setinfo, |
646 | .rmdir = CIFSSMBRmDir, | 951 | .rmdir = CIFSSMBRmDir, |
952 | .unlink = CIFSSMBDelFile, | ||
953 | .rename_pending_delete = cifs_rename_pending_delete, | ||
954 | .rename = CIFSSMBRename, | ||
955 | .create_hardlink = CIFSCreateHardLink, | ||
956 | .open = cifs_open_file, | ||
957 | .set_fid = cifs_set_fid, | ||
958 | .close = cifs_close_file, | ||
959 | .flush = cifs_flush_file, | ||
960 | .async_readv = cifs_async_readv, | ||
961 | .async_writev = cifs_async_writev, | ||
962 | .sync_read = cifs_sync_read, | ||
963 | .sync_write = cifs_sync_write, | ||
964 | .query_dir_first = cifs_query_dir_first, | ||
965 | .query_dir_next = cifs_query_dir_next, | ||
966 | .close_dir = cifs_close_dir, | ||
967 | .calc_smb_size = smbCalcSize, | ||
968 | .oplock_response = cifs_oplock_response, | ||
969 | .queryfs = cifs_queryfs, | ||
970 | .mand_lock = cifs_mand_lock, | ||
971 | .mand_unlock_range = cifs_unlock_range, | ||
972 | .push_mand_locks = cifs_push_mandatory_locks, | ||
647 | }; | 973 | }; |
648 | 974 | ||
649 | struct smb_version_values smb1_values = { | 975 | struct smb_version_values smb1_values = { |
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c new file mode 100644 index 000000000000..a93eec30a50d --- /dev/null +++ b/fs/cifs/smb2file.c | |||
@@ -0,0 +1,302 @@ | |||
1 | /* | ||
2 | * fs/cifs/smb2file.c | ||
3 | * | ||
4 | * Copyright (C) International Business Machines Corp., 2002, 2011 | ||
5 | * Author(s): Steve French (sfrench@us.ibm.com), | ||
6 | * Pavel Shilovsky ((pshilovsky@samba.org) 2012 | ||
7 | * | ||
8 | * This library is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Lesser General Public License as published | ||
10 | * by the Free Software Foundation; either version 2.1 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
16 | * the GNU Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public License | ||
19 | * along with this library; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | #include <linux/fs.h> | ||
23 | #include <linux/stat.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/pagemap.h> | ||
26 | #include <asm/div64.h> | ||
27 | #include "cifsfs.h" | ||
28 | #include "cifspdu.h" | ||
29 | #include "cifsglob.h" | ||
30 | #include "cifsproto.h" | ||
31 | #include "cifs_debug.h" | ||
32 | #include "cifs_fs_sb.h" | ||
33 | #include "cifs_unicode.h" | ||
34 | #include "fscache.h" | ||
35 | #include "smb2proto.h" | ||
36 | |||
37 | void | ||
38 | smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock) | ||
39 | { | ||
40 | oplock &= 0xFF; | ||
41 | if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) | ||
42 | return; | ||
43 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) { | ||
44 | cinode->clientCanCacheAll = true; | ||
45 | cinode->clientCanCacheRead = true; | ||
46 | cFYI(1, "Exclusive Oplock granted on inode %p", | ||
47 | &cinode->vfs_inode); | ||
48 | } else if (oplock == SMB2_OPLOCK_LEVEL_II) { | ||
49 | cinode->clientCanCacheAll = false; | ||
50 | cinode->clientCanCacheRead = true; | ||
51 | cFYI(1, "Level II Oplock granted on inode %p", | ||
52 | &cinode->vfs_inode); | ||
53 | } else { | ||
54 | cinode->clientCanCacheAll = false; | ||
55 | cinode->clientCanCacheRead = false; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | int | ||
60 | smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, | ||
61 | int disposition, int desired_access, int create_options, | ||
62 | struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf, | ||
63 | struct cifs_sb_info *cifs_sb) | ||
64 | { | ||
65 | int rc; | ||
66 | __le16 *smb2_path; | ||
67 | struct smb2_file_all_info *smb2_data = NULL; | ||
68 | __u8 smb2_oplock[17]; | ||
69 | |||
70 | smb2_path = cifs_convert_path_to_utf16(path, cifs_sb); | ||
71 | if (smb2_path == NULL) { | ||
72 | rc = -ENOMEM; | ||
73 | goto out; | ||
74 | } | ||
75 | |||
76 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
77 | GFP_KERNEL); | ||
78 | if (smb2_data == NULL) { | ||
79 | rc = -ENOMEM; | ||
80 | goto out; | ||
81 | } | ||
82 | |||
83 | desired_access |= FILE_READ_ATTRIBUTES; | ||
84 | *smb2_oplock = SMB2_OPLOCK_LEVEL_EXCLUSIVE; | ||
85 | |||
86 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) | ||
87 | memcpy(smb2_oplock + 1, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
88 | |||
89 | rc = SMB2_open(xid, tcon, smb2_path, &fid->persistent_fid, | ||
90 | &fid->volatile_fid, desired_access, disposition, | ||
91 | 0, 0, smb2_oplock, smb2_data); | ||
92 | if (rc) | ||
93 | goto out; | ||
94 | |||
95 | if (buf) { | ||
96 | /* open response does not have IndexNumber field - get it */ | ||
97 | rc = SMB2_get_srv_num(xid, tcon, fid->persistent_fid, | ||
98 | fid->volatile_fid, | ||
99 | &smb2_data->IndexNumber); | ||
100 | if (rc) { | ||
101 | /* let get_inode_info disable server inode numbers */ | ||
102 | smb2_data->IndexNumber = 0; | ||
103 | rc = 0; | ||
104 | } | ||
105 | move_smb2_info_to_cifs(buf, smb2_data); | ||
106 | } | ||
107 | |||
108 | *oplock = *smb2_oplock; | ||
109 | out: | ||
110 | kfree(smb2_data); | ||
111 | kfree(smb2_path); | ||
112 | return rc; | ||
113 | } | ||
114 | |||
115 | int | ||
116 | smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, | ||
117 | const unsigned int xid) | ||
118 | { | ||
119 | int rc = 0, stored_rc; | ||
120 | unsigned int max_num, num = 0, max_buf; | ||
121 | struct smb2_lock_element *buf, *cur; | ||
122 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
123 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
124 | struct cifsLockInfo *li, *tmp; | ||
125 | __u64 length = 1 + flock->fl_end - flock->fl_start; | ||
126 | struct list_head tmp_llist; | ||
127 | |||
128 | INIT_LIST_HEAD(&tmp_llist); | ||
129 | |||
130 | /* | ||
131 | * Accessing maxBuf is racy with cifs_reconnect - need to store value | ||
132 | * and check it for zero before using. | ||
133 | */ | ||
134 | max_buf = tcon->ses->server->maxBuf; | ||
135 | if (!max_buf) | ||
136 | return -EINVAL; | ||
137 | |||
138 | max_num = max_buf / sizeof(struct smb2_lock_element); | ||
139 | buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL); | ||
140 | if (!buf) | ||
141 | return -ENOMEM; | ||
142 | |||
143 | cur = buf; | ||
144 | |||
145 | down_write(&cinode->lock_sem); | ||
146 | list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { | ||
147 | if (flock->fl_start > li->offset || | ||
148 | (flock->fl_start + length) < | ||
149 | (li->offset + li->length)) | ||
150 | continue; | ||
151 | if (current->tgid != li->pid) | ||
152 | continue; | ||
153 | if (cinode->can_cache_brlcks) { | ||
154 | /* | ||
155 | * We can cache brlock requests - simply remove a lock | ||
156 | * from the file's list. | ||
157 | */ | ||
158 | list_del(&li->llist); | ||
159 | cifs_del_lock_waiters(li); | ||
160 | kfree(li); | ||
161 | continue; | ||
162 | } | ||
163 | cur->Length = cpu_to_le64(li->length); | ||
164 | cur->Offset = cpu_to_le64(li->offset); | ||
165 | cur->Flags = cpu_to_le32(SMB2_LOCKFLAG_UNLOCK); | ||
166 | /* | ||
167 | * We need to save a lock here to let us add it again to the | ||
168 | * file's list if the unlock range request fails on the server. | ||
169 | */ | ||
170 | list_move(&li->llist, &tmp_llist); | ||
171 | if (++num == max_num) { | ||
172 | stored_rc = smb2_lockv(xid, tcon, | ||
173 | cfile->fid.persistent_fid, | ||
174 | cfile->fid.volatile_fid, | ||
175 | current->tgid, num, buf); | ||
176 | if (stored_rc) { | ||
177 | /* | ||
178 | * We failed on the unlock range request - add | ||
179 | * all locks from the tmp list to the head of | ||
180 | * the file's list. | ||
181 | */ | ||
182 | cifs_move_llist(&tmp_llist, | ||
183 | &cfile->llist->locks); | ||
184 | rc = stored_rc; | ||
185 | } else | ||
186 | /* | ||
187 | * The unlock range request succeed - free the | ||
188 | * tmp list. | ||
189 | */ | ||
190 | cifs_free_llist(&tmp_llist); | ||
191 | cur = buf; | ||
192 | num = 0; | ||
193 | } else | ||
194 | cur++; | ||
195 | } | ||
196 | if (num) { | ||
197 | stored_rc = smb2_lockv(xid, tcon, cfile->fid.persistent_fid, | ||
198 | cfile->fid.volatile_fid, current->tgid, | ||
199 | num, buf); | ||
200 | if (stored_rc) { | ||
201 | cifs_move_llist(&tmp_llist, &cfile->llist->locks); | ||
202 | rc = stored_rc; | ||
203 | } else | ||
204 | cifs_free_llist(&tmp_llist); | ||
205 | } | ||
206 | up_write(&cinode->lock_sem); | ||
207 | |||
208 | kfree(buf); | ||
209 | return rc; | ||
210 | } | ||
211 | |||
212 | static int | ||
213 | smb2_push_mand_fdlocks(struct cifs_fid_locks *fdlocks, const unsigned int xid, | ||
214 | struct smb2_lock_element *buf, unsigned int max_num) | ||
215 | { | ||
216 | int rc = 0, stored_rc; | ||
217 | struct cifsFileInfo *cfile = fdlocks->cfile; | ||
218 | struct cifsLockInfo *li; | ||
219 | unsigned int num = 0; | ||
220 | struct smb2_lock_element *cur = buf; | ||
221 | struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); | ||
222 | |||
223 | list_for_each_entry(li, &fdlocks->locks, llist) { | ||
224 | cur->Length = cpu_to_le64(li->length); | ||
225 | cur->Offset = cpu_to_le64(li->offset); | ||
226 | cur->Flags = cpu_to_le32(li->type | | ||
227 | SMB2_LOCKFLAG_FAIL_IMMEDIATELY); | ||
228 | if (++num == max_num) { | ||
229 | stored_rc = smb2_lockv(xid, tcon, | ||
230 | cfile->fid.persistent_fid, | ||
231 | cfile->fid.volatile_fid, | ||
232 | current->tgid, num, buf); | ||
233 | if (stored_rc) | ||
234 | rc = stored_rc; | ||
235 | cur = buf; | ||
236 | num = 0; | ||
237 | } else | ||
238 | cur++; | ||
239 | } | ||
240 | if (num) { | ||
241 | stored_rc = smb2_lockv(xid, tcon, | ||
242 | cfile->fid.persistent_fid, | ||
243 | cfile->fid.volatile_fid, | ||
244 | current->tgid, num, buf); | ||
245 | if (stored_rc) | ||
246 | rc = stored_rc; | ||
247 | } | ||
248 | |||
249 | return rc; | ||
250 | } | ||
251 | |||
252 | int | ||
253 | smb2_push_mandatory_locks(struct cifsFileInfo *cfile) | ||
254 | { | ||
255 | int rc = 0, stored_rc; | ||
256 | unsigned int xid; | ||
257 | unsigned int max_num, max_buf; | ||
258 | struct smb2_lock_element *buf; | ||
259 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
260 | struct cifs_fid_locks *fdlocks; | ||
261 | |||
262 | xid = get_xid(); | ||
263 | /* we are going to update can_cache_brlcks here - need a write access */ | ||
264 | down_write(&cinode->lock_sem); | ||
265 | if (!cinode->can_cache_brlcks) { | ||
266 | up_write(&cinode->lock_sem); | ||
267 | free_xid(xid); | ||
268 | return rc; | ||
269 | } | ||
270 | |||
271 | /* | ||
272 | * Accessing maxBuf is racy with cifs_reconnect - need to store value | ||
273 | * and check it for zero before using. | ||
274 | */ | ||
275 | max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf; | ||
276 | if (!max_buf) { | ||
277 | up_write(&cinode->lock_sem); | ||
278 | free_xid(xid); | ||
279 | return -EINVAL; | ||
280 | } | ||
281 | |||
282 | max_num = max_buf / sizeof(struct smb2_lock_element); | ||
283 | buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL); | ||
284 | if (!buf) { | ||
285 | up_write(&cinode->lock_sem); | ||
286 | free_xid(xid); | ||
287 | return -ENOMEM; | ||
288 | } | ||
289 | |||
290 | list_for_each_entry(fdlocks, &cinode->llist, llist) { | ||
291 | stored_rc = smb2_push_mand_fdlocks(fdlocks, xid, buf, max_num); | ||
292 | if (stored_rc) | ||
293 | rc = stored_rc; | ||
294 | } | ||
295 | |||
296 | cinode->can_cache_brlcks = false; | ||
297 | kfree(buf); | ||
298 | |||
299 | up_write(&cinode->lock_sem); | ||
300 | free_xid(xid); | ||
301 | return rc; | ||
302 | } | ||
diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h index 33c1d89090c0..7c0e2143e775 100644 --- a/fs/cifs/smb2glob.h +++ b/fs/cifs/smb2glob.h | |||
@@ -23,6 +23,8 @@ | |||
23 | #ifndef _SMB2_GLOB_H | 23 | #ifndef _SMB2_GLOB_H |
24 | #define _SMB2_GLOB_H | 24 | #define _SMB2_GLOB_H |
25 | 25 | ||
26 | #define SMB2_MAGIC_NUMBER 0xFE534D42 | ||
27 | |||
26 | /* | 28 | /* |
27 | ***************************************************************** | 29 | ***************************************************************** |
28 | * Constants go here | 30 | * Constants go here |
@@ -40,5 +42,17 @@ | |||
40 | #define SMB2_OP_MKDIR 5 | 42 | #define SMB2_OP_MKDIR 5 |
41 | #define SMB2_OP_RENAME 6 | 43 | #define SMB2_OP_RENAME 6 |
42 | #define SMB2_OP_DELETE 7 | 44 | #define SMB2_OP_DELETE 7 |
45 | #define SMB2_OP_HARDLINK 8 | ||
46 | #define SMB2_OP_SET_EOF 9 | ||
47 | |||
48 | /* Used when constructing chained read requests. */ | ||
49 | #define CHAINED_REQUEST 1 | ||
50 | #define START_OF_CHAIN 2 | ||
51 | #define END_OF_CHAIN 4 | ||
52 | #define RELATED_REQUEST 8 | ||
53 | |||
54 | #define SMB2_SIGNATURE_SIZE (16) | ||
55 | #define SMB2_NTLMV2_SESSKEY_SIZE (16) | ||
56 | #define SMB2_HMACSHA256_SIZE (32) | ||
43 | 57 | ||
44 | #endif /* _SMB2_GLOB_H */ | 58 | #endif /* _SMB2_GLOB_H */ |
diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 2aa5cb08c526..706482452df4 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c | |||
@@ -47,6 +47,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
47 | int rc, tmprc = 0; | 47 | int rc, tmprc = 0; |
48 | u64 persistent_fid, volatile_fid; | 48 | u64 persistent_fid, volatile_fid; |
49 | __le16 *utf16_path; | 49 | __le16 *utf16_path; |
50 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
50 | 51 | ||
51 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | 52 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
52 | if (!utf16_path) | 53 | if (!utf16_path) |
@@ -54,7 +55,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
54 | 55 | ||
55 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | 56 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, |
56 | desired_access, create_disposition, file_attributes, | 57 | desired_access, create_disposition, file_attributes, |
57 | create_options); | 58 | create_options, &oplock, NULL); |
58 | if (rc) { | 59 | if (rc) { |
59 | kfree(utf16_path); | 60 | kfree(utf16_path); |
60 | return rc; | 61 | return rc; |
@@ -74,6 +75,22 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
74 | * SMB2_open() call. | 75 | * SMB2_open() call. |
75 | */ | 76 | */ |
76 | break; | 77 | break; |
78 | case SMB2_OP_RENAME: | ||
79 | tmprc = SMB2_rename(xid, tcon, persistent_fid, volatile_fid, | ||
80 | (__le16 *)data); | ||
81 | break; | ||
82 | case SMB2_OP_HARDLINK: | ||
83 | tmprc = SMB2_set_hardlink(xid, tcon, persistent_fid, | ||
84 | volatile_fid, (__le16 *)data); | ||
85 | break; | ||
86 | case SMB2_OP_SET_EOF: | ||
87 | tmprc = SMB2_set_eof(xid, tcon, persistent_fid, volatile_fid, | ||
88 | current->tgid, (__le64 *)data); | ||
89 | break; | ||
90 | case SMB2_OP_SET_INFO: | ||
91 | tmprc = SMB2_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
92 | (FILE_BASIC_INFO *)data); | ||
93 | break; | ||
77 | default: | 94 | default: |
78 | cERROR(1, "Invalid command"); | 95 | cERROR(1, "Invalid command"); |
79 | break; | 96 | break; |
@@ -86,7 +103,7 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
86 | return rc; | 103 | return rc; |
87 | } | 104 | } |
88 | 105 | ||
89 | static void | 106 | void |
90 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) | 107 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
91 | { | 108 | { |
92 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); | 109 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); |
@@ -161,3 +178,80 @@ smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | |||
161 | 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE, | 178 | 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE, |
162 | NULL, SMB2_OP_DELETE); | 179 | NULL, SMB2_OP_DELETE); |
163 | } | 180 | } |
181 | |||
182 | int | ||
183 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | ||
184 | struct cifs_sb_info *cifs_sb) | ||
185 | { | ||
186 | return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, | ||
187 | 0, CREATE_DELETE_ON_CLOSE, NULL, | ||
188 | SMB2_OP_DELETE); | ||
189 | } | ||
190 | |||
191 | static int | ||
192 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, | ||
193 | const char *from_name, const char *to_name, | ||
194 | struct cifs_sb_info *cifs_sb, __u32 access, int command) | ||
195 | { | ||
196 | __le16 *smb2_to_name = NULL; | ||
197 | int rc; | ||
198 | |||
199 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); | ||
200 | if (smb2_to_name == NULL) { | ||
201 | rc = -ENOMEM; | ||
202 | goto smb2_rename_path; | ||
203 | } | ||
204 | |||
205 | rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access, | ||
206 | FILE_OPEN, 0, 0, smb2_to_name, command); | ||
207 | smb2_rename_path: | ||
208 | kfree(smb2_to_name); | ||
209 | return rc; | ||
210 | } | ||
211 | |||
212 | int | ||
213 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, | ||
214 | const char *from_name, const char *to_name, | ||
215 | struct cifs_sb_info *cifs_sb) | ||
216 | { | ||
217 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, | ||
218 | DELETE, SMB2_OP_RENAME); | ||
219 | } | ||
220 | |||
221 | int | ||
222 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
223 | const char *from_name, const char *to_name, | ||
224 | struct cifs_sb_info *cifs_sb) | ||
225 | { | ||
226 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, | ||
227 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK); | ||
228 | } | ||
229 | |||
230 | int | ||
231 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
232 | const char *full_path, __u64 size, | ||
233 | struct cifs_sb_info *cifs_sb, bool set_alloc) | ||
234 | { | ||
235 | __le64 eof = cpu_to_le64(size); | ||
236 | return smb2_open_op_close(xid, tcon, cifs_sb, full_path, | ||
237 | FILE_WRITE_DATA, FILE_OPEN, 0, 0, &eof, | ||
238 | SMB2_OP_SET_EOF); | ||
239 | } | ||
240 | |||
241 | int | ||
242 | smb2_set_file_info(struct inode *inode, const char *full_path, | ||
243 | FILE_BASIC_INFO *buf, const unsigned int xid) | ||
244 | { | ||
245 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | ||
246 | struct tcon_link *tlink; | ||
247 | int rc; | ||
248 | |||
249 | tlink = cifs_sb_tlink(cifs_sb); | ||
250 | if (IS_ERR(tlink)) | ||
251 | return PTR_ERR(tlink); | ||
252 | rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path, | ||
253 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, 0, buf, | ||
254 | SMB2_OP_SET_INFO); | ||
255 | cifs_put_tlink(tlink); | ||
256 | return rc; | ||
257 | } | ||
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c index be41478acc05..494c912c76fe 100644 --- a/fs/cifs/smb2maperror.c +++ b/fs/cifs/smb2maperror.c | |||
@@ -453,7 +453,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = { | |||
453 | {STATUS_FILE_INVALID, -EIO, "STATUS_FILE_INVALID"}, | 453 | {STATUS_FILE_INVALID, -EIO, "STATUS_FILE_INVALID"}, |
454 | {STATUS_ALLOTTED_SPACE_EXCEEDED, -EIO, | 454 | {STATUS_ALLOTTED_SPACE_EXCEEDED, -EIO, |
455 | "STATUS_ALLOTTED_SPACE_EXCEEDED"}, | 455 | "STATUS_ALLOTTED_SPACE_EXCEEDED"}, |
456 | {STATUS_INSUFFICIENT_RESOURCES, -EIO, "STATUS_INSUFFICIENT_RESOURCES"}, | 456 | {STATUS_INSUFFICIENT_RESOURCES, -EREMOTEIO, |
457 | "STATUS_INSUFFICIENT_RESOURCES"}, | ||
457 | {STATUS_DFS_EXIT_PATH_FOUND, -EIO, "STATUS_DFS_EXIT_PATH_FOUND"}, | 458 | {STATUS_DFS_EXIT_PATH_FOUND, -EIO, "STATUS_DFS_EXIT_PATH_FOUND"}, |
458 | {STATUS_DEVICE_DATA_ERROR, -EIO, "STATUS_DEVICE_DATA_ERROR"}, | 459 | {STATUS_DEVICE_DATA_ERROR, -EIO, "STATUS_DEVICE_DATA_ERROR"}, |
459 | {STATUS_DEVICE_NOT_CONNECTED, -EIO, "STATUS_DEVICE_NOT_CONNECTED"}, | 460 | {STATUS_DEVICE_NOT_CONNECTED, -EIO, "STATUS_DEVICE_NOT_CONNECTED"}, |
@@ -2455,7 +2456,8 @@ map_smb2_to_linux_error(char *buf, bool log_err) | |||
2455 | return 0; | 2456 | return 0; |
2456 | 2457 | ||
2457 | /* mask facility */ | 2458 | /* mask facility */ |
2458 | if (log_err && (smb2err != (STATUS_MORE_PROCESSING_REQUIRED))) | 2459 | if (log_err && (smb2err != STATUS_MORE_PROCESSING_REQUIRED) && |
2460 | (smb2err != STATUS_END_OF_FILE)) | ||
2459 | smb2_print_status(smb2err); | 2461 | smb2_print_status(smb2err); |
2460 | else if (cifsFYI & CIFS_RC) | 2462 | else if (cifsFYI & CIFS_RC) |
2461 | smb2_print_status(smb2err); | 2463 | smb2_print_status(smb2err); |
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index e4d3b9964167..7b1c5e3287fb 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c | |||
@@ -142,12 +142,19 @@ smb2_check_message(char *buf, unsigned int length) | |||
142 | } | 142 | } |
143 | 143 | ||
144 | if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { | 144 | if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { |
145 | if (hdr->Status == 0 || | 145 | if (command != SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0 || |
146 | pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2) { | 146 | pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) { |
147 | /* error packets have 9 byte structure size */ | 147 | /* error packets have 9 byte structure size */ |
148 | cERROR(1, "Illegal response size %u for command %d", | 148 | cERROR(1, "Illegal response size %u for command %d", |
149 | le16_to_cpu(pdu->StructureSize2), command); | 149 | le16_to_cpu(pdu->StructureSize2), command); |
150 | return 1; | 150 | return 1; |
151 | } else if (command == SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0) | ||
152 | && (le16_to_cpu(pdu->StructureSize2) != 44) | ||
153 | && (le16_to_cpu(pdu->StructureSize2) != 36)) { | ||
154 | /* special case for SMB2.1 lease break message */ | ||
155 | cERROR(1, "Illegal response size %d for oplock break", | ||
156 | le16_to_cpu(pdu->StructureSize2)); | ||
157 | return 1; | ||
151 | } | 158 | } |
152 | } | 159 | } |
153 | 160 | ||
@@ -162,6 +169,9 @@ smb2_check_message(char *buf, unsigned int length) | |||
162 | if (4 + len != clc_len) { | 169 | if (4 + len != clc_len) { |
163 | cFYI(1, "Calculated size %u length %u mismatch mid %llu", | 170 | cFYI(1, "Calculated size %u length %u mismatch mid %llu", |
164 | clc_len, 4 + len, mid); | 171 | clc_len, 4 + len, mid); |
172 | /* Windows 7 server returns 24 bytes more */ | ||
173 | if (clc_len + 20 == len && command == SMB2_OPLOCK_BREAK_HE) | ||
174 | return 0; | ||
165 | /* server can return one byte more */ | 175 | /* server can return one byte more */ |
166 | if (clc_len == 4 + len + 1) | 176 | if (clc_len == 4 + len + 1) |
167 | return 0; | 177 | return 0; |
@@ -244,7 +254,15 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) | |||
244 | ((struct smb2_query_info_rsp *)hdr)->OutputBufferLength); | 254 | ((struct smb2_query_info_rsp *)hdr)->OutputBufferLength); |
245 | break; | 255 | break; |
246 | case SMB2_READ: | 256 | case SMB2_READ: |
257 | *off = ((struct smb2_read_rsp *)hdr)->DataOffset; | ||
258 | *len = le32_to_cpu(((struct smb2_read_rsp *)hdr)->DataLength); | ||
259 | break; | ||
247 | case SMB2_QUERY_DIRECTORY: | 260 | case SMB2_QUERY_DIRECTORY: |
261 | *off = le16_to_cpu( | ||
262 | ((struct smb2_query_directory_rsp *)hdr)->OutputBufferOffset); | ||
263 | *len = le32_to_cpu( | ||
264 | ((struct smb2_query_directory_rsp *)hdr)->OutputBufferLength); | ||
265 | break; | ||
248 | case SMB2_IOCTL: | 266 | case SMB2_IOCTL: |
249 | case SMB2_CHANGE_NOTIFY: | 267 | case SMB2_CHANGE_NOTIFY: |
250 | default: | 268 | default: |
@@ -287,8 +305,9 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) | |||
287 | * portion, the number of word parameters and the data portion of the message. | 305 | * portion, the number of word parameters and the data portion of the message. |
288 | */ | 306 | */ |
289 | unsigned int | 307 | unsigned int |
290 | smb2_calc_size(struct smb2_hdr *hdr) | 308 | smb2_calc_size(void *buf) |
291 | { | 309 | { |
310 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | ||
292 | struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; | 311 | struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; |
293 | int offset; /* the offset from the beginning of SMB to data area */ | 312 | int offset; /* the offset from the beginning of SMB to data area */ |
294 | int data_length; /* the length of the variable length data area */ | 313 | int data_length; /* the length of the variable length data area */ |
@@ -347,3 +366,218 @@ cifs_convert_path_to_utf16(const char *from, struct cifs_sb_info *cifs_sb) | |||
347 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 366 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
348 | return to; | 367 | return to; |
349 | } | 368 | } |
369 | |||
370 | __le32 | ||
371 | smb2_get_lease_state(struct cifsInodeInfo *cinode) | ||
372 | { | ||
373 | if (cinode->clientCanCacheAll) | ||
374 | return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; | ||
375 | else if (cinode->clientCanCacheRead) | ||
376 | return SMB2_LEASE_READ_CACHING; | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | __u8 smb2_map_lease_to_oplock(__le32 lease_state) | ||
381 | { | ||
382 | if (lease_state & SMB2_LEASE_WRITE_CACHING) { | ||
383 | if (lease_state & SMB2_LEASE_HANDLE_CACHING) | ||
384 | return SMB2_OPLOCK_LEVEL_BATCH; | ||
385 | else | ||
386 | return SMB2_OPLOCK_LEVEL_EXCLUSIVE; | ||
387 | } else if (lease_state & SMB2_LEASE_READ_CACHING) | ||
388 | return SMB2_OPLOCK_LEVEL_II; | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | struct smb2_lease_break_work { | ||
393 | struct work_struct lease_break; | ||
394 | struct tcon_link *tlink; | ||
395 | __u8 lease_key[16]; | ||
396 | __le32 lease_state; | ||
397 | }; | ||
398 | |||
399 | static void | ||
400 | cifs_ses_oplock_break(struct work_struct *work) | ||
401 | { | ||
402 | struct smb2_lease_break_work *lw = container_of(work, | ||
403 | struct smb2_lease_break_work, lease_break); | ||
404 | int rc; | ||
405 | |||
406 | rc = SMB2_lease_break(0, tlink_tcon(lw->tlink), lw->lease_key, | ||
407 | lw->lease_state); | ||
408 | cFYI(1, "Lease release rc %d", rc); | ||
409 | cifs_put_tlink(lw->tlink); | ||
410 | kfree(lw); | ||
411 | } | ||
412 | |||
413 | static bool | ||
414 | smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server) | ||
415 | { | ||
416 | struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer; | ||
417 | struct list_head *tmp, *tmp1, *tmp2; | ||
418 | struct cifs_ses *ses; | ||
419 | struct cifs_tcon *tcon; | ||
420 | struct cifsInodeInfo *cinode; | ||
421 | struct cifsFileInfo *cfile; | ||
422 | struct cifs_pending_open *open; | ||
423 | struct smb2_lease_break_work *lw; | ||
424 | bool found; | ||
425 | int ack_req = le32_to_cpu(rsp->Flags & | ||
426 | SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED); | ||
427 | |||
428 | lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL); | ||
429 | if (!lw) { | ||
430 | cERROR(1, "Memory allocation failed during lease break check"); | ||
431 | return false; | ||
432 | } | ||
433 | |||
434 | INIT_WORK(&lw->lease_break, cifs_ses_oplock_break); | ||
435 | lw->lease_state = rsp->NewLeaseState; | ||
436 | |||
437 | cFYI(1, "Checking for lease break"); | ||
438 | |||
439 | /* look up tcon based on tid & uid */ | ||
440 | spin_lock(&cifs_tcp_ses_lock); | ||
441 | list_for_each(tmp, &server->smb_ses_list) { | ||
442 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); | ||
443 | |||
444 | spin_lock(&cifs_file_list_lock); | ||
445 | list_for_each(tmp1, &ses->tcon_list) { | ||
446 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); | ||
447 | |||
448 | cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); | ||
449 | list_for_each(tmp2, &tcon->openFileList) { | ||
450 | cfile = list_entry(tmp2, struct cifsFileInfo, | ||
451 | tlist); | ||
452 | cinode = CIFS_I(cfile->dentry->d_inode); | ||
453 | |||
454 | if (memcmp(cinode->lease_key, rsp->LeaseKey, | ||
455 | SMB2_LEASE_KEY_SIZE)) | ||
456 | continue; | ||
457 | |||
458 | cFYI(1, "found in the open list"); | ||
459 | cFYI(1, "lease key match, lease break 0x%d", | ||
460 | le32_to_cpu(rsp->NewLeaseState)); | ||
461 | |||
462 | smb2_set_oplock_level(cinode, | ||
463 | smb2_map_lease_to_oplock(rsp->NewLeaseState)); | ||
464 | |||
465 | if (ack_req) | ||
466 | cfile->oplock_break_cancelled = false; | ||
467 | else | ||
468 | cfile->oplock_break_cancelled = true; | ||
469 | |||
470 | queue_work(cifsiod_wq, &cfile->oplock_break); | ||
471 | |||
472 | spin_unlock(&cifs_file_list_lock); | ||
473 | spin_unlock(&cifs_tcp_ses_lock); | ||
474 | return true; | ||
475 | } | ||
476 | |||
477 | found = false; | ||
478 | list_for_each_entry(open, &tcon->pending_opens, olist) { | ||
479 | if (memcmp(open->lease_key, rsp->LeaseKey, | ||
480 | SMB2_LEASE_KEY_SIZE)) | ||
481 | continue; | ||
482 | |||
483 | if (!found && ack_req) { | ||
484 | found = true; | ||
485 | memcpy(lw->lease_key, open->lease_key, | ||
486 | SMB2_LEASE_KEY_SIZE); | ||
487 | lw->tlink = cifs_get_tlink(open->tlink); | ||
488 | queue_work(cifsiod_wq, | ||
489 | &lw->lease_break); | ||
490 | } | ||
491 | |||
492 | cFYI(1, "found in the pending open list"); | ||
493 | cFYI(1, "lease key match, lease break 0x%d", | ||
494 | le32_to_cpu(rsp->NewLeaseState)); | ||
495 | |||
496 | open->oplock = | ||
497 | smb2_map_lease_to_oplock(rsp->NewLeaseState); | ||
498 | } | ||
499 | if (found) { | ||
500 | spin_unlock(&cifs_file_list_lock); | ||
501 | spin_unlock(&cifs_tcp_ses_lock); | ||
502 | return true; | ||
503 | } | ||
504 | } | ||
505 | spin_unlock(&cifs_file_list_lock); | ||
506 | } | ||
507 | spin_unlock(&cifs_tcp_ses_lock); | ||
508 | kfree(lw); | ||
509 | cFYI(1, "Can not process lease break - no lease matched"); | ||
510 | return false; | ||
511 | } | ||
512 | |||
513 | bool | ||
514 | smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) | ||
515 | { | ||
516 | struct smb2_oplock_break *rsp = (struct smb2_oplock_break *)buffer; | ||
517 | struct list_head *tmp, *tmp1, *tmp2; | ||
518 | struct cifs_ses *ses; | ||
519 | struct cifs_tcon *tcon; | ||
520 | struct cifsInodeInfo *cinode; | ||
521 | struct cifsFileInfo *cfile; | ||
522 | |||
523 | cFYI(1, "Checking for oplock break"); | ||
524 | |||
525 | if (rsp->hdr.Command != SMB2_OPLOCK_BREAK) | ||
526 | return false; | ||
527 | |||
528 | if (rsp->StructureSize != | ||
529 | smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) { | ||
530 | if (le16_to_cpu(rsp->StructureSize) == 44) | ||
531 | return smb2_is_valid_lease_break(buffer, server); | ||
532 | else | ||
533 | return false; | ||
534 | } | ||
535 | |||
536 | cFYI(1, "oplock level 0x%d", rsp->OplockLevel); | ||
537 | |||
538 | /* look up tcon based on tid & uid */ | ||
539 | spin_lock(&cifs_tcp_ses_lock); | ||
540 | list_for_each(tmp, &server->smb_ses_list) { | ||
541 | ses = list_entry(tmp, struct cifs_ses, smb_ses_list); | ||
542 | list_for_each(tmp1, &ses->tcon_list) { | ||
543 | tcon = list_entry(tmp1, struct cifs_tcon, tcon_list); | ||
544 | |||
545 | cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); | ||
546 | spin_lock(&cifs_file_list_lock); | ||
547 | list_for_each(tmp2, &tcon->openFileList) { | ||
548 | cfile = list_entry(tmp2, struct cifsFileInfo, | ||
549 | tlist); | ||
550 | if (rsp->PersistentFid != | ||
551 | cfile->fid.persistent_fid || | ||
552 | rsp->VolatileFid != | ||
553 | cfile->fid.volatile_fid) | ||
554 | continue; | ||
555 | |||
556 | cFYI(1, "file id match, oplock break"); | ||
557 | cinode = CIFS_I(cfile->dentry->d_inode); | ||
558 | |||
559 | if (!cinode->clientCanCacheAll && | ||
560 | rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE) | ||
561 | cfile->oplock_break_cancelled = true; | ||
562 | else | ||
563 | cfile->oplock_break_cancelled = false; | ||
564 | |||
565 | smb2_set_oplock_level(cinode, | ||
566 | rsp->OplockLevel ? SMB2_OPLOCK_LEVEL_II : 0); | ||
567 | |||
568 | queue_work(cifsiod_wq, &cfile->oplock_break); | ||
569 | |||
570 | spin_unlock(&cifs_file_list_lock); | ||
571 | spin_unlock(&cifs_tcp_ses_lock); | ||
572 | return true; | ||
573 | } | ||
574 | spin_unlock(&cifs_file_list_lock); | ||
575 | spin_unlock(&cifs_tcp_ses_lock); | ||
576 | cFYI(1, "No matching file for oplock break"); | ||
577 | return true; | ||
578 | } | ||
579 | } | ||
580 | spin_unlock(&cifs_tcp_ses_lock); | ||
581 | cFYI(1, "Can not process oplock break for non-existent connection"); | ||
582 | return false; | ||
583 | } | ||
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 826209bf3684..4d9dbe0b7385 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c | |||
@@ -17,11 +17,15 @@ | |||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/pagemap.h> | ||
21 | #include <linux/vfs.h> | ||
20 | #include "cifsglob.h" | 22 | #include "cifsglob.h" |
21 | #include "smb2pdu.h" | 23 | #include "smb2pdu.h" |
22 | #include "smb2proto.h" | 24 | #include "smb2proto.h" |
23 | #include "cifsproto.h" | 25 | #include "cifsproto.h" |
24 | #include "cifs_debug.h" | 26 | #include "cifs_debug.h" |
27 | #include "smb2status.h" | ||
28 | #include "smb2glob.h" | ||
25 | 29 | ||
26 | static int | 30 | static int |
27 | change_conf(struct TCP_Server_Info *server) | 31 | change_conf(struct TCP_Server_Info *server) |
@@ -63,6 +67,17 @@ smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add, | |||
63 | server->in_flight--; | 67 | server->in_flight--; |
64 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) | 68 | if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP) |
65 | rc = change_conf(server); | 69 | rc = change_conf(server); |
70 | /* | ||
71 | * Sometimes server returns 0 credits on oplock break ack - we need to | ||
72 | * rebalance credits in this case. | ||
73 | */ | ||
74 | else if (server->in_flight > 0 && server->oplock_credits == 0 && | ||
75 | server->oplocks) { | ||
76 | if (server->credits > 1) { | ||
77 | server->credits--; | ||
78 | server->oplock_credits++; | ||
79 | } | ||
80 | } | ||
66 | spin_unlock(&server->req_lock); | 81 | spin_unlock(&server->req_lock); |
67 | wake_up(&server->request_q); | 82 | wake_up(&server->request_q); |
68 | if (rc) | 83 | if (rc) |
@@ -157,6 +172,42 @@ smb2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
157 | return rc; | 172 | return rc; |
158 | } | 173 | } |
159 | 174 | ||
175 | static unsigned int | ||
176 | smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
177 | { | ||
178 | struct TCP_Server_Info *server = tcon->ses->server; | ||
179 | unsigned int wsize; | ||
180 | |||
181 | /* start with specified wsize, or default */ | ||
182 | wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE; | ||
183 | wsize = min_t(unsigned int, wsize, server->max_write); | ||
184 | /* | ||
185 | * limit write size to 2 ** 16, because we don't support multicredit | ||
186 | * requests now. | ||
187 | */ | ||
188 | wsize = min_t(unsigned int, wsize, 2 << 15); | ||
189 | |||
190 | return wsize; | ||
191 | } | ||
192 | |||
193 | static unsigned int | ||
194 | smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info) | ||
195 | { | ||
196 | struct TCP_Server_Info *server = tcon->ses->server; | ||
197 | unsigned int rsize; | ||
198 | |||
199 | /* start with specified rsize, or default */ | ||
200 | rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE; | ||
201 | rsize = min_t(unsigned int, rsize, server->max_read); | ||
202 | /* | ||
203 | * limit write size to 2 ** 16, because we don't support multicredit | ||
204 | * requests now. | ||
205 | */ | ||
206 | rsize = min_t(unsigned int, rsize, 2 << 15); | ||
207 | |||
208 | return rsize; | ||
209 | } | ||
210 | |||
160 | static int | 211 | static int |
161 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | 212 | smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, |
162 | struct cifs_sb_info *cifs_sb, const char *full_path) | 213 | struct cifs_sb_info *cifs_sb, const char *full_path) |
@@ -164,13 +215,14 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, | |||
164 | int rc; | 215 | int rc; |
165 | __u64 persistent_fid, volatile_fid; | 216 | __u64 persistent_fid, volatile_fid; |
166 | __le16 *utf16_path; | 217 | __le16 *utf16_path; |
218 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
167 | 219 | ||
168 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | 220 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
169 | if (!utf16_path) | 221 | if (!utf16_path) |
170 | return -ENOMEM; | 222 | return -ENOMEM; |
171 | 223 | ||
172 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | 224 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, |
173 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0); | 225 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); |
174 | if (rc) { | 226 | if (rc) { |
175 | kfree(utf16_path); | 227 | kfree(utf16_path); |
176 | return rc; | 228 | return rc; |
@@ -190,6 +242,26 @@ smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon, | |||
190 | return 0; | 242 | return 0; |
191 | } | 243 | } |
192 | 244 | ||
245 | static int | ||
246 | smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
247 | struct cifs_fid *fid, FILE_ALL_INFO *data) | ||
248 | { | ||
249 | int rc; | ||
250 | struct smb2_file_all_info *smb2_data; | ||
251 | |||
252 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
253 | GFP_KERNEL); | ||
254 | if (smb2_data == NULL) | ||
255 | return -ENOMEM; | ||
256 | |||
257 | rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, | ||
258 | smb2_data); | ||
259 | if (!rc) | ||
260 | move_smb2_info_to_cifs(data, smb2_data); | ||
261 | kfree(smb2_data); | ||
262 | return rc; | ||
263 | } | ||
264 | |||
193 | static char * | 265 | static char * |
194 | smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, | 266 | smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb, |
195 | struct cifs_tcon *tcon) | 267 | struct cifs_tcon *tcon) |
@@ -292,7 +364,221 @@ smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon) | |||
292 | #endif | 364 | #endif |
293 | } | 365 | } |
294 | 366 | ||
367 | static void | ||
368 | smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock) | ||
369 | { | ||
370 | struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); | ||
371 | cfile->fid.persistent_fid = fid->persistent_fid; | ||
372 | cfile->fid.volatile_fid = fid->volatile_fid; | ||
373 | smb2_set_oplock_level(cinode, oplock); | ||
374 | cinode->can_cache_brlcks = cinode->clientCanCacheAll; | ||
375 | } | ||
376 | |||
377 | static void | ||
378 | smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
379 | struct cifs_fid *fid) | ||
380 | { | ||
381 | SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
382 | } | ||
383 | |||
384 | static int | ||
385 | smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
386 | struct cifs_fid *fid) | ||
387 | { | ||
388 | return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
389 | } | ||
390 | |||
391 | static unsigned int | ||
392 | smb2_read_data_offset(char *buf) | ||
393 | { | ||
394 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | ||
395 | return rsp->DataOffset; | ||
396 | } | ||
397 | |||
398 | static unsigned int | ||
399 | smb2_read_data_length(char *buf) | ||
400 | { | ||
401 | struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf; | ||
402 | return le32_to_cpu(rsp->DataLength); | ||
403 | } | ||
404 | |||
405 | |||
406 | static int | ||
407 | smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile, | ||
408 | struct cifs_io_parms *parms, unsigned int *bytes_read, | ||
409 | char **buf, int *buf_type) | ||
410 | { | ||
411 | parms->persistent_fid = cfile->fid.persistent_fid; | ||
412 | parms->volatile_fid = cfile->fid.volatile_fid; | ||
413 | return SMB2_read(xid, parms, bytes_read, buf, buf_type); | ||
414 | } | ||
415 | |||
416 | static int | ||
417 | smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile, | ||
418 | struct cifs_io_parms *parms, unsigned int *written, | ||
419 | struct kvec *iov, unsigned long nr_segs) | ||
420 | { | ||
421 | |||
422 | parms->persistent_fid = cfile->fid.persistent_fid; | ||
423 | parms->volatile_fid = cfile->fid.volatile_fid; | ||
424 | return SMB2_write(xid, parms, written, iov, nr_segs); | ||
425 | } | ||
426 | |||
427 | static int | ||
428 | smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
429 | struct cifsFileInfo *cfile, __u64 size, bool set_alloc) | ||
430 | { | ||
431 | __le64 eof = cpu_to_le64(size); | ||
432 | return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, | ||
433 | cfile->fid.volatile_fid, cfile->pid, &eof); | ||
434 | } | ||
435 | |||
436 | static int | ||
437 | smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, | ||
438 | const char *path, struct cifs_sb_info *cifs_sb, | ||
439 | struct cifs_fid *fid, __u16 search_flags, | ||
440 | struct cifs_search_info *srch_inf) | ||
441 | { | ||
442 | __le16 *utf16_path; | ||
443 | int rc; | ||
444 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
445 | __u64 persistent_fid, volatile_fid; | ||
446 | |||
447 | utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); | ||
448 | if (!utf16_path) | ||
449 | return -ENOMEM; | ||
450 | |||
451 | rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid, | ||
452 | FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0, | ||
453 | &oplock, NULL); | ||
454 | kfree(utf16_path); | ||
455 | if (rc) { | ||
456 | cERROR(1, "open dir failed"); | ||
457 | return rc; | ||
458 | } | ||
459 | |||
460 | srch_inf->entries_in_buffer = 0; | ||
461 | srch_inf->index_of_last_entry = 0; | ||
462 | fid->persistent_fid = persistent_fid; | ||
463 | fid->volatile_fid = volatile_fid; | ||
464 | |||
465 | rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0, | ||
466 | srch_inf); | ||
467 | if (rc) { | ||
468 | cERROR(1, "query directory failed"); | ||
469 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | ||
470 | } | ||
471 | return rc; | ||
472 | } | ||
473 | |||
474 | static int | ||
475 | smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, | ||
476 | struct cifs_fid *fid, __u16 search_flags, | ||
477 | struct cifs_search_info *srch_inf) | ||
478 | { | ||
479 | return SMB2_query_directory(xid, tcon, fid->persistent_fid, | ||
480 | fid->volatile_fid, 0, srch_inf); | ||
481 | } | ||
482 | |||
483 | static int | ||
484 | smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon, | ||
485 | struct cifs_fid *fid) | ||
486 | { | ||
487 | return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid); | ||
488 | } | ||
489 | |||
490 | /* | ||
491 | * If we negotiate SMB2 protocol and get STATUS_PENDING - update | ||
492 | * the number of credits and return true. Otherwise - return false. | ||
493 | */ | ||
494 | static bool | ||
495 | smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) | ||
496 | { | ||
497 | struct smb2_hdr *hdr = (struct smb2_hdr *)buf; | ||
498 | |||
499 | if (hdr->Status != STATUS_PENDING) | ||
500 | return false; | ||
501 | |||
502 | if (!length) { | ||
503 | spin_lock(&server->req_lock); | ||
504 | server->credits += le16_to_cpu(hdr->CreditRequest); | ||
505 | spin_unlock(&server->req_lock); | ||
506 | wake_up(&server->request_q); | ||
507 | } | ||
508 | |||
509 | return true; | ||
510 | } | ||
511 | |||
512 | static int | ||
513 | smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, | ||
514 | struct cifsInodeInfo *cinode) | ||
515 | { | ||
516 | if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) | ||
517 | return SMB2_lease_break(0, tcon, cinode->lease_key, | ||
518 | smb2_get_lease_state(cinode)); | ||
519 | |||
520 | return SMB2_oplock_break(0, tcon, fid->persistent_fid, | ||
521 | fid->volatile_fid, | ||
522 | cinode->clientCanCacheRead ? 1 : 0); | ||
523 | } | ||
524 | |||
525 | static int | ||
526 | smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon, | ||
527 | struct kstatfs *buf) | ||
528 | { | ||
529 | int rc; | ||
530 | u64 persistent_fid, volatile_fid; | ||
531 | __le16 srch_path = 0; /* Null - open root of share */ | ||
532 | u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
533 | |||
534 | rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid, | ||
535 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL); | ||
536 | if (rc) | ||
537 | return rc; | ||
538 | buf->f_type = SMB2_MAGIC_NUMBER; | ||
539 | rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf); | ||
540 | SMB2_close(xid, tcon, persistent_fid, volatile_fid); | ||
541 | return rc; | ||
542 | } | ||
543 | |||
544 | static bool | ||
545 | smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2) | ||
546 | { | ||
547 | return ob1->fid.persistent_fid == ob2->fid.persistent_fid && | ||
548 | ob1->fid.volatile_fid == ob2->fid.volatile_fid; | ||
549 | } | ||
550 | |||
551 | static int | ||
552 | smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset, | ||
553 | __u64 length, __u32 type, int lock, int unlock, bool wait) | ||
554 | { | ||
555 | if (unlock && !lock) | ||
556 | type = SMB2_LOCKFLAG_UNLOCK; | ||
557 | return SMB2_lock(xid, tlink_tcon(cfile->tlink), | ||
558 | cfile->fid.persistent_fid, cfile->fid.volatile_fid, | ||
559 | current->tgid, length, offset, type, wait); | ||
560 | } | ||
561 | |||
562 | static void | ||
563 | smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid) | ||
564 | { | ||
565 | memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE); | ||
566 | } | ||
567 | |||
568 | static void | ||
569 | smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid) | ||
570 | { | ||
571 | memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
572 | } | ||
573 | |||
574 | static void | ||
575 | smb2_new_lease_key(struct cifs_fid *fid) | ||
576 | { | ||
577 | get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE); | ||
578 | } | ||
579 | |||
295 | struct smb_version_operations smb21_operations = { | 580 | struct smb_version_operations smb21_operations = { |
581 | .compare_fids = smb2_compare_fids, | ||
296 | .setup_request = smb2_setup_request, | 582 | .setup_request = smb2_setup_request, |
297 | .setup_async_request = smb2_setup_async_request, | 583 | .setup_async_request = smb2_setup_async_request, |
298 | .check_receive = smb2_check_receive, | 584 | .check_receive = smb2_check_receive, |
@@ -301,13 +587,19 @@ struct smb_version_operations smb21_operations = { | |||
301 | .get_credits_field = smb2_get_credits_field, | 587 | .get_credits_field = smb2_get_credits_field, |
302 | .get_credits = smb2_get_credits, | 588 | .get_credits = smb2_get_credits, |
303 | .get_next_mid = smb2_get_next_mid, | 589 | .get_next_mid = smb2_get_next_mid, |
590 | .read_data_offset = smb2_read_data_offset, | ||
591 | .read_data_length = smb2_read_data_length, | ||
592 | .map_error = map_smb2_to_linux_error, | ||
304 | .find_mid = smb2_find_mid, | 593 | .find_mid = smb2_find_mid, |
305 | .check_message = smb2_check_message, | 594 | .check_message = smb2_check_message, |
306 | .dump_detail = smb2_dump_detail, | 595 | .dump_detail = smb2_dump_detail, |
307 | .clear_stats = smb2_clear_stats, | 596 | .clear_stats = smb2_clear_stats, |
308 | .print_stats = smb2_print_stats, | 597 | .print_stats = smb2_print_stats, |
598 | .is_oplock_break = smb2_is_valid_oplock_break, | ||
309 | .need_neg = smb2_need_neg, | 599 | .need_neg = smb2_need_neg, |
310 | .negotiate = smb2_negotiate, | 600 | .negotiate = smb2_negotiate, |
601 | .negotiate_wsize = smb2_negotiate_wsize, | ||
602 | .negotiate_rsize = smb2_negotiate_rsize, | ||
311 | .sess_setup = SMB2_sess_setup, | 603 | .sess_setup = SMB2_sess_setup, |
312 | .logoff = SMB2_logoff, | 604 | .logoff = SMB2_logoff, |
313 | .tree_connect = SMB2_tcon, | 605 | .tree_connect = SMB2_tcon, |
@@ -317,16 +609,68 @@ struct smb_version_operations smb21_operations = { | |||
317 | .echo = SMB2_echo, | 609 | .echo = SMB2_echo, |
318 | .query_path_info = smb2_query_path_info, | 610 | .query_path_info = smb2_query_path_info, |
319 | .get_srv_inum = smb2_get_srv_inum, | 611 | .get_srv_inum = smb2_get_srv_inum, |
612 | .query_file_info = smb2_query_file_info, | ||
613 | .set_path_size = smb2_set_path_size, | ||
614 | .set_file_size = smb2_set_file_size, | ||
615 | .set_file_info = smb2_set_file_info, | ||
320 | .build_path_to_root = smb2_build_path_to_root, | 616 | .build_path_to_root = smb2_build_path_to_root, |
321 | .mkdir = smb2_mkdir, | 617 | .mkdir = smb2_mkdir, |
322 | .mkdir_setinfo = smb2_mkdir_setinfo, | 618 | .mkdir_setinfo = smb2_mkdir_setinfo, |
323 | .rmdir = smb2_rmdir, | 619 | .rmdir = smb2_rmdir, |
620 | .unlink = smb2_unlink, | ||
621 | .rename = smb2_rename_path, | ||
622 | .create_hardlink = smb2_create_hardlink, | ||
623 | .open = smb2_open_file, | ||
624 | .set_fid = smb2_set_fid, | ||
625 | .close = smb2_close_file, | ||
626 | .flush = smb2_flush_file, | ||
627 | .async_readv = smb2_async_readv, | ||
628 | .async_writev = smb2_async_writev, | ||
629 | .sync_read = smb2_sync_read, | ||
630 | .sync_write = smb2_sync_write, | ||
631 | .query_dir_first = smb2_query_dir_first, | ||
632 | .query_dir_next = smb2_query_dir_next, | ||
633 | .close_dir = smb2_close_dir, | ||
634 | .calc_smb_size = smb2_calc_size, | ||
635 | .is_status_pending = smb2_is_status_pending, | ||
636 | .oplock_response = smb2_oplock_response, | ||
637 | .queryfs = smb2_queryfs, | ||
638 | .mand_lock = smb2_mand_lock, | ||
639 | .mand_unlock_range = smb2_unlock_range, | ||
640 | .push_mand_locks = smb2_push_mandatory_locks, | ||
641 | .get_lease_key = smb2_get_lease_key, | ||
642 | .set_lease_key = smb2_set_lease_key, | ||
643 | .new_lease_key = smb2_new_lease_key, | ||
324 | }; | 644 | }; |
325 | 645 | ||
326 | struct smb_version_values smb21_values = { | 646 | struct smb_version_values smb21_values = { |
327 | .version_string = SMB21_VERSION_STRING, | 647 | .version_string = SMB21_VERSION_STRING, |
648 | .protocol_id = SMB21_PROT_ID, | ||
649 | .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */ | ||
650 | .large_lock_type = 0, | ||
651 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | ||
652 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | ||
653 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | ||
654 | .header_size = sizeof(struct smb2_hdr), | ||
655 | .max_header_size = MAX_SMB2_HDR_SIZE, | ||
656 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | ||
657 | .lock_cmd = SMB2_LOCK, | ||
658 | .cap_unix = 0, | ||
659 | .cap_nt_find = SMB2_NT_FIND, | ||
660 | .cap_large_files = SMB2_LARGE_FILES, | ||
661 | }; | ||
662 | |||
663 | struct smb_version_values smb30_values = { | ||
664 | .version_string = SMB30_VERSION_STRING, | ||
665 | .protocol_id = SMB30_PROT_ID, | ||
666 | .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU, | ||
667 | .large_lock_type = 0, | ||
668 | .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, | ||
669 | .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, | ||
670 | .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, | ||
328 | .header_size = sizeof(struct smb2_hdr), | 671 | .header_size = sizeof(struct smb2_hdr), |
329 | .max_header_size = MAX_SMB2_HDR_SIZE, | 672 | .max_header_size = MAX_SMB2_HDR_SIZE, |
673 | .read_rsp_size = sizeof(struct smb2_read_rsp) - 1, | ||
330 | .lock_cmd = SMB2_LOCK, | 674 | .lock_cmd = SMB2_LOCK, |
331 | .cap_unix = 0, | 675 | .cap_unix = 0, |
332 | .cap_nt_find = SMB2_NT_FIND, | 676 | .cap_nt_find = SMB2_NT_FIND, |
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 62b3f17d0613..cf33622cdac8 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * fs/cifs/smb2pdu.c | 2 | * fs/cifs/smb2pdu.c |
3 | * | 3 | * |
4 | * Copyright (C) International Business Machines Corp., 2009, 2011 | 4 | * Copyright (C) International Business Machines Corp., 2009, 2012 |
5 | * Etersoft, 2012 | 5 | * Etersoft, 2012 |
6 | * Author(s): Steve French (sfrench@us.ibm.com) | 6 | * Author(s): Steve French (sfrench@us.ibm.com) |
7 | * Pavel Shilovsky (pshilovsky@samba.org) 2012 | 7 | * Pavel Shilovsky (pshilovsky@samba.org) 2012 |
@@ -31,7 +31,9 @@ | |||
31 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/vfs.h> | 33 | #include <linux/vfs.h> |
34 | #include <linux/task_io_accounting_ops.h> | ||
34 | #include <linux/uaccess.h> | 35 | #include <linux/uaccess.h> |
36 | #include <linux/pagemap.h> | ||
35 | #include <linux/xattr.h> | 37 | #include <linux/xattr.h> |
36 | #include "smb2pdu.h" | 38 | #include "smb2pdu.h" |
37 | #include "cifsglob.h" | 39 | #include "cifsglob.h" |
@@ -42,6 +44,8 @@ | |||
42 | #include "cifs_debug.h" | 44 | #include "cifs_debug.h" |
43 | #include "ntlmssp.h" | 45 | #include "ntlmssp.h" |
44 | #include "smb2status.h" | 46 | #include "smb2status.h" |
47 | #include "smb2glob.h" | ||
48 | #include "cifspdu.h" | ||
45 | 49 | ||
46 | /* | 50 | /* |
47 | * The following table defines the expected "StructureSize" of SMB2 requests | 51 | * The following table defines the expected "StructureSize" of SMB2 requests |
@@ -115,9 +119,9 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , | |||
115 | /* BB how does SMB2 do case sensitive? */ | 119 | /* BB how does SMB2 do case sensitive? */ |
116 | /* if (tcon->nocase) | 120 | /* if (tcon->nocase) |
117 | hdr->Flags |= SMBFLG_CASELESS; */ | 121 | hdr->Flags |= SMBFLG_CASELESS; */ |
118 | /* if (tcon->ses && tcon->ses->server && | 122 | if (tcon->ses && tcon->ses->server && |
119 | (tcon->ses->server->sec_mode & SECMODE_SIGN_REQUIRED)) | 123 | (tcon->ses->server->sec_mode & SECMODE_SIGN_REQUIRED)) |
120 | hdr->Flags |= SMB2_FLAGS_SIGNED; */ | 124 | hdr->Flags |= SMB2_FLAGS_SIGNED; |
121 | out: | 125 | out: |
122 | pdu->StructureSize2 = cpu_to_le16(parmsize); | 126 | pdu->StructureSize2 = cpu_to_le16(parmsize); |
123 | return; | 127 | return; |
@@ -300,24 +304,6 @@ free_rsp_buf(int resp_buftype, void *rsp) | |||
300 | cifs_buf_release(rsp); | 304 | cifs_buf_release(rsp); |
301 | } | 305 | } |
302 | 306 | ||
303 | #define SMB2_NUM_PROT 1 | ||
304 | |||
305 | #define SMB2_PROT 0 | ||
306 | #define SMB21_PROT 1 | ||
307 | #define BAD_PROT 0xFFFF | ||
308 | |||
309 | #define SMB2_PROT_ID 0x0202 | ||
310 | #define SMB21_PROT_ID 0x0210 | ||
311 | #define BAD_PROT_ID 0xFFFF | ||
312 | |||
313 | static struct { | ||
314 | int index; | ||
315 | __le16 name; | ||
316 | } smb2protocols[] = { | ||
317 | {SMB2_PROT, cpu_to_le16(SMB2_PROT_ID)}, | ||
318 | {SMB21_PROT, cpu_to_le16(SMB21_PROT_ID)}, | ||
319 | {BAD_PROT, cpu_to_le16(BAD_PROT_ID)} | ||
320 | }; | ||
321 | 307 | ||
322 | /* | 308 | /* |
323 | * | 309 | * |
@@ -344,7 +330,6 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
344 | int resp_buftype; | 330 | int resp_buftype; |
345 | struct TCP_Server_Info *server; | 331 | struct TCP_Server_Info *server; |
346 | unsigned int sec_flags; | 332 | unsigned int sec_flags; |
347 | u16 i; | ||
348 | u16 temp = 0; | 333 | u16 temp = 0; |
349 | int blob_offset, blob_length; | 334 | int blob_offset, blob_length; |
350 | char *security_blob; | 335 | char *security_blob; |
@@ -373,11 +358,10 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
373 | 358 | ||
374 | req->hdr.SessionId = 0; | 359 | req->hdr.SessionId = 0; |
375 | 360 | ||
376 | for (i = 0; i < SMB2_NUM_PROT; i++) | 361 | req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id); |
377 | req->Dialects[i] = smb2protocols[i].name; | ||
378 | 362 | ||
379 | req->DialectCount = cpu_to_le16(i); | 363 | req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */ |
380 | inc_rfc1001_len(req, i * 2); | 364 | inc_rfc1001_len(req, 2); |
381 | 365 | ||
382 | /* only one of SMB2 signing flags may be set in SMB2 request */ | 366 | /* only one of SMB2 signing flags may be set in SMB2 request */ |
383 | if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) | 367 | if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) |
@@ -387,7 +371,9 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
387 | 371 | ||
388 | req->SecurityMode = cpu_to_le16(temp); | 372 | req->SecurityMode = cpu_to_le16(temp); |
389 | 373 | ||
390 | req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); | 374 | req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities); |
375 | |||
376 | memcpy(req->ClientGUID, cifs_client_guid, SMB2_CLIENT_GUID_SIZE); | ||
391 | 377 | ||
392 | iov[0].iov_base = (char *)req; | 378 | iov[0].iov_base = (char *)req; |
393 | /* 4 for rfc1002 length field */ | 379 | /* 4 for rfc1002 length field */ |
@@ -403,17 +389,16 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
403 | if (rc != 0) | 389 | if (rc != 0) |
404 | goto neg_exit; | 390 | goto neg_exit; |
405 | 391 | ||
406 | if (rsp == NULL) { | ||
407 | rc = -EIO; | ||
408 | goto neg_exit; | ||
409 | } | ||
410 | |||
411 | cFYI(1, "mode 0x%x", rsp->SecurityMode); | 392 | cFYI(1, "mode 0x%x", rsp->SecurityMode); |
412 | 393 | ||
413 | if (rsp->DialectRevision == smb2protocols[SMB21_PROT].name) | 394 | /* BB we may eventually want to match the negotiated vs. requested |
395 | dialect, even though we are only requesting one at a time */ | ||
396 | if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID)) | ||
397 | cFYI(1, "negotiated smb2.0 dialect"); | ||
398 | else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID)) | ||
414 | cFYI(1, "negotiated smb2.1 dialect"); | 399 | cFYI(1, "negotiated smb2.1 dialect"); |
415 | else if (rsp->DialectRevision == smb2protocols[SMB2_PROT].name) | 400 | else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID)) |
416 | cFYI(1, "negotiated smb2 dialect"); | 401 | cFYI(1, "negotiated smb3.0 dialect"); |
417 | else { | 402 | else { |
418 | cERROR(1, "Illegal dialect returned by server %d", | 403 | cERROR(1, "Illegal dialect returned by server %d", |
419 | le16_to_cpu(rsp->DialectRevision)); | 404 | le16_to_cpu(rsp->DialectRevision)); |
@@ -438,6 +423,38 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
438 | rc = -EIO; | 423 | rc = -EIO; |
439 | goto neg_exit; | 424 | goto neg_exit; |
440 | } | 425 | } |
426 | |||
427 | cFYI(1, "sec_flags 0x%x", sec_flags); | ||
428 | if (sec_flags & CIFSSEC_MUST_SIGN) { | ||
429 | cFYI(1, "Signing required"); | ||
430 | if (!(server->sec_mode & (SMB2_NEGOTIATE_SIGNING_REQUIRED | | ||
431 | SMB2_NEGOTIATE_SIGNING_ENABLED))) { | ||
432 | cERROR(1, "signing required but server lacks support"); | ||
433 | rc = -EOPNOTSUPP; | ||
434 | goto neg_exit; | ||
435 | } | ||
436 | server->sec_mode |= SECMODE_SIGN_REQUIRED; | ||
437 | } else if (sec_flags & CIFSSEC_MAY_SIGN) { | ||
438 | cFYI(1, "Signing optional"); | ||
439 | if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) { | ||
440 | cFYI(1, "Server requires signing"); | ||
441 | server->sec_mode |= SECMODE_SIGN_REQUIRED; | ||
442 | } else { | ||
443 | server->sec_mode &= | ||
444 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | ||
445 | } | ||
446 | } else { | ||
447 | cFYI(1, "Signing disabled"); | ||
448 | if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) { | ||
449 | cERROR(1, "Server requires packet signing to be enabled" | ||
450 | " in /proc/fs/cifs/SecurityFlags."); | ||
451 | rc = -EOPNOTSUPP; | ||
452 | goto neg_exit; | ||
453 | } | ||
454 | server->sec_mode &= | ||
455 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | ||
456 | } | ||
457 | |||
441 | #ifdef CONFIG_SMB2_ASN1 /* BB REMOVEME when updated asn1.c ready */ | 458 | #ifdef CONFIG_SMB2_ASN1 /* BB REMOVEME when updated asn1.c ready */ |
442 | rc = decode_neg_token_init(security_blob, blob_length, | 459 | rc = decode_neg_token_init(security_blob, blob_length, |
443 | &server->sec_type); | 460 | &server->sec_type); |
@@ -599,13 +616,14 @@ ssetup_ntlmssp_authenticate: | |||
599 | 616 | ||
600 | kfree(security_blob); | 617 | kfree(security_blob); |
601 | rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base; | 618 | rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base; |
602 | if (rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) { | 619 | if (resp_buftype != CIFS_NO_BUFFER && |
620 | rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) { | ||
603 | if (phase != NtLmNegotiate) { | 621 | if (phase != NtLmNegotiate) { |
604 | cERROR(1, "Unexpected more processing error"); | 622 | cERROR(1, "Unexpected more processing error"); |
605 | goto ssetup_exit; | 623 | goto ssetup_exit; |
606 | } | 624 | } |
607 | if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 != | 625 | if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 != |
608 | le16_to_cpu(rsp->SecurityBufferOffset)) { | 626 | le16_to_cpu(rsp->SecurityBufferOffset)) { |
609 | cERROR(1, "Invalid security buffer offset %d", | 627 | cERROR(1, "Invalid security buffer offset %d", |
610 | le16_to_cpu(rsp->SecurityBufferOffset)); | 628 | le16_to_cpu(rsp->SecurityBufferOffset)); |
611 | rc = -EIO; | 629 | rc = -EIO; |
@@ -631,11 +649,6 @@ ssetup_ntlmssp_authenticate: | |||
631 | if (rc != 0) | 649 | if (rc != 0) |
632 | goto ssetup_exit; | 650 | goto ssetup_exit; |
633 | 651 | ||
634 | if (rsp == NULL) { | ||
635 | rc = -EIO; | ||
636 | goto ssetup_exit; | ||
637 | } | ||
638 | |||
639 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); | 652 | ses->session_flags = le16_to_cpu(rsp->SessionFlags); |
640 | ssetup_exit: | 653 | ssetup_exit: |
641 | free_rsp_buf(resp_buftype, rsp); | 654 | free_rsp_buf(resp_buftype, rsp); |
@@ -666,6 +679,8 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses) | |||
666 | 679 | ||
667 | /* since no tcon, smb2_init can not do this, so do here */ | 680 | /* since no tcon, smb2_init can not do this, so do here */ |
668 | req->hdr.SessionId = ses->Suid; | 681 | req->hdr.SessionId = ses->Suid; |
682 | if (server->sec_mode & SECMODE_SIGN_REQUIRED) | ||
683 | req->hdr.Flags |= SMB2_FLAGS_SIGNED; | ||
669 | 684 | ||
670 | rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0); | 685 | rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0); |
671 | /* | 686 | /* |
@@ -753,11 +768,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, | |||
753 | goto tcon_error_exit; | 768 | goto tcon_error_exit; |
754 | } | 769 | } |
755 | 770 | ||
756 | if (rsp == NULL) { | ||
757 | rc = -EIO; | ||
758 | goto tcon_exit; | ||
759 | } | ||
760 | |||
761 | if (tcon == NULL) { | 771 | if (tcon == NULL) { |
762 | ses->ipc_tid = rsp->hdr.TreeId; | 772 | ses->ipc_tid = rsp->hdr.TreeId; |
763 | goto tcon_exit; | 773 | goto tcon_exit; |
@@ -830,18 +840,87 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) | |||
830 | return rc; | 840 | return rc; |
831 | } | 841 | } |
832 | 842 | ||
843 | static struct create_lease * | ||
844 | create_lease_buf(u8 *lease_key, u8 oplock) | ||
845 | { | ||
846 | struct create_lease *buf; | ||
847 | |||
848 | buf = kmalloc(sizeof(struct create_lease), GFP_KERNEL); | ||
849 | if (!buf) | ||
850 | return NULL; | ||
851 | |||
852 | memset(buf, 0, sizeof(struct create_lease)); | ||
853 | |||
854 | buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key)); | ||
855 | buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8))); | ||
856 | if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) | ||
857 | buf->lcontext.LeaseState = SMB2_LEASE_WRITE_CACHING | | ||
858 | SMB2_LEASE_READ_CACHING; | ||
859 | else if (oplock == SMB2_OPLOCK_LEVEL_II) | ||
860 | buf->lcontext.LeaseState = SMB2_LEASE_READ_CACHING; | ||
861 | else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) | ||
862 | buf->lcontext.LeaseState = SMB2_LEASE_HANDLE_CACHING | | ||
863 | SMB2_LEASE_READ_CACHING | | ||
864 | SMB2_LEASE_WRITE_CACHING; | ||
865 | |||
866 | buf->ccontext.DataOffset = cpu_to_le16(offsetof | ||
867 | (struct create_lease, lcontext)); | ||
868 | buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context)); | ||
869 | buf->ccontext.NameOffset = cpu_to_le16(offsetof | ||
870 | (struct create_lease, Name)); | ||
871 | buf->ccontext.NameLength = cpu_to_le16(4); | ||
872 | buf->Name[0] = 'R'; | ||
873 | buf->Name[1] = 'q'; | ||
874 | buf->Name[2] = 'L'; | ||
875 | buf->Name[3] = 's'; | ||
876 | return buf; | ||
877 | } | ||
878 | |||
879 | static __u8 | ||
880 | parse_lease_state(struct smb2_create_rsp *rsp) | ||
881 | { | ||
882 | char *data_offset; | ||
883 | struct create_lease *lc; | ||
884 | bool found = false; | ||
885 | |||
886 | data_offset = (char *)rsp; | ||
887 | data_offset += 4 + le32_to_cpu(rsp->CreateContextsOffset); | ||
888 | lc = (struct create_lease *)data_offset; | ||
889 | do { | ||
890 | char *name = le16_to_cpu(lc->ccontext.NameOffset) + (char *)lc; | ||
891 | if (le16_to_cpu(lc->ccontext.NameLength) != 4 || | ||
892 | strncmp(name, "RqLs", 4)) { | ||
893 | lc = (struct create_lease *)((char *)lc | ||
894 | + le32_to_cpu(lc->ccontext.Next)); | ||
895 | continue; | ||
896 | } | ||
897 | if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) | ||
898 | return SMB2_OPLOCK_LEVEL_NOCHANGE; | ||
899 | found = true; | ||
900 | break; | ||
901 | } while (le32_to_cpu(lc->ccontext.Next) != 0); | ||
902 | |||
903 | if (!found) | ||
904 | return 0; | ||
905 | |||
906 | return smb2_map_lease_to_oplock(lc->lcontext.LeaseState); | ||
907 | } | ||
908 | |||
833 | int | 909 | int |
834 | SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | 910 | SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, |
835 | u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access, | 911 | u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access, |
836 | __u32 create_disposition, __u32 file_attributes, __u32 create_options) | 912 | __u32 create_disposition, __u32 file_attributes, __u32 create_options, |
913 | __u8 *oplock, struct smb2_file_all_info *buf) | ||
837 | { | 914 | { |
838 | struct smb2_create_req *req; | 915 | struct smb2_create_req *req; |
839 | struct smb2_create_rsp *rsp; | 916 | struct smb2_create_rsp *rsp; |
840 | struct TCP_Server_Info *server; | 917 | struct TCP_Server_Info *server; |
841 | struct cifs_ses *ses = tcon->ses; | 918 | struct cifs_ses *ses = tcon->ses; |
842 | struct kvec iov[2]; | 919 | struct kvec iov[3]; |
843 | int resp_buftype; | 920 | int resp_buftype; |
844 | int uni_path_len; | 921 | int uni_path_len; |
922 | __le16 *copy_path = NULL; | ||
923 | int copy_size; | ||
845 | int rc = 0; | 924 | int rc = 0; |
846 | int num_iovecs = 2; | 925 | int num_iovecs = 2; |
847 | 926 | ||
@@ -856,10 +935,6 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
856 | if (rc) | 935 | if (rc) |
857 | return rc; | 936 | return rc; |
858 | 937 | ||
859 | if (enable_oplocks) | ||
860 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_BATCH; | ||
861 | else | ||
862 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_NONE; | ||
863 | req->ImpersonationLevel = IL_IMPERSONATION; | 938 | req->ImpersonationLevel = IL_IMPERSONATION; |
864 | req->DesiredAccess = cpu_to_le32(desired_access); | 939 | req->DesiredAccess = cpu_to_le32(desired_access); |
865 | /* File attributes ignored on open (used in create though) */ | 940 | /* File attributes ignored on open (used in create though) */ |
@@ -869,7 +944,7 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
869 | req->CreateOptions = cpu_to_le32(create_options); | 944 | req->CreateOptions = cpu_to_le32(create_options); |
870 | uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; | 945 | uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; |
871 | req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) | 946 | req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) |
872 | - 1 /* pad */ - 4 /* do not count rfc1001 len field */); | 947 | - 8 /* pad */ - 4 /* do not count rfc1001 len field */); |
873 | 948 | ||
874 | iov[0].iov_base = (char *)req; | 949 | iov[0].iov_base = (char *)req; |
875 | /* 4 for rfc1002 length field */ | 950 | /* 4 for rfc1002 length field */ |
@@ -880,6 +955,20 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
880 | req->NameLength = cpu_to_le16(uni_path_len - 2); | 955 | req->NameLength = cpu_to_le16(uni_path_len - 2); |
881 | /* -1 since last byte is buf[0] which is sent below (path) */ | 956 | /* -1 since last byte is buf[0] which is sent below (path) */ |
882 | iov[0].iov_len--; | 957 | iov[0].iov_len--; |
958 | if (uni_path_len % 8 != 0) { | ||
959 | copy_size = uni_path_len / 8 * 8; | ||
960 | if (copy_size < uni_path_len) | ||
961 | copy_size += 8; | ||
962 | |||
963 | copy_path = kzalloc(copy_size, GFP_KERNEL); | ||
964 | if (!copy_path) | ||
965 | return -ENOMEM; | ||
966 | memcpy((char *)copy_path, (const char *)path, | ||
967 | uni_path_len); | ||
968 | uni_path_len = copy_size; | ||
969 | path = copy_path; | ||
970 | } | ||
971 | |||
883 | iov[1].iov_len = uni_path_len; | 972 | iov[1].iov_len = uni_path_len; |
884 | iov[1].iov_base = path; | 973 | iov[1].iov_base = path; |
885 | /* | 974 | /* |
@@ -888,10 +977,37 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
888 | */ | 977 | */ |
889 | inc_rfc1001_len(req, uni_path_len - 1); | 978 | inc_rfc1001_len(req, uni_path_len - 1); |
890 | } else { | 979 | } else { |
980 | iov[0].iov_len += 7; | ||
981 | req->hdr.smb2_buf_length = cpu_to_be32(be32_to_cpu( | ||
982 | req->hdr.smb2_buf_length) + 8 - 1); | ||
891 | num_iovecs = 1; | 983 | num_iovecs = 1; |
892 | req->NameLength = 0; | 984 | req->NameLength = 0; |
893 | } | 985 | } |
894 | 986 | ||
987 | if (!server->oplocks) | ||
988 | *oplock = SMB2_OPLOCK_LEVEL_NONE; | ||
989 | |||
990 | if (!(tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) || | ||
991 | *oplock == SMB2_OPLOCK_LEVEL_NONE) | ||
992 | req->RequestedOplockLevel = *oplock; | ||
993 | else { | ||
994 | iov[num_iovecs].iov_base = create_lease_buf(oplock+1, *oplock); | ||
995 | if (iov[num_iovecs].iov_base == NULL) { | ||
996 | cifs_small_buf_release(req); | ||
997 | kfree(copy_path); | ||
998 | return -ENOMEM; | ||
999 | } | ||
1000 | iov[num_iovecs].iov_len = sizeof(struct create_lease); | ||
1001 | req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; | ||
1002 | req->CreateContextsOffset = cpu_to_le32( | ||
1003 | sizeof(struct smb2_create_req) - 4 - 8 + | ||
1004 | iov[num_iovecs-1].iov_len); | ||
1005 | req->CreateContextsLength = cpu_to_le32( | ||
1006 | sizeof(struct create_lease)); | ||
1007 | inc_rfc1001_len(&req->hdr, sizeof(struct create_lease)); | ||
1008 | num_iovecs++; | ||
1009 | } | ||
1010 | |||
895 | rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); | 1011 | rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); |
896 | rsp = (struct smb2_create_rsp *)iov[0].iov_base; | 1012 | rsp = (struct smb2_create_rsp *)iov[0].iov_base; |
897 | 1013 | ||
@@ -900,13 +1016,24 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path, | |||
900 | goto creat_exit; | 1016 | goto creat_exit; |
901 | } | 1017 | } |
902 | 1018 | ||
903 | if (rsp == NULL) { | ||
904 | rc = -EIO; | ||
905 | goto creat_exit; | ||
906 | } | ||
907 | *persistent_fid = rsp->PersistentFileId; | 1019 | *persistent_fid = rsp->PersistentFileId; |
908 | *volatile_fid = rsp->VolatileFileId; | 1020 | *volatile_fid = rsp->VolatileFileId; |
1021 | |||
1022 | if (buf) { | ||
1023 | memcpy(buf, &rsp->CreationTime, 32); | ||
1024 | buf->AllocationSize = rsp->AllocationSize; | ||
1025 | buf->EndOfFile = rsp->EndofFile; | ||
1026 | buf->Attributes = rsp->FileAttributes; | ||
1027 | buf->NumberOfLinks = cpu_to_le32(1); | ||
1028 | buf->DeletePending = 0; | ||
1029 | } | ||
1030 | |||
1031 | if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) | ||
1032 | *oplock = parse_lease_state(rsp); | ||
1033 | else | ||
1034 | *oplock = rsp->OplockLevel; | ||
909 | creat_exit: | 1035 | creat_exit: |
1036 | kfree(copy_path); | ||
910 | free_rsp_buf(resp_buftype, rsp); | 1037 | free_rsp_buf(resp_buftype, rsp); |
911 | return rc; | 1038 | return rc; |
912 | } | 1039 | } |
@@ -950,11 +1077,6 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
950 | goto close_exit; | 1077 | goto close_exit; |
951 | } | 1078 | } |
952 | 1079 | ||
953 | if (rsp == NULL) { | ||
954 | rc = -EIO; | ||
955 | goto close_exit; | ||
956 | } | ||
957 | |||
958 | /* BB FIXME - decode close response, update inode for caching */ | 1080 | /* BB FIXME - decode close response, update inode for caching */ |
959 | 1081 | ||
960 | close_exit: | 1082 | close_exit: |
@@ -1019,10 +1141,10 @@ validate_and_copy_buf(unsigned int offset, unsigned int buffer_length, | |||
1019 | return 0; | 1141 | return 0; |
1020 | } | 1142 | } |
1021 | 1143 | ||
1022 | int | 1144 | static int |
1023 | SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | 1145 | query_info(const unsigned int xid, struct cifs_tcon *tcon, |
1024 | u64 persistent_fid, u64 volatile_fid, | 1146 | u64 persistent_fid, u64 volatile_fid, u8 info_class, |
1025 | struct smb2_file_all_info *data) | 1147 | size_t output_len, size_t min_len, void *data) |
1026 | { | 1148 | { |
1027 | struct smb2_query_info_req *req; | 1149 | struct smb2_query_info_req *req; |
1028 | struct smb2_query_info_rsp *rsp = NULL; | 1150 | struct smb2_query_info_rsp *rsp = NULL; |
@@ -1044,37 +1166,56 @@ SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
1044 | return rc; | 1166 | return rc; |
1045 | 1167 | ||
1046 | req->InfoType = SMB2_O_INFO_FILE; | 1168 | req->InfoType = SMB2_O_INFO_FILE; |
1047 | req->FileInfoClass = FILE_ALL_INFORMATION; | 1169 | req->FileInfoClass = info_class; |
1048 | req->PersistentFileId = persistent_fid; | 1170 | req->PersistentFileId = persistent_fid; |
1049 | req->VolatileFileId = volatile_fid; | 1171 | req->VolatileFileId = volatile_fid; |
1050 | /* 4 for rfc1002 length field and 1 for Buffer */ | 1172 | /* 4 for rfc1002 length field and 1 for Buffer */ |
1051 | req->InputBufferOffset = | 1173 | req->InputBufferOffset = |
1052 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); | 1174 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); |
1053 | req->OutputBufferLength = | 1175 | req->OutputBufferLength = cpu_to_le32(output_len); |
1054 | cpu_to_le32(sizeof(struct smb2_file_all_info) + MAX_NAME * 2); | ||
1055 | 1176 | ||
1056 | iov[0].iov_base = (char *)req; | 1177 | iov[0].iov_base = (char *)req; |
1057 | /* 4 for rfc1002 length field */ | 1178 | /* 4 for rfc1002 length field */ |
1058 | iov[0].iov_len = get_rfc1002_length(req) + 4; | 1179 | iov[0].iov_len = get_rfc1002_length(req) + 4; |
1059 | 1180 | ||
1060 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); | 1181 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); |
1182 | rsp = (struct smb2_query_info_rsp *)iov[0].iov_base; | ||
1183 | |||
1061 | if (rc) { | 1184 | if (rc) { |
1062 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); | 1185 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); |
1063 | goto qinf_exit; | 1186 | goto qinf_exit; |
1064 | } | 1187 | } |
1065 | 1188 | ||
1066 | rsp = (struct smb2_query_info_rsp *)iov[0].iov_base; | ||
1067 | |||
1068 | rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset), | 1189 | rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset), |
1069 | le32_to_cpu(rsp->OutputBufferLength), | 1190 | le32_to_cpu(rsp->OutputBufferLength), |
1070 | &rsp->hdr, sizeof(struct smb2_file_all_info), | 1191 | &rsp->hdr, min_len, data); |
1071 | (char *)data); | ||
1072 | 1192 | ||
1073 | qinf_exit: | 1193 | qinf_exit: |
1074 | free_rsp_buf(resp_buftype, rsp); | 1194 | free_rsp_buf(resp_buftype, rsp); |
1075 | return rc; | 1195 | return rc; |
1076 | } | 1196 | } |
1077 | 1197 | ||
1198 | int | ||
1199 | SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
1200 | u64 persistent_fid, u64 volatile_fid, | ||
1201 | struct smb2_file_all_info *data) | ||
1202 | { | ||
1203 | return query_info(xid, tcon, persistent_fid, volatile_fid, | ||
1204 | FILE_ALL_INFORMATION, | ||
1205 | sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | ||
1206 | sizeof(struct smb2_file_all_info), data); | ||
1207 | } | ||
1208 | |||
1209 | int | ||
1210 | SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, | ||
1211 | u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid) | ||
1212 | { | ||
1213 | return query_info(xid, tcon, persistent_fid, volatile_fid, | ||
1214 | FILE_INTERNAL_INFORMATION, | ||
1215 | sizeof(struct smb2_file_internal_info), | ||
1216 | sizeof(struct smb2_file_internal_info), uniqueid); | ||
1217 | } | ||
1218 | |||
1078 | /* | 1219 | /* |
1079 | * This is a no-op for now. We're not really interested in the reply, but | 1220 | * This is a no-op for now. We're not really interested in the reply, but |
1080 | * rather in the fact that the server sent one and that server->lstrp | 1221 | * rather in the fact that the server sent one and that server->lstrp |
@@ -1102,6 +1243,8 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1102 | struct smb2_echo_req *req; | 1243 | struct smb2_echo_req *req; |
1103 | int rc = 0; | 1244 | int rc = 0; |
1104 | struct kvec iov; | 1245 | struct kvec iov; |
1246 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
1247 | .rq_nvec = 1 }; | ||
1105 | 1248 | ||
1106 | cFYI(1, "In echo request"); | 1249 | cFYI(1, "In echo request"); |
1107 | 1250 | ||
@@ -1115,7 +1258,7 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1115 | /* 4 for rfc1002 length field */ | 1258 | /* 4 for rfc1002 length field */ |
1116 | iov.iov_len = get_rfc1002_length(req) + 4; | 1259 | iov.iov_len = get_rfc1002_length(req) + 4; |
1117 | 1260 | ||
1118 | rc = cifs_call_async(server, &iov, 1, NULL, smb2_echo_callback, server, | 1261 | rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, server, |
1119 | CIFS_ECHO_OP); | 1262 | CIFS_ECHO_OP); |
1120 | if (rc) | 1263 | if (rc) |
1121 | cFYI(1, "Echo request failed: %d", rc); | 1264 | cFYI(1, "Echo request failed: %d", rc); |
@@ -1123,3 +1266,945 @@ SMB2_echo(struct TCP_Server_Info *server) | |||
1123 | cifs_small_buf_release(req); | 1266 | cifs_small_buf_release(req); |
1124 | return rc; | 1267 | return rc; |
1125 | } | 1268 | } |
1269 | |||
1270 | int | ||
1271 | SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, | ||
1272 | u64 volatile_fid) | ||
1273 | { | ||
1274 | struct smb2_flush_req *req; | ||
1275 | struct TCP_Server_Info *server; | ||
1276 | struct cifs_ses *ses = tcon->ses; | ||
1277 | struct kvec iov[1]; | ||
1278 | int resp_buftype; | ||
1279 | int rc = 0; | ||
1280 | |||
1281 | cFYI(1, "Flush"); | ||
1282 | |||
1283 | if (ses && (ses->server)) | ||
1284 | server = ses->server; | ||
1285 | else | ||
1286 | return -EIO; | ||
1287 | |||
1288 | rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req); | ||
1289 | if (rc) | ||
1290 | return rc; | ||
1291 | |||
1292 | req->PersistentFileId = persistent_fid; | ||
1293 | req->VolatileFileId = volatile_fid; | ||
1294 | |||
1295 | iov[0].iov_base = (char *)req; | ||
1296 | /* 4 for rfc1002 length field */ | ||
1297 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1298 | |||
1299 | rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0); | ||
1300 | |||
1301 | if ((rc != 0) && tcon) | ||
1302 | cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE); | ||
1303 | |||
1304 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1305 | return rc; | ||
1306 | } | ||
1307 | |||
1308 | /* | ||
1309 | * To form a chain of read requests, any read requests after the first should | ||
1310 | * have the end_of_chain boolean set to true. | ||
1311 | */ | ||
1312 | static int | ||
1313 | smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms, | ||
1314 | unsigned int remaining_bytes, int request_type) | ||
1315 | { | ||
1316 | int rc = -EACCES; | ||
1317 | struct smb2_read_req *req = NULL; | ||
1318 | |||
1319 | rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req); | ||
1320 | if (rc) | ||
1321 | return rc; | ||
1322 | if (io_parms->tcon->ses->server == NULL) | ||
1323 | return -ECONNABORTED; | ||
1324 | |||
1325 | req->hdr.ProcessId = cpu_to_le32(io_parms->pid); | ||
1326 | |||
1327 | req->PersistentFileId = io_parms->persistent_fid; | ||
1328 | req->VolatileFileId = io_parms->volatile_fid; | ||
1329 | req->ReadChannelInfoOffset = 0; /* reserved */ | ||
1330 | req->ReadChannelInfoLength = 0; /* reserved */ | ||
1331 | req->Channel = 0; /* reserved */ | ||
1332 | req->MinimumCount = 0; | ||
1333 | req->Length = cpu_to_le32(io_parms->length); | ||
1334 | req->Offset = cpu_to_le64(io_parms->offset); | ||
1335 | |||
1336 | if (request_type & CHAINED_REQUEST) { | ||
1337 | if (!(request_type & END_OF_CHAIN)) { | ||
1338 | /* 4 for rfc1002 length field */ | ||
1339 | req->hdr.NextCommand = | ||
1340 | cpu_to_le32(get_rfc1002_length(req) + 4); | ||
1341 | } else /* END_OF_CHAIN */ | ||
1342 | req->hdr.NextCommand = 0; | ||
1343 | if (request_type & RELATED_REQUEST) { | ||
1344 | req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS; | ||
1345 | /* | ||
1346 | * Related requests use info from previous read request | ||
1347 | * in chain. | ||
1348 | */ | ||
1349 | req->hdr.SessionId = 0xFFFFFFFF; | ||
1350 | req->hdr.TreeId = 0xFFFFFFFF; | ||
1351 | req->PersistentFileId = 0xFFFFFFFF; | ||
1352 | req->VolatileFileId = 0xFFFFFFFF; | ||
1353 | } | ||
1354 | } | ||
1355 | if (remaining_bytes > io_parms->length) | ||
1356 | req->RemainingBytes = cpu_to_le32(remaining_bytes); | ||
1357 | else | ||
1358 | req->RemainingBytes = 0; | ||
1359 | |||
1360 | iov[0].iov_base = (char *)req; | ||
1361 | /* 4 for rfc1002 length field */ | ||
1362 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1363 | return rc; | ||
1364 | } | ||
1365 | |||
1366 | static void | ||
1367 | smb2_readv_callback(struct mid_q_entry *mid) | ||
1368 | { | ||
1369 | struct cifs_readdata *rdata = mid->callback_data; | ||
1370 | struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); | ||
1371 | struct TCP_Server_Info *server = tcon->ses->server; | ||
1372 | struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base; | ||
1373 | unsigned int credits_received = 1; | ||
1374 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1375 | .rq_nvec = 1, | ||
1376 | .rq_pages = rdata->pages, | ||
1377 | .rq_npages = rdata->nr_pages, | ||
1378 | .rq_pagesz = rdata->pagesz, | ||
1379 | .rq_tailsz = rdata->tailsz }; | ||
1380 | |||
1381 | cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__, | ||
1382 | mid->mid, mid->mid_state, rdata->result, rdata->bytes); | ||
1383 | |||
1384 | switch (mid->mid_state) { | ||
1385 | case MID_RESPONSE_RECEIVED: | ||
1386 | credits_received = le16_to_cpu(buf->CreditRequest); | ||
1387 | /* result already set, check signature */ | ||
1388 | if (server->sec_mode & | ||
1389 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | ||
1390 | int rc; | ||
1391 | |||
1392 | rc = smb2_verify_signature(&rqst, server); | ||
1393 | if (rc) | ||
1394 | cERROR(1, "SMB signature verification returned " | ||
1395 | "error = %d", rc); | ||
1396 | } | ||
1397 | /* FIXME: should this be counted toward the initiating task? */ | ||
1398 | task_io_account_read(rdata->bytes); | ||
1399 | cifs_stats_bytes_read(tcon, rdata->bytes); | ||
1400 | break; | ||
1401 | case MID_REQUEST_SUBMITTED: | ||
1402 | case MID_RETRY_NEEDED: | ||
1403 | rdata->result = -EAGAIN; | ||
1404 | break; | ||
1405 | default: | ||
1406 | if (rdata->result != -ENODATA) | ||
1407 | rdata->result = -EIO; | ||
1408 | } | ||
1409 | |||
1410 | if (rdata->result) | ||
1411 | cifs_stats_fail_inc(tcon, SMB2_READ_HE); | ||
1412 | |||
1413 | queue_work(cifsiod_wq, &rdata->work); | ||
1414 | DeleteMidQEntry(mid); | ||
1415 | add_credits(server, credits_received, 0); | ||
1416 | } | ||
1417 | |||
1418 | /* smb2_async_readv - send an async write, and set up mid to handle result */ | ||
1419 | int | ||
1420 | smb2_async_readv(struct cifs_readdata *rdata) | ||
1421 | { | ||
1422 | int rc; | ||
1423 | struct smb2_hdr *buf; | ||
1424 | struct cifs_io_parms io_parms; | ||
1425 | struct smb_rqst rqst = { .rq_iov = &rdata->iov, | ||
1426 | .rq_nvec = 1 }; | ||
1427 | |||
1428 | cFYI(1, "%s: offset=%llu bytes=%u", __func__, | ||
1429 | rdata->offset, rdata->bytes); | ||
1430 | |||
1431 | io_parms.tcon = tlink_tcon(rdata->cfile->tlink); | ||
1432 | io_parms.offset = rdata->offset; | ||
1433 | io_parms.length = rdata->bytes; | ||
1434 | io_parms.persistent_fid = rdata->cfile->fid.persistent_fid; | ||
1435 | io_parms.volatile_fid = rdata->cfile->fid.volatile_fid; | ||
1436 | io_parms.pid = rdata->pid; | ||
1437 | rc = smb2_new_read_req(&rdata->iov, &io_parms, 0, 0); | ||
1438 | if (rc) | ||
1439 | return rc; | ||
1440 | |||
1441 | buf = (struct smb2_hdr *)rdata->iov.iov_base; | ||
1442 | /* 4 for rfc1002 length field */ | ||
1443 | rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4; | ||
1444 | |||
1445 | kref_get(&rdata->refcount); | ||
1446 | rc = cifs_call_async(io_parms.tcon->ses->server, &rqst, | ||
1447 | cifs_readv_receive, smb2_readv_callback, | ||
1448 | rdata, 0); | ||
1449 | if (rc) { | ||
1450 | kref_put(&rdata->refcount, cifs_readdata_release); | ||
1451 | cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); | ||
1452 | } | ||
1453 | |||
1454 | cifs_small_buf_release(buf); | ||
1455 | return rc; | ||
1456 | } | ||
1457 | |||
1458 | int | ||
1459 | SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
1460 | unsigned int *nbytes, char **buf, int *buf_type) | ||
1461 | { | ||
1462 | int resp_buftype, rc = -EACCES; | ||
1463 | struct smb2_read_rsp *rsp = NULL; | ||
1464 | struct kvec iov[1]; | ||
1465 | |||
1466 | *nbytes = 0; | ||
1467 | rc = smb2_new_read_req(iov, io_parms, 0, 0); | ||
1468 | if (rc) | ||
1469 | return rc; | ||
1470 | |||
1471 | rc = SendReceive2(xid, io_parms->tcon->ses, iov, 1, | ||
1472 | &resp_buftype, CIFS_LOG_ERROR); | ||
1473 | |||
1474 | rsp = (struct smb2_read_rsp *)iov[0].iov_base; | ||
1475 | |||
1476 | if (rsp->hdr.Status == STATUS_END_OF_FILE) { | ||
1477 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1478 | return 0; | ||
1479 | } | ||
1480 | |||
1481 | if (rc) { | ||
1482 | cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE); | ||
1483 | cERROR(1, "Send error in read = %d", rc); | ||
1484 | } else { | ||
1485 | *nbytes = le32_to_cpu(rsp->DataLength); | ||
1486 | if ((*nbytes > CIFS_MAX_MSGSIZE) || | ||
1487 | (*nbytes > io_parms->length)) { | ||
1488 | cFYI(1, "bad length %d for count %d", *nbytes, | ||
1489 | io_parms->length); | ||
1490 | rc = -EIO; | ||
1491 | *nbytes = 0; | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 | if (*buf) { | ||
1496 | memcpy(*buf, (char *)rsp->hdr.ProtocolId + rsp->DataOffset, | ||
1497 | *nbytes); | ||
1498 | free_rsp_buf(resp_buftype, iov[0].iov_base); | ||
1499 | } else if (resp_buftype != CIFS_NO_BUFFER) { | ||
1500 | *buf = iov[0].iov_base; | ||
1501 | if (resp_buftype == CIFS_SMALL_BUFFER) | ||
1502 | *buf_type = CIFS_SMALL_BUFFER; | ||
1503 | else if (resp_buftype == CIFS_LARGE_BUFFER) | ||
1504 | *buf_type = CIFS_LARGE_BUFFER; | ||
1505 | } | ||
1506 | return rc; | ||
1507 | } | ||
1508 | |||
1509 | /* | ||
1510 | * Check the mid_state and signature on received buffer (if any), and queue the | ||
1511 | * workqueue completion task. | ||
1512 | */ | ||
1513 | static void | ||
1514 | smb2_writev_callback(struct mid_q_entry *mid) | ||
1515 | { | ||
1516 | struct cifs_writedata *wdata = mid->callback_data; | ||
1517 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | ||
1518 | unsigned int written; | ||
1519 | struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf; | ||
1520 | unsigned int credits_received = 1; | ||
1521 | |||
1522 | switch (mid->mid_state) { | ||
1523 | case MID_RESPONSE_RECEIVED: | ||
1524 | credits_received = le16_to_cpu(rsp->hdr.CreditRequest); | ||
1525 | wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); | ||
1526 | if (wdata->result != 0) | ||
1527 | break; | ||
1528 | |||
1529 | written = le32_to_cpu(rsp->DataLength); | ||
1530 | /* | ||
1531 | * Mask off high 16 bits when bytes written as returned | ||
1532 | * by the server is greater than bytes requested by the | ||
1533 | * client. OS/2 servers are known to set incorrect | ||
1534 | * CountHigh values. | ||
1535 | */ | ||
1536 | if (written > wdata->bytes) | ||
1537 | written &= 0xFFFF; | ||
1538 | |||
1539 | if (written < wdata->bytes) | ||
1540 | wdata->result = -ENOSPC; | ||
1541 | else | ||
1542 | wdata->bytes = written; | ||
1543 | break; | ||
1544 | case MID_REQUEST_SUBMITTED: | ||
1545 | case MID_RETRY_NEEDED: | ||
1546 | wdata->result = -EAGAIN; | ||
1547 | break; | ||
1548 | default: | ||
1549 | wdata->result = -EIO; | ||
1550 | break; | ||
1551 | } | ||
1552 | |||
1553 | if (wdata->result) | ||
1554 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); | ||
1555 | |||
1556 | queue_work(cifsiod_wq, &wdata->work); | ||
1557 | DeleteMidQEntry(mid); | ||
1558 | add_credits(tcon->ses->server, credits_received, 0); | ||
1559 | } | ||
1560 | |||
1561 | /* smb2_async_writev - send an async write, and set up mid to handle result */ | ||
1562 | int | ||
1563 | smb2_async_writev(struct cifs_writedata *wdata) | ||
1564 | { | ||
1565 | int rc = -EACCES; | ||
1566 | struct smb2_write_req *req = NULL; | ||
1567 | struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); | ||
1568 | struct kvec iov; | ||
1569 | struct smb_rqst rqst; | ||
1570 | |||
1571 | rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req); | ||
1572 | if (rc) | ||
1573 | goto async_writev_out; | ||
1574 | |||
1575 | req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid); | ||
1576 | |||
1577 | req->PersistentFileId = wdata->cfile->fid.persistent_fid; | ||
1578 | req->VolatileFileId = wdata->cfile->fid.volatile_fid; | ||
1579 | req->WriteChannelInfoOffset = 0; | ||
1580 | req->WriteChannelInfoLength = 0; | ||
1581 | req->Channel = 0; | ||
1582 | req->Offset = cpu_to_le64(wdata->offset); | ||
1583 | /* 4 for rfc1002 length field */ | ||
1584 | req->DataOffset = cpu_to_le16( | ||
1585 | offsetof(struct smb2_write_req, Buffer) - 4); | ||
1586 | req->RemainingBytes = 0; | ||
1587 | |||
1588 | /* 4 for rfc1002 length field and 1 for Buffer */ | ||
1589 | iov.iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1590 | iov.iov_base = req; | ||
1591 | |||
1592 | rqst.rq_iov = &iov; | ||
1593 | rqst.rq_nvec = 1; | ||
1594 | rqst.rq_pages = wdata->pages; | ||
1595 | rqst.rq_npages = wdata->nr_pages; | ||
1596 | rqst.rq_pagesz = wdata->pagesz; | ||
1597 | rqst.rq_tailsz = wdata->tailsz; | ||
1598 | |||
1599 | cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); | ||
1600 | |||
1601 | req->Length = cpu_to_le32(wdata->bytes); | ||
1602 | |||
1603 | inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */); | ||
1604 | |||
1605 | kref_get(&wdata->refcount); | ||
1606 | rc = cifs_call_async(tcon->ses->server, &rqst, NULL, | ||
1607 | smb2_writev_callback, wdata, 0); | ||
1608 | |||
1609 | if (rc) { | ||
1610 | kref_put(&wdata->refcount, cifs_writedata_release); | ||
1611 | cifs_stats_fail_inc(tcon, SMB2_WRITE_HE); | ||
1612 | } | ||
1613 | |||
1614 | async_writev_out: | ||
1615 | cifs_small_buf_release(req); | ||
1616 | return rc; | ||
1617 | } | ||
1618 | |||
1619 | /* | ||
1620 | * SMB2_write function gets iov pointer to kvec array with n_vec as a length. | ||
1621 | * The length field from io_parms must be at least 1 and indicates a number of | ||
1622 | * elements with data to write that begins with position 1 in iov array. All | ||
1623 | * data length is specified by count. | ||
1624 | */ | ||
1625 | int | ||
1626 | SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
1627 | unsigned int *nbytes, struct kvec *iov, int n_vec) | ||
1628 | { | ||
1629 | int rc = 0; | ||
1630 | struct smb2_write_req *req = NULL; | ||
1631 | struct smb2_write_rsp *rsp = NULL; | ||
1632 | int resp_buftype; | ||
1633 | *nbytes = 0; | ||
1634 | |||
1635 | if (n_vec < 1) | ||
1636 | return rc; | ||
1637 | |||
1638 | rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req); | ||
1639 | if (rc) | ||
1640 | return rc; | ||
1641 | |||
1642 | if (io_parms->tcon->ses->server == NULL) | ||
1643 | return -ECONNABORTED; | ||
1644 | |||
1645 | req->hdr.ProcessId = cpu_to_le32(io_parms->pid); | ||
1646 | |||
1647 | req->PersistentFileId = io_parms->persistent_fid; | ||
1648 | req->VolatileFileId = io_parms->volatile_fid; | ||
1649 | req->WriteChannelInfoOffset = 0; | ||
1650 | req->WriteChannelInfoLength = 0; | ||
1651 | req->Channel = 0; | ||
1652 | req->Length = cpu_to_le32(io_parms->length); | ||
1653 | req->Offset = cpu_to_le64(io_parms->offset); | ||
1654 | /* 4 for rfc1002 length field */ | ||
1655 | req->DataOffset = cpu_to_le16( | ||
1656 | offsetof(struct smb2_write_req, Buffer) - 4); | ||
1657 | req->RemainingBytes = 0; | ||
1658 | |||
1659 | iov[0].iov_base = (char *)req; | ||
1660 | /* 4 for rfc1002 length field and 1 for Buffer */ | ||
1661 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1662 | |||
1663 | /* length of entire message including data to be written */ | ||
1664 | inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */); | ||
1665 | |||
1666 | rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1, | ||
1667 | &resp_buftype, 0); | ||
1668 | rsp = (struct smb2_write_rsp *)iov[0].iov_base; | ||
1669 | |||
1670 | if (rc) { | ||
1671 | cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE); | ||
1672 | cERROR(1, "Send error in write = %d", rc); | ||
1673 | } else | ||
1674 | *nbytes = le32_to_cpu(rsp->DataLength); | ||
1675 | |||
1676 | free_rsp_buf(resp_buftype, rsp); | ||
1677 | return rc; | ||
1678 | } | ||
1679 | |||
1680 | static unsigned int | ||
1681 | num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size) | ||
1682 | { | ||
1683 | int len; | ||
1684 | unsigned int entrycount = 0; | ||
1685 | unsigned int next_offset = 0; | ||
1686 | FILE_DIRECTORY_INFO *entryptr; | ||
1687 | |||
1688 | if (bufstart == NULL) | ||
1689 | return 0; | ||
1690 | |||
1691 | entryptr = (FILE_DIRECTORY_INFO *)bufstart; | ||
1692 | |||
1693 | while (1) { | ||
1694 | entryptr = (FILE_DIRECTORY_INFO *) | ||
1695 | ((char *)entryptr + next_offset); | ||
1696 | |||
1697 | if ((char *)entryptr + size > end_of_buf) { | ||
1698 | cERROR(1, "malformed search entry would overflow"); | ||
1699 | break; | ||
1700 | } | ||
1701 | |||
1702 | len = le32_to_cpu(entryptr->FileNameLength); | ||
1703 | if ((char *)entryptr + len + size > end_of_buf) { | ||
1704 | cERROR(1, "directory entry name would overflow frame " | ||
1705 | "end of buf %p", end_of_buf); | ||
1706 | break; | ||
1707 | } | ||
1708 | |||
1709 | *lastentry = (char *)entryptr; | ||
1710 | entrycount++; | ||
1711 | |||
1712 | next_offset = le32_to_cpu(entryptr->NextEntryOffset); | ||
1713 | if (!next_offset) | ||
1714 | break; | ||
1715 | } | ||
1716 | |||
1717 | return entrycount; | ||
1718 | } | ||
1719 | |||
1720 | /* | ||
1721 | * Readdir/FindFirst | ||
1722 | */ | ||
1723 | int | ||
1724 | SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, | ||
1725 | u64 persistent_fid, u64 volatile_fid, int index, | ||
1726 | struct cifs_search_info *srch_inf) | ||
1727 | { | ||
1728 | struct smb2_query_directory_req *req; | ||
1729 | struct smb2_query_directory_rsp *rsp = NULL; | ||
1730 | struct kvec iov[2]; | ||
1731 | int rc = 0; | ||
1732 | int len; | ||
1733 | int resp_buftype; | ||
1734 | unsigned char *bufptr; | ||
1735 | struct TCP_Server_Info *server; | ||
1736 | struct cifs_ses *ses = tcon->ses; | ||
1737 | __le16 asteriks = cpu_to_le16('*'); | ||
1738 | char *end_of_smb; | ||
1739 | unsigned int output_size = CIFSMaxBufSize; | ||
1740 | size_t info_buf_size; | ||
1741 | |||
1742 | if (ses && (ses->server)) | ||
1743 | server = ses->server; | ||
1744 | else | ||
1745 | return -EIO; | ||
1746 | |||
1747 | rc = small_smb2_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req); | ||
1748 | if (rc) | ||
1749 | return rc; | ||
1750 | |||
1751 | switch (srch_inf->info_level) { | ||
1752 | case SMB_FIND_FILE_DIRECTORY_INFO: | ||
1753 | req->FileInformationClass = FILE_DIRECTORY_INFORMATION; | ||
1754 | info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1; | ||
1755 | break; | ||
1756 | case SMB_FIND_FILE_ID_FULL_DIR_INFO: | ||
1757 | req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION; | ||
1758 | info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1; | ||
1759 | break; | ||
1760 | default: | ||
1761 | cERROR(1, "info level %u isn't supported", | ||
1762 | srch_inf->info_level); | ||
1763 | rc = -EINVAL; | ||
1764 | goto qdir_exit; | ||
1765 | } | ||
1766 | |||
1767 | req->FileIndex = cpu_to_le32(index); | ||
1768 | req->PersistentFileId = persistent_fid; | ||
1769 | req->VolatileFileId = volatile_fid; | ||
1770 | |||
1771 | len = 0x2; | ||
1772 | bufptr = req->Buffer; | ||
1773 | memcpy(bufptr, &asteriks, len); | ||
1774 | |||
1775 | req->FileNameOffset = | ||
1776 | cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1 - 4); | ||
1777 | req->FileNameLength = cpu_to_le16(len); | ||
1778 | /* | ||
1779 | * BB could be 30 bytes or so longer if we used SMB2 specific | ||
1780 | * buffer lengths, but this is safe and close enough. | ||
1781 | */ | ||
1782 | output_size = min_t(unsigned int, output_size, server->maxBuf); | ||
1783 | output_size = min_t(unsigned int, output_size, 2 << 15); | ||
1784 | req->OutputBufferLength = cpu_to_le32(output_size); | ||
1785 | |||
1786 | iov[0].iov_base = (char *)req; | ||
1787 | /* 4 for RFC1001 length and 1 for Buffer */ | ||
1788 | iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; | ||
1789 | |||
1790 | iov[1].iov_base = (char *)(req->Buffer); | ||
1791 | iov[1].iov_len = len; | ||
1792 | |||
1793 | inc_rfc1001_len(req, len - 1 /* Buffer */); | ||
1794 | |||
1795 | rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0); | ||
1796 | rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base; | ||
1797 | |||
1798 | if (rc) { | ||
1799 | cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE); | ||
1800 | goto qdir_exit; | ||
1801 | } | ||
1802 | |||
1803 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), | ||
1804 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, | ||
1805 | info_buf_size); | ||
1806 | if (rc) | ||
1807 | goto qdir_exit; | ||
1808 | |||
1809 | srch_inf->unicode = true; | ||
1810 | |||
1811 | if (srch_inf->ntwrk_buf_start) { | ||
1812 | if (srch_inf->smallBuf) | ||
1813 | cifs_small_buf_release(srch_inf->ntwrk_buf_start); | ||
1814 | else | ||
1815 | cifs_buf_release(srch_inf->ntwrk_buf_start); | ||
1816 | } | ||
1817 | srch_inf->ntwrk_buf_start = (char *)rsp; | ||
1818 | srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ + | ||
1819 | (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset); | ||
1820 | /* 4 for rfc1002 length field */ | ||
1821 | end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr; | ||
1822 | srch_inf->entries_in_buffer = | ||
1823 | num_entries(srch_inf->srch_entries_start, end_of_smb, | ||
1824 | &srch_inf->last_entry, info_buf_size); | ||
1825 | srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; | ||
1826 | cFYI(1, "num entries %d last_index %lld srch start %p srch end %p", | ||
1827 | srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, | ||
1828 | srch_inf->srch_entries_start, srch_inf->last_entry); | ||
1829 | if (resp_buftype == CIFS_LARGE_BUFFER) | ||
1830 | srch_inf->smallBuf = false; | ||
1831 | else if (resp_buftype == CIFS_SMALL_BUFFER) | ||
1832 | srch_inf->smallBuf = true; | ||
1833 | else | ||
1834 | cERROR(1, "illegal search buffer type"); | ||
1835 | |||
1836 | if (rsp->hdr.Status == STATUS_NO_MORE_FILES) | ||
1837 | srch_inf->endOfSearch = 1; | ||
1838 | else | ||
1839 | srch_inf->endOfSearch = 0; | ||
1840 | |||
1841 | return rc; | ||
1842 | |||
1843 | qdir_exit: | ||
1844 | free_rsp_buf(resp_buftype, rsp); | ||
1845 | return rc; | ||
1846 | } | ||
1847 | |||
1848 | static int | ||
1849 | send_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
1850 | u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class, | ||
1851 | unsigned int num, void **data, unsigned int *size) | ||
1852 | { | ||
1853 | struct smb2_set_info_req *req; | ||
1854 | struct smb2_set_info_rsp *rsp = NULL; | ||
1855 | struct kvec *iov; | ||
1856 | int rc = 0; | ||
1857 | int resp_buftype; | ||
1858 | unsigned int i; | ||
1859 | struct TCP_Server_Info *server; | ||
1860 | struct cifs_ses *ses = tcon->ses; | ||
1861 | |||
1862 | if (ses && (ses->server)) | ||
1863 | server = ses->server; | ||
1864 | else | ||
1865 | return -EIO; | ||
1866 | |||
1867 | if (!num) | ||
1868 | return -EINVAL; | ||
1869 | |||
1870 | iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL); | ||
1871 | if (!iov) | ||
1872 | return -ENOMEM; | ||
1873 | |||
1874 | rc = small_smb2_init(SMB2_SET_INFO, tcon, (void **) &req); | ||
1875 | if (rc) { | ||
1876 | kfree(iov); | ||
1877 | return rc; | ||
1878 | } | ||
1879 | |||
1880 | req->hdr.ProcessId = cpu_to_le32(pid); | ||
1881 | |||
1882 | req->InfoType = SMB2_O_INFO_FILE; | ||
1883 | req->FileInfoClass = info_class; | ||
1884 | req->PersistentFileId = persistent_fid; | ||
1885 | req->VolatileFileId = volatile_fid; | ||
1886 | |||
1887 | /* 4 for RFC1001 length and 1 for Buffer */ | ||
1888 | req->BufferOffset = | ||
1889 | cpu_to_le16(sizeof(struct smb2_set_info_req) - 1 - 4); | ||
1890 | req->BufferLength = cpu_to_le32(*size); | ||
1891 | |||
1892 | inc_rfc1001_len(req, *size - 1 /* Buffer */); | ||
1893 | |||
1894 | memcpy(req->Buffer, *data, *size); | ||
1895 | |||
1896 | iov[0].iov_base = (char *)req; | ||
1897 | /* 4 for RFC1001 length */ | ||
1898 | iov[0].iov_len = get_rfc1002_length(req) + 4; | ||
1899 | |||
1900 | for (i = 1; i < num; i++) { | ||
1901 | inc_rfc1001_len(req, size[i]); | ||
1902 | le32_add_cpu(&req->BufferLength, size[i]); | ||
1903 | iov[i].iov_base = (char *)data[i]; | ||
1904 | iov[i].iov_len = size[i]; | ||
1905 | } | ||
1906 | |||
1907 | rc = SendReceive2(xid, ses, iov, num, &resp_buftype, 0); | ||
1908 | rsp = (struct smb2_set_info_rsp *)iov[0].iov_base; | ||
1909 | |||
1910 | if (rc != 0) { | ||
1911 | cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE); | ||
1912 | goto out; | ||
1913 | } | ||
1914 | out: | ||
1915 | free_rsp_buf(resp_buftype, rsp); | ||
1916 | kfree(iov); | ||
1917 | return rc; | ||
1918 | } | ||
1919 | |||
1920 | int | ||
1921 | SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, | ||
1922 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) | ||
1923 | { | ||
1924 | struct smb2_file_rename_info info; | ||
1925 | void **data; | ||
1926 | unsigned int size[2]; | ||
1927 | int rc; | ||
1928 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); | ||
1929 | |||
1930 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); | ||
1931 | if (!data) | ||
1932 | return -ENOMEM; | ||
1933 | |||
1934 | info.ReplaceIfExists = 1; /* 1 = replace existing target with new */ | ||
1935 | /* 0 = fail if target already exists */ | ||
1936 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ | ||
1937 | info.FileNameLength = cpu_to_le32(len); | ||
1938 | |||
1939 | data[0] = &info; | ||
1940 | size[0] = sizeof(struct smb2_file_rename_info); | ||
1941 | |||
1942 | data[1] = target_file; | ||
1943 | size[1] = len + 2 /* null */; | ||
1944 | |||
1945 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
1946 | current->tgid, FILE_RENAME_INFORMATION, 2, data, | ||
1947 | size); | ||
1948 | kfree(data); | ||
1949 | return rc; | ||
1950 | } | ||
1951 | |||
1952 | int | ||
1953 | SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
1954 | u64 persistent_fid, u64 volatile_fid, __le16 *target_file) | ||
1955 | { | ||
1956 | struct smb2_file_link_info info; | ||
1957 | void **data; | ||
1958 | unsigned int size[2]; | ||
1959 | int rc; | ||
1960 | int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX)); | ||
1961 | |||
1962 | data = kmalloc(sizeof(void *) * 2, GFP_KERNEL); | ||
1963 | if (!data) | ||
1964 | return -ENOMEM; | ||
1965 | |||
1966 | info.ReplaceIfExists = 0; /* 1 = replace existing link with new */ | ||
1967 | /* 0 = fail if link already exists */ | ||
1968 | info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */ | ||
1969 | info.FileNameLength = cpu_to_le32(len); | ||
1970 | |||
1971 | data[0] = &info; | ||
1972 | size[0] = sizeof(struct smb2_file_link_info); | ||
1973 | |||
1974 | data[1] = target_file; | ||
1975 | size[1] = len + 2 /* null */; | ||
1976 | |||
1977 | rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
1978 | current->tgid, FILE_LINK_INFORMATION, 2, data, size); | ||
1979 | kfree(data); | ||
1980 | return rc; | ||
1981 | } | ||
1982 | |||
1983 | int | ||
1984 | SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, | ||
1985 | u64 volatile_fid, u32 pid, __le64 *eof) | ||
1986 | { | ||
1987 | struct smb2_file_eof_info info; | ||
1988 | void *data; | ||
1989 | unsigned int size; | ||
1990 | |||
1991 | info.EndOfFile = *eof; | ||
1992 | |||
1993 | data = &info; | ||
1994 | size = sizeof(struct smb2_file_eof_info); | ||
1995 | |||
1996 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid, | ||
1997 | FILE_END_OF_FILE_INFORMATION, 1, &data, &size); | ||
1998 | } | ||
1999 | |||
2000 | int | ||
2001 | SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
2002 | u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf) | ||
2003 | { | ||
2004 | unsigned int size; | ||
2005 | size = sizeof(FILE_BASIC_INFO); | ||
2006 | return send_set_info(xid, tcon, persistent_fid, volatile_fid, | ||
2007 | current->tgid, FILE_BASIC_INFORMATION, 1, | ||
2008 | (void **)&buf, &size); | ||
2009 | } | ||
2010 | |||
2011 | int | ||
2012 | SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
2013 | const u64 persistent_fid, const u64 volatile_fid, | ||
2014 | __u8 oplock_level) | ||
2015 | { | ||
2016 | int rc; | ||
2017 | struct smb2_oplock_break *req = NULL; | ||
2018 | |||
2019 | cFYI(1, "SMB2_oplock_break"); | ||
2020 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); | ||
2021 | |||
2022 | if (rc) | ||
2023 | return rc; | ||
2024 | |||
2025 | req->VolatileFid = volatile_fid; | ||
2026 | req->PersistentFid = persistent_fid; | ||
2027 | req->OplockLevel = oplock_level; | ||
2028 | req->hdr.CreditRequest = cpu_to_le16(1); | ||
2029 | |||
2030 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP); | ||
2031 | /* SMB2 buffer freed by function above */ | ||
2032 | |||
2033 | if (rc) { | ||
2034 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); | ||
2035 | cFYI(1, "Send error in Oplock Break = %d", rc); | ||
2036 | } | ||
2037 | |||
2038 | return rc; | ||
2039 | } | ||
2040 | |||
2041 | static void | ||
2042 | copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf, | ||
2043 | struct kstatfs *kst) | ||
2044 | { | ||
2045 | kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) * | ||
2046 | le32_to_cpu(pfs_inf->SectorsPerAllocationUnit); | ||
2047 | kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits); | ||
2048 | kst->f_bfree = le64_to_cpu(pfs_inf->ActualAvailableAllocationUnits); | ||
2049 | kst->f_bavail = le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits); | ||
2050 | return; | ||
2051 | } | ||
2052 | |||
2053 | static int | ||
2054 | build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level, | ||
2055 | int outbuf_len, u64 persistent_fid, u64 volatile_fid) | ||
2056 | { | ||
2057 | int rc; | ||
2058 | struct smb2_query_info_req *req; | ||
2059 | |||
2060 | cFYI(1, "Query FSInfo level %d", level); | ||
2061 | |||
2062 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) | ||
2063 | return -EIO; | ||
2064 | |||
2065 | rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req); | ||
2066 | if (rc) | ||
2067 | return rc; | ||
2068 | |||
2069 | req->InfoType = SMB2_O_INFO_FILESYSTEM; | ||
2070 | req->FileInfoClass = level; | ||
2071 | req->PersistentFileId = persistent_fid; | ||
2072 | req->VolatileFileId = volatile_fid; | ||
2073 | /* 4 for rfc1002 length field and 1 for pad */ | ||
2074 | req->InputBufferOffset = | ||
2075 | cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4); | ||
2076 | req->OutputBufferLength = cpu_to_le32( | ||
2077 | outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - 4); | ||
2078 | |||
2079 | iov->iov_base = (char *)req; | ||
2080 | /* 4 for rfc1002 length field */ | ||
2081 | iov->iov_len = get_rfc1002_length(req) + 4; | ||
2082 | return 0; | ||
2083 | } | ||
2084 | |||
2085 | int | ||
2086 | SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
2087 | u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata) | ||
2088 | { | ||
2089 | struct smb2_query_info_rsp *rsp = NULL; | ||
2090 | struct kvec iov; | ||
2091 | int rc = 0; | ||
2092 | int resp_buftype; | ||
2093 | struct cifs_ses *ses = tcon->ses; | ||
2094 | struct smb2_fs_full_size_info *info = NULL; | ||
2095 | |||
2096 | rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION, | ||
2097 | sizeof(struct smb2_fs_full_size_info), | ||
2098 | persistent_fid, volatile_fid); | ||
2099 | if (rc) | ||
2100 | return rc; | ||
2101 | |||
2102 | rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0); | ||
2103 | if (rc) { | ||
2104 | cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE); | ||
2105 | goto qinf_exit; | ||
2106 | } | ||
2107 | rsp = (struct smb2_query_info_rsp *)iov.iov_base; | ||
2108 | |||
2109 | info = (struct smb2_fs_full_size_info *)(4 /* RFC1001 len */ + | ||
2110 | le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr); | ||
2111 | rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset), | ||
2112 | le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr, | ||
2113 | sizeof(struct smb2_fs_full_size_info)); | ||
2114 | if (!rc) | ||
2115 | copy_fs_info_to_kstatfs(info, fsdata); | ||
2116 | |||
2117 | qinf_exit: | ||
2118 | free_rsp_buf(resp_buftype, iov.iov_base); | ||
2119 | return rc; | ||
2120 | } | ||
2121 | |||
2122 | int | ||
2123 | smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, | ||
2124 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, | ||
2125 | const __u32 num_lock, struct smb2_lock_element *buf) | ||
2126 | { | ||
2127 | int rc = 0; | ||
2128 | struct smb2_lock_req *req = NULL; | ||
2129 | struct kvec iov[2]; | ||
2130 | int resp_buf_type; | ||
2131 | unsigned int count; | ||
2132 | |||
2133 | cFYI(1, "smb2_lockv num lock %d", num_lock); | ||
2134 | |||
2135 | rc = small_smb2_init(SMB2_LOCK, tcon, (void **) &req); | ||
2136 | if (rc) | ||
2137 | return rc; | ||
2138 | |||
2139 | req->hdr.ProcessId = cpu_to_le32(pid); | ||
2140 | req->LockCount = cpu_to_le16(num_lock); | ||
2141 | |||
2142 | req->PersistentFileId = persist_fid; | ||
2143 | req->VolatileFileId = volatile_fid; | ||
2144 | |||
2145 | count = num_lock * sizeof(struct smb2_lock_element); | ||
2146 | inc_rfc1001_len(req, count - sizeof(struct smb2_lock_element)); | ||
2147 | |||
2148 | iov[0].iov_base = (char *)req; | ||
2149 | /* 4 for rfc1002 length field and count for all locks */ | ||
2150 | iov[0].iov_len = get_rfc1002_length(req) + 4 - count; | ||
2151 | iov[1].iov_base = (char *)buf; | ||
2152 | iov[1].iov_len = count; | ||
2153 | |||
2154 | cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); | ||
2155 | rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP); | ||
2156 | if (rc) { | ||
2157 | cFYI(1, "Send error in smb2_lockv = %d", rc); | ||
2158 | cifs_stats_fail_inc(tcon, SMB2_LOCK_HE); | ||
2159 | } | ||
2160 | |||
2161 | return rc; | ||
2162 | } | ||
2163 | |||
2164 | int | ||
2165 | SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, | ||
2166 | const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid, | ||
2167 | const __u64 length, const __u64 offset, const __u32 lock_flags, | ||
2168 | const bool wait) | ||
2169 | { | ||
2170 | struct smb2_lock_element lock; | ||
2171 | |||
2172 | lock.Offset = cpu_to_le64(offset); | ||
2173 | lock.Length = cpu_to_le64(length); | ||
2174 | lock.Flags = cpu_to_le32(lock_flags); | ||
2175 | if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK) | ||
2176 | lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY); | ||
2177 | |||
2178 | return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock); | ||
2179 | } | ||
2180 | |||
2181 | int | ||
2182 | SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
2183 | __u8 *lease_key, const __le32 lease_state) | ||
2184 | { | ||
2185 | int rc; | ||
2186 | struct smb2_lease_ack *req = NULL; | ||
2187 | |||
2188 | cFYI(1, "SMB2_lease_break"); | ||
2189 | rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req); | ||
2190 | |||
2191 | if (rc) | ||
2192 | return rc; | ||
2193 | |||
2194 | req->hdr.CreditRequest = cpu_to_le16(1); | ||
2195 | req->StructureSize = cpu_to_le16(36); | ||
2196 | inc_rfc1001_len(req, 12); | ||
2197 | |||
2198 | memcpy(req->LeaseKey, lease_key, 16); | ||
2199 | req->LeaseState = lease_state; | ||
2200 | |||
2201 | rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP); | ||
2202 | /* SMB2 buffer freed by function above */ | ||
2203 | |||
2204 | if (rc) { | ||
2205 | cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE); | ||
2206 | cFYI(1, "Send error in Lease Break = %d", rc); | ||
2207 | } | ||
2208 | |||
2209 | return rc; | ||
2210 | } | ||
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 15dc8eea8273..4cb4ced258cb 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h | |||
@@ -150,6 +150,10 @@ struct smb2_err_rsp { | |||
150 | __u8 ErrorData[1]; /* variable length */ | 150 | __u8 ErrorData[1]; /* variable length */ |
151 | } __packed; | 151 | } __packed; |
152 | 152 | ||
153 | #define SMB2_CLIENT_GUID_SIZE 16 | ||
154 | |||
155 | extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE]; | ||
156 | |||
153 | struct smb2_negotiate_req { | 157 | struct smb2_negotiate_req { |
154 | struct smb2_hdr hdr; | 158 | struct smb2_hdr hdr; |
155 | __le16 StructureSize; /* Must be 36 */ | 159 | __le16 StructureSize; /* Must be 36 */ |
@@ -157,11 +161,17 @@ struct smb2_negotiate_req { | |||
157 | __le16 SecurityMode; | 161 | __le16 SecurityMode; |
158 | __le16 Reserved; /* MBZ */ | 162 | __le16 Reserved; /* MBZ */ |
159 | __le32 Capabilities; | 163 | __le32 Capabilities; |
160 | __u8 ClientGUID[16]; /* MBZ */ | 164 | __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE]; |
161 | __le64 ClientStartTime; /* MBZ */ | 165 | __le64 ClientStartTime; /* MBZ */ |
162 | __le16 Dialects[2]; /* variable length */ | 166 | __le16 Dialects[1]; /* One dialect (vers=) at a time for now */ |
163 | } __packed; | 167 | } __packed; |
164 | 168 | ||
169 | /* Dialects */ | ||
170 | #define SMB20_PROT_ID 0x0202 | ||
171 | #define SMB21_PROT_ID 0x0210 | ||
172 | #define SMB30_PROT_ID 0x0300 | ||
173 | #define BAD_PROT_ID 0xFFFF | ||
174 | |||
165 | /* SecurityMode flags */ | 175 | /* SecurityMode flags */ |
166 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 | 176 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 |
167 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 | 177 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 |
@@ -169,6 +179,10 @@ struct smb2_negotiate_req { | |||
169 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 | 179 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 |
170 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ | 180 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ |
171 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ | 181 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ |
182 | #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */ | ||
183 | #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */ | ||
184 | #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */ | ||
185 | #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */ | ||
172 | /* Internal types */ | 186 | /* Internal types */ |
173 | #define SMB2_NT_FIND 0x00100000 | 187 | #define SMB2_NT_FIND 0x00100000 |
174 | #define SMB2_LARGE_FILES 0x00200000 | 188 | #define SMB2_LARGE_FILES 0x00200000 |
@@ -307,6 +321,8 @@ struct smb2_tree_disconnect_rsp { | |||
307 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 | 321 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 |
308 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 | 322 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 |
309 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF | 323 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF |
324 | /* Non-spec internal type */ | ||
325 | #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99 | ||
310 | 326 | ||
311 | /* Desired Access Flags */ | 327 | /* Desired Access Flags */ |
312 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) | 328 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) |
@@ -404,7 +420,7 @@ struct smb2_create_req { | |||
404 | __le16 NameLength; | 420 | __le16 NameLength; |
405 | __le32 CreateContextsOffset; | 421 | __le32 CreateContextsOffset; |
406 | __le32 CreateContextsLength; | 422 | __le32 CreateContextsLength; |
407 | __u8 Buffer[1]; | 423 | __u8 Buffer[8]; |
408 | } __packed; | 424 | } __packed; |
409 | 425 | ||
410 | struct smb2_create_rsp { | 426 | struct smb2_create_rsp { |
@@ -428,6 +444,39 @@ struct smb2_create_rsp { | |||
428 | __u8 Buffer[1]; | 444 | __u8 Buffer[1]; |
429 | } __packed; | 445 | } __packed; |
430 | 446 | ||
447 | struct create_context { | ||
448 | __le32 Next; | ||
449 | __le16 NameOffset; | ||
450 | __le16 NameLength; | ||
451 | __le16 Reserved; | ||
452 | __le16 DataOffset; | ||
453 | __le32 DataLength; | ||
454 | __u8 Buffer[0]; | ||
455 | } __packed; | ||
456 | |||
457 | #define SMB2_LEASE_NONE __constant_cpu_to_le32(0x00) | ||
458 | #define SMB2_LEASE_READ_CACHING __constant_cpu_to_le32(0x01) | ||
459 | #define SMB2_LEASE_HANDLE_CACHING __constant_cpu_to_le32(0x02) | ||
460 | #define SMB2_LEASE_WRITE_CACHING __constant_cpu_to_le32(0x04) | ||
461 | |||
462 | #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x02) | ||
463 | |||
464 | #define SMB2_LEASE_KEY_SIZE 16 | ||
465 | |||
466 | struct lease_context { | ||
467 | __le64 LeaseKeyLow; | ||
468 | __le64 LeaseKeyHigh; | ||
469 | __le32 LeaseState; | ||
470 | __le32 LeaseFlags; | ||
471 | __le64 LeaseDuration; | ||
472 | } __packed; | ||
473 | |||
474 | struct create_lease { | ||
475 | struct create_context ccontext; | ||
476 | __u8 Name[8]; | ||
477 | struct lease_context lcontext; | ||
478 | } __packed; | ||
479 | |||
431 | /* Currently defined values for close flags */ | 480 | /* Currently defined values for close flags */ |
432 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) | 481 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) |
433 | struct smb2_close_req { | 482 | struct smb2_close_req { |
@@ -453,6 +502,108 @@ struct smb2_close_rsp { | |||
453 | __le32 Attributes; | 502 | __le32 Attributes; |
454 | } __packed; | 503 | } __packed; |
455 | 504 | ||
505 | struct smb2_flush_req { | ||
506 | struct smb2_hdr hdr; | ||
507 | __le16 StructureSize; /* Must be 24 */ | ||
508 | __le16 Reserved1; | ||
509 | __le32 Reserved2; | ||
510 | __u64 PersistentFileId; /* opaque endianness */ | ||
511 | __u64 VolatileFileId; /* opaque endianness */ | ||
512 | } __packed; | ||
513 | |||
514 | struct smb2_flush_rsp { | ||
515 | struct smb2_hdr hdr; | ||
516 | __le16 StructureSize; | ||
517 | __le16 Reserved; | ||
518 | } __packed; | ||
519 | |||
520 | struct smb2_read_req { | ||
521 | struct smb2_hdr hdr; | ||
522 | __le16 StructureSize; /* Must be 49 */ | ||
523 | __u8 Padding; /* offset from start of SMB2 header to place read */ | ||
524 | __u8 Reserved; | ||
525 | __le32 Length; | ||
526 | __le64 Offset; | ||
527 | __u64 PersistentFileId; /* opaque endianness */ | ||
528 | __u64 VolatileFileId; /* opaque endianness */ | ||
529 | __le32 MinimumCount; | ||
530 | __le32 Channel; /* Reserved MBZ */ | ||
531 | __le32 RemainingBytes; | ||
532 | __le16 ReadChannelInfoOffset; /* Reserved MBZ */ | ||
533 | __le16 ReadChannelInfoLength; /* Reserved MBZ */ | ||
534 | __u8 Buffer[1]; | ||
535 | } __packed; | ||
536 | |||
537 | struct smb2_read_rsp { | ||
538 | struct smb2_hdr hdr; | ||
539 | __le16 StructureSize; /* Must be 17 */ | ||
540 | __u8 DataOffset; | ||
541 | __u8 Reserved; | ||
542 | __le32 DataLength; | ||
543 | __le32 DataRemaining; | ||
544 | __u32 Reserved2; | ||
545 | __u8 Buffer[1]; | ||
546 | } __packed; | ||
547 | |||
548 | /* For write request Flags field below the following flag is defined: */ | ||
549 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 | ||
550 | |||
551 | struct smb2_write_req { | ||
552 | struct smb2_hdr hdr; | ||
553 | __le16 StructureSize; /* Must be 49 */ | ||
554 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ | ||
555 | __le32 Length; | ||
556 | __le64 Offset; | ||
557 | __u64 PersistentFileId; /* opaque endianness */ | ||
558 | __u64 VolatileFileId; /* opaque endianness */ | ||
559 | __le32 Channel; /* Reserved MBZ */ | ||
560 | __le32 RemainingBytes; | ||
561 | __le16 WriteChannelInfoOffset; /* Reserved MBZ */ | ||
562 | __le16 WriteChannelInfoLength; /* Reserved MBZ */ | ||
563 | __le32 Flags; | ||
564 | __u8 Buffer[1]; | ||
565 | } __packed; | ||
566 | |||
567 | struct smb2_write_rsp { | ||
568 | struct smb2_hdr hdr; | ||
569 | __le16 StructureSize; /* Must be 17 */ | ||
570 | __u8 DataOffset; | ||
571 | __u8 Reserved; | ||
572 | __le32 DataLength; | ||
573 | __le32 DataRemaining; | ||
574 | __u32 Reserved2; | ||
575 | __u8 Buffer[1]; | ||
576 | } __packed; | ||
577 | |||
578 | #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001 | ||
579 | #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002 | ||
580 | #define SMB2_LOCKFLAG_UNLOCK 0x0004 | ||
581 | #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010 | ||
582 | |||
583 | struct smb2_lock_element { | ||
584 | __le64 Offset; | ||
585 | __le64 Length; | ||
586 | __le32 Flags; | ||
587 | __le32 Reserved; | ||
588 | } __packed; | ||
589 | |||
590 | struct smb2_lock_req { | ||
591 | struct smb2_hdr hdr; | ||
592 | __le16 StructureSize; /* Must be 48 */ | ||
593 | __le16 LockCount; | ||
594 | __le32 Reserved; | ||
595 | __u64 PersistentFileId; /* opaque endianness */ | ||
596 | __u64 VolatileFileId; /* opaque endianness */ | ||
597 | /* Followed by at least one */ | ||
598 | struct smb2_lock_element locks[1]; | ||
599 | } __packed; | ||
600 | |||
601 | struct smb2_lock_rsp { | ||
602 | struct smb2_hdr hdr; | ||
603 | __le16 StructureSize; /* Must be 4 */ | ||
604 | __le16 Reserved; | ||
605 | } __packed; | ||
606 | |||
456 | struct smb2_echo_req { | 607 | struct smb2_echo_req { |
457 | struct smb2_hdr hdr; | 608 | struct smb2_hdr hdr; |
458 | __le16 StructureSize; /* Must be 4 */ | 609 | __le16 StructureSize; /* Must be 4 */ |
@@ -465,6 +616,34 @@ struct smb2_echo_rsp { | |||
465 | __u16 Reserved; | 616 | __u16 Reserved; |
466 | } __packed; | 617 | } __packed; |
467 | 618 | ||
619 | /* search (query_directory) Flags field */ | ||
620 | #define SMB2_RESTART_SCANS 0x01 | ||
621 | #define SMB2_RETURN_SINGLE_ENTRY 0x02 | ||
622 | #define SMB2_INDEX_SPECIFIED 0x04 | ||
623 | #define SMB2_REOPEN 0x10 | ||
624 | |||
625 | struct smb2_query_directory_req { | ||
626 | struct smb2_hdr hdr; | ||
627 | __le16 StructureSize; /* Must be 33 */ | ||
628 | __u8 FileInformationClass; | ||
629 | __u8 Flags; | ||
630 | __le32 FileIndex; | ||
631 | __u64 PersistentFileId; /* opaque endianness */ | ||
632 | __u64 VolatileFileId; /* opaque endianness */ | ||
633 | __le16 FileNameOffset; | ||
634 | __le16 FileNameLength; | ||
635 | __le32 OutputBufferLength; | ||
636 | __u8 Buffer[1]; | ||
637 | } __packed; | ||
638 | |||
639 | struct smb2_query_directory_rsp { | ||
640 | struct smb2_hdr hdr; | ||
641 | __le16 StructureSize; /* Must be 9 */ | ||
642 | __le16 OutputBufferOffset; | ||
643 | __le32 OutputBufferLength; | ||
644 | __u8 Buffer[1]; | ||
645 | } __packed; | ||
646 | |||
468 | /* Possible InfoType values */ | 647 | /* Possible InfoType values */ |
469 | #define SMB2_O_INFO_FILE 0x01 | 648 | #define SMB2_O_INFO_FILE 0x01 |
470 | #define SMB2_O_INFO_FILESYSTEM 0x02 | 649 | #define SMB2_O_INFO_FILESYSTEM 0x02 |
@@ -495,11 +674,84 @@ struct smb2_query_info_rsp { | |||
495 | __u8 Buffer[1]; | 674 | __u8 Buffer[1]; |
496 | } __packed; | 675 | } __packed; |
497 | 676 | ||
677 | struct smb2_set_info_req { | ||
678 | struct smb2_hdr hdr; | ||
679 | __le16 StructureSize; /* Must be 33 */ | ||
680 | __u8 InfoType; | ||
681 | __u8 FileInfoClass; | ||
682 | __le32 BufferLength; | ||
683 | __le16 BufferOffset; | ||
684 | __u16 Reserved; | ||
685 | __le32 AdditionalInformation; | ||
686 | __u64 PersistentFileId; /* opaque endianness */ | ||
687 | __u64 VolatileFileId; /* opaque endianness */ | ||
688 | __u8 Buffer[1]; | ||
689 | } __packed; | ||
690 | |||
691 | struct smb2_set_info_rsp { | ||
692 | struct smb2_hdr hdr; | ||
693 | __le16 StructureSize; /* Must be 2 */ | ||
694 | } __packed; | ||
695 | |||
696 | struct smb2_oplock_break { | ||
697 | struct smb2_hdr hdr; | ||
698 | __le16 StructureSize; /* Must be 24 */ | ||
699 | __u8 OplockLevel; | ||
700 | __u8 Reserved; | ||
701 | __le32 Reserved2; | ||
702 | __u64 PersistentFid; | ||
703 | __u64 VolatileFid; | ||
704 | } __packed; | ||
705 | |||
706 | #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01) | ||
707 | |||
708 | struct smb2_lease_break { | ||
709 | struct smb2_hdr hdr; | ||
710 | __le16 StructureSize; /* Must be 44 */ | ||
711 | __le16 Reserved; | ||
712 | __le32 Flags; | ||
713 | __u8 LeaseKey[16]; | ||
714 | __le32 CurrentLeaseState; | ||
715 | __le32 NewLeaseState; | ||
716 | __le32 BreakReason; | ||
717 | __le32 AccessMaskHint; | ||
718 | __le32 ShareMaskHint; | ||
719 | } __packed; | ||
720 | |||
721 | struct smb2_lease_ack { | ||
722 | struct smb2_hdr hdr; | ||
723 | __le16 StructureSize; /* Must be 36 */ | ||
724 | __le16 Reserved; | ||
725 | __le32 Flags; | ||
726 | __u8 LeaseKey[16]; | ||
727 | __le32 LeaseState; | ||
728 | __le64 LeaseDuration; | ||
729 | } __packed; | ||
730 | |||
498 | /* | 731 | /* |
499 | * PDU infolevel structure definitions | 732 | * PDU infolevel structure definitions |
500 | * BB consider moving to a different header | 733 | * BB consider moving to a different header |
501 | */ | 734 | */ |
502 | 735 | ||
736 | /* File System Information Classes */ | ||
737 | #define FS_VOLUME_INFORMATION 1 /* Query */ | ||
738 | #define FS_LABEL_INFORMATION 2 /* Set */ | ||
739 | #define FS_SIZE_INFORMATION 3 /* Query */ | ||
740 | #define FS_DEVICE_INFORMATION 4 /* Query */ | ||
741 | #define FS_ATTRIBUTE_INFORMATION 5 /* Query */ | ||
742 | #define FS_CONTROL_INFORMATION 6 /* Query, Set */ | ||
743 | #define FS_FULL_SIZE_INFORMATION 7 /* Query */ | ||
744 | #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */ | ||
745 | #define FS_DRIVER_PATH_INFORMATION 9 /* Query */ | ||
746 | |||
747 | struct smb2_fs_full_size_info { | ||
748 | __le64 TotalAllocationUnits; | ||
749 | __le64 CallerAvailableAllocationUnits; | ||
750 | __le64 ActualAvailableAllocationUnits; | ||
751 | __le32 SectorsPerAllocationUnit; | ||
752 | __le32 BytesPerSector; | ||
753 | } __packed; | ||
754 | |||
503 | /* partial list of QUERY INFO levels */ | 755 | /* partial list of QUERY INFO levels */ |
504 | #define FILE_DIRECTORY_INFORMATION 1 | 756 | #define FILE_DIRECTORY_INFORMATION 1 |
505 | #define FILE_FULL_DIRECTORY_INFORMATION 2 | 757 | #define FILE_FULL_DIRECTORY_INFORMATION 2 |
@@ -548,6 +800,28 @@ struct smb2_query_info_rsp { | |||
548 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 | 800 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 |
549 | #define FILE_STANDARD_LINK_INFORMATION 54 | 801 | #define FILE_STANDARD_LINK_INFORMATION 54 |
550 | 802 | ||
803 | struct smb2_file_internal_info { | ||
804 | __le64 IndexNumber; | ||
805 | } __packed; /* level 6 Query */ | ||
806 | |||
807 | struct smb2_file_rename_info { /* encoding of request for level 10 */ | ||
808 | __u8 ReplaceIfExists; /* 1 = replace existing target with new */ | ||
809 | /* 0 = fail if target already exists */ | ||
810 | __u8 Reserved[7]; | ||
811 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | ||
812 | __le32 FileNameLength; | ||
813 | char FileName[0]; /* New name to be assigned */ | ||
814 | } __packed; /* level 10 Set */ | ||
815 | |||
816 | struct smb2_file_link_info { /* encoding of request for level 11 */ | ||
817 | __u8 ReplaceIfExists; /* 1 = replace existing link with new */ | ||
818 | /* 0 = fail if link already exists */ | ||
819 | __u8 Reserved[7]; | ||
820 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | ||
821 | __le32 FileNameLength; | ||
822 | char FileName[0]; /* Name to be assigned to new link */ | ||
823 | } __packed; /* level 11 Set */ | ||
824 | |||
551 | /* | 825 | /* |
552 | * This level 18, although with struct with same name is different from cifs | 826 | * This level 18, although with struct with same name is different from cifs |
553 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and | 827 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and |
@@ -576,4 +850,8 @@ struct smb2_file_all_info { /* data block encoding of response to level 18 */ | |||
576 | char FileName[1]; | 850 | char FileName[1]; |
577 | } __packed; /* level 18 Query */ | 851 | } __packed; /* level 18 Query */ |
578 | 852 | ||
853 | struct smb2_file_eof_info { /* encoding of request for level 10 */ | ||
854 | __le64 EndOfFile; /* new end of file value */ | ||
855 | } __packed; /* level 20 Set */ | ||
856 | |||
579 | #endif /* _SMB2PDU_H */ | 857 | #endif /* _SMB2PDU_H */ |
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index bfaa7b148afd..7d25f8b14f93 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/key-type.h> | 26 | #include <linux/key-type.h> |
27 | 27 | ||
28 | struct statfs; | 28 | struct statfs; |
29 | struct smb_rqst; | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | ***************************************************************** | 32 | ***************************************************************** |
@@ -34,24 +35,35 @@ struct statfs; | |||
34 | */ | 35 | */ |
35 | extern int map_smb2_to_linux_error(char *buf, bool log_err); | 36 | extern int map_smb2_to_linux_error(char *buf, bool log_err); |
36 | extern int smb2_check_message(char *buf, unsigned int length); | 37 | extern int smb2_check_message(char *buf, unsigned int length); |
37 | extern unsigned int smb2_calc_size(struct smb2_hdr *hdr); | 38 | extern unsigned int smb2_calc_size(void *buf); |
38 | extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr); | 39 | extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr); |
39 | extern __le16 *cifs_convert_path_to_utf16(const char *from, | 40 | extern __le16 *cifs_convert_path_to_utf16(const char *from, |
40 | struct cifs_sb_info *cifs_sb); | 41 | struct cifs_sb_info *cifs_sb); |
41 | 42 | ||
43 | extern int smb2_verify_signature(struct smb_rqst *, struct TCP_Server_Info *); | ||
42 | extern int smb2_check_receive(struct mid_q_entry *mid, | 44 | extern int smb2_check_receive(struct mid_q_entry *mid, |
43 | struct TCP_Server_Info *server, bool log_error); | 45 | struct TCP_Server_Info *server, bool log_error); |
44 | extern int smb2_setup_request(struct cifs_ses *ses, struct kvec *iov, | 46 | extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses, |
45 | unsigned int nvec, struct mid_q_entry **ret_mid); | 47 | struct smb_rqst *rqst); |
46 | extern int smb2_setup_async_request(struct TCP_Server_Info *server, | 48 | extern struct mid_q_entry *smb2_setup_async_request( |
47 | struct kvec *iov, unsigned int nvec, | 49 | struct TCP_Server_Info *server, struct smb_rqst *rqst); |
48 | struct mid_q_entry **ret_mid); | ||
49 | extern void smb2_echo_request(struct work_struct *work); | 50 | extern void smb2_echo_request(struct work_struct *work); |
51 | extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode); | ||
52 | extern __u8 smb2_map_lease_to_oplock(__le32 lease_state); | ||
53 | extern bool smb2_is_valid_oplock_break(char *buffer, | ||
54 | struct TCP_Server_Info *srv); | ||
50 | 55 | ||
56 | extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst, | ||
57 | struct smb2_file_all_info *src); | ||
51 | extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, | 58 | extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
52 | struct cifs_sb_info *cifs_sb, | 59 | struct cifs_sb_info *cifs_sb, |
53 | const char *full_path, FILE_ALL_INFO *data, | 60 | const char *full_path, FILE_ALL_INFO *data, |
54 | bool *adjust_tz); | 61 | bool *adjust_tz); |
62 | extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, | ||
63 | const char *full_path, __u64 size, | ||
64 | struct cifs_sb_info *cifs_sb, bool set_alloc); | ||
65 | extern int smb2_set_file_info(struct inode *inode, const char *full_path, | ||
66 | FILE_BASIC_INFO *buf, const unsigned int xid); | ||
55 | extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, | 67 | extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, |
56 | const char *name, struct cifs_sb_info *cifs_sb); | 68 | const char *name, struct cifs_sb_info *cifs_sb); |
57 | extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, | 69 | extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, |
@@ -59,6 +71,24 @@ extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path, | |||
59 | struct cifs_tcon *tcon, const unsigned int xid); | 71 | struct cifs_tcon *tcon, const unsigned int xid); |
60 | extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, | 72 | extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, |
61 | const char *name, struct cifs_sb_info *cifs_sb); | 73 | const char *name, struct cifs_sb_info *cifs_sb); |
74 | extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
75 | const char *name, struct cifs_sb_info *cifs_sb); | ||
76 | extern int smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, | ||
77 | const char *from_name, const char *to_name, | ||
78 | struct cifs_sb_info *cifs_sb); | ||
79 | extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
80 | const char *from_name, const char *to_name, | ||
81 | struct cifs_sb_info *cifs_sb); | ||
82 | |||
83 | extern int smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, | ||
84 | const char *full_path, int disposition, | ||
85 | int desired_access, int create_options, | ||
86 | struct cifs_fid *fid, __u32 *oplock, | ||
87 | FILE_ALL_INFO *buf, struct cifs_sb_info *cifs_sb); | ||
88 | extern void smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); | ||
89 | extern int smb2_unlock_range(struct cifsFileInfo *cfile, | ||
90 | struct file_lock *flock, const unsigned int xid); | ||
91 | extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile); | ||
62 | 92 | ||
63 | /* | 93 | /* |
64 | * SMB2 Worker functions - most of protocol specific implementation details | 94 | * SMB2 Worker functions - most of protocol specific implementation details |
@@ -75,12 +105,55 @@ extern int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon); | |||
75 | extern int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, | 105 | extern int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, |
76 | __le16 *path, u64 *persistent_fid, u64 *volatile_fid, | 106 | __le16 *path, u64 *persistent_fid, u64 *volatile_fid, |
77 | __u32 desired_access, __u32 create_disposition, | 107 | __u32 desired_access, __u32 create_disposition, |
78 | __u32 file_attributes, __u32 create_options); | 108 | __u32 file_attributes, __u32 create_options, |
109 | __u8 *oplock, struct smb2_file_all_info *buf); | ||
79 | extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, | 110 | extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, |
80 | u64 persistent_file_id, u64 volatile_file_id); | 111 | u64 persistent_file_id, u64 volatile_file_id); |
112 | extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, | ||
113 | u64 persistent_file_id, u64 volatile_file_id); | ||
81 | extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | 114 | extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, |
82 | u64 persistent_file_id, u64 volatile_file_id, | 115 | u64 persistent_file_id, u64 volatile_file_id, |
83 | struct smb2_file_all_info *data); | 116 | struct smb2_file_all_info *data); |
117 | extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, | ||
118 | u64 persistent_fid, u64 volatile_fid, | ||
119 | __le64 *uniqueid); | ||
120 | extern int smb2_async_readv(struct cifs_readdata *rdata); | ||
121 | extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
122 | unsigned int *nbytes, char **buf, int *buf_type); | ||
123 | extern int smb2_async_writev(struct cifs_writedata *wdata); | ||
124 | extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, | ||
125 | unsigned int *nbytes, struct kvec *iov, int n_vec); | ||
84 | extern int SMB2_echo(struct TCP_Server_Info *server); | 126 | extern int SMB2_echo(struct TCP_Server_Info *server); |
127 | extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, | ||
128 | u64 persistent_fid, u64 volatile_fid, int index, | ||
129 | struct cifs_search_info *srch_inf); | ||
130 | extern int SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, | ||
131 | u64 persistent_fid, u64 volatile_fid, | ||
132 | __le16 *target_file); | ||
133 | extern int SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | ||
134 | u64 persistent_fid, u64 volatile_fid, | ||
135 | __le16 *target_file); | ||
136 | extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, | ||
137 | u64 persistent_fid, u64 volatile_fid, u32 pid, | ||
138 | __le64 *eof); | ||
139 | extern int SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
140 | u64 persistent_fid, u64 volatile_fid, | ||
141 | FILE_BASIC_INFO *buf); | ||
142 | extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
143 | const u64 persistent_fid, const u64 volatile_fid, | ||
144 | const __u8 oplock_level); | ||
145 | extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, | ||
146 | u64 persistent_file_id, u64 volatile_file_id, | ||
147 | struct kstatfs *FSData); | ||
148 | extern int SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon, | ||
149 | const __u64 persist_fid, const __u64 volatile_fid, | ||
150 | const __u32 pid, const __u64 length, const __u64 offset, | ||
151 | const __u32 lockFlags, const bool wait); | ||
152 | extern int smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon, | ||
153 | const __u64 persist_fid, const __u64 volatile_fid, | ||
154 | const __u32 pid, const __u32 num_lock, | ||
155 | struct smb2_lock_element *buf); | ||
156 | extern int SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon, | ||
157 | __u8 *lease_key, const __le32 lease_state); | ||
85 | 158 | ||
86 | #endif /* _SMB2PROTO_H */ | 159 | #endif /* _SMB2PROTO_H */ |
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c index 31f5d420b3ea..2a5fdf26f79f 100644 --- a/fs/cifs/smb2transport.c +++ b/fs/cifs/smb2transport.c | |||
@@ -30,12 +30,156 @@ | |||
30 | #include <linux/uaccess.h> | 30 | #include <linux/uaccess.h> |
31 | #include <asm/processor.h> | 31 | #include <asm/processor.h> |
32 | #include <linux/mempool.h> | 32 | #include <linux/mempool.h> |
33 | #include <linux/highmem.h> | ||
33 | #include "smb2pdu.h" | 34 | #include "smb2pdu.h" |
34 | #include "cifsglob.h" | 35 | #include "cifsglob.h" |
35 | #include "cifsproto.h" | 36 | #include "cifsproto.h" |
36 | #include "smb2proto.h" | 37 | #include "smb2proto.h" |
37 | #include "cifs_debug.h" | 38 | #include "cifs_debug.h" |
38 | #include "smb2status.h" | 39 | #include "smb2status.h" |
40 | #include "smb2glob.h" | ||
41 | |||
42 | static int | ||
43 | smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
44 | { | ||
45 | int i, rc; | ||
46 | unsigned char smb2_signature[SMB2_HMACSHA256_SIZE]; | ||
47 | unsigned char *sigptr = smb2_signature; | ||
48 | struct kvec *iov = rqst->rq_iov; | ||
49 | int n_vec = rqst->rq_nvec; | ||
50 | struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; | ||
51 | |||
52 | memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE); | ||
53 | memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE); | ||
54 | |||
55 | rc = crypto_shash_setkey(server->secmech.hmacsha256, | ||
56 | server->session_key.response, SMB2_NTLMV2_SESSKEY_SIZE); | ||
57 | if (rc) { | ||
58 | cERROR(1, "%s: Could not update with response\n", __func__); | ||
59 | return rc; | ||
60 | } | ||
61 | |||
62 | rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash); | ||
63 | if (rc) { | ||
64 | cERROR(1, "%s: Could not init md5\n", __func__); | ||
65 | return rc; | ||
66 | } | ||
67 | |||
68 | for (i = 0; i < n_vec; i++) { | ||
69 | if (iov[i].iov_len == 0) | ||
70 | continue; | ||
71 | if (iov[i].iov_base == NULL) { | ||
72 | cERROR(1, "null iovec entry"); | ||
73 | return -EIO; | ||
74 | } | ||
75 | /* | ||
76 | * The first entry includes a length field (which does not get | ||
77 | * signed that occupies the first 4 bytes before the header). | ||
78 | */ | ||
79 | if (i == 0) { | ||
80 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ | ||
81 | break; /* nothing to sign or corrupt header */ | ||
82 | rc = | ||
83 | crypto_shash_update( | ||
84 | &server->secmech.sdeschmacsha256->shash, | ||
85 | iov[i].iov_base + 4, iov[i].iov_len - 4); | ||
86 | } else { | ||
87 | rc = | ||
88 | crypto_shash_update( | ||
89 | &server->secmech.sdeschmacsha256->shash, | ||
90 | iov[i].iov_base, iov[i].iov_len); | ||
91 | } | ||
92 | if (rc) { | ||
93 | cERROR(1, "%s: Could not update with payload\n", | ||
94 | __func__); | ||
95 | return rc; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /* now hash over the rq_pages array */ | ||
100 | for (i = 0; i < rqst->rq_npages; i++) { | ||
101 | struct kvec p_iov; | ||
102 | |||
103 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
104 | crypto_shash_update(&server->secmech.sdeschmacsha256->shash, | ||
105 | p_iov.iov_base, p_iov.iov_len); | ||
106 | kunmap(rqst->rq_pages[i]); | ||
107 | } | ||
108 | |||
109 | rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash, | ||
110 | sigptr); | ||
111 | if (rc) | ||
112 | cERROR(1, "%s: Could not generate sha256 hash\n", __func__); | ||
113 | |||
114 | memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE); | ||
115 | |||
116 | return rc; | ||
117 | } | ||
118 | |||
119 | /* must be called with server->srv_mutex held */ | ||
120 | static int | ||
121 | smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
122 | { | ||
123 | int rc = 0; | ||
124 | struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base; | ||
125 | |||
126 | if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) || | ||
127 | server->tcpStatus == CifsNeedNegotiate) | ||
128 | return rc; | ||
129 | |||
130 | if (!server->session_estab) { | ||
131 | strncpy(smb2_pdu->Signature, "BSRSPYL", 8); | ||
132 | return rc; | ||
133 | } | ||
134 | |||
135 | rc = smb2_calc_signature(rqst, server); | ||
136 | |||
137 | return rc; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) | ||
142 | { | ||
143 | unsigned int rc; | ||
144 | char server_response_sig[16]; | ||
145 | struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; | ||
146 | |||
147 | if ((smb2_pdu->Command == SMB2_NEGOTIATE) || | ||
148 | (smb2_pdu->Command == SMB2_OPLOCK_BREAK) || | ||
149 | (!server->session_estab)) | ||
150 | return 0; | ||
151 | |||
152 | /* | ||
153 | * BB what if signatures are supposed to be on for session but | ||
154 | * server does not send one? BB | ||
155 | */ | ||
156 | |||
157 | /* Do not need to verify session setups with signature "BSRSPYL " */ | ||
158 | if (memcmp(smb2_pdu->Signature, "BSRSPYL ", 8) == 0) | ||
159 | cFYI(1, "dummy signature received for smb command 0x%x", | ||
160 | smb2_pdu->Command); | ||
161 | |||
162 | /* | ||
163 | * Save off the origiginal signature so we can modify the smb and check | ||
164 | * our calculated signature against what the server sent. | ||
165 | */ | ||
166 | memcpy(server_response_sig, smb2_pdu->Signature, SMB2_SIGNATURE_SIZE); | ||
167 | |||
168 | memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE); | ||
169 | |||
170 | mutex_lock(&server->srv_mutex); | ||
171 | rc = smb2_calc_signature(rqst, server); | ||
172 | mutex_unlock(&server->srv_mutex); | ||
173 | |||
174 | if (rc) | ||
175 | return rc; | ||
176 | |||
177 | if (memcmp(server_response_sig, smb2_pdu->Signature, | ||
178 | SMB2_SIGNATURE_SIZE)) | ||
179 | return -EACCES; | ||
180 | else | ||
181 | return 0; | ||
182 | } | ||
39 | 183 | ||
40 | /* | 184 | /* |
41 | * Set message id for the request. Should be called after wait_for_free_request | 185 | * Set message id for the request. Should be called after wait_for_free_request |
@@ -115,58 +259,66 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
115 | bool log_error) | 259 | bool log_error) |
116 | { | 260 | { |
117 | unsigned int len = get_rfc1002_length(mid->resp_buf); | 261 | unsigned int len = get_rfc1002_length(mid->resp_buf); |
262 | struct kvec iov; | ||
263 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
264 | .rq_nvec = 1 }; | ||
265 | |||
266 | iov.iov_base = (char *)mid->resp_buf; | ||
267 | iov.iov_len = get_rfc1002_length(mid->resp_buf) + 4; | ||
118 | 268 | ||
119 | dump_smb(mid->resp_buf, min_t(u32, 80, len)); | 269 | dump_smb(mid->resp_buf, min_t(u32, 80, len)); |
120 | /* convert the length into a more usable form */ | 270 | /* convert the length into a more usable form */ |
121 | /* BB - uncomment with SMB2 signing implementation */ | 271 | if ((len > 24) && |
122 | /* if ((len > 24) && | ||
123 | (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) { | 272 | (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) { |
124 | if (smb2_verify_signature(mid->resp_buf, server)) | 273 | int rc; |
125 | cERROR(1, "Unexpected SMB signature"); | 274 | |
126 | } */ | 275 | rc = smb2_verify_signature(&rqst, server); |
276 | if (rc) | ||
277 | cERROR(1, "SMB signature verification returned error = " | ||
278 | "%d", rc); | ||
279 | } | ||
127 | 280 | ||
128 | return map_smb2_to_linux_error(mid->resp_buf, log_error); | 281 | return map_smb2_to_linux_error(mid->resp_buf, log_error); |
129 | } | 282 | } |
130 | 283 | ||
131 | int | 284 | struct mid_q_entry * |
132 | smb2_setup_request(struct cifs_ses *ses, struct kvec *iov, | 285 | smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
133 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
134 | { | 286 | { |
135 | int rc; | 287 | int rc; |
136 | struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; | 288 | struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; |
137 | struct mid_q_entry *mid; | 289 | struct mid_q_entry *mid; |
138 | 290 | ||
139 | smb2_seq_num_into_buf(ses->server, hdr); | 291 | smb2_seq_num_into_buf(ses->server, hdr); |
140 | 292 | ||
141 | rc = smb2_get_mid_entry(ses, hdr, &mid); | 293 | rc = smb2_get_mid_entry(ses, hdr, &mid); |
142 | if (rc) | 294 | if (rc) |
143 | return rc; | 295 | return ERR_PTR(rc); |
144 | /* rc = smb2_sign_smb2(iov, nvec, ses->server); | 296 | rc = smb2_sign_rqst(rqst, ses->server); |
145 | if (rc) | 297 | if (rc) { |
146 | delete_mid(mid); */ | 298 | cifs_delete_mid(mid); |
147 | *ret_mid = mid; | 299 | return ERR_PTR(rc); |
148 | return rc; | 300 | } |
301 | return mid; | ||
149 | } | 302 | } |
150 | 303 | ||
151 | int | 304 | struct mid_q_entry * |
152 | smb2_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | 305 | smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
153 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
154 | { | 306 | { |
155 | int rc = 0; | 307 | int rc; |
156 | struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; | 308 | struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; |
157 | struct mid_q_entry *mid; | 309 | struct mid_q_entry *mid; |
158 | 310 | ||
159 | smb2_seq_num_into_buf(server, hdr); | 311 | smb2_seq_num_into_buf(server, hdr); |
160 | 312 | ||
161 | mid = smb2_mid_entry_alloc(hdr, server); | 313 | mid = smb2_mid_entry_alloc(hdr, server); |
162 | if (mid == NULL) | 314 | if (mid == NULL) |
163 | return -ENOMEM; | 315 | return ERR_PTR(-ENOMEM); |
164 | 316 | ||
165 | /* rc = smb2_sign_smb2(iov, nvec, server); | 317 | rc = smb2_sign_rqst(rqst, server); |
166 | if (rc) { | 318 | if (rc) { |
167 | DeleteMidQEntry(mid); | 319 | DeleteMidQEntry(mid); |
168 | return rc; | 320 | return ERR_PTR(rc); |
169 | }*/ | 321 | } |
170 | *ret_mid = mid; | 322 | |
171 | return rc; | 323 | return mid; |
172 | } | 324 | } |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index d9b639b95fa8..2126ab185045 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
28 | #include <linux/delay.h> | 28 | #include <linux/delay.h> |
29 | #include <linux/freezer.h> | 29 | #include <linux/freezer.h> |
30 | #include <linux/tcp.h> | ||
31 | #include <linux/highmem.h> | ||
30 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
31 | #include <asm/processor.h> | 33 | #include <asm/processor.h> |
32 | #include <linux/mempool.h> | 34 | #include <linux/mempool.h> |
@@ -109,8 +111,8 @@ DeleteMidQEntry(struct mid_q_entry *midEntry) | |||
109 | mempool_free(midEntry, cifs_mid_poolp); | 111 | mempool_free(midEntry, cifs_mid_poolp); |
110 | } | 112 | } |
111 | 113 | ||
112 | static void | 114 | void |
113 | delete_mid(struct mid_q_entry *mid) | 115 | cifs_delete_mid(struct mid_q_entry *mid) |
114 | { | 116 | { |
115 | spin_lock(&GlobalMid_Lock); | 117 | spin_lock(&GlobalMid_Lock); |
116 | list_del(&mid->qhead); | 118 | list_del(&mid->qhead); |
@@ -119,18 +121,29 @@ delete_mid(struct mid_q_entry *mid) | |||
119 | DeleteMidQEntry(mid); | 121 | DeleteMidQEntry(mid); |
120 | } | 122 | } |
121 | 123 | ||
124 | /* | ||
125 | * smb_send_kvec - send an array of kvecs to the server | ||
126 | * @server: Server to send the data to | ||
127 | * @iov: Pointer to array of kvecs | ||
128 | * @n_vec: length of kvec array | ||
129 | * @sent: amount of data sent on socket is stored here | ||
130 | * | ||
131 | * Our basic "send data to server" function. Should be called with srv_mutex | ||
132 | * held. The caller is responsible for handling the results. | ||
133 | */ | ||
122 | static int | 134 | static int |
123 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | 135 | smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec, |
136 | size_t *sent) | ||
124 | { | 137 | { |
125 | int rc = 0; | 138 | int rc = 0; |
126 | int i = 0; | 139 | int i = 0; |
127 | struct msghdr smb_msg; | 140 | struct msghdr smb_msg; |
128 | unsigned int len = iov[0].iov_len; | 141 | unsigned int remaining; |
129 | unsigned int total_len; | 142 | size_t first_vec = 0; |
130 | int first_vec = 0; | ||
131 | unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); | ||
132 | struct socket *ssocket = server->ssocket; | 143 | struct socket *ssocket = server->ssocket; |
133 | 144 | ||
145 | *sent = 0; | ||
146 | |||
134 | if (ssocket == NULL) | 147 | if (ssocket == NULL) |
135 | return -ENOTSOCK; /* BB eventually add reconnect code here */ | 148 | return -ENOTSOCK; /* BB eventually add reconnect code here */ |
136 | 149 | ||
@@ -143,56 +156,60 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
143 | else | 156 | else |
144 | smb_msg.msg_flags = MSG_NOSIGNAL; | 157 | smb_msg.msg_flags = MSG_NOSIGNAL; |
145 | 158 | ||
146 | total_len = 0; | 159 | remaining = 0; |
147 | for (i = 0; i < n_vec; i++) | 160 | for (i = 0; i < n_vec; i++) |
148 | total_len += iov[i].iov_len; | 161 | remaining += iov[i].iov_len; |
149 | |||
150 | cFYI(1, "Sending smb: total_len %d", total_len); | ||
151 | dump_smb(iov[0].iov_base, len); | ||
152 | 162 | ||
153 | i = 0; | 163 | i = 0; |
154 | while (total_len) { | 164 | while (remaining) { |
165 | /* | ||
166 | * If blocking send, we try 3 times, since each can block | ||
167 | * for 5 seconds. For nonblocking we have to try more | ||
168 | * but wait increasing amounts of time allowing time for | ||
169 | * socket to clear. The overall time we wait in either | ||
170 | * case to send on the socket is about 15 seconds. | ||
171 | * Similarly we wait for 15 seconds for a response from | ||
172 | * the server in SendReceive[2] for the server to send | ||
173 | * a response back for most types of requests (except | ||
174 | * SMB Write past end of file which can be slow, and | ||
175 | * blocking lock operations). NFS waits slightly longer | ||
176 | * than CIFS, but this can make it take longer for | ||
177 | * nonresponsive servers to be detected and 15 seconds | ||
178 | * is more than enough time for modern networks to | ||
179 | * send a packet. In most cases if we fail to send | ||
180 | * after the retries we will kill the socket and | ||
181 | * reconnect which may clear the network problem. | ||
182 | */ | ||
155 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], | 183 | rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], |
156 | n_vec - first_vec, total_len); | 184 | n_vec - first_vec, remaining); |
157 | if ((rc == -ENOSPC) || (rc == -EAGAIN)) { | 185 | if (rc == -ENOSPC || rc == -EAGAIN) { |
158 | i++; | 186 | i++; |
159 | /* | 187 | if (i >= 14 || (!server->noblocksnd && (i > 2))) { |
160 | * If blocking send we try 3 times, since each can block | 188 | cERROR(1, "sends on sock %p stuck for 15 " |
161 | * for 5 seconds. For nonblocking we have to try more | 189 | "seconds", ssocket); |
162 | * but wait increasing amounts of time allowing time for | ||
163 | * socket to clear. The overall time we wait in either | ||
164 | * case to send on the socket is about 15 seconds. | ||
165 | * Similarly we wait for 15 seconds for a response from | ||
166 | * the server in SendReceive[2] for the server to send | ||
167 | * a response back for most types of requests (except | ||
168 | * SMB Write past end of file which can be slow, and | ||
169 | * blocking lock operations). NFS waits slightly longer | ||
170 | * than CIFS, but this can make it take longer for | ||
171 | * nonresponsive servers to be detected and 15 seconds | ||
172 | * is more than enough time for modern networks to | ||
173 | * send a packet. In most cases if we fail to send | ||
174 | * after the retries we will kill the socket and | ||
175 | * reconnect which may clear the network problem. | ||
176 | */ | ||
177 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { | ||
178 | cERROR(1, "sends on sock %p stuck for 15 seconds", | ||
179 | ssocket); | ||
180 | rc = -EAGAIN; | 190 | rc = -EAGAIN; |
181 | break; | 191 | break; |
182 | } | 192 | } |
183 | msleep(1 << i); | 193 | msleep(1 << i); |
184 | continue; | 194 | continue; |
185 | } | 195 | } |
196 | |||
186 | if (rc < 0) | 197 | if (rc < 0) |
187 | break; | 198 | break; |
188 | 199 | ||
189 | if (rc == total_len) { | 200 | /* send was at least partially successful */ |
190 | total_len = 0; | 201 | *sent += rc; |
202 | |||
203 | if (rc == remaining) { | ||
204 | remaining = 0; | ||
191 | break; | 205 | break; |
192 | } else if (rc > total_len) { | 206 | } |
193 | cERROR(1, "sent %d requested %d", rc, total_len); | 207 | |
208 | if (rc > remaining) { | ||
209 | cERROR(1, "sent %d requested %d", rc, remaining); | ||
194 | break; | 210 | break; |
195 | } | 211 | } |
212 | |||
196 | if (rc == 0) { | 213 | if (rc == 0) { |
197 | /* should never happen, letting socket clear before | 214 | /* should never happen, letting socket clear before |
198 | retrying is our only obvious option here */ | 215 | retrying is our only obvious option here */ |
@@ -200,7 +217,9 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
200 | msleep(500); | 217 | msleep(500); |
201 | continue; | 218 | continue; |
202 | } | 219 | } |
203 | total_len -= rc; | 220 | |
221 | remaining -= rc; | ||
222 | |||
204 | /* the line below resets i */ | 223 | /* the line below resets i */ |
205 | for (i = first_vec; i < n_vec; i++) { | 224 | for (i = first_vec; i < n_vec; i++) { |
206 | if (iov[i].iov_len) { | 225 | if (iov[i].iov_len) { |
@@ -215,16 +234,97 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
215 | } | 234 | } |
216 | } | 235 | } |
217 | } | 236 | } |
237 | |||
218 | i = 0; /* in case we get ENOSPC on the next send */ | 238 | i = 0; /* in case we get ENOSPC on the next send */ |
239 | rc = 0; | ||
219 | } | 240 | } |
241 | return rc; | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec | ||
246 | * @rqst: pointer to smb_rqst | ||
247 | * @idx: index into the array of the page | ||
248 | * @iov: pointer to struct kvec that will hold the result | ||
249 | * | ||
250 | * Helper function to convert a slot in the rqst->rq_pages array into a kvec. | ||
251 | * The page will be kmapped and the address placed into iov_base. The length | ||
252 | * will then be adjusted according to the ptailoff. | ||
253 | */ | ||
254 | void | ||
255 | cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx, | ||
256 | struct kvec *iov) | ||
257 | { | ||
258 | /* | ||
259 | * FIXME: We could avoid this kmap altogether if we used | ||
260 | * kernel_sendpage instead of kernel_sendmsg. That will only | ||
261 | * work if signing is disabled though as sendpage inlines the | ||
262 | * page directly into the fraglist. If userspace modifies the | ||
263 | * page after we calculate the signature, then the server will | ||
264 | * reject it and may break the connection. kernel_sendmsg does | ||
265 | * an extra copy of the data and avoids that issue. | ||
266 | */ | ||
267 | iov->iov_base = kmap(rqst->rq_pages[idx]); | ||
268 | |||
269 | /* if last page, don't send beyond this offset into page */ | ||
270 | if (idx == (rqst->rq_npages - 1)) | ||
271 | iov->iov_len = rqst->rq_tailsz; | ||
272 | else | ||
273 | iov->iov_len = rqst->rq_pagesz; | ||
274 | } | ||
275 | |||
276 | static int | ||
277 | smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) | ||
278 | { | ||
279 | int rc; | ||
280 | struct kvec *iov = rqst->rq_iov; | ||
281 | int n_vec = rqst->rq_nvec; | ||
282 | unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); | ||
283 | unsigned int i; | ||
284 | size_t total_len = 0, sent; | ||
285 | struct socket *ssocket = server->ssocket; | ||
286 | int val = 1; | ||
287 | |||
288 | cFYI(1, "Sending smb: smb_len=%u", smb_buf_length); | ||
289 | dump_smb(iov[0].iov_base, iov[0].iov_len); | ||
290 | |||
291 | /* cork the socket */ | ||
292 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, | ||
293 | (char *)&val, sizeof(val)); | ||
294 | |||
295 | rc = smb_send_kvec(server, iov, n_vec, &sent); | ||
296 | if (rc < 0) | ||
297 | goto uncork; | ||
298 | |||
299 | total_len += sent; | ||
300 | |||
301 | /* now walk the page array and send each page in it */ | ||
302 | for (i = 0; i < rqst->rq_npages; i++) { | ||
303 | struct kvec p_iov; | ||
304 | |||
305 | cifs_rqst_page_to_kvec(rqst, i, &p_iov); | ||
306 | rc = smb_send_kvec(server, &p_iov, 1, &sent); | ||
307 | kunmap(rqst->rq_pages[i]); | ||
308 | if (rc < 0) | ||
309 | break; | ||
310 | |||
311 | total_len += sent; | ||
312 | } | ||
313 | |||
314 | uncork: | ||
315 | /* uncork it */ | ||
316 | val = 0; | ||
317 | kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK, | ||
318 | (char *)&val, sizeof(val)); | ||
220 | 319 | ||
221 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { | 320 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { |
222 | cFYI(1, "partial send (%d remaining), terminating session", | 321 | cFYI(1, "partial send (wanted=%u sent=%zu): terminating " |
223 | total_len); | 322 | "session", smb_buf_length + 4, total_len); |
224 | /* If we have only sent part of an SMB then the next SMB | 323 | /* |
225 | could be taken as the remainder of this one. We need | 324 | * If we have only sent part of an SMB then the next SMB could |
226 | to kill the socket so the server throws away the partial | 325 | * be taken as the remainder of this one. We need to kill the |
227 | SMB */ | 326 | * socket so the server throws away the partial SMB |
327 | */ | ||
228 | server->tcpStatus = CifsNeedReconnect; | 328 | server->tcpStatus = CifsNeedReconnect; |
229 | } | 329 | } |
230 | 330 | ||
@@ -236,6 +336,15 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
236 | return rc; | 336 | return rc; |
237 | } | 337 | } |
238 | 338 | ||
339 | static int | ||
340 | smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | ||
341 | { | ||
342 | struct smb_rqst rqst = { .rq_iov = iov, | ||
343 | .rq_nvec = n_vec }; | ||
344 | |||
345 | return smb_send_rqst(server, &rqst); | ||
346 | } | ||
347 | |||
239 | int | 348 | int |
240 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, | 349 | smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, |
241 | unsigned int smb_buf_length) | 350 | unsigned int smb_buf_length) |
@@ -345,12 +454,11 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ) | |||
345 | return 0; | 454 | return 0; |
346 | } | 455 | } |
347 | 456 | ||
348 | int | 457 | struct mid_q_entry * |
349 | cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | 458 | cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) |
350 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
351 | { | 459 | { |
352 | int rc; | 460 | int rc; |
353 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; | 461 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
354 | struct mid_q_entry *mid; | 462 | struct mid_q_entry *mid; |
355 | 463 | ||
356 | /* enable signing if server requires it */ | 464 | /* enable signing if server requires it */ |
@@ -359,16 +467,15 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | |||
359 | 467 | ||
360 | mid = AllocMidQEntry(hdr, server); | 468 | mid = AllocMidQEntry(hdr, server); |
361 | if (mid == NULL) | 469 | if (mid == NULL) |
362 | return -ENOMEM; | 470 | return ERR_PTR(-ENOMEM); |
363 | 471 | ||
364 | rc = cifs_sign_smbv(iov, nvec, server, &mid->sequence_number); | 472 | rc = cifs_sign_rqst(rqst, server, &mid->sequence_number); |
365 | if (rc) { | 473 | if (rc) { |
366 | DeleteMidQEntry(mid); | 474 | DeleteMidQEntry(mid); |
367 | return rc; | 475 | return ERR_PTR(rc); |
368 | } | 476 | } |
369 | 477 | ||
370 | *ret_mid = mid; | 478 | return mid; |
371 | return 0; | ||
372 | } | 479 | } |
373 | 480 | ||
374 | /* | 481 | /* |
@@ -376,9 +483,9 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov, | |||
376 | * the result. Caller is responsible for dealing with timeouts. | 483 | * the result. Caller is responsible for dealing with timeouts. |
377 | */ | 484 | */ |
378 | int | 485 | int |
379 | cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | 486 | cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, |
380 | unsigned int nvec, mid_receive_t *receive, | 487 | mid_receive_t *receive, mid_callback_t *callback, |
381 | mid_callback_t *callback, void *cbdata, const int flags) | 488 | void *cbdata, const int flags) |
382 | { | 489 | { |
383 | int rc, timeout, optype; | 490 | int rc, timeout, optype; |
384 | struct mid_q_entry *mid; | 491 | struct mid_q_entry *mid; |
@@ -391,12 +498,12 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
391 | return rc; | 498 | return rc; |
392 | 499 | ||
393 | mutex_lock(&server->srv_mutex); | 500 | mutex_lock(&server->srv_mutex); |
394 | rc = server->ops->setup_async_request(server, iov, nvec, &mid); | 501 | mid = server->ops->setup_async_request(server, rqst); |
395 | if (rc) { | 502 | if (IS_ERR(mid)) { |
396 | mutex_unlock(&server->srv_mutex); | 503 | mutex_unlock(&server->srv_mutex); |
397 | add_credits(server, 1, optype); | 504 | add_credits(server, 1, optype); |
398 | wake_up(&server->request_q); | 505 | wake_up(&server->request_q); |
399 | return rc; | 506 | return PTR_ERR(mid); |
400 | } | 507 | } |
401 | 508 | ||
402 | mid->receive = receive; | 509 | mid->receive = receive; |
@@ -411,7 +518,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
411 | 518 | ||
412 | 519 | ||
413 | cifs_in_send_inc(server); | 520 | cifs_in_send_inc(server); |
414 | rc = smb_sendv(server, iov, nvec); | 521 | rc = smb_send_rqst(server, rqst); |
415 | cifs_in_send_dec(server); | 522 | cifs_in_send_dec(server); |
416 | cifs_save_when_sent(mid); | 523 | cifs_save_when_sent(mid); |
417 | mutex_unlock(&server->srv_mutex); | 524 | mutex_unlock(&server->srv_mutex); |
@@ -419,7 +526,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov, | |||
419 | if (rc == 0) | 526 | if (rc == 0) |
420 | return 0; | 527 | return 0; |
421 | 528 | ||
422 | delete_mid(mid); | 529 | cifs_delete_mid(mid); |
423 | add_credits(server, 1, optype); | 530 | add_credits(server, 1, optype); |
424 | wake_up(&server->request_q); | 531 | wake_up(&server->request_q); |
425 | return rc; | 532 | return rc; |
@@ -504,11 +611,13 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
504 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { | 611 | if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
505 | struct kvec iov; | 612 | struct kvec iov; |
506 | int rc = 0; | 613 | int rc = 0; |
614 | struct smb_rqst rqst = { .rq_iov = &iov, | ||
615 | .rq_nvec = 1 }; | ||
507 | 616 | ||
508 | iov.iov_base = mid->resp_buf; | 617 | iov.iov_base = mid->resp_buf; |
509 | iov.iov_len = len; | 618 | iov.iov_len = len; |
510 | /* FIXME: add code to kill session */ | 619 | /* FIXME: add code to kill session */ |
511 | rc = cifs_verify_signature(&iov, 1, server, | 620 | rc = cifs_verify_signature(&rqst, server, |
512 | mid->sequence_number + 1); | 621 | mid->sequence_number + 1); |
513 | if (rc) | 622 | if (rc) |
514 | cERROR(1, "SMB signature verification returned error = " | 623 | cERROR(1, "SMB signature verification returned error = " |
@@ -519,22 +628,22 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, | |||
519 | return map_smb_to_linux_error(mid->resp_buf, log_error); | 628 | return map_smb_to_linux_error(mid->resp_buf, log_error); |
520 | } | 629 | } |
521 | 630 | ||
522 | int | 631 | struct mid_q_entry * |
523 | cifs_setup_request(struct cifs_ses *ses, struct kvec *iov, | 632 | cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) |
524 | unsigned int nvec, struct mid_q_entry **ret_mid) | ||
525 | { | 633 | { |
526 | int rc; | 634 | int rc; |
527 | struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base; | 635 | struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base; |
528 | struct mid_q_entry *mid; | 636 | struct mid_q_entry *mid; |
529 | 637 | ||
530 | rc = allocate_mid(ses, hdr, &mid); | 638 | rc = allocate_mid(ses, hdr, &mid); |
531 | if (rc) | 639 | if (rc) |
532 | return rc; | 640 | return ERR_PTR(rc); |
533 | rc = cifs_sign_smbv(iov, nvec, ses->server, &mid->sequence_number); | 641 | rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number); |
534 | if (rc) | 642 | if (rc) { |
535 | delete_mid(mid); | 643 | cifs_delete_mid(mid); |
536 | *ret_mid = mid; | 644 | return ERR_PTR(rc); |
537 | return rc; | 645 | } |
646 | return mid; | ||
538 | } | 647 | } |
539 | 648 | ||
540 | int | 649 | int |
@@ -547,6 +656,8 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
547 | struct mid_q_entry *midQ; | 656 | struct mid_q_entry *midQ; |
548 | char *buf = iov[0].iov_base; | 657 | char *buf = iov[0].iov_base; |
549 | unsigned int credits = 1; | 658 | unsigned int credits = 1; |
659 | struct smb_rqst rqst = { .rq_iov = iov, | ||
660 | .rq_nvec = n_vec }; | ||
550 | 661 | ||
551 | timeout = flags & CIFS_TIMEOUT_MASK; | 662 | timeout = flags & CIFS_TIMEOUT_MASK; |
552 | optype = flags & CIFS_OP_MASK; | 663 | optype = flags & CIFS_OP_MASK; |
@@ -584,13 +695,13 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
584 | 695 | ||
585 | mutex_lock(&ses->server->srv_mutex); | 696 | mutex_lock(&ses->server->srv_mutex); |
586 | 697 | ||
587 | rc = ses->server->ops->setup_request(ses, iov, n_vec, &midQ); | 698 | midQ = ses->server->ops->setup_request(ses, &rqst); |
588 | if (rc) { | 699 | if (IS_ERR(midQ)) { |
589 | mutex_unlock(&ses->server->srv_mutex); | 700 | mutex_unlock(&ses->server->srv_mutex); |
590 | cifs_small_buf_release(buf); | 701 | cifs_small_buf_release(buf); |
591 | /* Update # of requests on wire to server */ | 702 | /* Update # of requests on wire to server */ |
592 | add_credits(ses->server, 1, optype); | 703 | add_credits(ses->server, 1, optype); |
593 | return rc; | 704 | return PTR_ERR(midQ); |
594 | } | 705 | } |
595 | 706 | ||
596 | midQ->mid_state = MID_REQUEST_SUBMITTED; | 707 | midQ->mid_state = MID_REQUEST_SUBMITTED; |
@@ -652,11 +763,11 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, | |||
652 | rc = ses->server->ops->check_receive(midQ, ses->server, | 763 | rc = ses->server->ops->check_receive(midQ, ses->server, |
653 | flags & CIFS_LOG_ERROR); | 764 | flags & CIFS_LOG_ERROR); |
654 | 765 | ||
655 | /* mark it so buf will not be freed by delete_mid */ | 766 | /* mark it so buf will not be freed by cifs_delete_mid */ |
656 | if ((flags & CIFS_NO_RESP) == 0) | 767 | if ((flags & CIFS_NO_RESP) == 0) |
657 | midQ->resp_buf = NULL; | 768 | midQ->resp_buf = NULL; |
658 | out: | 769 | out: |
659 | delete_mid(midQ); | 770 | cifs_delete_mid(midQ); |
660 | add_credits(ses->server, credits, optype); | 771 | add_credits(ses->server, credits, optype); |
661 | 772 | ||
662 | return rc; | 773 | return rc; |
@@ -762,7 +873,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, | |||
762 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); | 873 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
763 | rc = cifs_check_receive(midQ, ses->server, 0); | 874 | rc = cifs_check_receive(midQ, ses->server, 0); |
764 | out: | 875 | out: |
765 | delete_mid(midQ); | 876 | cifs_delete_mid(midQ); |
766 | add_credits(ses->server, 1, 0); | 877 | add_credits(ses->server, 1, 0); |
767 | 878 | ||
768 | return rc; | 879 | return rc; |
@@ -846,7 +957,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
846 | 957 | ||
847 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); | 958 | rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); |
848 | if (rc) { | 959 | if (rc) { |
849 | delete_mid(midQ); | 960 | cifs_delete_mid(midQ); |
850 | mutex_unlock(&ses->server->srv_mutex); | 961 | mutex_unlock(&ses->server->srv_mutex); |
851 | return rc; | 962 | return rc; |
852 | } | 963 | } |
@@ -859,7 +970,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
859 | mutex_unlock(&ses->server->srv_mutex); | 970 | mutex_unlock(&ses->server->srv_mutex); |
860 | 971 | ||
861 | if (rc < 0) { | 972 | if (rc < 0) { |
862 | delete_mid(midQ); | 973 | cifs_delete_mid(midQ); |
863 | return rc; | 974 | return rc; |
864 | } | 975 | } |
865 | 976 | ||
@@ -880,7 +991,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
880 | blocking lock to return. */ | 991 | blocking lock to return. */ |
881 | rc = send_cancel(ses->server, in_buf, midQ); | 992 | rc = send_cancel(ses->server, in_buf, midQ); |
882 | if (rc) { | 993 | if (rc) { |
883 | delete_mid(midQ); | 994 | cifs_delete_mid(midQ); |
884 | return rc; | 995 | return rc; |
885 | } | 996 | } |
886 | } else { | 997 | } else { |
@@ -892,7 +1003,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
892 | /* If we get -ENOLCK back the lock may have | 1003 | /* If we get -ENOLCK back the lock may have |
893 | already been removed. Don't exit in this case. */ | 1004 | already been removed. Don't exit in this case. */ |
894 | if (rc && rc != -ENOLCK) { | 1005 | if (rc && rc != -ENOLCK) { |
895 | delete_mid(midQ); | 1006 | cifs_delete_mid(midQ); |
896 | return rc; | 1007 | return rc; |
897 | } | 1008 | } |
898 | } | 1009 | } |
@@ -929,7 +1040,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, | |||
929 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); | 1040 | memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); |
930 | rc = cifs_check_receive(midQ, ses->server, 0); | 1041 | rc = cifs_check_receive(midQ, ses->server, 0); |
931 | out: | 1042 | out: |
932 | delete_mid(midQ); | 1043 | cifs_delete_mid(midQ); |
933 | if (rstart && rc == -EACCES) | 1044 | if (rstart && rc == -EACCES) |
934 | return -ERESTARTSYS; | 1045 | return -ERESTARTSYS; |
935 | return rc; | 1046 | return rc; |
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 48f1987bec34..f5054025f9da 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c | |||
@@ -866,6 +866,12 @@ COMPATIBLE_IOCTL(TIOCGPTN) | |||
866 | COMPATIBLE_IOCTL(TIOCSPTLCK) | 866 | COMPATIBLE_IOCTL(TIOCSPTLCK) |
867 | COMPATIBLE_IOCTL(TIOCSERGETLSR) | 867 | COMPATIBLE_IOCTL(TIOCSERGETLSR) |
868 | COMPATIBLE_IOCTL(TIOCSIG) | 868 | COMPATIBLE_IOCTL(TIOCSIG) |
869 | #ifdef TIOCSRS485 | ||
870 | COMPATIBLE_IOCTL(TIOCSRS485) | ||
871 | #endif | ||
872 | #ifdef TIOCGRS485 | ||
873 | COMPATIBLE_IOCTL(TIOCGRS485) | ||
874 | #endif | ||
869 | #ifdef TCGETS2 | 875 | #ifdef TCGETS2 |
870 | COMPATIBLE_IOCTL(TCGETS2) | 876 | COMPATIBLE_IOCTL(TCGETS2) |
871 | COMPATIBLE_IOCTL(TCSETS2) | 877 | COMPATIBLE_IOCTL(TCSETS2) |
@@ -897,6 +903,8 @@ COMPATIBLE_IOCTL(KDGKBSENT) | |||
897 | COMPATIBLE_IOCTL(KDSKBSENT) | 903 | COMPATIBLE_IOCTL(KDSKBSENT) |
898 | COMPATIBLE_IOCTL(KDGKBDIACR) | 904 | COMPATIBLE_IOCTL(KDGKBDIACR) |
899 | COMPATIBLE_IOCTL(KDSKBDIACR) | 905 | COMPATIBLE_IOCTL(KDSKBDIACR) |
906 | COMPATIBLE_IOCTL(KDGKBDIACRUC) | ||
907 | COMPATIBLE_IOCTL(KDSKBDIACRUC) | ||
900 | COMPATIBLE_IOCTL(KDKBDREP) | 908 | COMPATIBLE_IOCTL(KDKBDREP) |
901 | COMPATIBLE_IOCTL(KDGKBLED) | 909 | COMPATIBLE_IOCTL(KDGKBLED) |
902 | COMPATIBLE_IOCTL(KDGETLED) | 910 | COMPATIBLE_IOCTL(KDGETLED) |
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c index 0074362d9f7f..a9d35b0e06cf 100644 --- a/fs/configfs/inode.c +++ b/fs/configfs/inode.c | |||
@@ -79,8 +79,8 @@ int configfs_setattr(struct dentry * dentry, struct iattr * iattr) | |||
79 | return -ENOMEM; | 79 | return -ENOMEM; |
80 | /* assign default attributes */ | 80 | /* assign default attributes */ |
81 | sd_iattr->ia_mode = sd->s_mode; | 81 | sd_iattr->ia_mode = sd->s_mode; |
82 | sd_iattr->ia_uid = 0; | 82 | sd_iattr->ia_uid = GLOBAL_ROOT_UID; |
83 | sd_iattr->ia_gid = 0; | 83 | sd_iattr->ia_gid = GLOBAL_ROOT_GID; |
84 | sd_iattr->ia_atime = sd_iattr->ia_mtime = sd_iattr->ia_ctime = CURRENT_TIME; | 84 | sd_iattr->ia_atime = sd_iattr->ia_mtime = sd_iattr->ia_ctime = CURRENT_TIME; |
85 | sd->s_iattr = sd_iattr; | 85 | sd->s_iattr = sd_iattr; |
86 | } | 86 | } |
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 28cca01ca9c9..c6c3f91ecf06 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c | |||
@@ -90,8 +90,8 @@ static struct inode *get_cramfs_inode(struct super_block *sb, | |||
90 | } | 90 | } |
91 | 91 | ||
92 | inode->i_mode = cramfs_inode->mode; | 92 | inode->i_mode = cramfs_inode->mode; |
93 | inode->i_uid = cramfs_inode->uid; | 93 | i_uid_write(inode, cramfs_inode->uid); |
94 | inode->i_gid = cramfs_inode->gid; | 94 | i_gid_write(inode, cramfs_inode->gid); |
95 | 95 | ||
96 | /* if the lower 2 bits are zero, the inode contains data */ | 96 | /* if the lower 2 bits are zero, the inode contains data */ |
97 | if (!(inode->i_ino & 3)) { | 97 | if (!(inode->i_ino & 3)) { |
diff --git a/fs/dcache.c b/fs/dcache.c index fbee67b92651..3a463d0c4fe8 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -1134,6 +1134,8 @@ positive: | |||
1134 | return 1; | 1134 | return 1; |
1135 | 1135 | ||
1136 | rename_retry: | 1136 | rename_retry: |
1137 | if (locked) | ||
1138 | goto again; | ||
1137 | locked = 1; | 1139 | locked = 1; |
1138 | write_seqlock(&rename_lock); | 1140 | write_seqlock(&rename_lock); |
1139 | goto again; | 1141 | goto again; |
@@ -1141,7 +1143,7 @@ rename_retry: | |||
1141 | EXPORT_SYMBOL(have_submounts); | 1143 | EXPORT_SYMBOL(have_submounts); |
1142 | 1144 | ||
1143 | /* | 1145 | /* |
1144 | * Search the dentry child list for the specified parent, | 1146 | * Search the dentry child list of the specified parent, |
1145 | * and move any unused dentries to the end of the unused | 1147 | * and move any unused dentries to the end of the unused |
1146 | * list for prune_dcache(). We descend to the next level | 1148 | * list for prune_dcache(). We descend to the next level |
1147 | * whenever the d_subdirs list is non-empty and continue | 1149 | * whenever the d_subdirs list is non-empty and continue |
@@ -1236,6 +1238,8 @@ out: | |||
1236 | rename_retry: | 1238 | rename_retry: |
1237 | if (found) | 1239 | if (found) |
1238 | return found; | 1240 | return found; |
1241 | if (locked) | ||
1242 | goto again; | ||
1239 | locked = 1; | 1243 | locked = 1; |
1240 | write_seqlock(&rename_lock); | 1244 | write_seqlock(&rename_lock); |
1241 | goto again; | 1245 | goto again; |
@@ -3035,6 +3039,8 @@ resume: | |||
3035 | return; | 3039 | return; |
3036 | 3040 | ||
3037 | rename_retry: | 3041 | rename_retry: |
3042 | if (locked) | ||
3043 | goto again; | ||
3038 | locked = 1; | 3044 | locked = 1; |
3039 | write_seqlock(&rename_lock); | 3045 | write_seqlock(&rename_lock); |
3040 | goto again; | 3046 | goto again; |
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 4733eab34a23..b607d92cdf24 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <linux/magic.h> | 28 | #include <linux/magic.h> |
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | 30 | ||
31 | #define DEBUGFS_DEFAULT_MODE 0755 | 31 | #define DEBUGFS_DEFAULT_MODE 0700 |
32 | 32 | ||
33 | static struct vfsmount *debugfs_mount; | 33 | static struct vfsmount *debugfs_mount; |
34 | static int debugfs_mount_count; | 34 | static int debugfs_mount_count; |
@@ -128,8 +128,8 @@ static inline int debugfs_positive(struct dentry *dentry) | |||
128 | } | 128 | } |
129 | 129 | ||
130 | struct debugfs_mount_opts { | 130 | struct debugfs_mount_opts { |
131 | uid_t uid; | 131 | kuid_t uid; |
132 | gid_t gid; | 132 | kgid_t gid; |
133 | umode_t mode; | 133 | umode_t mode; |
134 | }; | 134 | }; |
135 | 135 | ||
@@ -156,6 +156,8 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts) | |||
156 | substring_t args[MAX_OPT_ARGS]; | 156 | substring_t args[MAX_OPT_ARGS]; |
157 | int option; | 157 | int option; |
158 | int token; | 158 | int token; |
159 | kuid_t uid; | ||
160 | kgid_t gid; | ||
159 | char *p; | 161 | char *p; |
160 | 162 | ||
161 | opts->mode = DEBUGFS_DEFAULT_MODE; | 163 | opts->mode = DEBUGFS_DEFAULT_MODE; |
@@ -169,12 +171,18 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts) | |||
169 | case Opt_uid: | 171 | case Opt_uid: |
170 | if (match_int(&args[0], &option)) | 172 | if (match_int(&args[0], &option)) |
171 | return -EINVAL; | 173 | return -EINVAL; |
172 | opts->uid = option; | 174 | uid = make_kuid(current_user_ns(), option); |
175 | if (!uid_valid(uid)) | ||
176 | return -EINVAL; | ||
177 | opts->uid = uid; | ||
173 | break; | 178 | break; |
174 | case Opt_gid: | 179 | case Opt_gid: |
175 | if (match_octal(&args[0], &option)) | 180 | if (match_octal(&args[0], &option)) |
176 | return -EINVAL; | 181 | return -EINVAL; |
177 | opts->gid = option; | 182 | gid = make_kgid(current_user_ns(), option); |
183 | if (!gid_valid(gid)) | ||
184 | return -EINVAL; | ||
185 | opts->gid = gid; | ||
178 | break; | 186 | break; |
179 | case Opt_mode: | 187 | case Opt_mode: |
180 | if (match_octal(&args[0], &option)) | 188 | if (match_octal(&args[0], &option)) |
@@ -226,10 +234,12 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root) | |||
226 | struct debugfs_fs_info *fsi = root->d_sb->s_fs_info; | 234 | struct debugfs_fs_info *fsi = root->d_sb->s_fs_info; |
227 | struct debugfs_mount_opts *opts = &fsi->mount_opts; | 235 | struct debugfs_mount_opts *opts = &fsi->mount_opts; |
228 | 236 | ||
229 | if (opts->uid != 0) | 237 | if (!uid_eq(opts->uid, GLOBAL_ROOT_UID)) |
230 | seq_printf(m, ",uid=%u", opts->uid); | 238 | seq_printf(m, ",uid=%u", |
231 | if (opts->gid != 0) | 239 | from_kuid_munged(&init_user_ns, opts->uid)); |
232 | seq_printf(m, ",gid=%u", opts->gid); | 240 | if (!gid_eq(opts->gid, GLOBAL_ROOT_GID)) |
241 | seq_printf(m, ",gid=%u", | ||
242 | from_kgid_munged(&init_user_ns, opts->gid)); | ||
233 | if (opts->mode != DEBUGFS_DEFAULT_MODE) | 243 | if (opts->mode != DEBUGFS_DEFAULT_MODE) |
234 | seq_printf(m, ",mode=%o", opts->mode); | 244 | seq_printf(m, ",mode=%o", opts->mode); |
235 | 245 | ||
@@ -291,9 +301,9 @@ static struct file_system_type debug_fs_type = { | |||
291 | .kill_sb = kill_litter_super, | 301 | .kill_sb = kill_litter_super, |
292 | }; | 302 | }; |
293 | 303 | ||
294 | struct dentry *__create_file(const char *name, umode_t mode, | 304 | static struct dentry *__create_file(const char *name, umode_t mode, |
295 | struct dentry *parent, void *data, | 305 | struct dentry *parent, void *data, |
296 | const struct file_operations *fops) | 306 | const struct file_operations *fops) |
297 | { | 307 | { |
298 | struct dentry *dentry = NULL; | 308 | struct dentry *dentry = NULL; |
299 | int error; | 309 | int error; |
diff --git a/fs/dlm/ast.c b/fs/dlm/ast.c index 63dc19c54d5a..27a6ba9aaeec 100644 --- a/fs/dlm/ast.c +++ b/fs/dlm/ast.c | |||
@@ -15,8 +15,8 @@ | |||
15 | #include "lock.h" | 15 | #include "lock.h" |
16 | #include "user.h" | 16 | #include "user.h" |
17 | 17 | ||
18 | static uint64_t dlm_cb_seq; | 18 | static uint64_t dlm_cb_seq; |
19 | static spinlock_t dlm_cb_seq_spin; | 19 | static DEFINE_SPINLOCK(dlm_cb_seq_spin); |
20 | 20 | ||
21 | static void dlm_dump_lkb_callbacks(struct dlm_lkb *lkb) | 21 | static void dlm_dump_lkb_callbacks(struct dlm_lkb *lkb) |
22 | { | 22 | { |
diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 9ccf7346834a..a0387dd8b1f0 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c | |||
@@ -750,6 +750,7 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf, | |||
750 | static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) | 750 | static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) |
751 | { | 751 | { |
752 | struct sockaddr_storage *addr; | 752 | struct sockaddr_storage *addr; |
753 | int rv; | ||
753 | 754 | ||
754 | if (len != sizeof(struct sockaddr_storage)) | 755 | if (len != sizeof(struct sockaddr_storage)) |
755 | return -EINVAL; | 756 | return -EINVAL; |
@@ -762,6 +763,13 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) | |||
762 | return -ENOMEM; | 763 | return -ENOMEM; |
763 | 764 | ||
764 | memcpy(addr, buf, len); | 765 | memcpy(addr, buf, len); |
766 | |||
767 | rv = dlm_lowcomms_addr(cm->nodeid, addr, len); | ||
768 | if (rv) { | ||
769 | kfree(addr); | ||
770 | return rv; | ||
771 | } | ||
772 | |||
765 | cm->addr[cm->addr_count++] = addr; | 773 | cm->addr[cm->addr_count++] = addr; |
766 | return len; | 774 | return len; |
767 | } | 775 | } |
@@ -878,34 +886,7 @@ static void put_space(struct dlm_space *sp) | |||
878 | config_item_put(&sp->group.cg_item); | 886 | config_item_put(&sp->group.cg_item); |
879 | } | 887 | } |
880 | 888 | ||
881 | static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y) | 889 | static struct dlm_comm *get_comm(int nodeid) |
882 | { | ||
883 | switch (x->ss_family) { | ||
884 | case AF_INET: { | ||
885 | struct sockaddr_in *sinx = (struct sockaddr_in *)x; | ||
886 | struct sockaddr_in *siny = (struct sockaddr_in *)y; | ||
887 | if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) | ||
888 | return 0; | ||
889 | if (sinx->sin_port != siny->sin_port) | ||
890 | return 0; | ||
891 | break; | ||
892 | } | ||
893 | case AF_INET6: { | ||
894 | struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x; | ||
895 | struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y; | ||
896 | if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr)) | ||
897 | return 0; | ||
898 | if (sinx->sin6_port != siny->sin6_port) | ||
899 | return 0; | ||
900 | break; | ||
901 | } | ||
902 | default: | ||
903 | return 0; | ||
904 | } | ||
905 | return 1; | ||
906 | } | ||
907 | |||
908 | static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) | ||
909 | { | 890 | { |
910 | struct config_item *i; | 891 | struct config_item *i; |
911 | struct dlm_comm *cm = NULL; | 892 | struct dlm_comm *cm = NULL; |
@@ -919,19 +900,11 @@ static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) | |||
919 | list_for_each_entry(i, &comm_list->cg_children, ci_entry) { | 900 | list_for_each_entry(i, &comm_list->cg_children, ci_entry) { |
920 | cm = config_item_to_comm(i); | 901 | cm = config_item_to_comm(i); |
921 | 902 | ||
922 | if (nodeid) { | 903 | if (cm->nodeid != nodeid) |
923 | if (cm->nodeid != nodeid) | 904 | continue; |
924 | continue; | 905 | found = 1; |
925 | found = 1; | 906 | config_item_get(i); |
926 | config_item_get(i); | 907 | break; |
927 | break; | ||
928 | } else { | ||
929 | if (!cm->addr_count || !addr_compare(cm->addr[0], addr)) | ||
930 | continue; | ||
931 | found = 1; | ||
932 | config_item_get(i); | ||
933 | break; | ||
934 | } | ||
935 | } | 908 | } |
936 | mutex_unlock(&clusters_root.subsys.su_mutex); | 909 | mutex_unlock(&clusters_root.subsys.su_mutex); |
937 | 910 | ||
@@ -995,7 +968,7 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out, | |||
995 | 968 | ||
996 | int dlm_comm_seq(int nodeid, uint32_t *seq) | 969 | int dlm_comm_seq(int nodeid, uint32_t *seq) |
997 | { | 970 | { |
998 | struct dlm_comm *cm = get_comm(nodeid, NULL); | 971 | struct dlm_comm *cm = get_comm(nodeid); |
999 | if (!cm) | 972 | if (!cm) |
1000 | return -EEXIST; | 973 | return -EEXIST; |
1001 | *seq = cm->seq; | 974 | *seq = cm->seq; |
@@ -1003,28 +976,6 @@ int dlm_comm_seq(int nodeid, uint32_t *seq) | |||
1003 | return 0; | 976 | return 0; |
1004 | } | 977 | } |
1005 | 978 | ||
1006 | int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr) | ||
1007 | { | ||
1008 | struct dlm_comm *cm = get_comm(nodeid, NULL); | ||
1009 | if (!cm) | ||
1010 | return -EEXIST; | ||
1011 | if (!cm->addr_count) | ||
1012 | return -ENOENT; | ||
1013 | memcpy(addr, cm->addr[0], sizeof(*addr)); | ||
1014 | put_comm(cm); | ||
1015 | return 0; | ||
1016 | } | ||
1017 | |||
1018 | int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid) | ||
1019 | { | ||
1020 | struct dlm_comm *cm = get_comm(0, addr); | ||
1021 | if (!cm) | ||
1022 | return -EEXIST; | ||
1023 | *nodeid = cm->nodeid; | ||
1024 | put_comm(cm); | ||
1025 | return 0; | ||
1026 | } | ||
1027 | |||
1028 | int dlm_our_nodeid(void) | 979 | int dlm_our_nodeid(void) |
1029 | { | 980 | { |
1030 | return local_comm ? local_comm->nodeid : 0; | 981 | return local_comm ? local_comm->nodeid : 0; |
diff --git a/fs/dlm/config.h b/fs/dlm/config.h index dbd35a08f3a5..f30697bc2780 100644 --- a/fs/dlm/config.h +++ b/fs/dlm/config.h | |||
@@ -46,8 +46,6 @@ void dlm_config_exit(void); | |||
46 | int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out, | 46 | int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out, |
47 | int *count_out); | 47 | int *count_out); |
48 | int dlm_comm_seq(int nodeid, uint32_t *seq); | 48 | int dlm_comm_seq(int nodeid, uint32_t *seq); |
49 | int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr); | ||
50 | int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid); | ||
51 | int dlm_our_nodeid(void); | 49 | int dlm_our_nodeid(void); |
52 | int dlm_our_addr(struct sockaddr_storage *addr, int num); | 50 | int dlm_our_addr(struct sockaddr_storage *addr, int num); |
53 | 51 | ||
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h index 9d3e485f88c8..871c1abf6029 100644 --- a/fs/dlm/dlm_internal.h +++ b/fs/dlm/dlm_internal.h | |||
@@ -604,6 +604,7 @@ struct dlm_ls { | |||
604 | struct idr ls_recover_idr; | 604 | struct idr ls_recover_idr; |
605 | spinlock_t ls_recover_idr_lock; | 605 | spinlock_t ls_recover_idr_lock; |
606 | wait_queue_head_t ls_wait_general; | 606 | wait_queue_head_t ls_wait_general; |
607 | wait_queue_head_t ls_recover_lock_wait; | ||
607 | struct mutex ls_clear_proc_locks; | 608 | struct mutex ls_clear_proc_locks; |
608 | 609 | ||
609 | struct list_head ls_root_list; /* root resources */ | 610 | struct list_head ls_root_list; /* root resources */ |
@@ -616,15 +617,40 @@ struct dlm_ls { | |||
616 | char ls_name[1]; | 617 | char ls_name[1]; |
617 | }; | 618 | }; |
618 | 619 | ||
619 | #define LSFL_WORK 0 | 620 | /* |
620 | #define LSFL_RUNNING 1 | 621 | * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines |
621 | #define LSFL_RECOVERY_STOP 2 | 622 | * that they should abort what they're doing so new recovery can be started. |
622 | #define LSFL_RCOM_READY 3 | 623 | * |
623 | #define LSFL_RCOM_WAIT 4 | 624 | * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it |
624 | #define LSFL_UEVENT_WAIT 5 | 625 | * should do down_write() on the in_recovery rw_semaphore. (doing down_write |
625 | #define LSFL_TIMEWARN 6 | 626 | * within dlm_ls_stop causes complaints about the lock acquired/released |
626 | #define LSFL_CB_DELAY 7 | 627 | * in different contexts.) |
627 | #define LSFL_NODIR 8 | 628 | * |
629 | * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore. | ||
630 | * It sets this after it is done with down_write() on the in_recovery | ||
631 | * rw_semaphore and clears it after it has released the rw_semaphore. | ||
632 | * | ||
633 | * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it | ||
634 | * should begin recovery of the lockspace. | ||
635 | * | ||
636 | * LSFL_RUNNING - set when normal locking activity is enabled. | ||
637 | * dlm_ls_stop() clears this to tell dlm locking routines that they should | ||
638 | * quit what they are doing so recovery can run. dlm_recoverd sets | ||
639 | * this after recovery is finished. | ||
640 | */ | ||
641 | |||
642 | #define LSFL_RECOVER_STOP 0 | ||
643 | #define LSFL_RECOVER_DOWN 1 | ||
644 | #define LSFL_RECOVER_LOCK 2 | ||
645 | #define LSFL_RECOVER_WORK 3 | ||
646 | #define LSFL_RUNNING 4 | ||
647 | |||
648 | #define LSFL_RCOM_READY 5 | ||
649 | #define LSFL_RCOM_WAIT 6 | ||
650 | #define LSFL_UEVENT_WAIT 7 | ||
651 | #define LSFL_TIMEWARN 8 | ||
652 | #define LSFL_CB_DELAY 9 | ||
653 | #define LSFL_NODIR 10 | ||
628 | 654 | ||
629 | /* much of this is just saving user space pointers associated with the | 655 | /* much of this is just saving user space pointers associated with the |
630 | lock that we pass back to the user lib with an ast */ | 656 | lock that we pass back to the user lib with an ast */ |
@@ -667,7 +693,7 @@ static inline int dlm_locking_stopped(struct dlm_ls *ls) | |||
667 | 693 | ||
668 | static inline int dlm_recovery_stopped(struct dlm_ls *ls) | 694 | static inline int dlm_recovery_stopped(struct dlm_ls *ls) |
669 | { | 695 | { |
670 | return test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); | 696 | return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags); |
671 | } | 697 | } |
672 | 698 | ||
673 | static inline int dlm_no_directory(struct dlm_ls *ls) | 699 | static inline int dlm_no_directory(struct dlm_ls *ls) |
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c index 952557d00ccd..2e99fb0c9737 100644 --- a/fs/dlm/lockspace.c +++ b/fs/dlm/lockspace.c | |||
@@ -582,8 +582,6 @@ static int new_lockspace(const char *name, const char *cluster, | |||
582 | INIT_LIST_HEAD(&ls->ls_root_list); | 582 | INIT_LIST_HEAD(&ls->ls_root_list); |
583 | init_rwsem(&ls->ls_root_sem); | 583 | init_rwsem(&ls->ls_root_sem); |
584 | 584 | ||
585 | down_write(&ls->ls_in_recovery); | ||
586 | |||
587 | spin_lock(&lslist_lock); | 585 | spin_lock(&lslist_lock); |
588 | ls->ls_create_count = 1; | 586 | ls->ls_create_count = 1; |
589 | list_add(&ls->ls_list, &lslist); | 587 | list_add(&ls->ls_list, &lslist); |
@@ -597,13 +595,24 @@ static int new_lockspace(const char *name, const char *cluster, | |||
597 | } | 595 | } |
598 | } | 596 | } |
599 | 597 | ||
600 | /* needs to find ls in lslist */ | 598 | init_waitqueue_head(&ls->ls_recover_lock_wait); |
599 | |||
600 | /* | ||
601 | * Once started, dlm_recoverd first looks for ls in lslist, then | ||
602 | * initializes ls_in_recovery as locked in "down" mode. We need | ||
603 | * to wait for the wakeup from dlm_recoverd because in_recovery | ||
604 | * has to start out in down mode. | ||
605 | */ | ||
606 | |||
601 | error = dlm_recoverd_start(ls); | 607 | error = dlm_recoverd_start(ls); |
602 | if (error) { | 608 | if (error) { |
603 | log_error(ls, "can't start dlm_recoverd %d", error); | 609 | log_error(ls, "can't start dlm_recoverd %d", error); |
604 | goto out_callback; | 610 | goto out_callback; |
605 | } | 611 | } |
606 | 612 | ||
613 | wait_event(ls->ls_recover_lock_wait, | ||
614 | test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags)); | ||
615 | |||
607 | ls->ls_kobj.kset = dlm_kset; | 616 | ls->ls_kobj.kset = dlm_kset; |
608 | error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL, | 617 | error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL, |
609 | "%s", ls->ls_name); | 618 | "%s", ls->ls_name); |
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 5c1b0e38c7a4..331ea4f94efd 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c | |||
@@ -140,6 +140,16 @@ struct writequeue_entry { | |||
140 | struct connection *con; | 140 | struct connection *con; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | struct dlm_node_addr { | ||
144 | struct list_head list; | ||
145 | int nodeid; | ||
146 | int addr_count; | ||
147 | struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT]; | ||
148 | }; | ||
149 | |||
150 | static LIST_HEAD(dlm_node_addrs); | ||
151 | static DEFINE_SPINLOCK(dlm_node_addrs_spin); | ||
152 | |||
143 | static struct sockaddr_storage *dlm_local_addr[DLM_MAX_ADDR_COUNT]; | 153 | static struct sockaddr_storage *dlm_local_addr[DLM_MAX_ADDR_COUNT]; |
144 | static int dlm_local_count; | 154 | static int dlm_local_count; |
145 | static int dlm_allow_conn; | 155 | static int dlm_allow_conn; |
@@ -264,31 +274,146 @@ static struct connection *assoc2con(int assoc_id) | |||
264 | return NULL; | 274 | return NULL; |
265 | } | 275 | } |
266 | 276 | ||
267 | static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr) | 277 | static struct dlm_node_addr *find_node_addr(int nodeid) |
278 | { | ||
279 | struct dlm_node_addr *na; | ||
280 | |||
281 | list_for_each_entry(na, &dlm_node_addrs, list) { | ||
282 | if (na->nodeid == nodeid) | ||
283 | return na; | ||
284 | } | ||
285 | return NULL; | ||
286 | } | ||
287 | |||
288 | static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y) | ||
289 | { | ||
290 | switch (x->ss_family) { | ||
291 | case AF_INET: { | ||
292 | struct sockaddr_in *sinx = (struct sockaddr_in *)x; | ||
293 | struct sockaddr_in *siny = (struct sockaddr_in *)y; | ||
294 | if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) | ||
295 | return 0; | ||
296 | if (sinx->sin_port != siny->sin_port) | ||
297 | return 0; | ||
298 | break; | ||
299 | } | ||
300 | case AF_INET6: { | ||
301 | struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x; | ||
302 | struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y; | ||
303 | if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr)) | ||
304 | return 0; | ||
305 | if (sinx->sin6_port != siny->sin6_port) | ||
306 | return 0; | ||
307 | break; | ||
308 | } | ||
309 | default: | ||
310 | return 0; | ||
311 | } | ||
312 | return 1; | ||
313 | } | ||
314 | |||
315 | static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out, | ||
316 | struct sockaddr *sa_out) | ||
268 | { | 317 | { |
269 | struct sockaddr_storage addr; | 318 | struct sockaddr_storage sas; |
270 | int error; | 319 | struct dlm_node_addr *na; |
271 | 320 | ||
272 | if (!dlm_local_count) | 321 | if (!dlm_local_count) |
273 | return -1; | 322 | return -1; |
274 | 323 | ||
275 | error = dlm_nodeid_to_addr(nodeid, &addr); | 324 | spin_lock(&dlm_node_addrs_spin); |
276 | if (error) | 325 | na = find_node_addr(nodeid); |
277 | return error; | 326 | if (na && na->addr_count) |
327 | memcpy(&sas, na->addr[0], sizeof(struct sockaddr_storage)); | ||
328 | spin_unlock(&dlm_node_addrs_spin); | ||
329 | |||
330 | if (!na) | ||
331 | return -EEXIST; | ||
332 | |||
333 | if (!na->addr_count) | ||
334 | return -ENOENT; | ||
335 | |||
336 | if (sas_out) | ||
337 | memcpy(sas_out, &sas, sizeof(struct sockaddr_storage)); | ||
338 | |||
339 | if (!sa_out) | ||
340 | return 0; | ||
278 | 341 | ||
279 | if (dlm_local_addr[0]->ss_family == AF_INET) { | 342 | if (dlm_local_addr[0]->ss_family == AF_INET) { |
280 | struct sockaddr_in *in4 = (struct sockaddr_in *) &addr; | 343 | struct sockaddr_in *in4 = (struct sockaddr_in *) &sas; |
281 | struct sockaddr_in *ret4 = (struct sockaddr_in *) retaddr; | 344 | struct sockaddr_in *ret4 = (struct sockaddr_in *) sa_out; |
282 | ret4->sin_addr.s_addr = in4->sin_addr.s_addr; | 345 | ret4->sin_addr.s_addr = in4->sin_addr.s_addr; |
283 | } else { | 346 | } else { |
284 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &addr; | 347 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &sas; |
285 | struct sockaddr_in6 *ret6 = (struct sockaddr_in6 *) retaddr; | 348 | struct sockaddr_in6 *ret6 = (struct sockaddr_in6 *) sa_out; |
286 | ret6->sin6_addr = in6->sin6_addr; | 349 | ret6->sin6_addr = in6->sin6_addr; |
287 | } | 350 | } |
288 | 351 | ||
289 | return 0; | 352 | return 0; |
290 | } | 353 | } |
291 | 354 | ||
355 | static int addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid) | ||
356 | { | ||
357 | struct dlm_node_addr *na; | ||
358 | int rv = -EEXIST; | ||
359 | |||
360 | spin_lock(&dlm_node_addrs_spin); | ||
361 | list_for_each_entry(na, &dlm_node_addrs, list) { | ||
362 | if (!na->addr_count) | ||
363 | continue; | ||
364 | |||
365 | if (!addr_compare(na->addr[0], addr)) | ||
366 | continue; | ||
367 | |||
368 | *nodeid = na->nodeid; | ||
369 | rv = 0; | ||
370 | break; | ||
371 | } | ||
372 | spin_unlock(&dlm_node_addrs_spin); | ||
373 | return rv; | ||
374 | } | ||
375 | |||
376 | int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len) | ||
377 | { | ||
378 | struct sockaddr_storage *new_addr; | ||
379 | struct dlm_node_addr *new_node, *na; | ||
380 | |||
381 | new_node = kzalloc(sizeof(struct dlm_node_addr), GFP_NOFS); | ||
382 | if (!new_node) | ||
383 | return -ENOMEM; | ||
384 | |||
385 | new_addr = kzalloc(sizeof(struct sockaddr_storage), GFP_NOFS); | ||
386 | if (!new_addr) { | ||
387 | kfree(new_node); | ||
388 | return -ENOMEM; | ||
389 | } | ||
390 | |||
391 | memcpy(new_addr, addr, len); | ||
392 | |||
393 | spin_lock(&dlm_node_addrs_spin); | ||
394 | na = find_node_addr(nodeid); | ||
395 | if (!na) { | ||
396 | new_node->nodeid = nodeid; | ||
397 | new_node->addr[0] = new_addr; | ||
398 | new_node->addr_count = 1; | ||
399 | list_add(&new_node->list, &dlm_node_addrs); | ||
400 | spin_unlock(&dlm_node_addrs_spin); | ||
401 | return 0; | ||
402 | } | ||
403 | |||
404 | if (na->addr_count >= DLM_MAX_ADDR_COUNT) { | ||
405 | spin_unlock(&dlm_node_addrs_spin); | ||
406 | kfree(new_addr); | ||
407 | kfree(new_node); | ||
408 | return -ENOSPC; | ||
409 | } | ||
410 | |||
411 | na->addr[na->addr_count++] = new_addr; | ||
412 | spin_unlock(&dlm_node_addrs_spin); | ||
413 | kfree(new_node); | ||
414 | return 0; | ||
415 | } | ||
416 | |||
292 | /* Data available on socket or listen socket received a connect */ | 417 | /* Data available on socket or listen socket received a connect */ |
293 | static void lowcomms_data_ready(struct sock *sk, int count_unused) | 418 | static void lowcomms_data_ready(struct sock *sk, int count_unused) |
294 | { | 419 | { |
@@ -348,7 +473,7 @@ int dlm_lowcomms_connect_node(int nodeid) | |||
348 | } | 473 | } |
349 | 474 | ||
350 | /* Make a socket active */ | 475 | /* Make a socket active */ |
351 | static int add_sock(struct socket *sock, struct connection *con) | 476 | static void add_sock(struct socket *sock, struct connection *con) |
352 | { | 477 | { |
353 | con->sock = sock; | 478 | con->sock = sock; |
354 | 479 | ||
@@ -358,7 +483,6 @@ static int add_sock(struct socket *sock, struct connection *con) | |||
358 | con->sock->sk->sk_state_change = lowcomms_state_change; | 483 | con->sock->sk->sk_state_change = lowcomms_state_change; |
359 | con->sock->sk->sk_user_data = con; | 484 | con->sock->sk->sk_user_data = con; |
360 | con->sock->sk->sk_allocation = GFP_NOFS; | 485 | con->sock->sk->sk_allocation = GFP_NOFS; |
361 | return 0; | ||
362 | } | 486 | } |
363 | 487 | ||
364 | /* Add the port number to an IPv6 or 4 sockaddr and return the address | 488 | /* Add the port number to an IPv6 or 4 sockaddr and return the address |
@@ -510,7 +634,7 @@ static void process_sctp_notification(struct connection *con, | |||
510 | return; | 634 | return; |
511 | } | 635 | } |
512 | make_sockaddr(&prim.ssp_addr, 0, &addr_len); | 636 | make_sockaddr(&prim.ssp_addr, 0, &addr_len); |
513 | if (dlm_addr_to_nodeid(&prim.ssp_addr, &nodeid)) { | 637 | if (addr_to_nodeid(&prim.ssp_addr, &nodeid)) { |
514 | unsigned char *b=(unsigned char *)&prim.ssp_addr; | 638 | unsigned char *b=(unsigned char *)&prim.ssp_addr; |
515 | log_print("reject connect from unknown addr"); | 639 | log_print("reject connect from unknown addr"); |
516 | print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE, | 640 | print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE, |
@@ -747,7 +871,7 @@ static int tcp_accept_from_sock(struct connection *con) | |||
747 | 871 | ||
748 | /* Get the new node's NODEID */ | 872 | /* Get the new node's NODEID */ |
749 | make_sockaddr(&peeraddr, 0, &len); | 873 | make_sockaddr(&peeraddr, 0, &len); |
750 | if (dlm_addr_to_nodeid(&peeraddr, &nodeid)) { | 874 | if (addr_to_nodeid(&peeraddr, &nodeid)) { |
751 | unsigned char *b=(unsigned char *)&peeraddr; | 875 | unsigned char *b=(unsigned char *)&peeraddr; |
752 | log_print("connect from non cluster node"); | 876 | log_print("connect from non cluster node"); |
753 | print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE, | 877 | print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE, |
@@ -862,7 +986,7 @@ static void sctp_init_assoc(struct connection *con) | |||
862 | if (con->retries++ > MAX_CONNECT_RETRIES) | 986 | if (con->retries++ > MAX_CONNECT_RETRIES) |
863 | return; | 987 | return; |
864 | 988 | ||
865 | if (nodeid_to_addr(con->nodeid, (struct sockaddr *)&rem_addr)) { | 989 | if (nodeid_to_addr(con->nodeid, NULL, (struct sockaddr *)&rem_addr)) { |
866 | log_print("no address for nodeid %d", con->nodeid); | 990 | log_print("no address for nodeid %d", con->nodeid); |
867 | return; | 991 | return; |
868 | } | 992 | } |
@@ -928,11 +1052,11 @@ static void sctp_init_assoc(struct connection *con) | |||
928 | /* Connect a new socket to its peer */ | 1052 | /* Connect a new socket to its peer */ |
929 | static void tcp_connect_to_sock(struct connection *con) | 1053 | static void tcp_connect_to_sock(struct connection *con) |
930 | { | 1054 | { |
931 | int result = -EHOSTUNREACH; | ||
932 | struct sockaddr_storage saddr, src_addr; | 1055 | struct sockaddr_storage saddr, src_addr; |
933 | int addr_len; | 1056 | int addr_len; |
934 | struct socket *sock = NULL; | 1057 | struct socket *sock = NULL; |
935 | int one = 1; | 1058 | int one = 1; |
1059 | int result; | ||
936 | 1060 | ||
937 | if (con->nodeid == 0) { | 1061 | if (con->nodeid == 0) { |
938 | log_print("attempt to connect sock 0 foiled"); | 1062 | log_print("attempt to connect sock 0 foiled"); |
@@ -944,10 +1068,8 @@ static void tcp_connect_to_sock(struct connection *con) | |||
944 | goto out; | 1068 | goto out; |
945 | 1069 | ||
946 | /* Some odd races can cause double-connects, ignore them */ | 1070 | /* Some odd races can cause double-connects, ignore them */ |
947 | if (con->sock) { | 1071 | if (con->sock) |
948 | result = 0; | ||
949 | goto out; | 1072 | goto out; |
950 | } | ||
951 | 1073 | ||
952 | /* Create a socket to communicate with */ | 1074 | /* Create a socket to communicate with */ |
953 | result = sock_create_kern(dlm_local_addr[0]->ss_family, SOCK_STREAM, | 1075 | result = sock_create_kern(dlm_local_addr[0]->ss_family, SOCK_STREAM, |
@@ -956,8 +1078,11 @@ static void tcp_connect_to_sock(struct connection *con) | |||
956 | goto out_err; | 1078 | goto out_err; |
957 | 1079 | ||
958 | memset(&saddr, 0, sizeof(saddr)); | 1080 | memset(&saddr, 0, sizeof(saddr)); |
959 | if (dlm_nodeid_to_addr(con->nodeid, &saddr)) | 1081 | result = nodeid_to_addr(con->nodeid, &saddr, NULL); |
1082 | if (result < 0) { | ||
1083 | log_print("no address for nodeid %d", con->nodeid); | ||
960 | goto out_err; | 1084 | goto out_err; |
1085 | } | ||
961 | 1086 | ||
962 | sock->sk->sk_user_data = con; | 1087 | sock->sk->sk_user_data = con; |
963 | con->rx_action = receive_from_sock; | 1088 | con->rx_action = receive_from_sock; |
@@ -983,8 +1108,7 @@ static void tcp_connect_to_sock(struct connection *con) | |||
983 | kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&one, | 1108 | kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&one, |
984 | sizeof(one)); | 1109 | sizeof(one)); |
985 | 1110 | ||
986 | result = | 1111 | result = sock->ops->connect(sock, (struct sockaddr *)&saddr, addr_len, |
987 | sock->ops->connect(sock, (struct sockaddr *)&saddr, addr_len, | ||
988 | O_NONBLOCK); | 1112 | O_NONBLOCK); |
989 | if (result == -EINPROGRESS) | 1113 | if (result == -EINPROGRESS) |
990 | result = 0; | 1114 | result = 0; |
@@ -1002,11 +1126,17 @@ out_err: | |||
1002 | * Some errors are fatal and this list might need adjusting. For other | 1126 | * Some errors are fatal and this list might need adjusting. For other |
1003 | * errors we try again until the max number of retries is reached. | 1127 | * errors we try again until the max number of retries is reached. |
1004 | */ | 1128 | */ |
1005 | if (result != -EHOSTUNREACH && result != -ENETUNREACH && | 1129 | if (result != -EHOSTUNREACH && |
1006 | result != -ENETDOWN && result != -EINVAL | 1130 | result != -ENETUNREACH && |
1007 | && result != -EPROTONOSUPPORT) { | 1131 | result != -ENETDOWN && |
1132 | result != -EINVAL && | ||
1133 | result != -EPROTONOSUPPORT) { | ||
1134 | log_print("connect %d try %d error %d", con->nodeid, | ||
1135 | con->retries, result); | ||
1136 | mutex_unlock(&con->sock_mutex); | ||
1137 | msleep(1000); | ||
1008 | lowcomms_connect_sock(con); | 1138 | lowcomms_connect_sock(con); |
1009 | result = 0; | 1139 | return; |
1010 | } | 1140 | } |
1011 | out: | 1141 | out: |
1012 | mutex_unlock(&con->sock_mutex); | 1142 | mutex_unlock(&con->sock_mutex); |
@@ -1044,10 +1174,8 @@ static struct socket *tcp_create_listen_sock(struct connection *con, | |||
1044 | if (result < 0) { | 1174 | if (result < 0) { |
1045 | log_print("Failed to set SO_REUSEADDR on socket: %d", result); | 1175 | log_print("Failed to set SO_REUSEADDR on socket: %d", result); |
1046 | } | 1176 | } |
1047 | sock->sk->sk_user_data = con; | ||
1048 | con->rx_action = tcp_accept_from_sock; | 1177 | con->rx_action = tcp_accept_from_sock; |
1049 | con->connect_action = tcp_connect_to_sock; | 1178 | con->connect_action = tcp_connect_to_sock; |
1050 | con->sock = sock; | ||
1051 | 1179 | ||
1052 | /* Bind to our port */ | 1180 | /* Bind to our port */ |
1053 | make_sockaddr(saddr, dlm_config.ci_tcp_port, &addr_len); | 1181 | make_sockaddr(saddr, dlm_config.ci_tcp_port, &addr_len); |
@@ -1358,8 +1486,7 @@ static void send_to_sock(struct connection *con) | |||
1358 | } | 1486 | } |
1359 | cond_resched(); | 1487 | cond_resched(); |
1360 | goto out; | 1488 | goto out; |
1361 | } | 1489 | } else if (ret < 0) |
1362 | if (ret <= 0) | ||
1363 | goto send_error; | 1490 | goto send_error; |
1364 | } | 1491 | } |
1365 | 1492 | ||
@@ -1376,7 +1503,6 @@ static void send_to_sock(struct connection *con) | |||
1376 | if (e->len == 0 && e->users == 0) { | 1503 | if (e->len == 0 && e->users == 0) { |
1377 | list_del(&e->list); | 1504 | list_del(&e->list); |
1378 | free_entry(e); | 1505 | free_entry(e); |
1379 | continue; | ||
1380 | } | 1506 | } |
1381 | } | 1507 | } |
1382 | spin_unlock(&con->writequeue_lock); | 1508 | spin_unlock(&con->writequeue_lock); |
@@ -1394,7 +1520,6 @@ out_connect: | |||
1394 | mutex_unlock(&con->sock_mutex); | 1520 | mutex_unlock(&con->sock_mutex); |
1395 | if (!test_bit(CF_INIT_PENDING, &con->flags)) | 1521 | if (!test_bit(CF_INIT_PENDING, &con->flags)) |
1396 | lowcomms_connect_sock(con); | 1522 | lowcomms_connect_sock(con); |
1397 | return; | ||
1398 | } | 1523 | } |
1399 | 1524 | ||
1400 | static void clean_one_writequeue(struct connection *con) | 1525 | static void clean_one_writequeue(struct connection *con) |
@@ -1414,6 +1539,7 @@ static void clean_one_writequeue(struct connection *con) | |||
1414 | int dlm_lowcomms_close(int nodeid) | 1539 | int dlm_lowcomms_close(int nodeid) |
1415 | { | 1540 | { |
1416 | struct connection *con; | 1541 | struct connection *con; |
1542 | struct dlm_node_addr *na; | ||
1417 | 1543 | ||
1418 | log_print("closing connection to node %d", nodeid); | 1544 | log_print("closing connection to node %d", nodeid); |
1419 | con = nodeid2con(nodeid, 0); | 1545 | con = nodeid2con(nodeid, 0); |
@@ -1428,6 +1554,17 @@ int dlm_lowcomms_close(int nodeid) | |||
1428 | clean_one_writequeue(con); | 1554 | clean_one_writequeue(con); |
1429 | close_connection(con, true); | 1555 | close_connection(con, true); |
1430 | } | 1556 | } |
1557 | |||
1558 | spin_lock(&dlm_node_addrs_spin); | ||
1559 | na = find_node_addr(nodeid); | ||
1560 | if (na) { | ||
1561 | list_del(&na->list); | ||
1562 | while (na->addr_count--) | ||
1563 | kfree(na->addr[na->addr_count]); | ||
1564 | kfree(na); | ||
1565 | } | ||
1566 | spin_unlock(&dlm_node_addrs_spin); | ||
1567 | |||
1431 | return 0; | 1568 | return 0; |
1432 | } | 1569 | } |
1433 | 1570 | ||
@@ -1577,3 +1714,17 @@ fail_destroy: | |||
1577 | fail: | 1714 | fail: |
1578 | return error; | 1715 | return error; |
1579 | } | 1716 | } |
1717 | |||
1718 | void dlm_lowcomms_exit(void) | ||
1719 | { | ||
1720 | struct dlm_node_addr *na, *safe; | ||
1721 | |||
1722 | spin_lock(&dlm_node_addrs_spin); | ||
1723 | list_for_each_entry_safe(na, safe, &dlm_node_addrs, list) { | ||
1724 | list_del(&na->list); | ||
1725 | while (na->addr_count--) | ||
1726 | kfree(na->addr[na->addr_count]); | ||
1727 | kfree(na); | ||
1728 | } | ||
1729 | spin_unlock(&dlm_node_addrs_spin); | ||
1730 | } | ||
diff --git a/fs/dlm/lowcomms.h b/fs/dlm/lowcomms.h index 1311e6426287..67462e54fc2f 100644 --- a/fs/dlm/lowcomms.h +++ b/fs/dlm/lowcomms.h | |||
@@ -16,10 +16,12 @@ | |||
16 | 16 | ||
17 | int dlm_lowcomms_start(void); | 17 | int dlm_lowcomms_start(void); |
18 | void dlm_lowcomms_stop(void); | 18 | void dlm_lowcomms_stop(void); |
19 | void dlm_lowcomms_exit(void); | ||
19 | int dlm_lowcomms_close(int nodeid); | 20 | int dlm_lowcomms_close(int nodeid); |
20 | void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc); | 21 | void *dlm_lowcomms_get_buffer(int nodeid, int len, gfp_t allocation, char **ppc); |
21 | void dlm_lowcomms_commit_buffer(void *mh); | 22 | void dlm_lowcomms_commit_buffer(void *mh); |
22 | int dlm_lowcomms_connect_node(int nodeid); | 23 | int dlm_lowcomms_connect_node(int nodeid); |
24 | int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len); | ||
23 | 25 | ||
24 | #endif /* __LOWCOMMS_DOT_H__ */ | 26 | #endif /* __LOWCOMMS_DOT_H__ */ |
25 | 27 | ||
diff --git a/fs/dlm/main.c b/fs/dlm/main.c index 5a59efa0bb46..079c0bd71ab7 100644 --- a/fs/dlm/main.c +++ b/fs/dlm/main.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "user.h" | 17 | #include "user.h" |
18 | #include "memory.h" | 18 | #include "memory.h" |
19 | #include "config.h" | 19 | #include "config.h" |
20 | #include "lowcomms.h" | ||
20 | 21 | ||
21 | static int __init init_dlm(void) | 22 | static int __init init_dlm(void) |
22 | { | 23 | { |
@@ -78,6 +79,7 @@ static void __exit exit_dlm(void) | |||
78 | dlm_config_exit(); | 79 | dlm_config_exit(); |
79 | dlm_memory_exit(); | 80 | dlm_memory_exit(); |
80 | dlm_lockspace_exit(); | 81 | dlm_lockspace_exit(); |
82 | dlm_lowcomms_exit(); | ||
81 | dlm_unregister_debugfs(); | 83 | dlm_unregister_debugfs(); |
82 | } | 84 | } |
83 | 85 | ||
diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 862640a36d5c..476557b54921 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c | |||
@@ -616,13 +616,13 @@ int dlm_ls_stop(struct dlm_ls *ls) | |||
616 | down_write(&ls->ls_recv_active); | 616 | down_write(&ls->ls_recv_active); |
617 | 617 | ||
618 | /* | 618 | /* |
619 | * Abort any recovery that's in progress (see RECOVERY_STOP, | 619 | * Abort any recovery that's in progress (see RECOVER_STOP, |
620 | * dlm_recovery_stopped()) and tell any other threads running in the | 620 | * dlm_recovery_stopped()) and tell any other threads running in the |
621 | * dlm to quit any processing (see RUNNING, dlm_locking_stopped()). | 621 | * dlm to quit any processing (see RUNNING, dlm_locking_stopped()). |
622 | */ | 622 | */ |
623 | 623 | ||
624 | spin_lock(&ls->ls_recover_lock); | 624 | spin_lock(&ls->ls_recover_lock); |
625 | set_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); | 625 | set_bit(LSFL_RECOVER_STOP, &ls->ls_flags); |
626 | new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags); | 626 | new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags); |
627 | ls->ls_recover_seq++; | 627 | ls->ls_recover_seq++; |
628 | spin_unlock(&ls->ls_recover_lock); | 628 | spin_unlock(&ls->ls_recover_lock); |
@@ -642,12 +642,16 @@ int dlm_ls_stop(struct dlm_ls *ls) | |||
642 | * when recovery is complete. | 642 | * when recovery is complete. |
643 | */ | 643 | */ |
644 | 644 | ||
645 | if (new) | 645 | if (new) { |
646 | down_write(&ls->ls_in_recovery); | 646 | set_bit(LSFL_RECOVER_DOWN, &ls->ls_flags); |
647 | wake_up_process(ls->ls_recoverd_task); | ||
648 | wait_event(ls->ls_recover_lock_wait, | ||
649 | test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags)); | ||
650 | } | ||
647 | 651 | ||
648 | /* | 652 | /* |
649 | * The recoverd suspend/resume makes sure that dlm_recoverd (if | 653 | * The recoverd suspend/resume makes sure that dlm_recoverd (if |
650 | * running) has noticed RECOVERY_STOP above and quit processing the | 654 | * running) has noticed RECOVER_STOP above and quit processing the |
651 | * previous recovery. | 655 | * previous recovery. |
652 | */ | 656 | */ |
653 | 657 | ||
@@ -709,7 +713,8 @@ int dlm_ls_start(struct dlm_ls *ls) | |||
709 | kfree(rv_old); | 713 | kfree(rv_old); |
710 | } | 714 | } |
711 | 715 | ||
712 | dlm_recoverd_kick(ls); | 716 | set_bit(LSFL_RECOVER_WORK, &ls->ls_flags); |
717 | wake_up_process(ls->ls_recoverd_task); | ||
713 | return 0; | 718 | return 0; |
714 | 719 | ||
715 | fail: | 720 | fail: |
diff --git a/fs/dlm/netlink.c b/fs/dlm/netlink.c index ef17e0169da1..60a327863b11 100644 --- a/fs/dlm/netlink.c +++ b/fs/dlm/netlink.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #include "dlm_internal.h" | 14 | #include "dlm_internal.h" |
15 | 15 | ||
16 | static uint32_t dlm_nl_seqnum; | 16 | static uint32_t dlm_nl_seqnum; |
17 | static uint32_t listener_nlpid; | 17 | static uint32_t listener_nlportid; |
18 | 18 | ||
19 | static struct genl_family family = { | 19 | static struct genl_family family = { |
20 | .id = GENL_ID_GENERATE, | 20 | .id = GENL_ID_GENERATE, |
@@ -64,13 +64,13 @@ static int send_data(struct sk_buff *skb) | |||
64 | return rv; | 64 | return rv; |
65 | } | 65 | } |
66 | 66 | ||
67 | return genlmsg_unicast(&init_net, skb, listener_nlpid); | 67 | return genlmsg_unicast(&init_net, skb, listener_nlportid); |
68 | } | 68 | } |
69 | 69 | ||
70 | static int user_cmd(struct sk_buff *skb, struct genl_info *info) | 70 | static int user_cmd(struct sk_buff *skb, struct genl_info *info) |
71 | { | 71 | { |
72 | listener_nlpid = info->snd_pid; | 72 | listener_nlportid = info->snd_portid; |
73 | printk("user_cmd nlpid %u\n", listener_nlpid); | 73 | printk("user_cmd nlpid %u\n", listener_nlportid); |
74 | return 0; | 74 | return 0; |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/fs/dlm/rcom.c b/fs/dlm/rcom.c index 87f1a56eab32..9d61947d473a 100644 --- a/fs/dlm/rcom.c +++ b/fs/dlm/rcom.c | |||
@@ -581,7 +581,7 @@ void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid) | |||
581 | 581 | ||
582 | spin_lock(&ls->ls_recover_lock); | 582 | spin_lock(&ls->ls_recover_lock); |
583 | status = ls->ls_recover_status; | 583 | status = ls->ls_recover_status; |
584 | stop = test_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); | 584 | stop = test_bit(LSFL_RECOVER_STOP, &ls->ls_flags); |
585 | seq = ls->ls_recover_seq; | 585 | seq = ls->ls_recover_seq; |
586 | spin_unlock(&ls->ls_recover_lock); | 586 | spin_unlock(&ls->ls_recover_lock); |
587 | 587 | ||
diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c index 88ce65ff021e..32f9f8926ec3 100644 --- a/fs/dlm/recoverd.c +++ b/fs/dlm/recoverd.c | |||
@@ -41,6 +41,7 @@ static int enable_locking(struct dlm_ls *ls, uint64_t seq) | |||
41 | set_bit(LSFL_RUNNING, &ls->ls_flags); | 41 | set_bit(LSFL_RUNNING, &ls->ls_flags); |
42 | /* unblocks processes waiting to enter the dlm */ | 42 | /* unblocks processes waiting to enter the dlm */ |
43 | up_write(&ls->ls_in_recovery); | 43 | up_write(&ls->ls_in_recovery); |
44 | clear_bit(LSFL_RECOVER_LOCK, &ls->ls_flags); | ||
44 | error = 0; | 45 | error = 0; |
45 | } | 46 | } |
46 | spin_unlock(&ls->ls_recover_lock); | 47 | spin_unlock(&ls->ls_recover_lock); |
@@ -262,7 +263,7 @@ static void do_ls_recovery(struct dlm_ls *ls) | |||
262 | rv = ls->ls_recover_args; | 263 | rv = ls->ls_recover_args; |
263 | ls->ls_recover_args = NULL; | 264 | ls->ls_recover_args = NULL; |
264 | if (rv && ls->ls_recover_seq == rv->seq) | 265 | if (rv && ls->ls_recover_seq == rv->seq) |
265 | clear_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); | 266 | clear_bit(LSFL_RECOVER_STOP, &ls->ls_flags); |
266 | spin_unlock(&ls->ls_recover_lock); | 267 | spin_unlock(&ls->ls_recover_lock); |
267 | 268 | ||
268 | if (rv) { | 269 | if (rv) { |
@@ -282,26 +283,34 @@ static int dlm_recoverd(void *arg) | |||
282 | return -1; | 283 | return -1; |
283 | } | 284 | } |
284 | 285 | ||
286 | down_write(&ls->ls_in_recovery); | ||
287 | set_bit(LSFL_RECOVER_LOCK, &ls->ls_flags); | ||
288 | wake_up(&ls->ls_recover_lock_wait); | ||
289 | |||
285 | while (!kthread_should_stop()) { | 290 | while (!kthread_should_stop()) { |
286 | set_current_state(TASK_INTERRUPTIBLE); | 291 | set_current_state(TASK_INTERRUPTIBLE); |
287 | if (!test_bit(LSFL_WORK, &ls->ls_flags)) | 292 | if (!test_bit(LSFL_RECOVER_WORK, &ls->ls_flags) && |
293 | !test_bit(LSFL_RECOVER_DOWN, &ls->ls_flags)) | ||
288 | schedule(); | 294 | schedule(); |
289 | set_current_state(TASK_RUNNING); | 295 | set_current_state(TASK_RUNNING); |
290 | 296 | ||
291 | if (test_and_clear_bit(LSFL_WORK, &ls->ls_flags)) | 297 | if (test_and_clear_bit(LSFL_RECOVER_DOWN, &ls->ls_flags)) { |
298 | down_write(&ls->ls_in_recovery); | ||
299 | set_bit(LSFL_RECOVER_LOCK, &ls->ls_flags); | ||
300 | wake_up(&ls->ls_recover_lock_wait); | ||
301 | } | ||
302 | |||
303 | if (test_and_clear_bit(LSFL_RECOVER_WORK, &ls->ls_flags)) | ||
292 | do_ls_recovery(ls); | 304 | do_ls_recovery(ls); |
293 | } | 305 | } |
294 | 306 | ||
307 | if (test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags)) | ||
308 | up_write(&ls->ls_in_recovery); | ||
309 | |||
295 | dlm_put_lockspace(ls); | 310 | dlm_put_lockspace(ls); |
296 | return 0; | 311 | return 0; |
297 | } | 312 | } |
298 | 313 | ||
299 | void dlm_recoverd_kick(struct dlm_ls *ls) | ||
300 | { | ||
301 | set_bit(LSFL_WORK, &ls->ls_flags); | ||
302 | wake_up_process(ls->ls_recoverd_task); | ||
303 | } | ||
304 | |||
305 | int dlm_recoverd_start(struct dlm_ls *ls) | 314 | int dlm_recoverd_start(struct dlm_ls *ls) |
306 | { | 315 | { |
307 | struct task_struct *p; | 316 | struct task_struct *p; |
diff --git a/fs/dlm/recoverd.h b/fs/dlm/recoverd.h index 866657c5d69d..8856079733fa 100644 --- a/fs/dlm/recoverd.h +++ b/fs/dlm/recoverd.h | |||
@@ -14,7 +14,6 @@ | |||
14 | #ifndef __RECOVERD_DOT_H__ | 14 | #ifndef __RECOVERD_DOT_H__ |
15 | #define __RECOVERD_DOT_H__ | 15 | #define __RECOVERD_DOT_H__ |
16 | 16 | ||
17 | void dlm_recoverd_kick(struct dlm_ls *ls); | ||
18 | void dlm_recoverd_stop(struct dlm_ls *ls); | 17 | void dlm_recoverd_stop(struct dlm_ls *ls); |
19 | int dlm_recoverd_start(struct dlm_ls *ls); | 18 | int dlm_recoverd_start(struct dlm_ls *ls); |
20 | void dlm_recoverd_suspend(struct dlm_ls *ls); | 19 | void dlm_recoverd_suspend(struct dlm_ls *ls); |
diff --git a/fs/dlm/user.c b/fs/dlm/user.c index eb4ed9ba3098..7ff49852b0cb 100644 --- a/fs/dlm/user.c +++ b/fs/dlm/user.c | |||
@@ -503,6 +503,13 @@ static ssize_t device_write(struct file *file, const char __user *buf, | |||
503 | #endif | 503 | #endif |
504 | return -EINVAL; | 504 | return -EINVAL; |
505 | 505 | ||
506 | #ifdef CONFIG_COMPAT | ||
507 | if (count > sizeof(struct dlm_write_request32) + DLM_RESNAME_MAXLEN) | ||
508 | #else | ||
509 | if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN) | ||
510 | #endif | ||
511 | return -EINVAL; | ||
512 | |||
506 | kbuf = kzalloc(count + 1, GFP_NOFS); | 513 | kbuf = kzalloc(count + 1, GFP_NOFS); |
507 | if (!kbuf) | 514 | if (!kbuf) |
508 | return -ENOMEM; | 515 | return -ENOMEM; |
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 34fcde765d24..4e0886c9e5c4 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -545,11 +545,12 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags | |||
545 | goto out_free; | 545 | goto out_free; |
546 | } | 546 | } |
547 | 547 | ||
548 | if (check_ruid && path.dentry->d_inode->i_uid != current_uid()) { | 548 | if (check_ruid && !uid_eq(path.dentry->d_inode->i_uid, current_uid())) { |
549 | rc = -EPERM; | 549 | rc = -EPERM; |
550 | printk(KERN_ERR "Mount of device (uid: %d) not owned by " | 550 | printk(KERN_ERR "Mount of device (uid: %d) not owned by " |
551 | "requested user (uid: %d)\n", | 551 | "requested user (uid: %d)\n", |
552 | path.dentry->d_inode->i_uid, current_uid()); | 552 | i_uid_read(path.dentry->d_inode), |
553 | from_kuid(&init_user_ns, current_uid())); | ||
553 | goto out_free; | 554 | goto out_free; |
554 | } | 555 | } |
555 | 556 | ||
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index b29bb8bfa8d9..5fa2471796c2 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c | |||
@@ -33,7 +33,7 @@ static struct hlist_head *ecryptfs_daemon_hash; | |||
33 | struct mutex ecryptfs_daemon_hash_mux; | 33 | struct mutex ecryptfs_daemon_hash_mux; |
34 | static int ecryptfs_hash_bits; | 34 | static int ecryptfs_hash_bits; |
35 | #define ecryptfs_current_euid_hash(uid) \ | 35 | #define ecryptfs_current_euid_hash(uid) \ |
36 | hash_long((unsigned long)current_euid(), ecryptfs_hash_bits) | 36 | hash_long((unsigned long)from_kuid(&init_user_ns, current_euid()), ecryptfs_hash_bits) |
37 | 37 | ||
38 | static u32 ecryptfs_msg_counter; | 38 | static u32 ecryptfs_msg_counter; |
39 | static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr; | 39 | static struct ecryptfs_msg_ctx *ecryptfs_msg_ctx_arr; |
@@ -121,8 +121,7 @@ int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon) | |||
121 | hlist_for_each_entry(*daemon, elem, | 121 | hlist_for_each_entry(*daemon, elem, |
122 | &ecryptfs_daemon_hash[ecryptfs_current_euid_hash()], | 122 | &ecryptfs_daemon_hash[ecryptfs_current_euid_hash()], |
123 | euid_chain) { | 123 | euid_chain) { |
124 | if ((*daemon)->file->f_cred->euid == current_euid() && | 124 | if (uid_eq((*daemon)->file->f_cred->euid, current_euid())) { |
125 | (*daemon)->file->f_cred->user_ns == current_user_ns()) { | ||
126 | rc = 0; | 125 | rc = 0; |
127 | goto out; | 126 | goto out; |
128 | } | 127 | } |
diff --git a/fs/efs/inode.c b/fs/efs/inode.c index bc84f365d75c..f3913eb2c474 100644 --- a/fs/efs/inode.c +++ b/fs/efs/inode.c | |||
@@ -97,8 +97,8 @@ struct inode *efs_iget(struct super_block *super, unsigned long ino) | |||
97 | 97 | ||
98 | inode->i_mode = be16_to_cpu(efs_inode->di_mode); | 98 | inode->i_mode = be16_to_cpu(efs_inode->di_mode); |
99 | set_nlink(inode, be16_to_cpu(efs_inode->di_nlink)); | 99 | set_nlink(inode, be16_to_cpu(efs_inode->di_nlink)); |
100 | inode->i_uid = (uid_t)be16_to_cpu(efs_inode->di_uid); | 100 | i_uid_write(inode, (uid_t)be16_to_cpu(efs_inode->di_uid)); |
101 | inode->i_gid = (gid_t)be16_to_cpu(efs_inode->di_gid); | 101 | i_gid_write(inode, (gid_t)be16_to_cpu(efs_inode->di_gid)); |
102 | inode->i_size = be32_to_cpu(efs_inode->di_size); | 102 | inode->i_size = be32_to_cpu(efs_inode->di_size); |
103 | inode->i_atime.tv_sec = be32_to_cpu(efs_inode->di_atime); | 103 | inode->i_atime.tv_sec = be32_to_cpu(efs_inode->di_atime); |
104 | inode->i_mtime.tv_sec = be32_to_cpu(efs_inode->di_mtime); | 104 | inode->i_mtime.tv_sec = be32_to_cpu(efs_inode->di_mtime); |
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 1562c27a2fab..b56181047751 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c | |||
@@ -1172,8 +1172,8 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) | |||
1172 | 1172 | ||
1173 | /* copy stuff from on-disk struct to in-memory struct */ | 1173 | /* copy stuff from on-disk struct to in-memory struct */ |
1174 | inode->i_mode = le16_to_cpu(fcb.i_mode); | 1174 | inode->i_mode = le16_to_cpu(fcb.i_mode); |
1175 | inode->i_uid = le32_to_cpu(fcb.i_uid); | 1175 | i_uid_write(inode, le32_to_cpu(fcb.i_uid)); |
1176 | inode->i_gid = le32_to_cpu(fcb.i_gid); | 1176 | i_gid_write(inode, le32_to_cpu(fcb.i_gid)); |
1177 | set_nlink(inode, le16_to_cpu(fcb.i_links_count)); | 1177 | set_nlink(inode, le16_to_cpu(fcb.i_links_count)); |
1178 | inode->i_ctime.tv_sec = (signed)le32_to_cpu(fcb.i_ctime); | 1178 | inode->i_ctime.tv_sec = (signed)le32_to_cpu(fcb.i_ctime); |
1179 | inode->i_atime.tv_sec = (signed)le32_to_cpu(fcb.i_atime); | 1179 | inode->i_atime.tv_sec = (signed)le32_to_cpu(fcb.i_atime); |
@@ -1385,8 +1385,8 @@ static int exofs_update_inode(struct inode *inode, int do_sync) | |||
1385 | fcb = &args->fcb; | 1385 | fcb = &args->fcb; |
1386 | 1386 | ||
1387 | fcb->i_mode = cpu_to_le16(inode->i_mode); | 1387 | fcb->i_mode = cpu_to_le16(inode->i_mode); |
1388 | fcb->i_uid = cpu_to_le32(inode->i_uid); | 1388 | fcb->i_uid = cpu_to_le32(i_uid_read(inode)); |
1389 | fcb->i_gid = cpu_to_le32(inode->i_gid); | 1389 | fcb->i_gid = cpu_to_le32(i_gid_read(inode)); |
1390 | fcb->i_links_count = cpu_to_le16(inode->i_nlink); | 1390 | fcb->i_links_count = cpu_to_le16(inode->i_nlink); |
1391 | fcb->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); | 1391 | fcb->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); |
1392 | fcb->i_atime = cpu_to_le32(inode->i_atime.tv_sec); | 1392 | fcb->i_atime = cpu_to_le32(inode->i_atime.tv_sec); |
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c index 35d6a3cfd9ff..110b6b371a4e 100644 --- a/fs/ext2/acl.c +++ b/fs/ext2/acl.c | |||
@@ -53,16 +53,23 @@ ext2_acl_from_disk(const void *value, size_t size) | |||
53 | case ACL_OTHER: | 53 | case ACL_OTHER: |
54 | value = (char *)value + | 54 | value = (char *)value + |
55 | sizeof(ext2_acl_entry_short); | 55 | sizeof(ext2_acl_entry_short); |
56 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; | ||
57 | break; | 56 | break; |
58 | 57 | ||
59 | case ACL_USER: | 58 | case ACL_USER: |
59 | value = (char *)value + sizeof(ext2_acl_entry); | ||
60 | if ((char *)value > end) | ||
61 | goto fail; | ||
62 | acl->a_entries[n].e_uid = | ||
63 | make_kuid(&init_user_ns, | ||
64 | le32_to_cpu(entry->e_id)); | ||
65 | break; | ||
60 | case ACL_GROUP: | 66 | case ACL_GROUP: |
61 | value = (char *)value + sizeof(ext2_acl_entry); | 67 | value = (char *)value + sizeof(ext2_acl_entry); |
62 | if ((char *)value > end) | 68 | if ((char *)value > end) |
63 | goto fail; | 69 | goto fail; |
64 | acl->a_entries[n].e_id = | 70 | acl->a_entries[n].e_gid = |
65 | le32_to_cpu(entry->e_id); | 71 | make_kgid(&init_user_ns, |
72 | le32_to_cpu(entry->e_id)); | ||
66 | break; | 73 | break; |
67 | 74 | ||
68 | default: | 75 | default: |
@@ -96,14 +103,19 @@ ext2_acl_to_disk(const struct posix_acl *acl, size_t *size) | |||
96 | ext_acl->a_version = cpu_to_le32(EXT2_ACL_VERSION); | 103 | ext_acl->a_version = cpu_to_le32(EXT2_ACL_VERSION); |
97 | e = (char *)ext_acl + sizeof(ext2_acl_header); | 104 | e = (char *)ext_acl + sizeof(ext2_acl_header); |
98 | for (n=0; n < acl->a_count; n++) { | 105 | for (n=0; n < acl->a_count; n++) { |
106 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; | ||
99 | ext2_acl_entry *entry = (ext2_acl_entry *)e; | 107 | ext2_acl_entry *entry = (ext2_acl_entry *)e; |
100 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 108 | entry->e_tag = cpu_to_le16(acl_e->e_tag); |
101 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 109 | entry->e_perm = cpu_to_le16(acl_e->e_perm); |
102 | switch(acl->a_entries[n].e_tag) { | 110 | switch(acl_e->e_tag) { |
103 | case ACL_USER: | 111 | case ACL_USER: |
112 | entry->e_id = cpu_to_le32( | ||
113 | from_kuid(&init_user_ns, acl_e->e_uid)); | ||
114 | e += sizeof(ext2_acl_entry); | ||
115 | break; | ||
104 | case ACL_GROUP: | 116 | case ACL_GROUP: |
105 | entry->e_id = | 117 | entry->e_id = cpu_to_le32( |
106 | cpu_to_le32(acl->a_entries[n].e_id); | 118 | from_kgid(&init_user_ns, acl_e->e_gid)); |
107 | e += sizeof(ext2_acl_entry); | 119 | e += sizeof(ext2_acl_entry); |
108 | break; | 120 | break; |
109 | 121 | ||
@@ -350,7 +362,7 @@ ext2_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, | |||
350 | return PTR_ERR(acl); | 362 | return PTR_ERR(acl); |
351 | if (acl == NULL) | 363 | if (acl == NULL) |
352 | return -ENODATA; | 364 | return -ENODATA; |
353 | error = posix_acl_to_xattr(acl, buffer, size); | 365 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
354 | posix_acl_release(acl); | 366 | posix_acl_release(acl); |
355 | 367 | ||
356 | return error; | 368 | return error; |
@@ -371,7 +383,7 @@ ext2_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, | |||
371 | return -EPERM; | 383 | return -EPERM; |
372 | 384 | ||
373 | if (value) { | 385 | if (value) { |
374 | acl = posix_acl_from_xattr(value, size); | 386 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
375 | if (IS_ERR(acl)) | 387 | if (IS_ERR(acl)) |
376 | return PTR_ERR(acl); | 388 | return PTR_ERR(acl); |
377 | else if (acl) { | 389 | else if (acl) { |
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c index 376aa77f3ca7..2616d0ea5c5c 100644 --- a/fs/ext2/balloc.c +++ b/fs/ext2/balloc.c | |||
@@ -479,7 +479,7 @@ void ext2_discard_reservation(struct inode *inode) | |||
479 | /** | 479 | /** |
480 | * ext2_free_blocks() -- Free given blocks and update quota and i_blocks | 480 | * ext2_free_blocks() -- Free given blocks and update quota and i_blocks |
481 | * @inode: inode | 481 | * @inode: inode |
482 | * @block: start physcial block to free | 482 | * @block: start physical block to free |
483 | * @count: number of blocks to free | 483 | * @count: number of blocks to free |
484 | */ | 484 | */ |
485 | void ext2_free_blocks (struct inode * inode, unsigned long block, | 485 | void ext2_free_blocks (struct inode * inode, unsigned long block, |
diff --git a/fs/ext3/acl.c b/fs/ext3/acl.c index c76832c8d192..dbb5ad59a7fc 100644 --- a/fs/ext3/acl.c +++ b/fs/ext3/acl.c | |||
@@ -48,16 +48,23 @@ ext3_acl_from_disk(const void *value, size_t size) | |||
48 | case ACL_OTHER: | 48 | case ACL_OTHER: |
49 | value = (char *)value + | 49 | value = (char *)value + |
50 | sizeof(ext3_acl_entry_short); | 50 | sizeof(ext3_acl_entry_short); |
51 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; | ||
52 | break; | 51 | break; |
53 | 52 | ||
54 | case ACL_USER: | 53 | case ACL_USER: |
54 | value = (char *)value + sizeof(ext3_acl_entry); | ||
55 | if ((char *)value > end) | ||
56 | goto fail; | ||
57 | acl->a_entries[n].e_uid = | ||
58 | make_kuid(&init_user_ns, | ||
59 | le32_to_cpu(entry->e_id)); | ||
60 | break; | ||
55 | case ACL_GROUP: | 61 | case ACL_GROUP: |
56 | value = (char *)value + sizeof(ext3_acl_entry); | 62 | value = (char *)value + sizeof(ext3_acl_entry); |
57 | if ((char *)value > end) | 63 | if ((char *)value > end) |
58 | goto fail; | 64 | goto fail; |
59 | acl->a_entries[n].e_id = | 65 | acl->a_entries[n].e_gid = |
60 | le32_to_cpu(entry->e_id); | 66 | make_kgid(&init_user_ns, |
67 | le32_to_cpu(entry->e_id)); | ||
61 | break; | 68 | break; |
62 | 69 | ||
63 | default: | 70 | default: |
@@ -91,14 +98,19 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size) | |||
91 | ext_acl->a_version = cpu_to_le32(EXT3_ACL_VERSION); | 98 | ext_acl->a_version = cpu_to_le32(EXT3_ACL_VERSION); |
92 | e = (char *)ext_acl + sizeof(ext3_acl_header); | 99 | e = (char *)ext_acl + sizeof(ext3_acl_header); |
93 | for (n=0; n < acl->a_count; n++) { | 100 | for (n=0; n < acl->a_count; n++) { |
101 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; | ||
94 | ext3_acl_entry *entry = (ext3_acl_entry *)e; | 102 | ext3_acl_entry *entry = (ext3_acl_entry *)e; |
95 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 103 | entry->e_tag = cpu_to_le16(acl_e->e_tag); |
96 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 104 | entry->e_perm = cpu_to_le16(acl_e->e_perm); |
97 | switch(acl->a_entries[n].e_tag) { | 105 | switch(acl_e->e_tag) { |
98 | case ACL_USER: | 106 | case ACL_USER: |
107 | entry->e_id = cpu_to_le32( | ||
108 | from_kuid(&init_user_ns, acl_e->e_uid)); | ||
109 | e += sizeof(ext3_acl_entry); | ||
110 | break; | ||
99 | case ACL_GROUP: | 111 | case ACL_GROUP: |
100 | entry->e_id = | 112 | entry->e_id = cpu_to_le32( |
101 | cpu_to_le32(acl->a_entries[n].e_id); | 113 | from_kgid(&init_user_ns, acl_e->e_gid)); |
102 | e += sizeof(ext3_acl_entry); | 114 | e += sizeof(ext3_acl_entry); |
103 | break; | 115 | break; |
104 | 116 | ||
@@ -369,7 +381,7 @@ ext3_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, | |||
369 | return PTR_ERR(acl); | 381 | return PTR_ERR(acl); |
370 | if (acl == NULL) | 382 | if (acl == NULL) |
371 | return -ENODATA; | 383 | return -ENODATA; |
372 | error = posix_acl_to_xattr(acl, buffer, size); | 384 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
373 | posix_acl_release(acl); | 385 | posix_acl_release(acl); |
374 | 386 | ||
375 | return error; | 387 | return error; |
@@ -392,7 +404,7 @@ ext3_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, | |||
392 | return -EPERM; | 404 | return -EPERM; |
393 | 405 | ||
394 | if (value) { | 406 | if (value) { |
395 | acl = posix_acl_from_xattr(value, size); | 407 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
396 | if (IS_ERR(acl)) | 408 | if (IS_ERR(acl)) |
397 | return PTR_ERR(acl); | 409 | return PTR_ERR(acl); |
398 | else if (acl) { | 410 | else if (acl) { |
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c index 90d901f0486b..7320a66e958f 100644 --- a/fs/ext3/balloc.c +++ b/fs/ext3/balloc.c | |||
@@ -483,7 +483,7 @@ void ext3_discard_reservation(struct inode *inode) | |||
483 | * ext3_free_blocks_sb() -- Free given blocks and update quota | 483 | * ext3_free_blocks_sb() -- Free given blocks and update quota |
484 | * @handle: handle to this transaction | 484 | * @handle: handle to this transaction |
485 | * @sb: super block | 485 | * @sb: super block |
486 | * @block: start physcial block to free | 486 | * @block: start physical block to free |
487 | * @count: number of blocks to free | 487 | * @count: number of blocks to free |
488 | * @pdquot_freed_blocks: pointer to quota | 488 | * @pdquot_freed_blocks: pointer to quota |
489 | */ | 489 | */ |
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index ff574b4e345e..7e87e37a372a 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -3207,7 +3207,7 @@ out_brelse: | |||
3207 | * | 3207 | * |
3208 | * - Within generic_file_write() for O_SYNC files. | 3208 | * - Within generic_file_write() for O_SYNC files. |
3209 | * Here, there will be no transaction running. We wait for any running | 3209 | * Here, there will be no transaction running. We wait for any running |
3210 | * trasnaction to commit. | 3210 | * transaction to commit. |
3211 | * | 3211 | * |
3212 | * - Within sys_sync(), kupdate and such. | 3212 | * - Within sys_sync(), kupdate and such. |
3213 | * We wait on commit, if tol to. | 3213 | * We wait on commit, if tol to. |
diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 8d41c8889eee..bd29894c8fbc 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c | |||
@@ -2808,7 +2808,7 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) | |||
2808 | 2808 | ||
2809 | static inline struct inode *dquot_to_inode(struct dquot *dquot) | 2809 | static inline struct inode *dquot_to_inode(struct dquot *dquot) |
2810 | { | 2810 | { |
2811 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; | 2811 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type]; |
2812 | } | 2812 | } |
2813 | 2813 | ||
2814 | static int ext3_write_dquot(struct dquot *dquot) | 2814 | static int ext3_write_dquot(struct dquot *dquot) |
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c index a5c29bb3b835..d3c5b88fd89f 100644 --- a/fs/ext4/acl.c +++ b/fs/ext4/acl.c | |||
@@ -55,16 +55,23 @@ ext4_acl_from_disk(const void *value, size_t size) | |||
55 | case ACL_OTHER: | 55 | case ACL_OTHER: |
56 | value = (char *)value + | 56 | value = (char *)value + |
57 | sizeof(ext4_acl_entry_short); | 57 | sizeof(ext4_acl_entry_short); |
58 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; | ||
59 | break; | 58 | break; |
60 | 59 | ||
61 | case ACL_USER: | 60 | case ACL_USER: |
61 | value = (char *)value + sizeof(ext4_acl_entry); | ||
62 | if ((char *)value > end) | ||
63 | goto fail; | ||
64 | acl->a_entries[n].e_uid = | ||
65 | make_kuid(&init_user_ns, | ||
66 | le32_to_cpu(entry->e_id)); | ||
67 | break; | ||
62 | case ACL_GROUP: | 68 | case ACL_GROUP: |
63 | value = (char *)value + sizeof(ext4_acl_entry); | 69 | value = (char *)value + sizeof(ext4_acl_entry); |
64 | if ((char *)value > end) | 70 | if ((char *)value > end) |
65 | goto fail; | 71 | goto fail; |
66 | acl->a_entries[n].e_id = | 72 | acl->a_entries[n].e_gid = |
67 | le32_to_cpu(entry->e_id); | 73 | make_kgid(&init_user_ns, |
74 | le32_to_cpu(entry->e_id)); | ||
68 | break; | 75 | break; |
69 | 76 | ||
70 | default: | 77 | default: |
@@ -98,13 +105,19 @@ ext4_acl_to_disk(const struct posix_acl *acl, size_t *size) | |||
98 | ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); | 105 | ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); |
99 | e = (char *)ext_acl + sizeof(ext4_acl_header); | 106 | e = (char *)ext_acl + sizeof(ext4_acl_header); |
100 | for (n = 0; n < acl->a_count; n++) { | 107 | for (n = 0; n < acl->a_count; n++) { |
108 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; | ||
101 | ext4_acl_entry *entry = (ext4_acl_entry *)e; | 109 | ext4_acl_entry *entry = (ext4_acl_entry *)e; |
102 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 110 | entry->e_tag = cpu_to_le16(acl_e->e_tag); |
103 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 111 | entry->e_perm = cpu_to_le16(acl_e->e_perm); |
104 | switch (acl->a_entries[n].e_tag) { | 112 | switch (acl_e->e_tag) { |
105 | case ACL_USER: | 113 | case ACL_USER: |
114 | entry->e_id = cpu_to_le32( | ||
115 | from_kuid(&init_user_ns, acl_e->e_uid)); | ||
116 | e += sizeof(ext4_acl_entry); | ||
117 | break; | ||
106 | case ACL_GROUP: | 118 | case ACL_GROUP: |
107 | entry->e_id = cpu_to_le32(acl->a_entries[n].e_id); | 119 | entry->e_id = cpu_to_le32( |
120 | from_kgid(&init_user_ns, acl_e->e_gid)); | ||
108 | e += sizeof(ext4_acl_entry); | 121 | e += sizeof(ext4_acl_entry); |
109 | break; | 122 | break; |
110 | 123 | ||
@@ -374,7 +387,7 @@ ext4_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, | |||
374 | return PTR_ERR(acl); | 387 | return PTR_ERR(acl); |
375 | if (acl == NULL) | 388 | if (acl == NULL) |
376 | return -ENODATA; | 389 | return -ENODATA; |
377 | error = posix_acl_to_xattr(acl, buffer, size); | 390 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
378 | posix_acl_release(acl); | 391 | posix_acl_release(acl); |
379 | 392 | ||
380 | return error; | 393 | return error; |
@@ -397,7 +410,7 @@ ext4_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, | |||
397 | return -EPERM; | 410 | return -EPERM; |
398 | 411 | ||
399 | if (value) { | 412 | if (value) { |
400 | acl = posix_acl_from_xattr(value, size); | 413 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
401 | if (IS_ERR(acl)) | 414 | if (IS_ERR(acl)) |
402 | return PTR_ERR(acl); | 415 | return PTR_ERR(acl); |
403 | else if (acl) { | 416 | else if (acl) { |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index dff171c3a123..c862ee5fe79d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -3313,7 +3313,7 @@ int ext4_discard_partial_page_buffers(handle_t *handle, | |||
3313 | * handle: The journal handle | 3313 | * handle: The journal handle |
3314 | * inode: The files inode | 3314 | * inode: The files inode |
3315 | * page: A locked page that contains the offset "from" | 3315 | * page: A locked page that contains the offset "from" |
3316 | * from: The starting byte offset (from the begining of the file) | 3316 | * from: The starting byte offset (from the beginning of the file) |
3317 | * to begin discarding | 3317 | * to begin discarding |
3318 | * len: The length of bytes to discard | 3318 | * len: The length of bytes to discard |
3319 | * flags: Optional flags that may be used: | 3319 | * flags: Optional flags that may be used: |
@@ -3321,11 +3321,11 @@ int ext4_discard_partial_page_buffers(handle_t *handle, | |||
3321 | * EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED | 3321 | * EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED |
3322 | * Only zero the regions of the page whose buffer heads | 3322 | * Only zero the regions of the page whose buffer heads |
3323 | * have already been unmapped. This flag is appropriate | 3323 | * have already been unmapped. This flag is appropriate |
3324 | * for updateing the contents of a page whose blocks may | 3324 | * for updating the contents of a page whose blocks may |
3325 | * have already been released, and we only want to zero | 3325 | * have already been released, and we only want to zero |
3326 | * out the regions that correspond to those released blocks. | 3326 | * out the regions that correspond to those released blocks. |
3327 | * | 3327 | * |
3328 | * Returns zero on sucess or negative on failure. | 3328 | * Returns zero on success or negative on failure. |
3329 | */ | 3329 | */ |
3330 | static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle, | 3330 | static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle, |
3331 | struct inode *inode, struct page *page, loff_t from, | 3331 | struct inode *inode, struct page *page, loff_t from, |
@@ -3486,7 +3486,7 @@ int ext4_can_truncate(struct inode *inode) | |||
3486 | * @offset: The offset where the hole will begin | 3486 | * @offset: The offset where the hole will begin |
3487 | * @len: The length of the hole | 3487 | * @len: The length of the hole |
3488 | * | 3488 | * |
3489 | * Returns: 0 on sucess or negative on failure | 3489 | * Returns: 0 on success or negative on failure |
3490 | */ | 3490 | */ |
3491 | 3491 | ||
3492 | int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) | 3492 | int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) |
@@ -4008,7 +4008,7 @@ static int ext4_inode_blocks_set(handle_t *handle, | |||
4008 | 4008 | ||
4009 | if (i_blocks <= ~0U) { | 4009 | if (i_blocks <= ~0U) { |
4010 | /* | 4010 | /* |
4011 | * i_blocks can be represnted in a 32 bit variable | 4011 | * i_blocks can be represented in a 32 bit variable |
4012 | * as multiple of 512 bytes | 4012 | * as multiple of 512 bytes |
4013 | */ | 4013 | */ |
4014 | raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); | 4014 | raw_inode->i_blocks_lo = cpu_to_le32(i_blocks); |
@@ -4169,7 +4169,7 @@ out_brelse: | |||
4169 | * | 4169 | * |
4170 | * - Within generic_file_write() for O_SYNC files. | 4170 | * - Within generic_file_write() for O_SYNC files. |
4171 | * Here, there will be no transaction running. We wait for any running | 4171 | * Here, there will be no transaction running. We wait for any running |
4172 | * trasnaction to commit. | 4172 | * transaction to commit. |
4173 | * | 4173 | * |
4174 | * - Within sys_sync(), kupdate and such. | 4174 | * - Within sys_sync(), kupdate and such. |
4175 | * We wait on commit, if tol to. | 4175 | * We wait on commit, if tol to. |
@@ -4413,7 +4413,7 @@ static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) | |||
4413 | * worse case, the indexs blocks spread over different block groups | 4413 | * worse case, the indexs blocks spread over different block groups |
4414 | * | 4414 | * |
4415 | * If datablocks are discontiguous, they are possible to spread over | 4415 | * If datablocks are discontiguous, they are possible to spread over |
4416 | * different block groups too. If they are contiuguous, with flexbg, | 4416 | * different block groups too. If they are contiguous, with flexbg, |
4417 | * they could still across block group boundary. | 4417 | * they could still across block group boundary. |
4418 | * | 4418 | * |
4419 | * Also account for superblock, inode, quota and xattr blocks | 4419 | * Also account for superblock, inode, quota and xattr blocks |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 8eae94771c45..08778f6cdfe9 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -4709,7 +4709,7 @@ error_return: | |||
4709 | * ext4_group_add_blocks() -- Add given blocks to an existing group | 4709 | * ext4_group_add_blocks() -- Add given blocks to an existing group |
4710 | * @handle: handle to this transaction | 4710 | * @handle: handle to this transaction |
4711 | * @sb: super block | 4711 | * @sb: super block |
4712 | * @block: start physcial block to add to the block group | 4712 | * @block: start physical block to add to the block group |
4713 | * @count: number of blocks to free | 4713 | * @count: number of blocks to free |
4714 | * | 4714 | * |
4715 | * This marks the blocks as free in the bitmap and buddy. | 4715 | * This marks the blocks as free in the bitmap and buddy. |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 455b7d8c6d62..69c55d4e4626 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -4796,7 +4796,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
4796 | 4796 | ||
4797 | static inline struct inode *dquot_to_inode(struct dquot *dquot) | 4797 | static inline struct inode *dquot_to_inode(struct dquot *dquot) |
4798 | { | 4798 | { |
4799 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; | 4799 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type]; |
4800 | } | 4800 | } |
4801 | 4801 | ||
4802 | static int ext4_write_dquot(struct dquot *dquot) | 4802 | static int ext4_write_dquot(struct dquot *dquot) |
diff --git a/fs/fat/fat.h b/fs/fat/fat.h index 2deeeb86f331..7d8e0dcac5d5 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h | |||
@@ -23,8 +23,8 @@ | |||
23 | #define FAT_ERRORS_RO 3 /* remount r/o on error */ | 23 | #define FAT_ERRORS_RO 3 /* remount r/o on error */ |
24 | 24 | ||
25 | struct fat_mount_options { | 25 | struct fat_mount_options { |
26 | uid_t fs_uid; | 26 | kuid_t fs_uid; |
27 | gid_t fs_gid; | 27 | kgid_t fs_gid; |
28 | unsigned short fs_fmask; | 28 | unsigned short fs_fmask; |
29 | unsigned short fs_dmask; | 29 | unsigned short fs_dmask; |
30 | unsigned short codepage; /* Codepage for shortname conversions */ | 30 | unsigned short codepage; /* Codepage for shortname conversions */ |
diff --git a/fs/fat/file.c b/fs/fat/file.c index e007b8bd8e5e..a62e0ecbe2db 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c | |||
@@ -352,7 +352,7 @@ static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode) | |||
352 | { | 352 | { |
353 | umode_t allow_utime = sbi->options.allow_utime; | 353 | umode_t allow_utime = sbi->options.allow_utime; |
354 | 354 | ||
355 | if (current_fsuid() != inode->i_uid) { | 355 | if (!uid_eq(current_fsuid(), inode->i_uid)) { |
356 | if (in_group_p(inode->i_gid)) | 356 | if (in_group_p(inode->i_gid)) |
357 | allow_utime >>= 3; | 357 | allow_utime >>= 3; |
358 | if (allow_utime & MAY_WRITE) | 358 | if (allow_utime & MAY_WRITE) |
@@ -407,9 +407,9 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr) | |||
407 | } | 407 | } |
408 | 408 | ||
409 | if (((attr->ia_valid & ATTR_UID) && | 409 | if (((attr->ia_valid & ATTR_UID) && |
410 | (attr->ia_uid != sbi->options.fs_uid)) || | 410 | (!uid_eq(attr->ia_uid, sbi->options.fs_uid))) || |
411 | ((attr->ia_valid & ATTR_GID) && | 411 | ((attr->ia_valid & ATTR_GID) && |
412 | (attr->ia_gid != sbi->options.fs_gid)) || | 412 | (!gid_eq(attr->ia_gid, sbi->options.fs_gid))) || |
413 | ((attr->ia_valid & ATTR_MODE) && | 413 | ((attr->ia_valid & ATTR_MODE) && |
414 | (attr->ia_mode & ~FAT_VALID_MODE))) | 414 | (attr->ia_mode & ~FAT_VALID_MODE))) |
415 | error = -EPERM; | 415 | error = -EPERM; |
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index fd8e47cd898b..4e5a6ac54ebd 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c | |||
@@ -796,10 +796,12 @@ static int fat_show_options(struct seq_file *m, struct dentry *root) | |||
796 | struct fat_mount_options *opts = &sbi->options; | 796 | struct fat_mount_options *opts = &sbi->options; |
797 | int isvfat = opts->isvfat; | 797 | int isvfat = opts->isvfat; |
798 | 798 | ||
799 | if (opts->fs_uid != 0) | 799 | if (!uid_eq(opts->fs_uid, GLOBAL_ROOT_UID)) |
800 | seq_printf(m, ",uid=%u", opts->fs_uid); | 800 | seq_printf(m, ",uid=%u", |
801 | if (opts->fs_gid != 0) | 801 | from_kuid_munged(&init_user_ns, opts->fs_uid)); |
802 | seq_printf(m, ",gid=%u", opts->fs_gid); | 802 | if (!gid_eq(opts->fs_gid, GLOBAL_ROOT_GID)) |
803 | seq_printf(m, ",gid=%u", | ||
804 | from_kgid_munged(&init_user_ns, opts->fs_gid)); | ||
803 | seq_printf(m, ",fmask=%04o", opts->fs_fmask); | 805 | seq_printf(m, ",fmask=%04o", opts->fs_fmask); |
804 | seq_printf(m, ",dmask=%04o", opts->fs_dmask); | 806 | seq_printf(m, ",dmask=%04o", opts->fs_dmask); |
805 | if (opts->allow_utime) | 807 | if (opts->allow_utime) |
@@ -1042,12 +1044,16 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat, | |||
1042 | case Opt_uid: | 1044 | case Opt_uid: |
1043 | if (match_int(&args[0], &option)) | 1045 | if (match_int(&args[0], &option)) |
1044 | return 0; | 1046 | return 0; |
1045 | opts->fs_uid = option; | 1047 | opts->fs_uid = make_kuid(current_user_ns(), option); |
1048 | if (!uid_valid(opts->fs_uid)) | ||
1049 | return 0; | ||
1046 | break; | 1050 | break; |
1047 | case Opt_gid: | 1051 | case Opt_gid: |
1048 | if (match_int(&args[0], &option)) | 1052 | if (match_int(&args[0], &option)) |
1049 | return 0; | 1053 | return 0; |
1050 | opts->fs_gid = option; | 1054 | opts->fs_gid = make_kgid(current_user_ns(), option); |
1055 | if (!gid_valid(opts->fs_gid)) | ||
1056 | return 0; | ||
1051 | break; | 1057 | break; |
1052 | case Opt_umask: | 1058 | case Opt_umask: |
1053 | if (match_octal(&args[0], &option)) | 1059 | if (match_octal(&args[0], &option)) |
diff --git a/fs/freevxfs/vxfs_inode.c b/fs/freevxfs/vxfs_inode.c index ef67c95f12d4..f47df72cef17 100644 --- a/fs/freevxfs/vxfs_inode.c +++ b/fs/freevxfs/vxfs_inode.c | |||
@@ -224,8 +224,8 @@ vxfs_iinit(struct inode *ip, struct vxfs_inode_info *vip) | |||
224 | { | 224 | { |
225 | 225 | ||
226 | ip->i_mode = vxfs_transmod(vip); | 226 | ip->i_mode = vxfs_transmod(vip); |
227 | ip->i_uid = (uid_t)vip->vii_uid; | 227 | i_uid_write(ip, (uid_t)vip->vii_uid); |
228 | ip->i_gid = (gid_t)vip->vii_gid; | 228 | i_gid_write(ip, (gid_t)vip->vii_gid); |
229 | 229 | ||
230 | set_nlink(ip, vip->vii_nlink); | 230 | set_nlink(ip, vip->vii_nlink); |
231 | ip->i_size = vip->vii_size; | 231 | ip->i_size = vip->vii_size; |
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index be3efc4f64f4..6d46c0d78338 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c | |||
@@ -577,10 +577,6 @@ static long writeback_chunk_size(struct backing_dev_info *bdi, | |||
577 | /* | 577 | /* |
578 | * Write a portion of b_io inodes which belong to @sb. | 578 | * Write a portion of b_io inodes which belong to @sb. |
579 | * | 579 | * |
580 | * If @only_this_sb is true, then find and write all such | ||
581 | * inodes. Otherwise write only ones which go sequentially | ||
582 | * in reverse order. | ||
583 | * | ||
584 | * Return the number of pages and/or inodes written. | 580 | * Return the number of pages and/or inodes written. |
585 | */ | 581 | */ |
586 | static long writeback_sb_inodes(struct super_block *sb, | 582 | static long writeback_sb_inodes(struct super_block *sb, |
diff --git a/fs/generic_acl.c b/fs/generic_acl.c index d0dddaceac59..b3f3676796d3 100644 --- a/fs/generic_acl.c +++ b/fs/generic_acl.c | |||
@@ -56,7 +56,7 @@ generic_acl_get(struct dentry *dentry, const char *name, void *buffer, | |||
56 | acl = get_cached_acl(dentry->d_inode, type); | 56 | acl = get_cached_acl(dentry->d_inode, type); |
57 | if (!acl) | 57 | if (!acl) |
58 | return -ENODATA; | 58 | return -ENODATA; |
59 | error = posix_acl_to_xattr(acl, buffer, size); | 59 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
60 | posix_acl_release(acl); | 60 | posix_acl_release(acl); |
61 | 61 | ||
62 | return error; | 62 | return error; |
@@ -77,7 +77,7 @@ generic_acl_set(struct dentry *dentry, const char *name, const void *value, | |||
77 | if (!inode_owner_or_capable(inode)) | 77 | if (!inode_owner_or_capable(inode)) |
78 | return -EPERM; | 78 | return -EPERM; |
79 | if (value) { | 79 | if (value) { |
80 | acl = posix_acl_from_xattr(value, size); | 80 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
81 | if (IS_ERR(acl)) | 81 | if (IS_ERR(acl)) |
82 | return PTR_ERR(acl); | 82 | return PTR_ERR(acl); |
83 | } | 83 | } |
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c index bd4a5892c93c..f850020ad906 100644 --- a/fs/gfs2/acl.c +++ b/fs/gfs2/acl.c | |||
@@ -63,7 +63,7 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type) | |||
63 | if (len == 0) | 63 | if (len == 0) |
64 | return NULL; | 64 | return NULL; |
65 | 65 | ||
66 | acl = posix_acl_from_xattr(data, len); | 66 | acl = posix_acl_from_xattr(&init_user_ns, data, len); |
67 | kfree(data); | 67 | kfree(data); |
68 | return acl; | 68 | return acl; |
69 | } | 69 | } |
@@ -88,13 +88,13 @@ static int gfs2_acl_set(struct inode *inode, int type, struct posix_acl *acl) | |||
88 | const char *name = gfs2_acl_name(type); | 88 | const char *name = gfs2_acl_name(type); |
89 | 89 | ||
90 | BUG_ON(name == NULL); | 90 | BUG_ON(name == NULL); |
91 | len = posix_acl_to_xattr(acl, NULL, 0); | 91 | len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0); |
92 | if (len == 0) | 92 | if (len == 0) |
93 | return 0; | 93 | return 0; |
94 | data = kmalloc(len, GFP_NOFS); | 94 | data = kmalloc(len, GFP_NOFS); |
95 | if (data == NULL) | 95 | if (data == NULL) |
96 | return -ENOMEM; | 96 | return -ENOMEM; |
97 | error = posix_acl_to_xattr(acl, data, len); | 97 | error = posix_acl_to_xattr(&init_user_ns, acl, data, len); |
98 | if (error < 0) | 98 | if (error < 0) |
99 | goto out; | 99 | goto out; |
100 | error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS); | 100 | error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS); |
@@ -166,12 +166,12 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) | |||
166 | if (error) | 166 | if (error) |
167 | return error; | 167 | return error; |
168 | 168 | ||
169 | len = posix_acl_to_xattr(acl, NULL, 0); | 169 | len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0); |
170 | data = kmalloc(len, GFP_NOFS); | 170 | data = kmalloc(len, GFP_NOFS); |
171 | error = -ENOMEM; | 171 | error = -ENOMEM; |
172 | if (data == NULL) | 172 | if (data == NULL) |
173 | goto out; | 173 | goto out; |
174 | posix_acl_to_xattr(acl, data, len); | 174 | posix_acl_to_xattr(&init_user_ns, acl, data, len); |
175 | error = gfs2_xattr_acl_chmod(ip, attr, data); | 175 | error = gfs2_xattr_acl_chmod(ip, attr, data); |
176 | kfree(data); | 176 | kfree(data); |
177 | set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl); | 177 | set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl); |
@@ -212,7 +212,7 @@ static int gfs2_xattr_system_get(struct dentry *dentry, const char *name, | |||
212 | if (acl == NULL) | 212 | if (acl == NULL) |
213 | return -ENODATA; | 213 | return -ENODATA; |
214 | 214 | ||
215 | error = posix_acl_to_xattr(acl, buffer, size); | 215 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
216 | posix_acl_release(acl); | 216 | posix_acl_release(acl); |
217 | 217 | ||
218 | return error; | 218 | return error; |
@@ -245,7 +245,7 @@ static int gfs2_xattr_system_set(struct dentry *dentry, const char *name, | |||
245 | if (!value) | 245 | if (!value) |
246 | goto set_acl; | 246 | goto set_acl; |
247 | 247 | ||
248 | acl = posix_acl_from_xattr(value, size); | 248 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
249 | if (!acl) { | 249 | if (!acl) { |
250 | /* | 250 | /* |
251 | * acl_set_file(3) may request that we set default ACLs with | 251 | * acl_set_file(3) may request that we set default ACLs with |
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index d6526347d386..01c4975da4bc 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c | |||
@@ -612,6 +612,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
612 | struct gfs2_sbd *sdp = GFS2_SB(mapping->host); | 612 | struct gfs2_sbd *sdp = GFS2_SB(mapping->host); |
613 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); | 613 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
614 | unsigned int data_blocks = 0, ind_blocks = 0, rblocks; | 614 | unsigned int data_blocks = 0, ind_blocks = 0, rblocks; |
615 | unsigned requested = 0; | ||
615 | int alloc_required; | 616 | int alloc_required; |
616 | int error = 0; | 617 | int error = 0; |
617 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; | 618 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; |
@@ -641,7 +642,8 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
641 | if (error) | 642 | if (error) |
642 | goto out_unlock; | 643 | goto out_unlock; |
643 | 644 | ||
644 | error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks); | 645 | requested = data_blocks + ind_blocks; |
646 | error = gfs2_inplace_reserve(ip, requested); | ||
645 | if (error) | 647 | if (error) |
646 | goto out_qunlock; | 648 | goto out_qunlock; |
647 | } | 649 | } |
@@ -654,7 +656,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
654 | if (&ip->i_inode == sdp->sd_rindex) | 656 | if (&ip->i_inode == sdp->sd_rindex) |
655 | rblocks += 2 * RES_STATFS; | 657 | rblocks += 2 * RES_STATFS; |
656 | if (alloc_required) | 658 | if (alloc_required) |
657 | rblocks += gfs2_rg_blocks(ip); | 659 | rblocks += gfs2_rg_blocks(ip, requested); |
658 | 660 | ||
659 | error = gfs2_trans_begin(sdp, rblocks, | 661 | error = gfs2_trans_begin(sdp, rblocks, |
660 | PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); | 662 | PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); |
@@ -868,8 +870,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping, | |||
868 | brelse(dibh); | 870 | brelse(dibh); |
869 | failed: | 871 | failed: |
870 | gfs2_trans_end(sdp); | 872 | gfs2_trans_end(sdp); |
871 | if (gfs2_mb_reserved(ip)) | 873 | gfs2_inplace_release(ip); |
872 | gfs2_inplace_release(ip); | ||
873 | if (ip->i_res->rs_qa_qd_num) | 874 | if (ip->i_res->rs_qa_qd_num) |
874 | gfs2_quota_unlock(ip); | 875 | gfs2_quota_unlock(ip); |
875 | if (inode == sdp->sd_rindex) { | 876 | if (inode == sdp->sd_rindex) { |
@@ -1023,7 +1024,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, | |||
1023 | offset, nr_segs, gfs2_get_block_direct, | 1024 | offset, nr_segs, gfs2_get_block_direct, |
1024 | NULL, NULL, 0); | 1025 | NULL, NULL, 0); |
1025 | out: | 1026 | out: |
1026 | gfs2_glock_dq_m(1, &gh); | 1027 | gfs2_glock_dq(&gh); |
1027 | gfs2_holder_uninit(&gh); | 1028 | gfs2_holder_uninit(&gh); |
1028 | return rv; | 1029 | return rv; |
1029 | } | 1030 | } |
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 49cd7dd4a9fa..1fd3ae237bdd 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
@@ -786,7 +786,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, | |||
786 | goto out_rlist; | 786 | goto out_rlist; |
787 | 787 | ||
788 | if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ | 788 | if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ |
789 | gfs2_rs_deltree(ip->i_res); | 789 | gfs2_rs_deltree(ip, ip->i_res); |
790 | 790 | ||
791 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + | 791 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + |
792 | RES_INDIRECT + RES_STATFS + RES_QUOTA, | 792 | RES_INDIRECT + RES_STATFS + RES_QUOTA, |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 382000ffac1f..30e21997a1a1 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -441,7 +441,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
441 | rblocks += data_blocks ? data_blocks : 1; | 441 | rblocks += data_blocks ? data_blocks : 1; |
442 | if (ind_blocks || data_blocks) { | 442 | if (ind_blocks || data_blocks) { |
443 | rblocks += RES_STATFS + RES_QUOTA; | 443 | rblocks += RES_STATFS + RES_QUOTA; |
444 | rblocks += gfs2_rg_blocks(ip); | 444 | rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
445 | } | 445 | } |
446 | ret = gfs2_trans_begin(sdp, rblocks, 0); | 446 | ret = gfs2_trans_begin(sdp, rblocks, 0); |
447 | if (ret) | 447 | if (ret) |
@@ -845,7 +845,7 @@ retry: | |||
845 | &max_bytes, &data_blocks, &ind_blocks); | 845 | &max_bytes, &data_blocks, &ind_blocks); |
846 | 846 | ||
847 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + | 847 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + |
848 | RES_RG_HDR + gfs2_rg_blocks(ip); | 848 | RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
849 | if (gfs2_is_jdata(ip)) | 849 | if (gfs2_is_jdata(ip)) |
850 | rblocks += data_blocks ? data_blocks : 1; | 850 | rblocks += data_blocks ? data_blocks : 1; |
851 | 851 | ||
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 1ed81f40da0d..e6c2fd53cab2 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -186,20 +186,6 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) | |||
186 | } | 186 | } |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * __gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list | ||
190 | * @gl: the glock | ||
191 | * | ||
192 | * If the glock is demotable, then we add it (or move it) to the end | ||
193 | * of the glock LRU list. | ||
194 | */ | ||
195 | |||
196 | static void __gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) | ||
197 | { | ||
198 | if (demote_ok(gl)) | ||
199 | gfs2_glock_add_to_lru(gl); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * gfs2_glock_put_nolock() - Decrement reference count on glock | 189 | * gfs2_glock_put_nolock() - Decrement reference count on glock |
204 | * @gl: The glock to put | 190 | * @gl: The glock to put |
205 | * | 191 | * |
@@ -883,7 +869,14 @@ static int gfs2_glock_demote_wait(void *word) | |||
883 | return 0; | 869 | return 0; |
884 | } | 870 | } |
885 | 871 | ||
886 | static void wait_on_holder(struct gfs2_holder *gh) | 872 | /** |
873 | * gfs2_glock_wait - wait on a glock acquisition | ||
874 | * @gh: the glock holder | ||
875 | * | ||
876 | * Returns: 0 on success | ||
877 | */ | ||
878 | |||
879 | int gfs2_glock_wait(struct gfs2_holder *gh) | ||
887 | { | 880 | { |
888 | unsigned long time1 = jiffies; | 881 | unsigned long time1 = jiffies; |
889 | 882 | ||
@@ -894,12 +887,7 @@ static void wait_on_holder(struct gfs2_holder *gh) | |||
894 | gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + | 887 | gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + |
895 | GL_GLOCK_HOLD_INCR, | 888 | GL_GLOCK_HOLD_INCR, |
896 | GL_GLOCK_MAX_HOLD); | 889 | GL_GLOCK_MAX_HOLD); |
897 | } | 890 | return gh->gh_error; |
898 | |||
899 | static void wait_on_demote(struct gfs2_glock *gl) | ||
900 | { | ||
901 | might_sleep(); | ||
902 | wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE); | ||
903 | } | 891 | } |
904 | 892 | ||
905 | /** | 893 | /** |
@@ -929,19 +917,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state, | |||
929 | trace_gfs2_demote_rq(gl); | 917 | trace_gfs2_demote_rq(gl); |
930 | } | 918 | } |
931 | 919 | ||
932 | /** | ||
933 | * gfs2_glock_wait - wait on a glock acquisition | ||
934 | * @gh: the glock holder | ||
935 | * | ||
936 | * Returns: 0 on success | ||
937 | */ | ||
938 | |||
939 | int gfs2_glock_wait(struct gfs2_holder *gh) | ||
940 | { | ||
941 | wait_on_holder(gh); | ||
942 | return gh->gh_error; | ||
943 | } | ||
944 | |||
945 | void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) | 920 | void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) |
946 | { | 921 | { |
947 | struct va_format vaf; | 922 | struct va_format vaf; |
@@ -979,7 +954,7 @@ __acquires(&gl->gl_spin) | |||
979 | struct gfs2_sbd *sdp = gl->gl_sbd; | 954 | struct gfs2_sbd *sdp = gl->gl_sbd; |
980 | struct list_head *insert_pt = NULL; | 955 | struct list_head *insert_pt = NULL; |
981 | struct gfs2_holder *gh2; | 956 | struct gfs2_holder *gh2; |
982 | int try_lock = 0; | 957 | int try_futile = 0; |
983 | 958 | ||
984 | BUG_ON(gh->gh_owner_pid == NULL); | 959 | BUG_ON(gh->gh_owner_pid == NULL); |
985 | if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) | 960 | if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) |
@@ -987,7 +962,7 @@ __acquires(&gl->gl_spin) | |||
987 | 962 | ||
988 | if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { | 963 | if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { |
989 | if (test_bit(GLF_LOCK, &gl->gl_flags)) | 964 | if (test_bit(GLF_LOCK, &gl->gl_flags)) |
990 | try_lock = 1; | 965 | try_futile = !may_grant(gl, gh); |
991 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) | 966 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) |
992 | goto fail; | 967 | goto fail; |
993 | } | 968 | } |
@@ -996,9 +971,8 @@ __acquires(&gl->gl_spin) | |||
996 | if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && | 971 | if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && |
997 | (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) | 972 | (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) |
998 | goto trap_recursive; | 973 | goto trap_recursive; |
999 | if (try_lock && | 974 | if (try_futile && |
1000 | !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) && | 975 | !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { |
1001 | !may_grant(gl, gh)) { | ||
1002 | fail: | 976 | fail: |
1003 | gh->gh_error = GLR_TRYFAILED; | 977 | gh->gh_error = GLR_TRYFAILED; |
1004 | gfs2_holder_wake(gh); | 978 | gfs2_holder_wake(gh); |
@@ -1121,8 +1095,9 @@ void gfs2_glock_dq(struct gfs2_holder *gh) | |||
1121 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1095 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) |
1122 | fast_path = 1; | 1096 | fast_path = 1; |
1123 | } | 1097 | } |
1124 | if (!test_bit(GLF_LFLUSH, &gl->gl_flags)) | 1098 | if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl)) |
1125 | __gfs2_glock_schedule_for_reclaim(gl); | 1099 | gfs2_glock_add_to_lru(gl); |
1100 | |||
1126 | trace_gfs2_glock_queue(gh, 0); | 1101 | trace_gfs2_glock_queue(gh, 0); |
1127 | spin_unlock(&gl->gl_spin); | 1102 | spin_unlock(&gl->gl_spin); |
1128 | if (likely(fast_path)) | 1103 | if (likely(fast_path)) |
@@ -1141,7 +1116,8 @@ void gfs2_glock_dq_wait(struct gfs2_holder *gh) | |||
1141 | { | 1116 | { |
1142 | struct gfs2_glock *gl = gh->gh_gl; | 1117 | struct gfs2_glock *gl = gh->gh_gl; |
1143 | gfs2_glock_dq(gh); | 1118 | gfs2_glock_dq(gh); |
1144 | wait_on_demote(gl); | 1119 | might_sleep(); |
1120 | wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE); | ||
1145 | } | 1121 | } |
1146 | 1122 | ||
1147 | /** | 1123 | /** |
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 4bdcf3784187..32cc4fde975c 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c | |||
@@ -94,6 +94,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl) | |||
94 | /* A shortened, inline version of gfs2_trans_begin() */ | 94 | /* A shortened, inline version of gfs2_trans_begin() */ |
95 | tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64)); | 95 | tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64)); |
96 | tr.tr_ip = (unsigned long)__builtin_return_address(0); | 96 | tr.tr_ip = (unsigned long)__builtin_return_address(0); |
97 | sb_start_intwrite(sdp->sd_vfs); | ||
97 | gfs2_log_reserve(sdp, tr.tr_reserved); | 98 | gfs2_log_reserve(sdp, tr.tr_reserved); |
98 | BUG_ON(current->journal_info); | 99 | BUG_ON(current->journal_info); |
99 | current->journal_info = &tr; | 100 | current->journal_info = &tr; |
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index aaecc8085fc5..3d469d37345e 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h | |||
@@ -99,9 +99,26 @@ struct gfs2_rgrpd { | |||
99 | #define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */ | 99 | #define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */ |
100 | spinlock_t rd_rsspin; /* protects reservation related vars */ | 100 | spinlock_t rd_rsspin; /* protects reservation related vars */ |
101 | struct rb_root rd_rstree; /* multi-block reservation tree */ | 101 | struct rb_root rd_rstree; /* multi-block reservation tree */ |
102 | u32 rd_rs_cnt; /* count of current reservations */ | ||
103 | }; | 102 | }; |
104 | 103 | ||
104 | struct gfs2_rbm { | ||
105 | struct gfs2_rgrpd *rgd; | ||
106 | struct gfs2_bitmap *bi; /* Bitmap must belong to the rgd */ | ||
107 | u32 offset; /* The offset is bitmap relative */ | ||
108 | }; | ||
109 | |||
110 | static inline u64 gfs2_rbm_to_block(const struct gfs2_rbm *rbm) | ||
111 | { | ||
112 | return rbm->rgd->rd_data0 + (rbm->bi->bi_start * GFS2_NBBY) + rbm->offset; | ||
113 | } | ||
114 | |||
115 | static inline bool gfs2_rbm_eq(const struct gfs2_rbm *rbm1, | ||
116 | const struct gfs2_rbm *rbm2) | ||
117 | { | ||
118 | return (rbm1->rgd == rbm2->rgd) && (rbm1->bi == rbm2->bi) && | ||
119 | (rbm1->offset == rbm2->offset); | ||
120 | } | ||
121 | |||
105 | enum gfs2_state_bits { | 122 | enum gfs2_state_bits { |
106 | BH_Pinned = BH_PrivateStart, | 123 | BH_Pinned = BH_PrivateStart, |
107 | BH_Escaped = BH_PrivateStart + 1, | 124 | BH_Escaped = BH_PrivateStart + 1, |
@@ -250,18 +267,11 @@ struct gfs2_blkreserv { | |||
250 | /* components used during write (step 1): */ | 267 | /* components used during write (step 1): */ |
251 | atomic_t rs_sizehint; /* hint of the write size */ | 268 | atomic_t rs_sizehint; /* hint of the write size */ |
252 | 269 | ||
253 | /* components used during inplace_reserve (step 2): */ | ||
254 | u32 rs_requested; /* Filled in by caller of gfs2_inplace_reserve() */ | ||
255 | |||
256 | /* components used during get_local_rgrp (step 3): */ | ||
257 | struct gfs2_rgrpd *rs_rgd; /* pointer to the gfs2_rgrpd */ | ||
258 | struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */ | 270 | struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */ |
259 | struct rb_node rs_node; /* link to other block reservations */ | 271 | struct rb_node rs_node; /* link to other block reservations */ |
260 | 272 | struct gfs2_rbm rs_rbm; /* Start of reservation */ | |
261 | /* components used during block searches and assignments (step 4): */ | ||
262 | struct gfs2_bitmap *rs_bi; /* bitmap for the current allocation */ | ||
263 | u32 rs_biblk; /* start block relative to the bi */ | ||
264 | u32 rs_free; /* how many blocks are still free */ | 273 | u32 rs_free; /* how many blocks are still free */ |
274 | u64 rs_inum; /* Inode number for reservation */ | ||
265 | 275 | ||
266 | /* ancillary quota stuff */ | 276 | /* ancillary quota stuff */ |
267 | struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; | 277 | struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 753af3d86bbc..381893ceefa4 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -712,14 +712,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, | |||
712 | if (error) | 712 | if (error) |
713 | goto fail_gunlock2; | 713 | goto fail_gunlock2; |
714 | 714 | ||
715 | /* The newly created inode needs a reservation so it can allocate | 715 | error = gfs2_rs_alloc(ip); |
716 | xattrs. At the same time, we want new blocks allocated to the new | 716 | if (error) |
717 | dinode to be as contiguous as possible. Since we allocated the | 717 | goto fail_gunlock2; |
718 | dinode block under the directory's reservation, we transfer | ||
719 | ownership of that reservation to the new inode. The directory | ||
720 | doesn't need a reservation unless it needs a new allocation. */ | ||
721 | ip->i_res = dip->i_res; | ||
722 | dip->i_res = NULL; | ||
723 | 718 | ||
724 | error = gfs2_acl_create(dip, inode); | 719 | error = gfs2_acl_create(dip, inode); |
725 | if (error) | 720 | if (error) |
@@ -737,10 +732,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, | |||
737 | brelse(bh); | 732 | brelse(bh); |
738 | 733 | ||
739 | gfs2_trans_end(sdp); | 734 | gfs2_trans_end(sdp); |
740 | /* Check if we reserved space in the rgrp. Function link_dinode may | 735 | gfs2_inplace_release(dip); |
741 | not, depending on whether alloc is required. */ | ||
742 | if (gfs2_mb_reserved(dip)) | ||
743 | gfs2_inplace_release(dip); | ||
744 | gfs2_quota_unlock(dip); | 736 | gfs2_quota_unlock(dip); |
745 | mark_inode_dirty(inode); | 737 | mark_inode_dirty(inode); |
746 | gfs2_glock_dq_uninit_m(2, ghs); | 738 | gfs2_glock_dq_uninit_m(2, ghs); |
@@ -897,7 +889,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, | |||
897 | goto out_gunlock_q; | 889 | goto out_gunlock_q; |
898 | 890 | ||
899 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 891 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
900 | gfs2_rg_blocks(dip) + | 892 | gfs2_rg_blocks(dip, sdp->sd_max_dirres) + |
901 | 2 * RES_DINODE + RES_STATFS + | 893 | 2 * RES_DINODE + RES_STATFS + |
902 | RES_QUOTA, 0); | 894 | RES_QUOTA, 0); |
903 | if (error) | 895 | if (error) |
@@ -1378,7 +1370,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
1378 | goto out_gunlock_q; | 1370 | goto out_gunlock_q; |
1379 | 1371 | ||
1380 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 1372 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
1381 | gfs2_rg_blocks(ndip) + | 1373 | gfs2_rg_blocks(ndip, sdp->sd_max_dirres) + |
1382 | 4 * RES_DINODE + 4 * RES_LEAF + | 1374 | 4 * RES_DINODE + 4 * RES_LEAF + |
1383 | RES_STATFS + RES_QUOTA + 4, 0); | 1375 | RES_STATFS + RES_QUOTA + 4, 0); |
1384 | if (error) | 1376 | if (error) |
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c index 4a38db739ca0..0fb6539b0c8c 100644 --- a/fs/gfs2/lock_dlm.c +++ b/fs/gfs2/lock_dlm.c | |||
@@ -1289,7 +1289,7 @@ static void gdlm_unmount(struct gfs2_sbd *sdp) | |||
1289 | spin_lock(&ls->ls_recover_spin); | 1289 | spin_lock(&ls->ls_recover_spin); |
1290 | set_bit(DFL_UNMOUNT, &ls->ls_recover_flags); | 1290 | set_bit(DFL_UNMOUNT, &ls->ls_recover_flags); |
1291 | spin_unlock(&ls->ls_recover_spin); | 1291 | spin_unlock(&ls->ls_recover_spin); |
1292 | flush_delayed_work_sync(&sdp->sd_control_work); | 1292 | flush_delayed_work(&sdp->sd_control_work); |
1293 | 1293 | ||
1294 | /* mounted_lock and control_lock will be purged in dlm recovery */ | 1294 | /* mounted_lock and control_lock will be purged in dlm recovery */ |
1295 | release: | 1295 | release: |
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e5af9dc420ef..e443966c8106 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/mount.h> | 19 | #include <linux/mount.h> |
20 | #include <linux/gfs2_ondisk.h> | 20 | #include <linux/gfs2_ondisk.h> |
21 | #include <linux/quotaops.h> | 21 | #include <linux/quotaops.h> |
22 | #include <linux/lockdep.h> | ||
22 | 23 | ||
23 | #include "gfs2.h" | 24 | #include "gfs2.h" |
24 | #include "incore.h" | 25 | #include "incore.h" |
@@ -766,6 +767,7 @@ fail: | |||
766 | return error; | 767 | return error; |
767 | } | 768 | } |
768 | 769 | ||
770 | static struct lock_class_key gfs2_quota_imutex_key; | ||
769 | 771 | ||
770 | static int init_inodes(struct gfs2_sbd *sdp, int undo) | 772 | static int init_inodes(struct gfs2_sbd *sdp, int undo) |
771 | { | 773 | { |
@@ -803,6 +805,12 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) | |||
803 | fs_err(sdp, "can't get quota file inode: %d\n", error); | 805 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
804 | goto fail_rindex; | 806 | goto fail_rindex; |
805 | } | 807 | } |
808 | /* | ||
809 | * i_mutex on quota files is special. Since this inode is hidden system | ||
810 | * file, we are safe to define locking ourselves. | ||
811 | */ | ||
812 | lockdep_set_class(&sdp->sd_quota_inode->i_mutex, | ||
813 | &gfs2_quota_imutex_key); | ||
806 | 814 | ||
807 | error = gfs2_rindex_update(sdp); | 815 | error = gfs2_rindex_update(sdp); |
808 | if (error) | 816 | if (error) |
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index a3bde91645c2..40c4b0d42fa8 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c | |||
@@ -765,6 +765,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
765 | struct gfs2_holder *ghs, i_gh; | 765 | struct gfs2_holder *ghs, i_gh; |
766 | unsigned int qx, x; | 766 | unsigned int qx, x; |
767 | struct gfs2_quota_data *qd; | 767 | struct gfs2_quota_data *qd; |
768 | unsigned reserved; | ||
768 | loff_t offset; | 769 | loff_t offset; |
769 | unsigned int nalloc = 0, blocks; | 770 | unsigned int nalloc = 0, blocks; |
770 | int error; | 771 | int error; |
@@ -781,7 +782,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
781 | return -ENOMEM; | 782 | return -ENOMEM; |
782 | 783 | ||
783 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); | 784 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); |
784 | mutex_lock_nested(&ip->i_inode.i_mutex, I_MUTEX_QUOTA); | 785 | mutex_lock(&ip->i_inode.i_mutex); |
785 | for (qx = 0; qx < num_qd; qx++) { | 786 | for (qx = 0; qx < num_qd; qx++) { |
786 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, | 787 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, |
787 | GL_NOCACHE, &ghs[qx]); | 788 | GL_NOCACHE, &ghs[qx]); |
@@ -811,13 +812,13 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
811 | * two blocks need to be updated instead of 1 */ | 812 | * two blocks need to be updated instead of 1 */ |
812 | blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; | 813 | blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; |
813 | 814 | ||
814 | error = gfs2_inplace_reserve(ip, 1 + | 815 | reserved = 1 + (nalloc * (data_blocks + ind_blocks)); |
815 | (nalloc * (data_blocks + ind_blocks))); | 816 | error = gfs2_inplace_reserve(ip, reserved); |
816 | if (error) | 817 | if (error) |
817 | goto out_alloc; | 818 | goto out_alloc; |
818 | 819 | ||
819 | if (nalloc) | 820 | if (nalloc) |
820 | blocks += gfs2_rg_blocks(ip) + nalloc * ind_blocks + RES_STATFS; | 821 | blocks += gfs2_rg_blocks(ip, reserved) + nalloc * ind_blocks + RES_STATFS; |
821 | 822 | ||
822 | error = gfs2_trans_begin(sdp, blocks, 0); | 823 | error = gfs2_trans_begin(sdp, blocks, 0); |
823 | if (error) | 824 | if (error) |
@@ -1070,8 +1071,10 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) | |||
1070 | 1071 | ||
1071 | if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { | 1072 | if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { |
1072 | print_message(qd, "exceeded"); | 1073 | print_message(qd, "exceeded"); |
1073 | quota_send_warning(test_bit(QDF_USER, &qd->qd_flags) ? | 1074 | quota_send_warning(make_kqid(&init_user_ns, |
1074 | USRQUOTA : GRPQUOTA, qd->qd_id, | 1075 | test_bit(QDF_USER, &qd->qd_flags) ? |
1076 | USRQUOTA : GRPQUOTA, | ||
1077 | qd->qd_id), | ||
1075 | sdp->sd_vfs->s_dev, QUOTA_NL_BHARDWARN); | 1078 | sdp->sd_vfs->s_dev, QUOTA_NL_BHARDWARN); |
1076 | 1079 | ||
1077 | error = -EDQUOT; | 1080 | error = -EDQUOT; |
@@ -1081,8 +1084,10 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) | |||
1081 | time_after_eq(jiffies, qd->qd_last_warn + | 1084 | time_after_eq(jiffies, qd->qd_last_warn + |
1082 | gfs2_tune_get(sdp, | 1085 | gfs2_tune_get(sdp, |
1083 | gt_quota_warn_period) * HZ)) { | 1086 | gt_quota_warn_period) * HZ)) { |
1084 | quota_send_warning(test_bit(QDF_USER, &qd->qd_flags) ? | 1087 | quota_send_warning(make_kqid(&init_user_ns, |
1085 | USRQUOTA : GRPQUOTA, qd->qd_id, | 1088 | test_bit(QDF_USER, &qd->qd_flags) ? |
1089 | USRQUOTA : GRPQUOTA, | ||
1090 | qd->qd_id), | ||
1086 | sdp->sd_vfs->s_dev, QUOTA_NL_BSOFTWARN); | 1091 | sdp->sd_vfs->s_dev, QUOTA_NL_BSOFTWARN); |
1087 | error = print_message(qd, "warning"); | 1092 | error = print_message(qd, "warning"); |
1088 | qd->qd_last_warn = jiffies; | 1093 | qd->qd_last_warn = jiffies; |
@@ -1469,7 +1474,7 @@ static int gfs2_quota_get_xstate(struct super_block *sb, | |||
1469 | return 0; | 1474 | return 0; |
1470 | } | 1475 | } |
1471 | 1476 | ||
1472 | static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id, | 1477 | static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid, |
1473 | struct fs_disk_quota *fdq) | 1478 | struct fs_disk_quota *fdq) |
1474 | { | 1479 | { |
1475 | struct gfs2_sbd *sdp = sb->s_fs_info; | 1480 | struct gfs2_sbd *sdp = sb->s_fs_info; |
@@ -1477,20 +1482,21 @@ static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id, | |||
1477 | struct gfs2_quota_data *qd; | 1482 | struct gfs2_quota_data *qd; |
1478 | struct gfs2_holder q_gh; | 1483 | struct gfs2_holder q_gh; |
1479 | int error; | 1484 | int error; |
1485 | int type; | ||
1480 | 1486 | ||
1481 | memset(fdq, 0, sizeof(struct fs_disk_quota)); | 1487 | memset(fdq, 0, sizeof(struct fs_disk_quota)); |
1482 | 1488 | ||
1483 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) | 1489 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
1484 | return -ESRCH; /* Crazy XFS error code */ | 1490 | return -ESRCH; /* Crazy XFS error code */ |
1485 | 1491 | ||
1486 | if (type == USRQUOTA) | 1492 | if (qid.type == USRQUOTA) |
1487 | type = QUOTA_USER; | 1493 | type = QUOTA_USER; |
1488 | else if (type == GRPQUOTA) | 1494 | else if (qid.type == GRPQUOTA) |
1489 | type = QUOTA_GROUP; | 1495 | type = QUOTA_GROUP; |
1490 | else | 1496 | else |
1491 | return -EINVAL; | 1497 | return -EINVAL; |
1492 | 1498 | ||
1493 | error = qd_get(sdp, type, id, &qd); | 1499 | error = qd_get(sdp, type, from_kqid(&init_user_ns, qid), &qd); |
1494 | if (error) | 1500 | if (error) |
1495 | return error; | 1501 | return error; |
1496 | error = do_glock(qd, FORCE, &q_gh); | 1502 | error = do_glock(qd, FORCE, &q_gh); |
@@ -1500,7 +1506,7 @@ static int gfs2_get_dqblk(struct super_block *sb, int type, qid_t id, | |||
1500 | qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; | 1506 | qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; |
1501 | fdq->d_version = FS_DQUOT_VERSION; | 1507 | fdq->d_version = FS_DQUOT_VERSION; |
1502 | fdq->d_flags = (type == QUOTA_USER) ? FS_USER_QUOTA : FS_GROUP_QUOTA; | 1508 | fdq->d_flags = (type == QUOTA_USER) ? FS_USER_QUOTA : FS_GROUP_QUOTA; |
1503 | fdq->d_id = id; | 1509 | fdq->d_id = from_kqid(&init_user_ns, qid); |
1504 | fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift; | 1510 | fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift; |
1505 | fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift; | 1511 | fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift; |
1506 | fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift; | 1512 | fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift; |
@@ -1514,7 +1520,7 @@ out: | |||
1514 | /* GFS2 only supports a subset of the XFS fields */ | 1520 | /* GFS2 only supports a subset of the XFS fields */ |
1515 | #define GFS2_FIELDMASK (FS_DQ_BSOFT|FS_DQ_BHARD|FS_DQ_BCOUNT) | 1521 | #define GFS2_FIELDMASK (FS_DQ_BSOFT|FS_DQ_BHARD|FS_DQ_BCOUNT) |
1516 | 1522 | ||
1517 | static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, | 1523 | static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid, |
1518 | struct fs_disk_quota *fdq) | 1524 | struct fs_disk_quota *fdq) |
1519 | { | 1525 | { |
1520 | struct gfs2_sbd *sdp = sb->s_fs_info; | 1526 | struct gfs2_sbd *sdp = sb->s_fs_info; |
@@ -1526,11 +1532,12 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, | |||
1526 | int alloc_required; | 1532 | int alloc_required; |
1527 | loff_t offset; | 1533 | loff_t offset; |
1528 | int error; | 1534 | int error; |
1535 | int type; | ||
1529 | 1536 | ||
1530 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) | 1537 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
1531 | return -ESRCH; /* Crazy XFS error code */ | 1538 | return -ESRCH; /* Crazy XFS error code */ |
1532 | 1539 | ||
1533 | switch(type) { | 1540 | switch(qid.type) { |
1534 | case USRQUOTA: | 1541 | case USRQUOTA: |
1535 | type = QUOTA_USER; | 1542 | type = QUOTA_USER; |
1536 | if (fdq->d_flags != FS_USER_QUOTA) | 1543 | if (fdq->d_flags != FS_USER_QUOTA) |
@@ -1547,10 +1554,10 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, | |||
1547 | 1554 | ||
1548 | if (fdq->d_fieldmask & ~GFS2_FIELDMASK) | 1555 | if (fdq->d_fieldmask & ~GFS2_FIELDMASK) |
1549 | return -EINVAL; | 1556 | return -EINVAL; |
1550 | if (fdq->d_id != id) | 1557 | if (fdq->d_id != from_kqid(&init_user_ns, qid)) |
1551 | return -EINVAL; | 1558 | return -EINVAL; |
1552 | 1559 | ||
1553 | error = qd_get(sdp, type, id, &qd); | 1560 | error = qd_get(sdp, type, from_kqid(&init_user_ns, qid), &qd); |
1554 | if (error) | 1561 | if (error) |
1555 | return error; | 1562 | return error; |
1556 | 1563 | ||
@@ -1598,7 +1605,7 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, | |||
1598 | error = gfs2_inplace_reserve(ip, blocks); | 1605 | error = gfs2_inplace_reserve(ip, blocks); |
1599 | if (error) | 1606 | if (error) |
1600 | goto out_i; | 1607 | goto out_i; |
1601 | blocks += gfs2_rg_blocks(ip); | 1608 | blocks += gfs2_rg_blocks(ip, blocks); |
1602 | } | 1609 | } |
1603 | 1610 | ||
1604 | /* Some quotas span block boundaries and can update two blocks, | 1611 | /* Some quotas span block boundaries and can update two blocks, |
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index c9ed814eeb6f..3cc402ce6fea 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -35,9 +35,6 @@ | |||
35 | #define BFITNOENT ((u32)~0) | 35 | #define BFITNOENT ((u32)~0) |
36 | #define NO_BLOCK ((u64)~0) | 36 | #define NO_BLOCK ((u64)~0) |
37 | 37 | ||
38 | #define RSRV_CONTENTION_FACTOR 4 | ||
39 | #define RGRP_RSRV_MAX_CONTENDERS 2 | ||
40 | |||
41 | #if BITS_PER_LONG == 32 | 38 | #if BITS_PER_LONG == 32 |
42 | #define LBITMASK (0x55555555UL) | 39 | #define LBITMASK (0x55555555UL) |
43 | #define LBITSKIP55 (0x55555555UL) | 40 | #define LBITSKIP55 (0x55555555UL) |
@@ -67,53 +64,48 @@ static const char valid_change[16] = { | |||
67 | 1, 0, 0, 0 | 64 | 1, 0, 0, 0 |
68 | }; | 65 | }; |
69 | 66 | ||
70 | static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, | 67 | static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, |
71 | unsigned char old_state, | 68 | const struct gfs2_inode *ip, bool nowrap); |
72 | struct gfs2_bitmap **rbi); | 69 | |
73 | 70 | ||
74 | /** | 71 | /** |
75 | * gfs2_setbit - Set a bit in the bitmaps | 72 | * gfs2_setbit - Set a bit in the bitmaps |
76 | * @rgd: the resource group descriptor | 73 | * @rbm: The position of the bit to set |
77 | * @buf2: the clone buffer that holds the bitmaps | 74 | * @do_clone: Also set the clone bitmap, if it exists |
78 | * @bi: the bitmap structure | ||
79 | * @block: the block to set | ||
80 | * @new_state: the new state of the block | 75 | * @new_state: the new state of the block |
81 | * | 76 | * |
82 | */ | 77 | */ |
83 | 78 | ||
84 | static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, | 79 | static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone, |
85 | struct gfs2_bitmap *bi, u32 block, | ||
86 | unsigned char new_state) | 80 | unsigned char new_state) |
87 | { | 81 | { |
88 | unsigned char *byte1, *byte2, *end, cur_state; | 82 | unsigned char *byte1, *byte2, *end, cur_state; |
89 | unsigned int buflen = bi->bi_len; | 83 | unsigned int buflen = rbm->bi->bi_len; |
90 | const unsigned int bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; | 84 | const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; |
91 | 85 | ||
92 | byte1 = bi->bi_bh->b_data + bi->bi_offset + (block / GFS2_NBBY); | 86 | byte1 = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY); |
93 | end = bi->bi_bh->b_data + bi->bi_offset + buflen; | 87 | end = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + buflen; |
94 | 88 | ||
95 | BUG_ON(byte1 >= end); | 89 | BUG_ON(byte1 >= end); |
96 | 90 | ||
97 | cur_state = (*byte1 >> bit) & GFS2_BIT_MASK; | 91 | cur_state = (*byte1 >> bit) & GFS2_BIT_MASK; |
98 | 92 | ||
99 | if (unlikely(!valid_change[new_state * 4 + cur_state])) { | 93 | if (unlikely(!valid_change[new_state * 4 + cur_state])) { |
100 | printk(KERN_WARNING "GFS2: buf_blk = 0x%llx old_state=%d, " | 94 | printk(KERN_WARNING "GFS2: buf_blk = 0x%x old_state=%d, " |
101 | "new_state=%d\n", | 95 | "new_state=%d\n", rbm->offset, cur_state, new_state); |
102 | (unsigned long long)block, cur_state, new_state); | 96 | printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%x\n", |
103 | printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%lx\n", | 97 | (unsigned long long)rbm->rgd->rd_addr, |
104 | (unsigned long long)rgd->rd_addr, | 98 | rbm->bi->bi_start); |
105 | (unsigned long)bi->bi_start); | 99 | printk(KERN_WARNING "GFS2: bi_offset=0x%x bi_len=0x%x\n", |
106 | printk(KERN_WARNING "GFS2: bi_offset=0x%lx bi_len=0x%lx\n", | 100 | rbm->bi->bi_offset, rbm->bi->bi_len); |
107 | (unsigned long)bi->bi_offset, | ||
108 | (unsigned long)bi->bi_len); | ||
109 | dump_stack(); | 101 | dump_stack(); |
110 | gfs2_consist_rgrpd(rgd); | 102 | gfs2_consist_rgrpd(rbm->rgd); |
111 | return; | 103 | return; |
112 | } | 104 | } |
113 | *byte1 ^= (cur_state ^ new_state) << bit; | 105 | *byte1 ^= (cur_state ^ new_state) << bit; |
114 | 106 | ||
115 | if (buf2) { | 107 | if (do_clone && rbm->bi->bi_clone) { |
116 | byte2 = buf2 + bi->bi_offset + (block / GFS2_NBBY); | 108 | byte2 = rbm->bi->bi_clone + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY); |
117 | cur_state = (*byte2 >> bit) & GFS2_BIT_MASK; | 109 | cur_state = (*byte2 >> bit) & GFS2_BIT_MASK; |
118 | *byte2 ^= (cur_state ^ new_state) << bit; | 110 | *byte2 ^= (cur_state ^ new_state) << bit; |
119 | } | 111 | } |
@@ -121,30 +113,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, | |||
121 | 113 | ||
122 | /** | 114 | /** |
123 | * gfs2_testbit - test a bit in the bitmaps | 115 | * gfs2_testbit - test a bit in the bitmaps |
124 | * @rgd: the resource group descriptor | 116 | * @rbm: The bit to test |
125 | * @buffer: the buffer that holds the bitmaps | ||
126 | * @buflen: the length (in bytes) of the buffer | ||
127 | * @block: the block to read | ||
128 | * | 117 | * |
118 | * Returns: The two bit block state of the requested bit | ||
129 | */ | 119 | */ |
130 | 120 | ||
131 | static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, | 121 | static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm) |
132 | const unsigned char *buffer, | ||
133 | unsigned int buflen, u32 block) | ||
134 | { | 122 | { |
135 | const unsigned char *byte, *end; | 123 | const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset; |
136 | unsigned char cur_state; | 124 | const u8 *byte; |
137 | unsigned int bit; | 125 | unsigned int bit; |
138 | 126 | ||
139 | byte = buffer + (block / GFS2_NBBY); | 127 | byte = buffer + (rbm->offset / GFS2_NBBY); |
140 | bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; | 128 | bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; |
141 | end = buffer + buflen; | ||
142 | |||
143 | gfs2_assert(rgd->rd_sbd, byte < end); | ||
144 | 129 | ||
145 | cur_state = (*byte >> bit) & GFS2_BIT_MASK; | 130 | return (*byte >> bit) & GFS2_BIT_MASK; |
146 | |||
147 | return cur_state; | ||
148 | } | 131 | } |
149 | 132 | ||
150 | /** | 133 | /** |
@@ -192,7 +175,7 @@ static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state) | |||
192 | */ | 175 | */ |
193 | static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) | 176 | static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) |
194 | { | 177 | { |
195 | u64 startblk = gfs2_rs_startblk(rs); | 178 | u64 startblk = gfs2_rbm_to_block(&rs->rs_rbm); |
196 | 179 | ||
197 | if (blk >= startblk + rs->rs_free) | 180 | if (blk >= startblk + rs->rs_free) |
198 | return 1; | 181 | return 1; |
@@ -202,36 +185,6 @@ static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) | |||
202 | } | 185 | } |
203 | 186 | ||
204 | /** | 187 | /** |
205 | * rs_find - Find a rgrp multi-block reservation that contains a given block | ||
206 | * @rgd: The rgrp | ||
207 | * @rgblk: The block we're looking for, relative to the rgrp | ||
208 | */ | ||
209 | static struct gfs2_blkreserv *rs_find(struct gfs2_rgrpd *rgd, u32 rgblk) | ||
210 | { | ||
211 | struct rb_node **newn; | ||
212 | int rc; | ||
213 | u64 fsblk = rgblk + rgd->rd_data0; | ||
214 | |||
215 | spin_lock(&rgd->rd_rsspin); | ||
216 | newn = &rgd->rd_rstree.rb_node; | ||
217 | while (*newn) { | ||
218 | struct gfs2_blkreserv *cur = | ||
219 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); | ||
220 | rc = rs_cmp(fsblk, 1, cur); | ||
221 | if (rc < 0) | ||
222 | newn = &((*newn)->rb_left); | ||
223 | else if (rc > 0) | ||
224 | newn = &((*newn)->rb_right); | ||
225 | else { | ||
226 | spin_unlock(&rgd->rd_rsspin); | ||
227 | return cur; | ||
228 | } | ||
229 | } | ||
230 | spin_unlock(&rgd->rd_rsspin); | ||
231 | return NULL; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing | 188 | * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing |
236 | * a block in a given allocation state. | 189 | * a block in a given allocation state. |
237 | * @buf: the buffer that holds the bitmaps | 190 | * @buf: the buffer that holds the bitmaps |
@@ -262,8 +215,6 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len, | |||
262 | u64 mask = 0x5555555555555555ULL; | 215 | u64 mask = 0x5555555555555555ULL; |
263 | u32 bit; | 216 | u32 bit; |
264 | 217 | ||
265 | BUG_ON(state > 3); | ||
266 | |||
267 | /* Mask off bits we don't care about at the start of the search */ | 218 | /* Mask off bits we don't care about at the start of the search */ |
268 | mask <<= spoint; | 219 | mask <<= spoint; |
269 | tmp = gfs2_bit_search(ptr, mask, state); | 220 | tmp = gfs2_bit_search(ptr, mask, state); |
@@ -285,6 +236,131 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len, | |||
285 | } | 236 | } |
286 | 237 | ||
287 | /** | 238 | /** |
239 | * gfs2_rbm_from_block - Set the rbm based upon rgd and block number | ||
240 | * @rbm: The rbm with rgd already set correctly | ||
241 | * @block: The block number (filesystem relative) | ||
242 | * | ||
243 | * This sets the bi and offset members of an rbm based on a | ||
244 | * resource group and a filesystem relative block number. The | ||
245 | * resource group must be set in the rbm on entry, the bi and | ||
246 | * offset members will be set by this function. | ||
247 | * | ||
248 | * Returns: 0 on success, or an error code | ||
249 | */ | ||
250 | |||
251 | static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) | ||
252 | { | ||
253 | u64 rblock = block - rbm->rgd->rd_data0; | ||
254 | u32 goal = (u32)rblock; | ||
255 | int x; | ||
256 | |||
257 | if (WARN_ON_ONCE(rblock > UINT_MAX)) | ||
258 | return -EINVAL; | ||
259 | if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data) | ||
260 | return -E2BIG; | ||
261 | |||
262 | for (x = 0; x < rbm->rgd->rd_length; x++) { | ||
263 | rbm->bi = rbm->rgd->rd_bits + x; | ||
264 | if (goal < (rbm->bi->bi_start + rbm->bi->bi_len) * GFS2_NBBY) { | ||
265 | rbm->offset = goal - (rbm->bi->bi_start * GFS2_NBBY); | ||
266 | break; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned | ||
275 | * @rbm: Position to search (value/result) | ||
276 | * @n_unaligned: Number of unaligned blocks to check | ||
277 | * @len: Decremented for each block found (terminate on zero) | ||
278 | * | ||
279 | * Returns: true if a non-free block is encountered | ||
280 | */ | ||
281 | |||
282 | static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *len) | ||
283 | { | ||
284 | u64 block; | ||
285 | u32 n; | ||
286 | u8 res; | ||
287 | |||
288 | for (n = 0; n < n_unaligned; n++) { | ||
289 | res = gfs2_testbit(rbm); | ||
290 | if (res != GFS2_BLKST_FREE) | ||
291 | return true; | ||
292 | (*len)--; | ||
293 | if (*len == 0) | ||
294 | return true; | ||
295 | block = gfs2_rbm_to_block(rbm); | ||
296 | if (gfs2_rbm_from_block(rbm, block + 1)) | ||
297 | return true; | ||
298 | } | ||
299 | |||
300 | return false; | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * gfs2_free_extlen - Return extent length of free blocks | ||
305 | * @rbm: Starting position | ||
306 | * @len: Max length to check | ||
307 | * | ||
308 | * Starting at the block specified by the rbm, see how many free blocks | ||
309 | * there are, not reading more than len blocks ahead. This can be done | ||
310 | * using memchr_inv when the blocks are byte aligned, but has to be done | ||
311 | * on a block by block basis in case of unaligned blocks. Also this | ||
312 | * function can cope with bitmap boundaries (although it must stop on | ||
313 | * a resource group boundary) | ||
314 | * | ||
315 | * Returns: Number of free blocks in the extent | ||
316 | */ | ||
317 | |||
318 | static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len) | ||
319 | { | ||
320 | struct gfs2_rbm rbm = *rrbm; | ||
321 | u32 n_unaligned = rbm.offset & 3; | ||
322 | u32 size = len; | ||
323 | u32 bytes; | ||
324 | u32 chunk_size; | ||
325 | u8 *ptr, *start, *end; | ||
326 | u64 block; | ||
327 | |||
328 | if (n_unaligned && | ||
329 | gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len)) | ||
330 | goto out; | ||
331 | |||
332 | n_unaligned = len & 3; | ||
333 | /* Start is now byte aligned */ | ||
334 | while (len > 3) { | ||
335 | start = rbm.bi->bi_bh->b_data; | ||
336 | if (rbm.bi->bi_clone) | ||
337 | start = rbm.bi->bi_clone; | ||
338 | end = start + rbm.bi->bi_bh->b_size; | ||
339 | start += rbm.bi->bi_offset; | ||
340 | BUG_ON(rbm.offset & 3); | ||
341 | start += (rbm.offset / GFS2_NBBY); | ||
342 | bytes = min_t(u32, len / GFS2_NBBY, (end - start)); | ||
343 | ptr = memchr_inv(start, 0, bytes); | ||
344 | chunk_size = ((ptr == NULL) ? bytes : (ptr - start)); | ||
345 | chunk_size *= GFS2_NBBY; | ||
346 | BUG_ON(len < chunk_size); | ||
347 | len -= chunk_size; | ||
348 | block = gfs2_rbm_to_block(&rbm); | ||
349 | gfs2_rbm_from_block(&rbm, block + chunk_size); | ||
350 | n_unaligned = 3; | ||
351 | if (ptr) | ||
352 | break; | ||
353 | n_unaligned = len & 3; | ||
354 | } | ||
355 | |||
356 | /* Deal with any bits left over at the end */ | ||
357 | if (n_unaligned) | ||
358 | gfs2_unaligned_extlen(&rbm, n_unaligned, &len); | ||
359 | out: | ||
360 | return size - len; | ||
361 | } | ||
362 | |||
363 | /** | ||
288 | * gfs2_bitcount - count the number of bits in a certain state | 364 | * gfs2_bitcount - count the number of bits in a certain state |
289 | * @rgd: the resource group descriptor | 365 | * @rgd: the resource group descriptor |
290 | * @buffer: the buffer that holds the bitmaps | 366 | * @buffer: the buffer that holds the bitmaps |
@@ -487,6 +563,8 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
487 | if (!res) | 563 | if (!res) |
488 | error = -ENOMEM; | 564 | error = -ENOMEM; |
489 | 565 | ||
566 | RB_CLEAR_NODE(&res->rs_node); | ||
567 | |||
490 | down_write(&ip->i_rw_mutex); | 568 | down_write(&ip->i_rw_mutex); |
491 | if (ip->i_res) | 569 | if (ip->i_res) |
492 | kmem_cache_free(gfs2_rsrv_cachep, res); | 570 | kmem_cache_free(gfs2_rsrv_cachep, res); |
@@ -496,11 +574,12 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
496 | return error; | 574 | return error; |
497 | } | 575 | } |
498 | 576 | ||
499 | static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | 577 | static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs) |
500 | { | 578 | { |
501 | gfs2_print_dbg(seq, " r: %llu s:%llu b:%u f:%u\n", | 579 | gfs2_print_dbg(seq, " B: n:%llu s:%llu b:%u f:%u\n", |
502 | rs->rs_rgd->rd_addr, gfs2_rs_startblk(rs), rs->rs_biblk, | 580 | (unsigned long long)rs->rs_inum, |
503 | rs->rs_free); | 581 | (unsigned long long)gfs2_rbm_to_block(&rs->rs_rbm), |
582 | rs->rs_rbm.offset, rs->rs_free); | ||
504 | } | 583 | } |
505 | 584 | ||
506 | /** | 585 | /** |
@@ -508,41 +587,26 @@ static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | |||
508 | * @rs: The reservation to remove | 587 | * @rs: The reservation to remove |
509 | * | 588 | * |
510 | */ | 589 | */ |
511 | static void __rs_deltree(struct gfs2_blkreserv *rs) | 590 | static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) |
512 | { | 591 | { |
513 | struct gfs2_rgrpd *rgd; | 592 | struct gfs2_rgrpd *rgd; |
514 | 593 | ||
515 | if (!gfs2_rs_active(rs)) | 594 | if (!gfs2_rs_active(rs)) |
516 | return; | 595 | return; |
517 | 596 | ||
518 | rgd = rs->rs_rgd; | 597 | rgd = rs->rs_rbm.rgd; |
519 | /* We can't do this: The reason is that when the rgrp is invalidated, | 598 | trace_gfs2_rs(rs, TRACE_RS_TREEDEL); |
520 | it's in the "middle" of acquiring the glock, but the HOLDER bit | 599 | rb_erase(&rs->rs_node, &rgd->rd_rstree); |
521 | isn't set yet: | 600 | RB_CLEAR_NODE(&rs->rs_node); |
522 | BUG_ON(!gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl));*/ | ||
523 | trace_gfs2_rs(NULL, rs, TRACE_RS_TREEDEL); | ||
524 | |||
525 | if (!RB_EMPTY_ROOT(&rgd->rd_rstree)) | ||
526 | rb_erase(&rs->rs_node, &rgd->rd_rstree); | ||
527 | BUG_ON(!rgd->rd_rs_cnt); | ||
528 | rgd->rd_rs_cnt--; | ||
529 | 601 | ||
530 | if (rs->rs_free) { | 602 | if (rs->rs_free) { |
531 | /* return reserved blocks to the rgrp and the ip */ | 603 | /* return reserved blocks to the rgrp and the ip */ |
532 | BUG_ON(rs->rs_rgd->rd_reserved < rs->rs_free); | 604 | BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); |
533 | rs->rs_rgd->rd_reserved -= rs->rs_free; | 605 | rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; |
534 | rs->rs_free = 0; | 606 | rs->rs_free = 0; |
535 | clear_bit(GBF_FULL, &rs->rs_bi->bi_flags); | 607 | clear_bit(GBF_FULL, &rs->rs_rbm.bi->bi_flags); |
536 | smp_mb__after_clear_bit(); | 608 | smp_mb__after_clear_bit(); |
537 | } | 609 | } |
538 | /* We can't change any of the step 1 or step 2 components of the rs. | ||
539 | E.g. We can't set rs_rgd to NULL because the rgd glock is held and | ||
540 | dequeued through this pointer. | ||
541 | Can't: atomic_set(&rs->rs_sizehint, 0); | ||
542 | Can't: rs->rs_requested = 0; | ||
543 | Can't: rs->rs_rgd = NULL;*/ | ||
544 | rs->rs_bi = NULL; | ||
545 | rs->rs_biblk = 0; | ||
546 | } | 610 | } |
547 | 611 | ||
548 | /** | 612 | /** |
@@ -550,17 +614,16 @@ static void __rs_deltree(struct gfs2_blkreserv *rs) | |||
550 | * @rs: The reservation to remove | 614 | * @rs: The reservation to remove |
551 | * | 615 | * |
552 | */ | 616 | */ |
553 | void gfs2_rs_deltree(struct gfs2_blkreserv *rs) | 617 | void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) |
554 | { | 618 | { |
555 | struct gfs2_rgrpd *rgd; | 619 | struct gfs2_rgrpd *rgd; |
556 | 620 | ||
557 | if (!gfs2_rs_active(rs)) | 621 | rgd = rs->rs_rbm.rgd; |
558 | return; | 622 | if (rgd) { |
559 | 623 | spin_lock(&rgd->rd_rsspin); | |
560 | rgd = rs->rs_rgd; | 624 | __rs_deltree(ip, rs); |
561 | spin_lock(&rgd->rd_rsspin); | 625 | spin_unlock(&rgd->rd_rsspin); |
562 | __rs_deltree(rs); | 626 | } |
563 | spin_unlock(&rgd->rd_rsspin); | ||
564 | } | 627 | } |
565 | 628 | ||
566 | /** | 629 | /** |
@@ -572,8 +635,7 @@ void gfs2_rs_delete(struct gfs2_inode *ip) | |||
572 | { | 635 | { |
573 | down_write(&ip->i_rw_mutex); | 636 | down_write(&ip->i_rw_mutex); |
574 | if (ip->i_res) { | 637 | if (ip->i_res) { |
575 | gfs2_rs_deltree(ip->i_res); | 638 | gfs2_rs_deltree(ip, ip->i_res); |
576 | trace_gfs2_rs(ip, ip->i_res, TRACE_RS_DELETE); | ||
577 | BUG_ON(ip->i_res->rs_free); | 639 | BUG_ON(ip->i_res->rs_free); |
578 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); | 640 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); |
579 | ip->i_res = NULL; | 641 | ip->i_res = NULL; |
@@ -597,7 +659,7 @@ static void return_all_reservations(struct gfs2_rgrpd *rgd) | |||
597 | spin_lock(&rgd->rd_rsspin); | 659 | spin_lock(&rgd->rd_rsspin); |
598 | while ((n = rb_first(&rgd->rd_rstree))) { | 660 | while ((n = rb_first(&rgd->rd_rstree))) { |
599 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); | 661 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); |
600 | __rs_deltree(rs); | 662 | __rs_deltree(NULL, rs); |
601 | } | 663 | } |
602 | spin_unlock(&rgd->rd_rsspin); | 664 | spin_unlock(&rgd->rd_rsspin); |
603 | } | 665 | } |
@@ -1270,211 +1332,276 @@ out: | |||
1270 | 1332 | ||
1271 | /** | 1333 | /** |
1272 | * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree | 1334 | * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree |
1273 | * @bi: the bitmap with the blocks | ||
1274 | * @ip: the inode structure | 1335 | * @ip: the inode structure |
1275 | * @biblk: the 32-bit block number relative to the start of the bitmap | ||
1276 | * @amount: the number of blocks to reserve | ||
1277 | * | 1336 | * |
1278 | * Returns: NULL - reservation was already taken, so not inserted | ||
1279 | * pointer to the inserted reservation | ||
1280 | */ | 1337 | */ |
1281 | static struct gfs2_blkreserv *rs_insert(struct gfs2_bitmap *bi, | 1338 | static void rs_insert(struct gfs2_inode *ip) |
1282 | struct gfs2_inode *ip, u32 biblk, | ||
1283 | int amount) | ||
1284 | { | 1339 | { |
1285 | struct rb_node **newn, *parent = NULL; | 1340 | struct rb_node **newn, *parent = NULL; |
1286 | int rc; | 1341 | int rc; |
1287 | struct gfs2_blkreserv *rs = ip->i_res; | 1342 | struct gfs2_blkreserv *rs = ip->i_res; |
1288 | struct gfs2_rgrpd *rgd = rs->rs_rgd; | 1343 | struct gfs2_rgrpd *rgd = rs->rs_rbm.rgd; |
1289 | u64 fsblock = gfs2_bi2rgd_blk(bi, biblk) + rgd->rd_data0; | 1344 | u64 fsblock = gfs2_rbm_to_block(&rs->rs_rbm); |
1345 | |||
1346 | BUG_ON(gfs2_rs_active(rs)); | ||
1290 | 1347 | ||
1291 | spin_lock(&rgd->rd_rsspin); | 1348 | spin_lock(&rgd->rd_rsspin); |
1292 | newn = &rgd->rd_rstree.rb_node; | 1349 | newn = &rgd->rd_rstree.rb_node; |
1293 | BUG_ON(!ip->i_res); | ||
1294 | BUG_ON(gfs2_rs_active(rs)); | ||
1295 | /* Figure out where to put new node */ | ||
1296 | /*BUG_ON(!gfs2_glock_is_locked_by_me(rgd->rd_gl));*/ | ||
1297 | while (*newn) { | 1350 | while (*newn) { |
1298 | struct gfs2_blkreserv *cur = | 1351 | struct gfs2_blkreserv *cur = |
1299 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); | 1352 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); |
1300 | 1353 | ||
1301 | parent = *newn; | 1354 | parent = *newn; |
1302 | rc = rs_cmp(fsblock, amount, cur); | 1355 | rc = rs_cmp(fsblock, rs->rs_free, cur); |
1303 | if (rc > 0) | 1356 | if (rc > 0) |
1304 | newn = &((*newn)->rb_right); | 1357 | newn = &((*newn)->rb_right); |
1305 | else if (rc < 0) | 1358 | else if (rc < 0) |
1306 | newn = &((*newn)->rb_left); | 1359 | newn = &((*newn)->rb_left); |
1307 | else { | 1360 | else { |
1308 | spin_unlock(&rgd->rd_rsspin); | 1361 | spin_unlock(&rgd->rd_rsspin); |
1309 | return NULL; /* reservation already in use */ | 1362 | WARN_ON(1); |
1363 | return; | ||
1310 | } | 1364 | } |
1311 | } | 1365 | } |
1312 | 1366 | ||
1313 | /* Do our reservation work */ | ||
1314 | rs = ip->i_res; | ||
1315 | rs->rs_free = amount; | ||
1316 | rs->rs_biblk = biblk; | ||
1317 | rs->rs_bi = bi; | ||
1318 | rb_link_node(&rs->rs_node, parent, newn); | 1367 | rb_link_node(&rs->rs_node, parent, newn); |
1319 | rb_insert_color(&rs->rs_node, &rgd->rd_rstree); | 1368 | rb_insert_color(&rs->rs_node, &rgd->rd_rstree); |
1320 | 1369 | ||
1321 | /* Do our inode accounting for the reservation */ | ||
1322 | /*BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));*/ | ||
1323 | |||
1324 | /* Do our rgrp accounting for the reservation */ | 1370 | /* Do our rgrp accounting for the reservation */ |
1325 | rgd->rd_reserved += amount; /* blocks reserved */ | 1371 | rgd->rd_reserved += rs->rs_free; /* blocks reserved */ |
1326 | rgd->rd_rs_cnt++; /* number of in-tree reservations */ | ||
1327 | spin_unlock(&rgd->rd_rsspin); | 1372 | spin_unlock(&rgd->rd_rsspin); |
1328 | trace_gfs2_rs(ip, rs, TRACE_RS_INSERT); | 1373 | trace_gfs2_rs(rs, TRACE_RS_INSERT); |
1329 | return rs; | ||
1330 | } | ||
1331 | |||
1332 | /** | ||
1333 | * unclaimed_blocks - return number of blocks that aren't spoken for | ||
1334 | */ | ||
1335 | static u32 unclaimed_blocks(struct gfs2_rgrpd *rgd) | ||
1336 | { | ||
1337 | return rgd->rd_free_clone - rgd->rd_reserved; | ||
1338 | } | 1374 | } |
1339 | 1375 | ||
1340 | /** | 1376 | /** |
1341 | * rg_mblk_search - find a group of multiple free blocks | 1377 | * rg_mblk_search - find a group of multiple free blocks to form a reservation |
1342 | * @rgd: the resource group descriptor | 1378 | * @rgd: the resource group descriptor |
1343 | * @rs: the block reservation | ||
1344 | * @ip: pointer to the inode for which we're reserving blocks | 1379 | * @ip: pointer to the inode for which we're reserving blocks |
1380 | * @requested: number of blocks required for this allocation | ||
1345 | * | 1381 | * |
1346 | * This is very similar to rgblk_search, except we're looking for whole | ||
1347 | * 64-bit words that represent a chunk of 32 free blocks. I'm only focusing | ||
1348 | * on aligned dwords for speed's sake. | ||
1349 | * | ||
1350 | * Returns: 0 if successful or BFITNOENT if there isn't enough free space | ||
1351 | */ | 1382 | */ |
1352 | 1383 | ||
1353 | static int rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | 1384 | static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip, |
1385 | unsigned requested) | ||
1354 | { | 1386 | { |
1355 | struct gfs2_bitmap *bi = rgd->rd_bits; | 1387 | struct gfs2_rbm rbm = { .rgd = rgd, }; |
1356 | const u32 length = rgd->rd_length; | 1388 | u64 goal; |
1357 | u32 blk; | 1389 | struct gfs2_blkreserv *rs = ip->i_res; |
1358 | unsigned int buf, x, search_bytes; | 1390 | u32 extlen; |
1359 | u8 *buffer = NULL; | 1391 | u32 free_blocks = rgd->rd_free_clone - rgd->rd_reserved; |
1360 | u8 *ptr, *end, *nonzero; | 1392 | int ret; |
1361 | u32 goal, rsv_bytes; | 1393 | |
1362 | struct gfs2_blkreserv *rs; | 1394 | extlen = max_t(u32, atomic_read(&rs->rs_sizehint), requested); |
1363 | u32 best_rs_bytes, unclaimed; | 1395 | extlen = clamp(extlen, RGRP_RSRV_MINBLKS, free_blocks); |
1364 | int best_rs_blocks; | 1396 | if ((rgd->rd_free_clone < rgd->rd_reserved) || (free_blocks < extlen)) |
1397 | return; | ||
1365 | 1398 | ||
1366 | /* Find bitmap block that contains bits for goal block */ | 1399 | /* Find bitmap block that contains bits for goal block */ |
1367 | if (rgrp_contains_block(rgd, ip->i_goal)) | 1400 | if (rgrp_contains_block(rgd, ip->i_goal)) |
1368 | goal = ip->i_goal - rgd->rd_data0; | 1401 | goal = ip->i_goal; |
1369 | else | 1402 | else |
1370 | goal = rgd->rd_last_alloc; | 1403 | goal = rgd->rd_last_alloc + rgd->rd_data0; |
1371 | for (buf = 0; buf < length; buf++) { | 1404 | |
1372 | bi = rgd->rd_bits + buf; | 1405 | if (WARN_ON(gfs2_rbm_from_block(&rbm, goal))) |
1373 | /* Convert scope of "goal" from rgrp-wide to within | 1406 | return; |
1374 | found bit block */ | 1407 | |
1375 | if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) { | 1408 | ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, extlen, ip, true); |
1376 | goal -= bi->bi_start * GFS2_NBBY; | 1409 | if (ret == 0) { |
1377 | goto do_search; | 1410 | rs->rs_rbm = rbm; |
1378 | } | 1411 | rs->rs_free = extlen; |
1412 | rs->rs_inum = ip->i_no_addr; | ||
1413 | rs_insert(ip); | ||
1379 | } | 1414 | } |
1380 | buf = 0; | 1415 | } |
1381 | goal = 0; | 1416 | |
1382 | 1417 | /** | |
1383 | do_search: | 1418 | * gfs2_next_unreserved_block - Return next block that is not reserved |
1384 | best_rs_blocks = max_t(int, atomic_read(&ip->i_res->rs_sizehint), | 1419 | * @rgd: The resource group |
1385 | (RGRP_RSRV_MINBLKS * rgd->rd_length)); | 1420 | * @block: The starting block |
1386 | best_rs_bytes = (best_rs_blocks * | 1421 | * @length: The required length |
1387 | (1 + (RSRV_CONTENTION_FACTOR * rgd->rd_rs_cnt))) / | 1422 | * @ip: Ignore any reservations for this inode |
1388 | GFS2_NBBY; /* 1 + is for our not-yet-created reservation */ | 1423 | * |
1389 | best_rs_bytes = ALIGN(best_rs_bytes, sizeof(u64)); | 1424 | * If the block does not appear in any reservation, then return the |
1390 | unclaimed = unclaimed_blocks(rgd); | 1425 | * block number unchanged. If it does appear in the reservation, then |
1391 | if (best_rs_bytes * GFS2_NBBY > unclaimed) | 1426 | * keep looking through the tree of reservations in order to find the |
1392 | best_rs_bytes = unclaimed >> GFS2_BIT_SIZE; | 1427 | * first block number which is not reserved. |
1393 | 1428 | */ | |
1394 | for (x = 0; x <= length; x++) { | ||
1395 | bi = rgd->rd_bits + buf; | ||
1396 | 1429 | ||
1397 | if (test_bit(GBF_FULL, &bi->bi_flags)) | 1430 | static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block, |
1398 | goto skip; | 1431 | u32 length, |
1432 | const struct gfs2_inode *ip) | ||
1433 | { | ||
1434 | struct gfs2_blkreserv *rs; | ||
1435 | struct rb_node *n; | ||
1436 | int rc; | ||
1399 | 1437 | ||
1400 | WARN_ON(!buffer_uptodate(bi->bi_bh)); | 1438 | spin_lock(&rgd->rd_rsspin); |
1401 | if (bi->bi_clone) | 1439 | n = rgd->rd_rstree.rb_node; |
1402 | buffer = bi->bi_clone + bi->bi_offset; | 1440 | while (n) { |
1441 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); | ||
1442 | rc = rs_cmp(block, length, rs); | ||
1443 | if (rc < 0) | ||
1444 | n = n->rb_left; | ||
1445 | else if (rc > 0) | ||
1446 | n = n->rb_right; | ||
1403 | else | 1447 | else |
1404 | buffer = bi->bi_bh->b_data + bi->bi_offset; | 1448 | break; |
1405 | 1449 | } | |
1406 | /* We have to keep the reservations aligned on u64 boundaries | 1450 | |
1407 | otherwise we could get situations where a byte can't be | 1451 | if (n) { |
1408 | used because it's after a reservation, but a free bit still | 1452 | while ((rs_cmp(block, length, rs) == 0) && (ip->i_res != rs)) { |
1409 | is within the reservation's area. */ | 1453 | block = gfs2_rbm_to_block(&rs->rs_rbm) + rs->rs_free; |
1410 | ptr = buffer + ALIGN(goal >> GFS2_BIT_SIZE, sizeof(u64)); | 1454 | n = n->rb_right; |
1411 | end = (buffer + bi->bi_len); | 1455 | if (n == NULL) |
1412 | while (ptr < end) { | 1456 | break; |
1413 | rsv_bytes = 0; | 1457 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); |
1414 | if ((ptr + best_rs_bytes) <= end) | ||
1415 | search_bytes = best_rs_bytes; | ||
1416 | else | ||
1417 | search_bytes = end - ptr; | ||
1418 | BUG_ON(!search_bytes); | ||
1419 | nonzero = memchr_inv(ptr, 0, search_bytes); | ||
1420 | /* If the lot is all zeroes, reserve the whole size. If | ||
1421 | there's enough zeroes to satisfy the request, use | ||
1422 | what we can. If there's not enough, keep looking. */ | ||
1423 | if (nonzero == NULL) | ||
1424 | rsv_bytes = search_bytes; | ||
1425 | else if ((nonzero - ptr) * GFS2_NBBY >= | ||
1426 | ip->i_res->rs_requested) | ||
1427 | rsv_bytes = (nonzero - ptr); | ||
1428 | |||
1429 | if (rsv_bytes) { | ||
1430 | blk = ((ptr - buffer) * GFS2_NBBY); | ||
1431 | BUG_ON(blk >= bi->bi_len * GFS2_NBBY); | ||
1432 | rs = rs_insert(bi, ip, blk, | ||
1433 | rsv_bytes * GFS2_NBBY); | ||
1434 | if (IS_ERR(rs)) | ||
1435 | return PTR_ERR(rs); | ||
1436 | if (rs) | ||
1437 | return 0; | ||
1438 | } | ||
1439 | ptr += ALIGN(search_bytes, sizeof(u64)); | ||
1440 | } | 1458 | } |
1441 | skip: | ||
1442 | /* Try next bitmap block (wrap back to rgrp header | ||
1443 | if at end) */ | ||
1444 | buf++; | ||
1445 | buf %= length; | ||
1446 | goal = 0; | ||
1447 | } | 1459 | } |
1448 | 1460 | ||
1449 | return BFITNOENT; | 1461 | spin_unlock(&rgd->rd_rsspin); |
1462 | return block; | ||
1450 | } | 1463 | } |
1451 | 1464 | ||
1452 | /** | 1465 | /** |
1453 | * try_rgrp_fit - See if a given reservation will fit in a given RG | 1466 | * gfs2_reservation_check_and_update - Check for reservations during block alloc |
1454 | * @rgd: the RG data | 1467 | * @rbm: The current position in the resource group |
1455 | * @ip: the inode | 1468 | * @ip: The inode for which we are searching for blocks |
1469 | * @minext: The minimum extent length | ||
1456 | * | 1470 | * |
1457 | * If there's room for the requested blocks to be allocated from the RG: | 1471 | * This checks the current position in the rgrp to see whether there is |
1458 | * This will try to get a multi-block reservation first, and if that doesn't | 1472 | * a reservation covering this block. If not then this function is a |
1459 | * fit, it will take what it can. | 1473 | * no-op. If there is, then the position is moved to the end of the |
1474 | * contiguous reservation(s) so that we are pointing at the first | ||
1475 | * non-reserved block. | ||
1460 | * | 1476 | * |
1461 | * Returns: 1 on success (it fits), 0 on failure (it doesn't fit) | 1477 | * Returns: 0 if no reservation, 1 if @rbm has changed, otherwise an error |
1462 | */ | 1478 | */ |
1463 | 1479 | ||
1464 | static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | 1480 | static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm, |
1481 | const struct gfs2_inode *ip, | ||
1482 | u32 minext) | ||
1465 | { | 1483 | { |
1466 | struct gfs2_blkreserv *rs = ip->i_res; | 1484 | u64 block = gfs2_rbm_to_block(rbm); |
1485 | u32 extlen = 1; | ||
1486 | u64 nblock; | ||
1487 | int ret; | ||
1467 | 1488 | ||
1468 | if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) | 1489 | /* |
1490 | * If we have a minimum extent length, then skip over any extent | ||
1491 | * which is less than the min extent length in size. | ||
1492 | */ | ||
1493 | if (minext) { | ||
1494 | extlen = gfs2_free_extlen(rbm, minext); | ||
1495 | nblock = block + extlen; | ||
1496 | if (extlen < minext) | ||
1497 | goto fail; | ||
1498 | } | ||
1499 | |||
1500 | /* | ||
1501 | * Check the extent which has been found against the reservations | ||
1502 | * and skip if parts of it are already reserved | ||
1503 | */ | ||
1504 | nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip); | ||
1505 | if (nblock == block) | ||
1469 | return 0; | 1506 | return 0; |
1470 | /* Look for a multi-block reservation. */ | 1507 | fail: |
1471 | if (unclaimed_blocks(rgd) >= RGRP_RSRV_MINBLKS && | 1508 | ret = gfs2_rbm_from_block(rbm, nblock); |
1472 | rg_mblk_search(rgd, ip) != BFITNOENT) | 1509 | if (ret < 0) |
1473 | return 1; | 1510 | return ret; |
1474 | if (unclaimed_blocks(rgd) >= rs->rs_requested) | 1511 | return 1; |
1475 | return 1; | 1512 | } |
1476 | 1513 | ||
1477 | return 0; | 1514 | /** |
1515 | * gfs2_rbm_find - Look for blocks of a particular state | ||
1516 | * @rbm: Value/result starting position and final position | ||
1517 | * @state: The state which we want to find | ||
1518 | * @minext: The requested extent length (0 for a single block) | ||
1519 | * @ip: If set, check for reservations | ||
1520 | * @nowrap: Stop looking at the end of the rgrp, rather than wrapping | ||
1521 | * around until we've reached the starting point. | ||
1522 | * | ||
1523 | * Side effects: | ||
1524 | * - If looking for free blocks, we set GBF_FULL on each bitmap which | ||
1525 | * has no free blocks in it. | ||
1526 | * | ||
1527 | * Returns: 0 on success, -ENOSPC if there is no block of the requested state | ||
1528 | */ | ||
1529 | |||
1530 | static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, | ||
1531 | const struct gfs2_inode *ip, bool nowrap) | ||
1532 | { | ||
1533 | struct buffer_head *bh; | ||
1534 | struct gfs2_bitmap *initial_bi; | ||
1535 | u32 initial_offset; | ||
1536 | u32 offset; | ||
1537 | u8 *buffer; | ||
1538 | int index; | ||
1539 | int n = 0; | ||
1540 | int iters = rbm->rgd->rd_length; | ||
1541 | int ret; | ||
1542 | |||
1543 | /* If we are not starting at the beginning of a bitmap, then we | ||
1544 | * need to add one to the bitmap count to ensure that we search | ||
1545 | * the starting bitmap twice. | ||
1546 | */ | ||
1547 | if (rbm->offset != 0) | ||
1548 | iters++; | ||
1549 | |||
1550 | while(1) { | ||
1551 | if (test_bit(GBF_FULL, &rbm->bi->bi_flags) && | ||
1552 | (state == GFS2_BLKST_FREE)) | ||
1553 | goto next_bitmap; | ||
1554 | |||
1555 | bh = rbm->bi->bi_bh; | ||
1556 | buffer = bh->b_data + rbm->bi->bi_offset; | ||
1557 | WARN_ON(!buffer_uptodate(bh)); | ||
1558 | if (state != GFS2_BLKST_UNLINKED && rbm->bi->bi_clone) | ||
1559 | buffer = rbm->bi->bi_clone + rbm->bi->bi_offset; | ||
1560 | initial_offset = rbm->offset; | ||
1561 | offset = gfs2_bitfit(buffer, rbm->bi->bi_len, rbm->offset, state); | ||
1562 | if (offset == BFITNOENT) | ||
1563 | goto bitmap_full; | ||
1564 | rbm->offset = offset; | ||
1565 | if (ip == NULL) | ||
1566 | return 0; | ||
1567 | |||
1568 | initial_bi = rbm->bi; | ||
1569 | ret = gfs2_reservation_check_and_update(rbm, ip, minext); | ||
1570 | if (ret == 0) | ||
1571 | return 0; | ||
1572 | if (ret > 0) { | ||
1573 | n += (rbm->bi - initial_bi); | ||
1574 | goto next_iter; | ||
1575 | } | ||
1576 | if (ret == -E2BIG) { | ||
1577 | index = 0; | ||
1578 | rbm->offset = 0; | ||
1579 | n += (rbm->bi - initial_bi); | ||
1580 | goto res_covered_end_of_rgrp; | ||
1581 | } | ||
1582 | return ret; | ||
1583 | |||
1584 | bitmap_full: /* Mark bitmap as full and fall through */ | ||
1585 | if ((state == GFS2_BLKST_FREE) && initial_offset == 0) | ||
1586 | set_bit(GBF_FULL, &rbm->bi->bi_flags); | ||
1587 | |||
1588 | next_bitmap: /* Find next bitmap in the rgrp */ | ||
1589 | rbm->offset = 0; | ||
1590 | index = rbm->bi - rbm->rgd->rd_bits; | ||
1591 | index++; | ||
1592 | if (index == rbm->rgd->rd_length) | ||
1593 | index = 0; | ||
1594 | res_covered_end_of_rgrp: | ||
1595 | rbm->bi = &rbm->rgd->rd_bits[index]; | ||
1596 | if ((index == 0) && nowrap) | ||
1597 | break; | ||
1598 | n++; | ||
1599 | next_iter: | ||
1600 | if (n >= iters) | ||
1601 | break; | ||
1602 | } | ||
1603 | |||
1604 | return -ENOSPC; | ||
1478 | } | 1605 | } |
1479 | 1606 | ||
1480 | /** | 1607 | /** |
@@ -1489,34 +1616,33 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | |||
1489 | 1616 | ||
1490 | static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip) | 1617 | static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip) |
1491 | { | 1618 | { |
1492 | u32 goal = 0, block; | 1619 | u64 block; |
1493 | u64 no_addr; | ||
1494 | struct gfs2_sbd *sdp = rgd->rd_sbd; | 1620 | struct gfs2_sbd *sdp = rgd->rd_sbd; |
1495 | struct gfs2_glock *gl; | 1621 | struct gfs2_glock *gl; |
1496 | struct gfs2_inode *ip; | 1622 | struct gfs2_inode *ip; |
1497 | int error; | 1623 | int error; |
1498 | int found = 0; | 1624 | int found = 0; |
1499 | struct gfs2_bitmap *bi; | 1625 | struct gfs2_rbm rbm = { .rgd = rgd, .bi = rgd->rd_bits, .offset = 0 }; |
1500 | 1626 | ||
1501 | while (goal < rgd->rd_data) { | 1627 | while (1) { |
1502 | down_write(&sdp->sd_log_flush_lock); | 1628 | down_write(&sdp->sd_log_flush_lock); |
1503 | block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, &bi); | 1629 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, 0, NULL, true); |
1504 | up_write(&sdp->sd_log_flush_lock); | 1630 | up_write(&sdp->sd_log_flush_lock); |
1505 | if (block == BFITNOENT) | 1631 | if (error == -ENOSPC) |
1632 | break; | ||
1633 | if (WARN_ON_ONCE(error)) | ||
1506 | break; | 1634 | break; |
1507 | 1635 | ||
1508 | block = gfs2_bi2rgd_blk(bi, block); | 1636 | block = gfs2_rbm_to_block(&rbm); |
1509 | /* rgblk_search can return a block < goal, so we need to | 1637 | if (gfs2_rbm_from_block(&rbm, block + 1)) |
1510 | keep it marching forward. */ | 1638 | break; |
1511 | no_addr = block + rgd->rd_data0; | 1639 | if (*last_unlinked != NO_BLOCK && block <= *last_unlinked) |
1512 | goal = max(block + 1, goal + 1); | ||
1513 | if (*last_unlinked != NO_BLOCK && no_addr <= *last_unlinked) | ||
1514 | continue; | 1640 | continue; |
1515 | if (no_addr == skip) | 1641 | if (block == skip) |
1516 | continue; | 1642 | continue; |
1517 | *last_unlinked = no_addr; | 1643 | *last_unlinked = block; |
1518 | 1644 | ||
1519 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl); | 1645 | error = gfs2_glock_get(sdp, block, &gfs2_inode_glops, CREATE, &gl); |
1520 | if (error) | 1646 | if (error) |
1521 | continue; | 1647 | continue; |
1522 | 1648 | ||
@@ -1543,6 +1669,19 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip | |||
1543 | return; | 1669 | return; |
1544 | } | 1670 | } |
1545 | 1671 | ||
1672 | static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *begin) | ||
1673 | { | ||
1674 | struct gfs2_rgrpd *rgd = *pos; | ||
1675 | |||
1676 | rgd = gfs2_rgrpd_get_next(rgd); | ||
1677 | if (rgd == NULL) | ||
1678 | rgd = gfs2_rgrpd_get_next(NULL); | ||
1679 | *pos = rgd; | ||
1680 | if (rgd != begin) /* If we didn't wrap */ | ||
1681 | return true; | ||
1682 | return false; | ||
1683 | } | ||
1684 | |||
1546 | /** | 1685 | /** |
1547 | * gfs2_inplace_reserve - Reserve space in the filesystem | 1686 | * gfs2_inplace_reserve - Reserve space in the filesystem |
1548 | * @ip: the inode to reserve space for | 1687 | * @ip: the inode to reserve space for |
@@ -1562,103 +1701,96 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested) | |||
1562 | 1701 | ||
1563 | if (sdp->sd_args.ar_rgrplvb) | 1702 | if (sdp->sd_args.ar_rgrplvb) |
1564 | flags |= GL_SKIP; | 1703 | flags |= GL_SKIP; |
1565 | rs->rs_requested = requested; | 1704 | if (gfs2_assert_warn(sdp, requested)) |
1566 | if (gfs2_assert_warn(sdp, requested)) { | 1705 | return -EINVAL; |
1567 | error = -EINVAL; | ||
1568 | goto out; | ||
1569 | } | ||
1570 | if (gfs2_rs_active(rs)) { | 1706 | if (gfs2_rs_active(rs)) { |
1571 | begin = rs->rs_rgd; | 1707 | begin = rs->rs_rbm.rgd; |
1572 | flags = 0; /* Yoda: Do or do not. There is no try */ | 1708 | flags = 0; /* Yoda: Do or do not. There is no try */ |
1573 | } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) { | 1709 | } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) { |
1574 | rs->rs_rgd = begin = ip->i_rgd; | 1710 | rs->rs_rbm.rgd = begin = ip->i_rgd; |
1575 | } else { | 1711 | } else { |
1576 | rs->rs_rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); | 1712 | rs->rs_rbm.rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); |
1577 | } | 1713 | } |
1578 | if (rs->rs_rgd == NULL) | 1714 | if (rs->rs_rbm.rgd == NULL) |
1579 | return -EBADSLT; | 1715 | return -EBADSLT; |
1580 | 1716 | ||
1581 | while (loops < 3) { | 1717 | while (loops < 3) { |
1582 | rg_locked = 0; | 1718 | rg_locked = 1; |
1583 | 1719 | ||
1584 | if (gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl)) { | 1720 | if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) { |
1585 | rg_locked = 1; | 1721 | rg_locked = 0; |
1586 | error = 0; | 1722 | error = gfs2_glock_nq_init(rs->rs_rbm.rgd->rd_gl, |
1587 | } else if (!loops && !gfs2_rs_active(rs) && | ||
1588 | rs->rs_rgd->rd_rs_cnt > RGRP_RSRV_MAX_CONTENDERS) { | ||
1589 | /* If the rgrp already is maxed out for contenders, | ||
1590 | we can eliminate it as a "first pass" without even | ||
1591 | requesting the rgrp glock. */ | ||
1592 | error = GLR_TRYFAILED; | ||
1593 | } else { | ||
1594 | error = gfs2_glock_nq_init(rs->rs_rgd->rd_gl, | ||
1595 | LM_ST_EXCLUSIVE, flags, | 1723 | LM_ST_EXCLUSIVE, flags, |
1596 | &rs->rs_rgd_gh); | 1724 | &rs->rs_rgd_gh); |
1597 | if (!error && sdp->sd_args.ar_rgrplvb) { | 1725 | if (error == GLR_TRYFAILED) |
1598 | error = update_rgrp_lvb(rs->rs_rgd); | 1726 | goto next_rgrp; |
1599 | if (error) { | 1727 | if (unlikely(error)) |
1728 | return error; | ||
1729 | if (sdp->sd_args.ar_rgrplvb) { | ||
1730 | error = update_rgrp_lvb(rs->rs_rbm.rgd); | ||
1731 | if (unlikely(error)) { | ||
1600 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | 1732 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); |
1601 | return error; | 1733 | return error; |
1602 | } | 1734 | } |
1603 | } | 1735 | } |
1604 | } | 1736 | } |
1605 | switch (error) { | ||
1606 | case 0: | ||
1607 | if (gfs2_rs_active(rs)) { | ||
1608 | if (unclaimed_blocks(rs->rs_rgd) + | ||
1609 | rs->rs_free >= rs->rs_requested) { | ||
1610 | ip->i_rgd = rs->rs_rgd; | ||
1611 | return 0; | ||
1612 | } | ||
1613 | /* We have a multi-block reservation, but the | ||
1614 | rgrp doesn't have enough free blocks to | ||
1615 | satisfy the request. Free the reservation | ||
1616 | and look for a suitable rgrp. */ | ||
1617 | gfs2_rs_deltree(rs); | ||
1618 | } | ||
1619 | if (try_rgrp_fit(rs->rs_rgd, ip)) { | ||
1620 | if (sdp->sd_args.ar_rgrplvb) | ||
1621 | gfs2_rgrp_bh_get(rs->rs_rgd); | ||
1622 | ip->i_rgd = rs->rs_rgd; | ||
1623 | return 0; | ||
1624 | } | ||
1625 | if (rs->rs_rgd->rd_flags & GFS2_RDF_CHECK) { | ||
1626 | if (sdp->sd_args.ar_rgrplvb) | ||
1627 | gfs2_rgrp_bh_get(rs->rs_rgd); | ||
1628 | try_rgrp_unlink(rs->rs_rgd, &last_unlinked, | ||
1629 | ip->i_no_addr); | ||
1630 | } | ||
1631 | if (!rg_locked) | ||
1632 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | ||
1633 | /* fall through */ | ||
1634 | case GLR_TRYFAILED: | ||
1635 | rs->rs_rgd = gfs2_rgrpd_get_next(rs->rs_rgd); | ||
1636 | rs->rs_rgd = rs->rs_rgd ? : begin; /* if NULL, wrap */ | ||
1637 | if (rs->rs_rgd != begin) /* If we didn't wrap */ | ||
1638 | break; | ||
1639 | 1737 | ||
1640 | flags &= ~LM_FLAG_TRY; | 1738 | /* Skip unuseable resource groups */ |
1641 | loops++; | 1739 | if (rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) |
1642 | /* Check that fs hasn't grown if writing to rindex */ | 1740 | goto skip_rgrp; |
1643 | if (ip == GFS2_I(sdp->sd_rindex) && | 1741 | |
1644 | !sdp->sd_rindex_uptodate) { | 1742 | if (sdp->sd_args.ar_rgrplvb) |
1645 | error = gfs2_ri_update(ip); | 1743 | gfs2_rgrp_bh_get(rs->rs_rbm.rgd); |
1646 | if (error) | 1744 | |
1647 | goto out; | 1745 | /* Get a reservation if we don't already have one */ |
1648 | } else if (loops == 2) | 1746 | if (!gfs2_rs_active(rs)) |
1649 | /* Flushing the log may release space */ | 1747 | rg_mblk_search(rs->rs_rbm.rgd, ip, requested); |
1650 | gfs2_log_flush(sdp, NULL); | 1748 | |
1651 | break; | 1749 | /* Skip rgrps when we can't get a reservation on first pass */ |
1652 | default: | 1750 | if (!gfs2_rs_active(rs) && (loops < 1)) |
1653 | goto out; | 1751 | goto check_rgrp; |
1752 | |||
1753 | /* If rgrp has enough free space, use it */ | ||
1754 | if (rs->rs_rbm.rgd->rd_free_clone >= requested) { | ||
1755 | ip->i_rgd = rs->rs_rbm.rgd; | ||
1756 | return 0; | ||
1757 | } | ||
1758 | |||
1759 | /* Drop reservation, if we couldn't use reserved rgrp */ | ||
1760 | if (gfs2_rs_active(rs)) | ||
1761 | gfs2_rs_deltree(ip, rs); | ||
1762 | check_rgrp: | ||
1763 | /* Check for unlinked inodes which can be reclaimed */ | ||
1764 | if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) | ||
1765 | try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked, | ||
1766 | ip->i_no_addr); | ||
1767 | skip_rgrp: | ||
1768 | /* Unlock rgrp if required */ | ||
1769 | if (!rg_locked) | ||
1770 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | ||
1771 | next_rgrp: | ||
1772 | /* Find the next rgrp, and continue looking */ | ||
1773 | if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin)) | ||
1774 | continue; | ||
1775 | |||
1776 | /* If we've scanned all the rgrps, but found no free blocks | ||
1777 | * then this checks for some less likely conditions before | ||
1778 | * trying again. | ||
1779 | */ | ||
1780 | flags &= ~LM_FLAG_TRY; | ||
1781 | loops++; | ||
1782 | /* Check that fs hasn't grown if writing to rindex */ | ||
1783 | if (ip == GFS2_I(sdp->sd_rindex) && !sdp->sd_rindex_uptodate) { | ||
1784 | error = gfs2_ri_update(ip); | ||
1785 | if (error) | ||
1786 | return error; | ||
1654 | } | 1787 | } |
1788 | /* Flushing the log may release space */ | ||
1789 | if (loops == 2) | ||
1790 | gfs2_log_flush(sdp, NULL); | ||
1655 | } | 1791 | } |
1656 | error = -ENOSPC; | ||
1657 | 1792 | ||
1658 | out: | 1793 | return -ENOSPC; |
1659 | if (error) | ||
1660 | rs->rs_requested = 0; | ||
1661 | return error; | ||
1662 | } | 1794 | } |
1663 | 1795 | ||
1664 | /** | 1796 | /** |
@@ -1672,15 +1804,8 @@ void gfs2_inplace_release(struct gfs2_inode *ip) | |||
1672 | { | 1804 | { |
1673 | struct gfs2_blkreserv *rs = ip->i_res; | 1805 | struct gfs2_blkreserv *rs = ip->i_res; |
1674 | 1806 | ||
1675 | if (!rs) | ||
1676 | return; | ||
1677 | |||
1678 | if (!rs->rs_free) | ||
1679 | gfs2_rs_deltree(rs); | ||
1680 | |||
1681 | if (rs->rs_rgd_gh.gh_gl) | 1807 | if (rs->rs_rgd_gh.gh_gl) |
1682 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | 1808 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); |
1683 | rs->rs_requested = 0; | ||
1684 | } | 1809 | } |
1685 | 1810 | ||
1686 | /** | 1811 | /** |
@@ -1693,173 +1818,47 @@ void gfs2_inplace_release(struct gfs2_inode *ip) | |||
1693 | 1818 | ||
1694 | static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) | 1819 | static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) |
1695 | { | 1820 | { |
1696 | struct gfs2_bitmap *bi = NULL; | 1821 | struct gfs2_rbm rbm = { .rgd = rgd, }; |
1697 | u32 length, rgrp_block, buf_block; | 1822 | int ret; |
1698 | unsigned int buf; | ||
1699 | unsigned char type; | ||
1700 | |||
1701 | length = rgd->rd_length; | ||
1702 | rgrp_block = block - rgd->rd_data0; | ||
1703 | |||
1704 | for (buf = 0; buf < length; buf++) { | ||
1705 | bi = rgd->rd_bits + buf; | ||
1706 | if (rgrp_block < (bi->bi_start + bi->bi_len) * GFS2_NBBY) | ||
1707 | break; | ||
1708 | } | ||
1709 | |||
1710 | gfs2_assert(rgd->rd_sbd, buf < length); | ||
1711 | buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; | ||
1712 | 1823 | ||
1713 | type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, | 1824 | ret = gfs2_rbm_from_block(&rbm, block); |
1714 | bi->bi_len, buf_block); | 1825 | WARN_ON_ONCE(ret != 0); |
1715 | 1826 | ||
1716 | return type; | 1827 | return gfs2_testbit(&rbm); |
1717 | } | 1828 | } |
1718 | 1829 | ||
1719 | /** | ||
1720 | * rgblk_search - find a block in @state | ||
1721 | * @rgd: the resource group descriptor | ||
1722 | * @goal: the goal block within the RG (start here to search for avail block) | ||
1723 | * @state: GFS2_BLKST_XXX the before-allocation state to find | ||
1724 | * @rbi: address of the pointer to the bitmap containing the block found | ||
1725 | * | ||
1726 | * Walk rgrp's bitmap to find bits that represent a block in @state. | ||
1727 | * | ||
1728 | * This function never fails, because we wouldn't call it unless we | ||
1729 | * know (from reservation results, etc.) that a block is available. | ||
1730 | * | ||
1731 | * Scope of @goal is just within rgrp, not the whole filesystem. | ||
1732 | * Scope of @returned block is just within bitmap, not the whole filesystem. | ||
1733 | * | ||
1734 | * Returns: the block number found relative to the bitmap rbi | ||
1735 | */ | ||
1736 | |||
1737 | static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, unsigned char state, | ||
1738 | struct gfs2_bitmap **rbi) | ||
1739 | { | ||
1740 | struct gfs2_bitmap *bi = NULL; | ||
1741 | const u32 length = rgd->rd_length; | ||
1742 | u32 biblk = BFITNOENT; | ||
1743 | unsigned int buf, x; | ||
1744 | const u8 *buffer = NULL; | ||
1745 | |||
1746 | *rbi = NULL; | ||
1747 | /* Find bitmap block that contains bits for goal block */ | ||
1748 | for (buf = 0; buf < length; buf++) { | ||
1749 | bi = rgd->rd_bits + buf; | ||
1750 | /* Convert scope of "goal" from rgrp-wide to within found bit block */ | ||
1751 | if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) { | ||
1752 | goal -= bi->bi_start * GFS2_NBBY; | ||
1753 | goto do_search; | ||
1754 | } | ||
1755 | } | ||
1756 | buf = 0; | ||
1757 | goal = 0; | ||
1758 | |||
1759 | do_search: | ||
1760 | /* Search (up to entire) bitmap in this rgrp for allocatable block. | ||
1761 | "x <= length", instead of "x < length", because we typically start | ||
1762 | the search in the middle of a bit block, but if we can't find an | ||
1763 | allocatable block anywhere else, we want to be able wrap around and | ||
1764 | search in the first part of our first-searched bit block. */ | ||
1765 | for (x = 0; x <= length; x++) { | ||
1766 | bi = rgd->rd_bits + buf; | ||
1767 | |||
1768 | if (test_bit(GBF_FULL, &bi->bi_flags) && | ||
1769 | (state == GFS2_BLKST_FREE)) | ||
1770 | goto skip; | ||
1771 | |||
1772 | /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone | ||
1773 | bitmaps, so we must search the originals for that. */ | ||
1774 | buffer = bi->bi_bh->b_data + bi->bi_offset; | ||
1775 | WARN_ON(!buffer_uptodate(bi->bi_bh)); | ||
1776 | if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) | ||
1777 | buffer = bi->bi_clone + bi->bi_offset; | ||
1778 | |||
1779 | while (1) { | ||
1780 | struct gfs2_blkreserv *rs; | ||
1781 | u32 rgblk; | ||
1782 | |||
1783 | biblk = gfs2_bitfit(buffer, bi->bi_len, goal, state); | ||
1784 | if (biblk == BFITNOENT) | ||
1785 | break; | ||
1786 | /* Check if this block is reserved() */ | ||
1787 | rgblk = gfs2_bi2rgd_blk(bi, biblk); | ||
1788 | rs = rs_find(rgd, rgblk); | ||
1789 | if (rs == NULL) | ||
1790 | break; | ||
1791 | |||
1792 | BUG_ON(rs->rs_bi != bi); | ||
1793 | biblk = BFITNOENT; | ||
1794 | /* This should jump to the first block after the | ||
1795 | reservation. */ | ||
1796 | goal = rs->rs_biblk + rs->rs_free; | ||
1797 | if (goal >= bi->bi_len * GFS2_NBBY) | ||
1798 | break; | ||
1799 | } | ||
1800 | if (biblk != BFITNOENT) | ||
1801 | break; | ||
1802 | |||
1803 | if ((goal == 0) && (state == GFS2_BLKST_FREE)) | ||
1804 | set_bit(GBF_FULL, &bi->bi_flags); | ||
1805 | |||
1806 | /* Try next bitmap block (wrap back to rgrp header if at end) */ | ||
1807 | skip: | ||
1808 | buf++; | ||
1809 | buf %= length; | ||
1810 | goal = 0; | ||
1811 | } | ||
1812 | |||
1813 | if (biblk != BFITNOENT) | ||
1814 | *rbi = bi; | ||
1815 | |||
1816 | return biblk; | ||
1817 | } | ||
1818 | 1830 | ||
1819 | /** | 1831 | /** |
1820 | * gfs2_alloc_extent - allocate an extent from a given bitmap | 1832 | * gfs2_alloc_extent - allocate an extent from a given bitmap |
1821 | * @rgd: the resource group descriptor | 1833 | * @rbm: the resource group information |
1822 | * @bi: the bitmap within the rgrp | ||
1823 | * @blk: the block within the bitmap | ||
1824 | * @dinode: TRUE if the first block we allocate is for a dinode | 1834 | * @dinode: TRUE if the first block we allocate is for a dinode |
1825 | * @n: The extent length | 1835 | * @n: The extent length (value/result) |
1826 | * | 1836 | * |
1827 | * Add the found bitmap buffer to the transaction. | 1837 | * Add the bitmap buffer to the transaction. |
1828 | * Set the found bits to @new_state to change block's allocation state. | 1838 | * Set the found bits to @new_state to change block's allocation state. |
1829 | * Returns: starting block number of the extent (fs scope) | ||
1830 | */ | 1839 | */ |
1831 | static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi, | 1840 | static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode, |
1832 | u32 blk, bool dinode, unsigned int *n) | 1841 | unsigned int *n) |
1833 | { | 1842 | { |
1843 | struct gfs2_rbm pos = { .rgd = rbm->rgd, }; | ||
1834 | const unsigned int elen = *n; | 1844 | const unsigned int elen = *n; |
1835 | u32 goal, rgblk; | 1845 | u64 block; |
1836 | const u8 *buffer = NULL; | 1846 | int ret; |
1837 | struct gfs2_blkreserv *rs; | 1847 | |
1838 | 1848 | *n = 1; | |
1839 | *n = 0; | 1849 | block = gfs2_rbm_to_block(rbm); |
1840 | buffer = bi->bi_bh->b_data + bi->bi_offset; | 1850 | gfs2_trans_add_bh(rbm->rgd->rd_gl, rbm->bi->bi_bh, 1); |
1841 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | 1851 | gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); |
1842 | gfs2_setbit(rgd, bi->bi_clone, bi, blk, | 1852 | block++; |
1843 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | ||
1844 | (*n)++; | ||
1845 | goal = blk; | ||
1846 | while (*n < elen) { | 1853 | while (*n < elen) { |
1847 | goal++; | 1854 | ret = gfs2_rbm_from_block(&pos, block); |
1848 | if (goal >= (bi->bi_len * GFS2_NBBY)) | 1855 | if (ret || gfs2_testbit(&pos) != GFS2_BLKST_FREE) |
1849 | break; | ||
1850 | rgblk = gfs2_bi2rgd_blk(bi, goal); | ||
1851 | rs = rs_find(rgd, rgblk); | ||
1852 | if (rs) /* Oops, we bumped into someone's reservation */ | ||
1853 | break; | ||
1854 | if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) != | ||
1855 | GFS2_BLKST_FREE) | ||
1856 | break; | 1856 | break; |
1857 | gfs2_setbit(rgd, bi->bi_clone, bi, goal, GFS2_BLKST_USED); | 1857 | gfs2_trans_add_bh(pos.rgd->rd_gl, pos.bi->bi_bh, 1); |
1858 | gfs2_setbit(&pos, true, GFS2_BLKST_USED); | ||
1858 | (*n)++; | 1859 | (*n)++; |
1860 | block++; | ||
1859 | } | 1861 | } |
1860 | blk = gfs2_bi2rgd_blk(bi, blk); | ||
1861 | rgd->rd_last_alloc = blk + *n - 1; | ||
1862 | return rgd->rd_data0 + blk; | ||
1863 | } | 1862 | } |
1864 | 1863 | ||
1865 | /** | 1864 | /** |
@@ -1875,46 +1874,30 @@ static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi, | |||
1875 | static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, | 1874 | static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, |
1876 | u32 blen, unsigned char new_state) | 1875 | u32 blen, unsigned char new_state) |
1877 | { | 1876 | { |
1878 | struct gfs2_rgrpd *rgd; | 1877 | struct gfs2_rbm rbm; |
1879 | struct gfs2_bitmap *bi = NULL; | ||
1880 | u32 length, rgrp_blk, buf_blk; | ||
1881 | unsigned int buf; | ||
1882 | 1878 | ||
1883 | rgd = gfs2_blk2rgrpd(sdp, bstart, 1); | 1879 | rbm.rgd = gfs2_blk2rgrpd(sdp, bstart, 1); |
1884 | if (!rgd) { | 1880 | if (!rbm.rgd) { |
1885 | if (gfs2_consist(sdp)) | 1881 | if (gfs2_consist(sdp)) |
1886 | fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); | 1882 | fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); |
1887 | return NULL; | 1883 | return NULL; |
1888 | } | 1884 | } |
1889 | 1885 | ||
1890 | length = rgd->rd_length; | ||
1891 | |||
1892 | rgrp_blk = bstart - rgd->rd_data0; | ||
1893 | |||
1894 | while (blen--) { | 1886 | while (blen--) { |
1895 | for (buf = 0; buf < length; buf++) { | 1887 | gfs2_rbm_from_block(&rbm, bstart); |
1896 | bi = rgd->rd_bits + buf; | 1888 | bstart++; |
1897 | if (rgrp_blk < (bi->bi_start + bi->bi_len) * GFS2_NBBY) | 1889 | if (!rbm.bi->bi_clone) { |
1898 | break; | 1890 | rbm.bi->bi_clone = kmalloc(rbm.bi->bi_bh->b_size, |
1891 | GFP_NOFS | __GFP_NOFAIL); | ||
1892 | memcpy(rbm.bi->bi_clone + rbm.bi->bi_offset, | ||
1893 | rbm.bi->bi_bh->b_data + rbm.bi->bi_offset, | ||
1894 | rbm.bi->bi_len); | ||
1899 | } | 1895 | } |
1900 | 1896 | gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.bi->bi_bh, 1); | |
1901 | gfs2_assert(rgd->rd_sbd, buf < length); | 1897 | gfs2_setbit(&rbm, false, new_state); |
1902 | |||
1903 | buf_blk = rgrp_blk - bi->bi_start * GFS2_NBBY; | ||
1904 | rgrp_blk++; | ||
1905 | |||
1906 | if (!bi->bi_clone) { | ||
1907 | bi->bi_clone = kmalloc(bi->bi_bh->b_size, | ||
1908 | GFP_NOFS | __GFP_NOFAIL); | ||
1909 | memcpy(bi->bi_clone + bi->bi_offset, | ||
1910 | bi->bi_bh->b_data + bi->bi_offset, | ||
1911 | bi->bi_len); | ||
1912 | } | ||
1913 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | ||
1914 | gfs2_setbit(rgd, NULL, bi, buf_blk, new_state); | ||
1915 | } | 1898 | } |
1916 | 1899 | ||
1917 | return rgd; | 1900 | return rbm.rgd; |
1918 | } | 1901 | } |
1919 | 1902 | ||
1920 | /** | 1903 | /** |
@@ -1956,46 +1939,41 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) | |||
1956 | } | 1939 | } |
1957 | 1940 | ||
1958 | /** | 1941 | /** |
1959 | * claim_reserved_blks - Claim previously reserved blocks | 1942 | * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation |
1960 | * @ip: the inode that's claiming the reservation | 1943 | * @ip: The inode we have just allocated blocks for |
1961 | * @dinode: 1 if this block is a dinode block, otherwise data block | 1944 | * @rbm: The start of the allocated blocks |
1962 | * @nblocks: desired extent length | 1945 | * @len: The extent length |
1963 | * | 1946 | * |
1964 | * Lay claim to previously reserved blocks. | 1947 | * Adjusts a reservation after an allocation has taken place. If the |
1965 | * Returns: Starting block number of the blocks claimed. | 1948 | * reservation does not match the allocation, or if it is now empty |
1966 | * Sets *nblocks to the actual extent length allocated. | 1949 | * then it is removed. |
1967 | */ | 1950 | */ |
1968 | static u64 claim_reserved_blks(struct gfs2_inode *ip, bool dinode, | 1951 | |
1969 | unsigned int *nblocks) | 1952 | static void gfs2_adjust_reservation(struct gfs2_inode *ip, |
1953 | const struct gfs2_rbm *rbm, unsigned len) | ||
1970 | { | 1954 | { |
1971 | struct gfs2_blkreserv *rs = ip->i_res; | 1955 | struct gfs2_blkreserv *rs = ip->i_res; |
1972 | struct gfs2_rgrpd *rgd = rs->rs_rgd; | 1956 | struct gfs2_rgrpd *rgd = rbm->rgd; |
1973 | struct gfs2_bitmap *bi; | 1957 | unsigned rlen; |
1974 | u64 start_block = gfs2_rs_startblk(rs); | 1958 | u64 block; |
1975 | const unsigned int elen = *nblocks; | 1959 | int ret; |
1976 | 1960 | ||
1977 | bi = rs->rs_bi; | 1961 | spin_lock(&rgd->rd_rsspin); |
1978 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | 1962 | if (gfs2_rs_active(rs)) { |
1979 | 1963 | if (gfs2_rbm_eq(&rs->rs_rbm, rbm)) { | |
1980 | for (*nblocks = 0; *nblocks < elen && rs->rs_free; (*nblocks)++) { | 1964 | block = gfs2_rbm_to_block(rbm); |
1981 | if (gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, | 1965 | ret = gfs2_rbm_from_block(&rs->rs_rbm, block + len); |
1982 | bi->bi_len, rs->rs_biblk) != GFS2_BLKST_FREE) | 1966 | rlen = min(rs->rs_free, len); |
1983 | break; | 1967 | rs->rs_free -= rlen; |
1984 | gfs2_setbit(rgd, bi->bi_clone, bi, rs->rs_biblk, | 1968 | rgd->rd_reserved -= rlen; |
1985 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | 1969 | trace_gfs2_rs(rs, TRACE_RS_CLAIM); |
1986 | rs->rs_biblk++; | 1970 | if (rs->rs_free && !ret) |
1987 | rs->rs_free--; | 1971 | goto out; |
1988 | 1972 | } | |
1989 | BUG_ON(!rgd->rd_reserved); | 1973 | __rs_deltree(ip, rs); |
1990 | rgd->rd_reserved--; | ||
1991 | dinode = false; | ||
1992 | } | 1974 | } |
1993 | 1975 | out: | |
1994 | trace_gfs2_rs(ip, rs, TRACE_RS_CLAIM); | 1976 | spin_unlock(&rgd->rd_rsspin); |
1995 | if (!rs->rs_free || *nblocks != elen) | ||
1996 | gfs2_rs_deltree(rs); | ||
1997 | |||
1998 | return start_block; | ||
1999 | } | 1977 | } |
2000 | 1978 | ||
2001 | /** | 1979 | /** |
@@ -2014,47 +1992,40 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, | |||
2014 | { | 1992 | { |
2015 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 1993 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
2016 | struct buffer_head *dibh; | 1994 | struct buffer_head *dibh; |
2017 | struct gfs2_rgrpd *rgd; | 1995 | struct gfs2_rbm rbm = { .rgd = ip->i_rgd, }; |
2018 | unsigned int ndata; | 1996 | unsigned int ndata; |
2019 | u32 goal, blk; /* block, within the rgrp scope */ | 1997 | u64 goal; |
2020 | u64 block; /* block, within the file system scope */ | 1998 | u64 block; /* block, within the file system scope */ |
2021 | int error; | 1999 | int error; |
2022 | struct gfs2_bitmap *bi; | ||
2023 | 2000 | ||
2024 | /* Only happens if there is a bug in gfs2, return something distinctive | 2001 | if (gfs2_rs_active(ip->i_res)) |
2025 | * to ensure that it is noticed. | 2002 | goal = gfs2_rbm_to_block(&ip->i_res->rs_rbm); |
2026 | */ | 2003 | else if (!dinode && rgrp_contains_block(rbm.rgd, ip->i_goal)) |
2027 | if (ip->i_res->rs_requested == 0) | 2004 | goal = ip->i_goal; |
2028 | return -ECANCELED; | ||
2029 | |||
2030 | /* If we have a reservation, claim blocks from it. */ | ||
2031 | if (gfs2_rs_active(ip->i_res)) { | ||
2032 | BUG_ON(!ip->i_res->rs_free); | ||
2033 | rgd = ip->i_res->rs_rgd; | ||
2034 | block = claim_reserved_blks(ip, dinode, nblocks); | ||
2035 | if (*nblocks) | ||
2036 | goto found_blocks; | ||
2037 | } | ||
2038 | |||
2039 | rgd = ip->i_rgd; | ||
2040 | |||
2041 | if (!dinode && rgrp_contains_block(rgd, ip->i_goal)) | ||
2042 | goal = ip->i_goal - rgd->rd_data0; | ||
2043 | else | 2005 | else |
2044 | goal = rgd->rd_last_alloc; | 2006 | goal = rbm.rgd->rd_last_alloc + rbm.rgd->rd_data0; |
2045 | 2007 | ||
2046 | blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, &bi); | 2008 | gfs2_rbm_from_block(&rbm, goal); |
2009 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); | ||
2010 | |||
2011 | if (error == -ENOSPC) { | ||
2012 | gfs2_rbm_from_block(&rbm, goal); | ||
2013 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); | ||
2014 | } | ||
2047 | 2015 | ||
2048 | /* Since all blocks are reserved in advance, this shouldn't happen */ | 2016 | /* Since all blocks are reserved in advance, this shouldn't happen */ |
2049 | if (blk == BFITNOENT) { | 2017 | if (error) { |
2050 | printk(KERN_WARNING "BFITNOENT, nblocks=%u\n", *nblocks); | 2018 | fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d\n", |
2051 | printk(KERN_WARNING "FULL=%d\n", | 2019 | (unsigned long long)ip->i_no_addr, error, *nblocks, |
2052 | test_bit(GBF_FULL, &rgd->rd_bits->bi_flags)); | 2020 | test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags)); |
2053 | goto rgrp_error; | 2021 | goto rgrp_error; |
2054 | } | 2022 | } |
2055 | 2023 | ||
2056 | block = gfs2_alloc_extent(rgd, bi, blk, dinode, nblocks); | 2024 | gfs2_alloc_extent(&rbm, dinode, nblocks); |
2057 | found_blocks: | 2025 | block = gfs2_rbm_to_block(&rbm); |
2026 | rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0; | ||
2027 | if (gfs2_rs_active(ip->i_res)) | ||
2028 | gfs2_adjust_reservation(ip, &rbm, *nblocks); | ||
2058 | ndata = *nblocks; | 2029 | ndata = *nblocks; |
2059 | if (dinode) | 2030 | if (dinode) |
2060 | ndata--; | 2031 | ndata--; |
@@ -2071,22 +2042,22 @@ found_blocks: | |||
2071 | brelse(dibh); | 2042 | brelse(dibh); |
2072 | } | 2043 | } |
2073 | } | 2044 | } |
2074 | if (rgd->rd_free < *nblocks) { | 2045 | if (rbm.rgd->rd_free < *nblocks) { |
2075 | printk(KERN_WARNING "nblocks=%u\n", *nblocks); | 2046 | printk(KERN_WARNING "nblocks=%u\n", *nblocks); |
2076 | goto rgrp_error; | 2047 | goto rgrp_error; |
2077 | } | 2048 | } |
2078 | 2049 | ||
2079 | rgd->rd_free -= *nblocks; | 2050 | rbm.rgd->rd_free -= *nblocks; |
2080 | if (dinode) { | 2051 | if (dinode) { |
2081 | rgd->rd_dinodes++; | 2052 | rbm.rgd->rd_dinodes++; |
2082 | *generation = rgd->rd_igeneration++; | 2053 | *generation = rbm.rgd->rd_igeneration++; |
2083 | if (*generation == 0) | 2054 | if (*generation == 0) |
2084 | *generation = rgd->rd_igeneration++; | 2055 | *generation = rbm.rgd->rd_igeneration++; |
2085 | } | 2056 | } |
2086 | 2057 | ||
2087 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); | 2058 | gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.rgd->rd_bits[0].bi_bh, 1); |
2088 | gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); | 2059 | gfs2_rgrp_out(rbm.rgd, rbm.rgd->rd_bits[0].bi_bh->b_data); |
2089 | gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, rgd->rd_bits[0].bi_bh->b_data); | 2060 | gfs2_rgrp_ondisk2lvb(rbm.rgd->rd_rgl, rbm.rgd->rd_bits[0].bi_bh->b_data); |
2090 | 2061 | ||
2091 | gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); | 2062 | gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); |
2092 | if (dinode) | 2063 | if (dinode) |
@@ -2100,14 +2071,14 @@ found_blocks: | |||
2100 | gfs2_quota_change(ip, ndata, ip->i_inode.i_uid, | 2071 | gfs2_quota_change(ip, ndata, ip->i_inode.i_uid, |
2101 | ip->i_inode.i_gid); | 2072 | ip->i_inode.i_gid); |
2102 | 2073 | ||
2103 | rgd->rd_free_clone -= *nblocks; | 2074 | rbm.rgd->rd_free_clone -= *nblocks; |
2104 | trace_gfs2_block_alloc(ip, rgd, block, *nblocks, | 2075 | trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks, |
2105 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | 2076 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); |
2106 | *bn = block; | 2077 | *bn = block; |
2107 | return 0; | 2078 | return 0; |
2108 | 2079 | ||
2109 | rgrp_error: | 2080 | rgrp_error: |
2110 | gfs2_rgrp_error(rgd); | 2081 | gfs2_rgrp_error(rbm.rgd); |
2111 | return -EIO; | 2082 | return -EIO; |
2112 | } | 2083 | } |
2113 | 2084 | ||
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index ca6e26729b86..24077958dcf6 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h | |||
@@ -46,7 +46,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n, | |||
46 | bool dinode, u64 *generation); | 46 | bool dinode, u64 *generation); |
47 | 47 | ||
48 | extern int gfs2_rs_alloc(struct gfs2_inode *ip); | 48 | extern int gfs2_rs_alloc(struct gfs2_inode *ip); |
49 | extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs); | 49 | extern void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs); |
50 | extern void gfs2_rs_delete(struct gfs2_inode *ip); | 50 | extern void gfs2_rs_delete(struct gfs2_inode *ip); |
51 | extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); | 51 | extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); |
52 | extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); | 52 | extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); |
@@ -73,30 +73,10 @@ extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, | |||
73 | const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); | 73 | const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); |
74 | extern int gfs2_fitrim(struct file *filp, void __user *argp); | 74 | extern int gfs2_fitrim(struct file *filp, void __user *argp); |
75 | 75 | ||
76 | /* This is how to tell if a multi-block reservation is "inplace" reserved: */ | 76 | /* This is how to tell if a reservation is in the rgrp tree: */ |
77 | static inline int gfs2_mb_reserved(struct gfs2_inode *ip) | 77 | static inline bool gfs2_rs_active(struct gfs2_blkreserv *rs) |
78 | { | 78 | { |
79 | if (ip->i_res && ip->i_res->rs_requested) | 79 | return rs && !RB_EMPTY_NODE(&rs->rs_node); |
80 | return 1; | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | /* This is how to tell if a multi-block reservation is in the rgrp tree: */ | ||
85 | static inline int gfs2_rs_active(struct gfs2_blkreserv *rs) | ||
86 | { | ||
87 | if (rs && rs->rs_bi) | ||
88 | return 1; | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static inline u32 gfs2_bi2rgd_blk(const struct gfs2_bitmap *bi, u32 blk) | ||
93 | { | ||
94 | return (bi->bi_start * GFS2_NBBY) + blk; | ||
95 | } | ||
96 | |||
97 | static inline u64 gfs2_rs_startblk(const struct gfs2_blkreserv *rs) | ||
98 | { | ||
99 | return gfs2_bi2rgd_blk(rs->rs_bi, rs->rs_biblk) + rs->rs_rgd->rd_data0; | ||
100 | } | 80 | } |
101 | 81 | ||
102 | #endif /* __RGRP_DOT_H__ */ | 82 | #endif /* __RGRP_DOT_H__ */ |
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index fc3168f47a14..bc737261f234 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c | |||
@@ -1366,6 +1366,8 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1366 | val = sdp->sd_tune.gt_statfs_quantum; | 1366 | val = sdp->sd_tune.gt_statfs_quantum; |
1367 | if (val != 30) | 1367 | if (val != 30) |
1368 | seq_printf(s, ",statfs_quantum=%d", val); | 1368 | seq_printf(s, ",statfs_quantum=%d", val); |
1369 | else if (sdp->sd_tune.gt_statfs_slow) | ||
1370 | seq_puts(s, ",statfs_quantum=0"); | ||
1369 | val = sdp->sd_tune.gt_quota_quantum; | 1371 | val = sdp->sd_tune.gt_quota_quantum; |
1370 | if (val != 60) | 1372 | if (val != 60) |
1371 | seq_printf(s, ",quota_quantum=%d", val); | 1373 | seq_printf(s, ",quota_quantum=%d", val); |
@@ -1543,6 +1545,11 @@ static void gfs2_evict_inode(struct inode *inode) | |||
1543 | 1545 | ||
1544 | out_truncate: | 1546 | out_truncate: |
1545 | gfs2_log_flush(sdp, ip->i_gl); | 1547 | gfs2_log_flush(sdp, ip->i_gl); |
1548 | if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) { | ||
1549 | struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl); | ||
1550 | filemap_fdatawrite(metamapping); | ||
1551 | filemap_fdatawait(metamapping); | ||
1552 | } | ||
1546 | write_inode_now(inode, 1); | 1553 | write_inode_now(inode, 1); |
1547 | gfs2_ail_flush(ip->i_gl, 0); | 1554 | gfs2_ail_flush(ip->i_gl, 0); |
1548 | 1555 | ||
@@ -1557,7 +1564,7 @@ out_truncate: | |||
1557 | out_unlock: | 1564 | out_unlock: |
1558 | /* Error path for case 1 */ | 1565 | /* Error path for case 1 */ |
1559 | if (gfs2_rs_active(ip->i_res)) | 1566 | if (gfs2_rs_active(ip->i_res)) |
1560 | gfs2_rs_deltree(ip->i_res); | 1567 | gfs2_rs_deltree(ip, ip->i_res); |
1561 | 1568 | ||
1562 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) | 1569 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) |
1563 | gfs2_glock_dq(&ip->i_iopen_gh); | 1570 | gfs2_glock_dq(&ip->i_iopen_gh); |
@@ -1572,7 +1579,7 @@ out: | |||
1572 | clear_inode(inode); | 1579 | clear_inode(inode); |
1573 | gfs2_dir_hash_inval(ip); | 1580 | gfs2_dir_hash_inval(ip); |
1574 | ip->i_gl->gl_object = NULL; | 1581 | ip->i_gl->gl_object = NULL; |
1575 | flush_delayed_work_sync(&ip->i_gl->gl_work); | 1582 | flush_delayed_work(&ip->i_gl->gl_work); |
1576 | gfs2_glock_add_to_lru(ip->i_gl); | 1583 | gfs2_glock_add_to_lru(ip->i_gl); |
1577 | gfs2_glock_put(ip->i_gl); | 1584 | gfs2_glock_put(ip->i_gl); |
1578 | ip->i_gl = NULL; | 1585 | ip->i_gl = NULL; |
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h index a25c252fe412..bbdc78af60ca 100644 --- a/fs/gfs2/trace_gfs2.h +++ b/fs/gfs2/trace_gfs2.h | |||
@@ -509,10 +509,9 @@ TRACE_EVENT(gfs2_block_alloc, | |||
509 | /* Keep track of multi-block reservations as they are allocated/freed */ | 509 | /* Keep track of multi-block reservations as they are allocated/freed */ |
510 | TRACE_EVENT(gfs2_rs, | 510 | TRACE_EVENT(gfs2_rs, |
511 | 511 | ||
512 | TP_PROTO(const struct gfs2_inode *ip, const struct gfs2_blkreserv *rs, | 512 | TP_PROTO(const struct gfs2_blkreserv *rs, u8 func), |
513 | u8 func), | ||
514 | 513 | ||
515 | TP_ARGS(ip, rs, func), | 514 | TP_ARGS(rs, func), |
516 | 515 | ||
517 | TP_STRUCT__entry( | 516 | TP_STRUCT__entry( |
518 | __field( dev_t, dev ) | 517 | __field( dev_t, dev ) |
@@ -526,18 +525,17 @@ TRACE_EVENT(gfs2_rs, | |||
526 | ), | 525 | ), |
527 | 526 | ||
528 | TP_fast_assign( | 527 | TP_fast_assign( |
529 | __entry->dev = rs->rs_rgd ? rs->rs_rgd->rd_sbd->sd_vfs->s_dev : 0; | 528 | __entry->dev = rs->rs_rbm.rgd->rd_sbd->sd_vfs->s_dev; |
530 | __entry->rd_addr = rs->rs_rgd ? rs->rs_rgd->rd_addr : 0; | 529 | __entry->rd_addr = rs->rs_rbm.rgd->rd_addr; |
531 | __entry->rd_free_clone = rs->rs_rgd ? rs->rs_rgd->rd_free_clone : 0; | 530 | __entry->rd_free_clone = rs->rs_rbm.rgd->rd_free_clone; |
532 | __entry->rd_reserved = rs->rs_rgd ? rs->rs_rgd->rd_reserved : 0; | 531 | __entry->rd_reserved = rs->rs_rbm.rgd->rd_reserved; |
533 | __entry->inum = ip ? ip->i_no_addr : 0; | 532 | __entry->inum = rs->rs_inum; |
534 | __entry->start = gfs2_rs_startblk(rs); | 533 | __entry->start = gfs2_rbm_to_block(&rs->rs_rbm); |
535 | __entry->free = rs->rs_free; | 534 | __entry->free = rs->rs_free; |
536 | __entry->func = func; | 535 | __entry->func = func; |
537 | ), | 536 | ), |
538 | 537 | ||
539 | TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s " | 538 | TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s f:%lu", |
540 | "f:%lu", | ||
541 | MAJOR(__entry->dev), MINOR(__entry->dev), | 539 | MAJOR(__entry->dev), MINOR(__entry->dev), |
542 | (unsigned long long)__entry->inum, | 540 | (unsigned long long)__entry->inum, |
543 | (unsigned long long)__entry->start, | 541 | (unsigned long long)__entry->start, |
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 41f42cdccbb8..bf2ae9aeee7a 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h | |||
@@ -28,11 +28,10 @@ struct gfs2_glock; | |||
28 | 28 | ||
29 | /* reserve either the number of blocks to be allocated plus the rg header | 29 | /* reserve either the number of blocks to be allocated plus the rg header |
30 | * block, or all of the blocks in the rg, whichever is smaller */ | 30 | * block, or all of the blocks in the rg, whichever is smaller */ |
31 | static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip) | 31 | static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip, unsigned requested) |
32 | { | 32 | { |
33 | const struct gfs2_blkreserv *rs = ip->i_res; | 33 | if (requested < ip->i_rgd->rd_length) |
34 | if (rs && rs->rs_requested < ip->i_rgd->rd_length) | 34 | return requested + 1; |
35 | return rs->rs_requested + 1; | ||
36 | return ip->i_rgd->rd_length; | 35 | return ip->i_rgd->rd_length; |
37 | } | 36 | } |
38 | 37 | ||
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c index 27a0b4a901f5..db330e5518cd 100644 --- a/fs/gfs2/xattr.c +++ b/fs/gfs2/xattr.c | |||
@@ -448,17 +448,18 @@ ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
448 | } | 448 | } |
449 | 449 | ||
450 | /** | 450 | /** |
451 | * ea_get_unstuffed - actually copies the unstuffed data into the | 451 | * ea_iter_unstuffed - copies the unstuffed xattr data to/from the |
452 | * request buffer | 452 | * request buffer |
453 | * @ip: The GFS2 inode | 453 | * @ip: The GFS2 inode |
454 | * @ea: The extended attribute header structure | 454 | * @ea: The extended attribute header structure |
455 | * @data: The data to be copied | 455 | * @din: The data to be copied in |
456 | * @dout: The data to be copied out (one of din,dout will be NULL) | ||
456 | * | 457 | * |
457 | * Returns: errno | 458 | * Returns: errno |
458 | */ | 459 | */ |
459 | 460 | ||
460 | static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | 461 | static int gfs2_iter_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, |
461 | char *data) | 462 | const char *din, char *dout) |
462 | { | 463 | { |
463 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 464 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
464 | struct buffer_head **bh; | 465 | struct buffer_head **bh; |
@@ -467,6 +468,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | |||
467 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); | 468 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); |
468 | unsigned int x; | 469 | unsigned int x; |
469 | int error = 0; | 470 | int error = 0; |
471 | unsigned char *pos; | ||
472 | unsigned cp_size; | ||
470 | 473 | ||
471 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); | 474 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); |
472 | if (!bh) | 475 | if (!bh) |
@@ -497,12 +500,21 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | |||
497 | goto out; | 500 | goto out; |
498 | } | 501 | } |
499 | 502 | ||
500 | memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), | 503 | pos = bh[x]->b_data + sizeof(struct gfs2_meta_header); |
501 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); | 504 | cp_size = (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize; |
502 | 505 | ||
503 | amount -= sdp->sd_jbsize; | 506 | if (dout) { |
504 | data += sdp->sd_jbsize; | 507 | memcpy(dout, pos, cp_size); |
508 | dout += sdp->sd_jbsize; | ||
509 | } | ||
510 | |||
511 | if (din) { | ||
512 | gfs2_trans_add_bh(ip->i_gl, bh[x], 1); | ||
513 | memcpy(pos, din, cp_size); | ||
514 | din += sdp->sd_jbsize; | ||
515 | } | ||
505 | 516 | ||
517 | amount -= sdp->sd_jbsize; | ||
506 | brelse(bh[x]); | 518 | brelse(bh[x]); |
507 | } | 519 | } |
508 | 520 | ||
@@ -523,7 +535,7 @@ static int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, | |||
523 | memcpy(data, GFS2_EA2DATA(el->el_ea), len); | 535 | memcpy(data, GFS2_EA2DATA(el->el_ea), len); |
524 | return len; | 536 | return len; |
525 | } | 537 | } |
526 | ret = ea_get_unstuffed(ip, el->el_ea, data); | 538 | ret = gfs2_iter_unstuffed(ip, el->el_ea, NULL, data); |
527 | if (ret < 0) | 539 | if (ret < 0) |
528 | return ret; | 540 | return ret; |
529 | return len; | 541 | return len; |
@@ -727,7 +739,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, | |||
727 | goto out_gunlock_q; | 739 | goto out_gunlock_q; |
728 | 740 | ||
729 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), | 741 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), |
730 | blks + gfs2_rg_blocks(ip) + | 742 | blks + gfs2_rg_blocks(ip, blks) + |
731 | RES_DINODE + RES_STATFS + RES_QUOTA, 0); | 743 | RES_DINODE + RES_STATFS + RES_QUOTA, 0); |
732 | if (error) | 744 | if (error) |
733 | goto out_ipres; | 745 | goto out_ipres; |
@@ -1220,69 +1232,23 @@ static int gfs2_xattr_set(struct dentry *dentry, const char *name, | |||
1220 | size, flags, type); | 1232 | size, flags, type); |
1221 | } | 1233 | } |
1222 | 1234 | ||
1235 | |||
1223 | static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, | 1236 | static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, |
1224 | struct gfs2_ea_header *ea, char *data) | 1237 | struct gfs2_ea_header *ea, char *data) |
1225 | { | 1238 | { |
1226 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 1239 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
1227 | struct buffer_head **bh; | ||
1228 | unsigned int amount = GFS2_EA_DATA_LEN(ea); | 1240 | unsigned int amount = GFS2_EA_DATA_LEN(ea); |
1229 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); | 1241 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); |
1230 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); | 1242 | int ret; |
1231 | unsigned int x; | ||
1232 | int error; | ||
1233 | |||
1234 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); | ||
1235 | if (!bh) | ||
1236 | return -ENOMEM; | ||
1237 | |||
1238 | error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); | ||
1239 | if (error) | ||
1240 | goto out; | ||
1241 | |||
1242 | for (x = 0; x < nptrs; x++) { | ||
1243 | error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, | ||
1244 | bh + x); | ||
1245 | if (error) { | ||
1246 | while (x--) | ||
1247 | brelse(bh[x]); | ||
1248 | goto fail; | ||
1249 | } | ||
1250 | dataptrs++; | ||
1251 | } | ||
1252 | |||
1253 | for (x = 0; x < nptrs; x++) { | ||
1254 | error = gfs2_meta_wait(sdp, bh[x]); | ||
1255 | if (error) { | ||
1256 | for (; x < nptrs; x++) | ||
1257 | brelse(bh[x]); | ||
1258 | goto fail; | ||
1259 | } | ||
1260 | if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { | ||
1261 | for (; x < nptrs; x++) | ||
1262 | brelse(bh[x]); | ||
1263 | error = -EIO; | ||
1264 | goto fail; | ||
1265 | } | ||
1266 | |||
1267 | gfs2_trans_add_bh(ip->i_gl, bh[x], 1); | ||
1268 | |||
1269 | memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data, | ||
1270 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); | ||
1271 | |||
1272 | amount -= sdp->sd_jbsize; | ||
1273 | data += sdp->sd_jbsize; | ||
1274 | |||
1275 | brelse(bh[x]); | ||
1276 | } | ||
1277 | 1243 | ||
1278 | out: | 1244 | ret = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); |
1279 | kfree(bh); | 1245 | if (ret) |
1280 | return error; | 1246 | return ret; |
1281 | 1247 | ||
1282 | fail: | 1248 | ret = gfs2_iter_unstuffed(ip, ea, data, NULL); |
1283 | gfs2_trans_end(sdp); | 1249 | gfs2_trans_end(sdp); |
1284 | kfree(bh); | 1250 | |
1285 | return error; | 1251 | return ret; |
1286 | } | 1252 | } |
1287 | 1253 | ||
1288 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) | 1254 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) |
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h index 8275175acf6e..693df9fe52b2 100644 --- a/fs/hfs/hfs_fs.h +++ b/fs/hfs/hfs_fs.h | |||
@@ -134,8 +134,8 @@ struct hfs_sb_info { | |||
134 | permissions on all files */ | 134 | permissions on all files */ |
135 | umode_t s_dir_umask; /* The umask applied to the | 135 | umode_t s_dir_umask; /* The umask applied to the |
136 | permissions on all dirs */ | 136 | permissions on all dirs */ |
137 | uid_t s_uid; /* The uid of all files */ | 137 | kuid_t s_uid; /* The uid of all files */ |
138 | gid_t s_gid; /* The gid of all files */ | 138 | kgid_t s_gid; /* The gid of all files */ |
139 | 139 | ||
140 | int session, part; | 140 | int session, part; |
141 | struct nls_table *nls_io, *nls_disk; | 141 | struct nls_table *nls_io, *nls_disk; |
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index ee1bc55677f1..0b35903219bc 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c | |||
@@ -594,9 +594,9 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr) | |||
594 | 594 | ||
595 | /* no uig/gid changes and limit which mode bits can be set */ | 595 | /* no uig/gid changes and limit which mode bits can be set */ |
596 | if (((attr->ia_valid & ATTR_UID) && | 596 | if (((attr->ia_valid & ATTR_UID) && |
597 | (attr->ia_uid != hsb->s_uid)) || | 597 | (!uid_eq(attr->ia_uid, hsb->s_uid))) || |
598 | ((attr->ia_valid & ATTR_GID) && | 598 | ((attr->ia_valid & ATTR_GID) && |
599 | (attr->ia_gid != hsb->s_gid)) || | 599 | (!gid_eq(attr->ia_gid, hsb->s_gid))) || |
600 | ((attr->ia_valid & ATTR_MODE) && | 600 | ((attr->ia_valid & ATTR_MODE) && |
601 | ((S_ISDIR(inode->i_mode) && | 601 | ((S_ISDIR(inode->i_mode) && |
602 | (attr->ia_mode != inode->i_mode)) || | 602 | (attr->ia_mode != inode->i_mode)) || |
@@ -644,7 +644,7 @@ static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end, | |||
644 | 644 | ||
645 | /* sync the superblock to buffers */ | 645 | /* sync the superblock to buffers */ |
646 | sb = inode->i_sb; | 646 | sb = inode->i_sb; |
647 | flush_delayed_work_sync(&HFS_SB(sb)->mdb_work); | 647 | flush_delayed_work(&HFS_SB(sb)->mdb_work); |
648 | /* .. finally sync the buffers to disk */ | 648 | /* .. finally sync the buffers to disk */ |
649 | err = sync_blockdev(sb->s_bdev); | 649 | err = sync_blockdev(sb->s_bdev); |
650 | if (!ret) | 650 | if (!ret) |
diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 941d7a8c2197..e93ddaadfd1e 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c | |||
@@ -138,7 +138,9 @@ static int hfs_show_options(struct seq_file *seq, struct dentry *root) | |||
138 | seq_printf(seq, ",creator=%.4s", (char *)&sbi->s_creator); | 138 | seq_printf(seq, ",creator=%.4s", (char *)&sbi->s_creator); |
139 | if (sbi->s_type != cpu_to_be32(0x3f3f3f3f)) | 139 | if (sbi->s_type != cpu_to_be32(0x3f3f3f3f)) |
140 | seq_printf(seq, ",type=%.4s", (char *)&sbi->s_type); | 140 | seq_printf(seq, ",type=%.4s", (char *)&sbi->s_type); |
141 | seq_printf(seq, ",uid=%u,gid=%u", sbi->s_uid, sbi->s_gid); | 141 | seq_printf(seq, ",uid=%u,gid=%u", |
142 | from_kuid_munged(&init_user_ns, sbi->s_uid), | ||
143 | from_kgid_munged(&init_user_ns, sbi->s_gid)); | ||
142 | if (sbi->s_file_umask != 0133) | 144 | if (sbi->s_file_umask != 0133) |
143 | seq_printf(seq, ",file_umask=%o", sbi->s_file_umask); | 145 | seq_printf(seq, ",file_umask=%o", sbi->s_file_umask); |
144 | if (sbi->s_dir_umask != 0022) | 146 | if (sbi->s_dir_umask != 0022) |
@@ -254,14 +256,22 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) | |||
254 | printk(KERN_ERR "hfs: uid requires an argument\n"); | 256 | printk(KERN_ERR "hfs: uid requires an argument\n"); |
255 | return 0; | 257 | return 0; |
256 | } | 258 | } |
257 | hsb->s_uid = (uid_t)tmp; | 259 | hsb->s_uid = make_kuid(current_user_ns(), (uid_t)tmp); |
260 | if (!uid_valid(hsb->s_uid)) { | ||
261 | printk(KERN_ERR "hfs: invalid uid %d\n", tmp); | ||
262 | return 0; | ||
263 | } | ||
258 | break; | 264 | break; |
259 | case opt_gid: | 265 | case opt_gid: |
260 | if (match_int(&args[0], &tmp)) { | 266 | if (match_int(&args[0], &tmp)) { |
261 | printk(KERN_ERR "hfs: gid requires an argument\n"); | 267 | printk(KERN_ERR "hfs: gid requires an argument\n"); |
262 | return 0; | 268 | return 0; |
263 | } | 269 | } |
264 | hsb->s_gid = (gid_t)tmp; | 270 | hsb->s_gid = make_kgid(current_user_ns(), (gid_t)tmp); |
271 | if (!gid_valid(hsb->s_gid)) { | ||
272 | printk(KERN_ERR "hfs: invalid gid %d\n", tmp); | ||
273 | return 0; | ||
274 | } | ||
265 | break; | 275 | break; |
266 | case opt_umask: | 276 | case opt_umask: |
267 | if (match_octal(&args[0], &tmp)) { | 277 | if (match_octal(&args[0], &tmp)) { |
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c index ec2a9c23f0c9..798d9c4c5e71 100644 --- a/fs/hfsplus/catalog.c +++ b/fs/hfsplus/catalog.c | |||
@@ -80,8 +80,8 @@ void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms) | |||
80 | 80 | ||
81 | perms->userflags = HFSPLUS_I(inode)->userflags; | 81 | perms->userflags = HFSPLUS_I(inode)->userflags; |
82 | perms->mode = cpu_to_be16(inode->i_mode); | 82 | perms->mode = cpu_to_be16(inode->i_mode); |
83 | perms->owner = cpu_to_be32(inode->i_uid); | 83 | perms->owner = cpu_to_be32(i_uid_read(inode)); |
84 | perms->group = cpu_to_be32(inode->i_gid); | 84 | perms->group = cpu_to_be32(i_gid_read(inode)); |
85 | 85 | ||
86 | if (S_ISREG(inode->i_mode)) | 86 | if (S_ISREG(inode->i_mode)) |
87 | perms->dev = cpu_to_be32(inode->i_nlink); | 87 | perms->dev = cpu_to_be32(inode->i_nlink); |
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h index 558dbb463a4e..c571de224b15 100644 --- a/fs/hfsplus/hfsplus_fs.h +++ b/fs/hfsplus/hfsplus_fs.h | |||
@@ -149,8 +149,8 @@ struct hfsplus_sb_info { | |||
149 | u32 type; | 149 | u32 type; |
150 | 150 | ||
151 | umode_t umask; | 151 | umode_t umask; |
152 | uid_t uid; | 152 | kuid_t uid; |
153 | gid_t gid; | 153 | kgid_t gid; |
154 | 154 | ||
155 | int part, session; | 155 | int part, session; |
156 | unsigned long flags; | 156 | unsigned long flags; |
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 3d8b4a675ba0..2172aa5976f5 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c | |||
@@ -233,12 +233,12 @@ static void hfsplus_get_perms(struct inode *inode, | |||
233 | 233 | ||
234 | mode = be16_to_cpu(perms->mode); | 234 | mode = be16_to_cpu(perms->mode); |
235 | 235 | ||
236 | inode->i_uid = be32_to_cpu(perms->owner); | 236 | i_uid_write(inode, be32_to_cpu(perms->owner)); |
237 | if (!inode->i_uid && !mode) | 237 | if (!i_uid_read(inode) && !mode) |
238 | inode->i_uid = sbi->uid; | 238 | inode->i_uid = sbi->uid; |
239 | 239 | ||
240 | inode->i_gid = be32_to_cpu(perms->group); | 240 | i_gid_write(inode, be32_to_cpu(perms->group)); |
241 | if (!inode->i_gid && !mode) | 241 | if (!i_gid_read(inode) && !mode) |
242 | inode->i_gid = sbi->gid; | 242 | inode->i_gid = sbi->gid; |
243 | 243 | ||
244 | if (dir) { | 244 | if (dir) { |
diff --git a/fs/hfsplus/options.c b/fs/hfsplus/options.c index 06fa5618600c..ed257c671615 100644 --- a/fs/hfsplus/options.c +++ b/fs/hfsplus/options.c | |||
@@ -135,14 +135,22 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) | |||
135 | printk(KERN_ERR "hfs: uid requires an argument\n"); | 135 | printk(KERN_ERR "hfs: uid requires an argument\n"); |
136 | return 0; | 136 | return 0; |
137 | } | 137 | } |
138 | sbi->uid = (uid_t)tmp; | 138 | sbi->uid = make_kuid(current_user_ns(), (uid_t)tmp); |
139 | if (!uid_valid(sbi->uid)) { | ||
140 | printk(KERN_ERR "hfs: invalid uid specified\n"); | ||
141 | return 0; | ||
142 | } | ||
139 | break; | 143 | break; |
140 | case opt_gid: | 144 | case opt_gid: |
141 | if (match_int(&args[0], &tmp)) { | 145 | if (match_int(&args[0], &tmp)) { |
142 | printk(KERN_ERR "hfs: gid requires an argument\n"); | 146 | printk(KERN_ERR "hfs: gid requires an argument\n"); |
143 | return 0; | 147 | return 0; |
144 | } | 148 | } |
145 | sbi->gid = (gid_t)tmp; | 149 | sbi->gid = make_kgid(current_user_ns(), (gid_t)tmp); |
150 | if (!gid_valid(sbi->gid)) { | ||
151 | printk(KERN_ERR "hfs: invalid gid specified\n"); | ||
152 | return 0; | ||
153 | } | ||
146 | break; | 154 | break; |
147 | case opt_part: | 155 | case opt_part: |
148 | if (match_int(&args[0], &sbi->part)) { | 156 | if (match_int(&args[0], &sbi->part)) { |
@@ -215,7 +223,8 @@ int hfsplus_show_options(struct seq_file *seq, struct dentry *root) | |||
215 | if (sbi->type != HFSPLUS_DEF_CR_TYPE) | 223 | if (sbi->type != HFSPLUS_DEF_CR_TYPE) |
216 | seq_printf(seq, ",type=%.4s", (char *)&sbi->type); | 224 | seq_printf(seq, ",type=%.4s", (char *)&sbi->type); |
217 | seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, | 225 | seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask, |
218 | sbi->uid, sbi->gid); | 226 | from_kuid_munged(&init_user_ns, sbi->uid), |
227 | from_kgid_munged(&init_user_ns, sbi->gid)); | ||
219 | if (sbi->part >= 0) | 228 | if (sbi->part >= 0) |
220 | seq_printf(seq, ",part=%u", sbi->part); | 229 | seq_printf(seq, ",part=%u", sbi->part); |
221 | if (sbi->session >= 0) | 230 | if (sbi->session >= 0) |
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index 124146543aa7..6c9f3a9d5e21 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c | |||
@@ -542,8 +542,8 @@ static int read_name(struct inode *ino, char *name) | |||
542 | ino->i_ino = st.ino; | 542 | ino->i_ino = st.ino; |
543 | ino->i_mode = st.mode; | 543 | ino->i_mode = st.mode; |
544 | set_nlink(ino, st.nlink); | 544 | set_nlink(ino, st.nlink); |
545 | ino->i_uid = st.uid; | 545 | i_uid_write(ino, st.uid); |
546 | ino->i_gid = st.gid; | 546 | i_gid_write(ino, st.gid); |
547 | ino->i_atime = st.atime; | 547 | ino->i_atime = st.atime; |
548 | ino->i_mtime = st.mtime; | 548 | ino->i_mtime = st.mtime; |
549 | ino->i_ctime = st.ctime; | 549 | ino->i_ctime = st.ctime; |
@@ -808,11 +808,11 @@ int hostfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
808 | } | 808 | } |
809 | if (attr->ia_valid & ATTR_UID) { | 809 | if (attr->ia_valid & ATTR_UID) { |
810 | attrs.ia_valid |= HOSTFS_ATTR_UID; | 810 | attrs.ia_valid |= HOSTFS_ATTR_UID; |
811 | attrs.ia_uid = attr->ia_uid; | 811 | attrs.ia_uid = from_kuid(&init_user_ns, attr->ia_uid); |
812 | } | 812 | } |
813 | if (attr->ia_valid & ATTR_GID) { | 813 | if (attr->ia_valid & ATTR_GID) { |
814 | attrs.ia_valid |= HOSTFS_ATTR_GID; | 814 | attrs.ia_valid |= HOSTFS_ATTR_GID; |
815 | attrs.ia_gid = attr->ia_gid; | 815 | attrs.ia_gid = from_kgid(&init_user_ns, attr->ia_gid); |
816 | } | 816 | } |
817 | if (attr->ia_valid & ATTR_SIZE) { | 817 | if (attr->ia_valid & ATTR_SIZE) { |
818 | attrs.ia_valid |= HOSTFS_ATTR_SIZE; | 818 | attrs.ia_valid |= HOSTFS_ATTR_SIZE; |
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h index ac1ead194db5..7102aaecc244 100644 --- a/fs/hpfs/hpfs_fn.h +++ b/fs/hpfs/hpfs_fn.h | |||
@@ -63,8 +63,8 @@ struct hpfs_sb_info { | |||
63 | unsigned sb_dmap; /* sector number of dnode bit map */ | 63 | unsigned sb_dmap; /* sector number of dnode bit map */ |
64 | unsigned sb_n_free; /* free blocks for statfs, or -1 */ | 64 | unsigned sb_n_free; /* free blocks for statfs, or -1 */ |
65 | unsigned sb_n_free_dnodes; /* free dnodes for statfs, or -1 */ | 65 | unsigned sb_n_free_dnodes; /* free dnodes for statfs, or -1 */ |
66 | uid_t sb_uid; /* uid from mount options */ | 66 | kuid_t sb_uid; /* uid from mount options */ |
67 | gid_t sb_gid; /* gid from mount options */ | 67 | kgid_t sb_gid; /* gid from mount options */ |
68 | umode_t sb_mode; /* mode from mount options */ | 68 | umode_t sb_mode; /* mode from mount options */ |
69 | unsigned sb_eas : 2; /* eas: 0-ignore, 1-ro, 2-rw */ | 69 | unsigned sb_eas : 2; /* eas: 0-ignore, 1-ro, 2-rw */ |
70 | unsigned sb_err : 2; /* on errs: 0-cont, 1-ro, 2-panic */ | 70 | unsigned sb_err : 2; /* on errs: 0-cont, 1-ro, 2-panic */ |
diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c index ed671e0ea784..804a9a842cbc 100644 --- a/fs/hpfs/inode.c +++ b/fs/hpfs/inode.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
10 | #include <linux/user_namespace.h> | ||
10 | #include "hpfs_fn.h" | 11 | #include "hpfs_fn.h" |
11 | 12 | ||
12 | void hpfs_init_inode(struct inode *i) | 13 | void hpfs_init_inode(struct inode *i) |
@@ -60,14 +61,14 @@ void hpfs_read_inode(struct inode *i) | |||
60 | if (hpfs_sb(i->i_sb)->sb_eas) { | 61 | if (hpfs_sb(i->i_sb)->sb_eas) { |
61 | if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) { | 62 | if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) { |
62 | if (ea_size == 2) { | 63 | if (ea_size == 2) { |
63 | i->i_uid = le16_to_cpu(*(__le16*)ea); | 64 | i_uid_write(i, le16_to_cpu(*(__le16*)ea)); |
64 | hpfs_inode->i_ea_uid = 1; | 65 | hpfs_inode->i_ea_uid = 1; |
65 | } | 66 | } |
66 | kfree(ea); | 67 | kfree(ea); |
67 | } | 68 | } |
68 | if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) { | 69 | if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) { |
69 | if (ea_size == 2) { | 70 | if (ea_size == 2) { |
70 | i->i_gid = le16_to_cpu(*(__le16*)ea); | 71 | i_gid_write(i, le16_to_cpu(*(__le16*)ea)); |
71 | hpfs_inode->i_ea_gid = 1; | 72 | hpfs_inode->i_ea_gid = 1; |
72 | } | 73 | } |
73 | kfree(ea); | 74 | kfree(ea); |
@@ -149,13 +150,13 @@ static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode) | |||
149 | hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino); | 150 | hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino); |
150 | } else*/ if (hpfs_sb(i->i_sb)->sb_eas >= 2) { | 151 | } else*/ if (hpfs_sb(i->i_sb)->sb_eas >= 2) { |
151 | __le32 ea; | 152 | __le32 ea; |
152 | if ((i->i_uid != hpfs_sb(i->i_sb)->sb_uid) || hpfs_inode->i_ea_uid) { | 153 | if (!uid_eq(i->i_uid, hpfs_sb(i->i_sb)->sb_uid) || hpfs_inode->i_ea_uid) { |
153 | ea = cpu_to_le32(i->i_uid); | 154 | ea = cpu_to_le32(i_uid_read(i)); |
154 | hpfs_set_ea(i, fnode, "UID", (char*)&ea, 2); | 155 | hpfs_set_ea(i, fnode, "UID", (char*)&ea, 2); |
155 | hpfs_inode->i_ea_uid = 1; | 156 | hpfs_inode->i_ea_uid = 1; |
156 | } | 157 | } |
157 | if ((i->i_gid != hpfs_sb(i->i_sb)->sb_gid) || hpfs_inode->i_ea_gid) { | 158 | if (!gid_eq(i->i_gid, hpfs_sb(i->i_sb)->sb_gid) || hpfs_inode->i_ea_gid) { |
158 | ea = cpu_to_le32(i->i_gid); | 159 | ea = cpu_to_le32(i_gid_read(i)); |
159 | hpfs_set_ea(i, fnode, "GID", (char *)&ea, 2); | 160 | hpfs_set_ea(i, fnode, "GID", (char *)&ea, 2); |
160 | hpfs_inode->i_ea_gid = 1; | 161 | hpfs_inode->i_ea_gid = 1; |
161 | } | 162 | } |
@@ -261,9 +262,11 @@ int hpfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
261 | hpfs_lock(inode->i_sb); | 262 | hpfs_lock(inode->i_sb); |
262 | if (inode->i_ino == hpfs_sb(inode->i_sb)->sb_root) | 263 | if (inode->i_ino == hpfs_sb(inode->i_sb)->sb_root) |
263 | goto out_unlock; | 264 | goto out_unlock; |
264 | if ((attr->ia_valid & ATTR_UID) && attr->ia_uid >= 0x10000) | 265 | if ((attr->ia_valid & ATTR_UID) && |
266 | from_kuid(&init_user_ns, attr->ia_uid) >= 0x10000) | ||
265 | goto out_unlock; | 267 | goto out_unlock; |
266 | if ((attr->ia_valid & ATTR_GID) && attr->ia_gid >= 0x10000) | 268 | if ((attr->ia_valid & ATTR_GID) && |
269 | from_kgid(&init_user_ns, attr->ia_gid) >= 0x10000) | ||
267 | goto out_unlock; | 270 | goto out_unlock; |
268 | if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size) | 271 | if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size) |
269 | goto out_unlock; | 272 | goto out_unlock; |
diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c index bc9082482f68..345713d2f8f3 100644 --- a/fs/hpfs/namei.c +++ b/fs/hpfs/namei.c | |||
@@ -91,8 +91,8 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
91 | inc_nlink(dir); | 91 | inc_nlink(dir); |
92 | insert_inode_hash(result); | 92 | insert_inode_hash(result); |
93 | 93 | ||
94 | if (result->i_uid != current_fsuid() || | 94 | if (!uid_eq(result->i_uid, current_fsuid()) || |
95 | result->i_gid != current_fsgid() || | 95 | !gid_eq(result->i_gid, current_fsgid()) || |
96 | result->i_mode != (mode | S_IFDIR)) { | 96 | result->i_mode != (mode | S_IFDIR)) { |
97 | result->i_uid = current_fsuid(); | 97 | result->i_uid = current_fsuid(); |
98 | result->i_gid = current_fsgid(); | 98 | result->i_gid = current_fsgid(); |
@@ -179,8 +179,8 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, b | |||
179 | 179 | ||
180 | insert_inode_hash(result); | 180 | insert_inode_hash(result); |
181 | 181 | ||
182 | if (result->i_uid != current_fsuid() || | 182 | if (!uid_eq(result->i_uid, current_fsuid()) || |
183 | result->i_gid != current_fsgid() || | 183 | !gid_eq(result->i_gid, current_fsgid()) || |
184 | result->i_mode != (mode | S_IFREG)) { | 184 | result->i_mode != (mode | S_IFREG)) { |
185 | result->i_uid = current_fsuid(); | 185 | result->i_uid = current_fsuid(); |
186 | result->i_gid = current_fsgid(); | 186 | result->i_gid = current_fsgid(); |
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c index 3cb1da56eb73..bc28bf077a6a 100644 --- a/fs/hpfs/super.c +++ b/fs/hpfs/super.c | |||
@@ -256,7 +256,7 @@ static const match_table_t tokens = { | |||
256 | {Opt_err, NULL}, | 256 | {Opt_err, NULL}, |
257 | }; | 257 | }; |
258 | 258 | ||
259 | static int parse_opts(char *opts, uid_t *uid, gid_t *gid, umode_t *umask, | 259 | static int parse_opts(char *opts, kuid_t *uid, kgid_t *gid, umode_t *umask, |
260 | int *lowercase, int *eas, int *chk, int *errs, | 260 | int *lowercase, int *eas, int *chk, int *errs, |
261 | int *chkdsk, int *timeshift) | 261 | int *chkdsk, int *timeshift) |
262 | { | 262 | { |
@@ -281,12 +281,16 @@ static int parse_opts(char *opts, uid_t *uid, gid_t *gid, umode_t *umask, | |||
281 | case Opt_uid: | 281 | case Opt_uid: |
282 | if (match_int(args, &option)) | 282 | if (match_int(args, &option)) |
283 | return 0; | 283 | return 0; |
284 | *uid = option; | 284 | *uid = make_kuid(current_user_ns(), option); |
285 | if (!uid_valid(*uid)) | ||
286 | return 0; | ||
285 | break; | 287 | break; |
286 | case Opt_gid: | 288 | case Opt_gid: |
287 | if (match_int(args, &option)) | 289 | if (match_int(args, &option)) |
288 | return 0; | 290 | return 0; |
289 | *gid = option; | 291 | *gid = make_kgid(current_user_ns(), option); |
292 | if (!gid_valid(*gid)) | ||
293 | return 0; | ||
290 | break; | 294 | break; |
291 | case Opt_umask: | 295 | case Opt_umask: |
292 | if (match_octal(args, &option)) | 296 | if (match_octal(args, &option)) |
@@ -383,8 +387,8 @@ HPFS filesystem options:\n\ | |||
383 | 387 | ||
384 | static int hpfs_remount_fs(struct super_block *s, int *flags, char *data) | 388 | static int hpfs_remount_fs(struct super_block *s, int *flags, char *data) |
385 | { | 389 | { |
386 | uid_t uid; | 390 | kuid_t uid; |
387 | gid_t gid; | 391 | kgid_t gid; |
388 | umode_t umask; | 392 | umode_t umask; |
389 | int lowercase, eas, chk, errs, chkdsk, timeshift; | 393 | int lowercase, eas, chk, errs, chkdsk, timeshift; |
390 | int o; | 394 | int o; |
@@ -460,8 +464,8 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) | |||
460 | struct hpfs_sb_info *sbi; | 464 | struct hpfs_sb_info *sbi; |
461 | struct inode *root; | 465 | struct inode *root; |
462 | 466 | ||
463 | uid_t uid; | 467 | kuid_t uid; |
464 | gid_t gid; | 468 | kgid_t gid; |
465 | umode_t umask; | 469 | umode_t umask; |
466 | int lowercase, eas, chk, errs, chkdsk, timeshift; | 470 | int lowercase, eas, chk, errs, chkdsk, timeshift; |
467 | 471 | ||
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index c4b85d064e6b..9460120a5170 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c | |||
@@ -42,8 +42,8 @@ static const struct inode_operations hugetlbfs_dir_inode_operations; | |||
42 | static const struct inode_operations hugetlbfs_inode_operations; | 42 | static const struct inode_operations hugetlbfs_inode_operations; |
43 | 43 | ||
44 | struct hugetlbfs_config { | 44 | struct hugetlbfs_config { |
45 | uid_t uid; | 45 | kuid_t uid; |
46 | gid_t gid; | 46 | kgid_t gid; |
47 | umode_t mode; | 47 | umode_t mode; |
48 | long nr_blocks; | 48 | long nr_blocks; |
49 | long nr_inodes; | 49 | long nr_inodes; |
@@ -785,13 +785,17 @@ hugetlbfs_parse_options(char *options, struct hugetlbfs_config *pconfig) | |||
785 | case Opt_uid: | 785 | case Opt_uid: |
786 | if (match_int(&args[0], &option)) | 786 | if (match_int(&args[0], &option)) |
787 | goto bad_val; | 787 | goto bad_val; |
788 | pconfig->uid = option; | 788 | pconfig->uid = make_kuid(current_user_ns(), option); |
789 | if (!uid_valid(pconfig->uid)) | ||
790 | goto bad_val; | ||
789 | break; | 791 | break; |
790 | 792 | ||
791 | case Opt_gid: | 793 | case Opt_gid: |
792 | if (match_int(&args[0], &option)) | 794 | if (match_int(&args[0], &option)) |
793 | goto bad_val; | 795 | goto bad_val; |
794 | pconfig->gid = option; | 796 | pconfig->gid = make_kgid(current_user_ns(), option); |
797 | if (!gid_valid(pconfig->gid)) | ||
798 | goto bad_val; | ||
795 | break; | 799 | break; |
796 | 800 | ||
797 | case Opt_mode: | 801 | case Opt_mode: |
@@ -924,7 +928,9 @@ static struct vfsmount *hugetlbfs_vfsmount; | |||
924 | 928 | ||
925 | static int can_do_hugetlb_shm(void) | 929 | static int can_do_hugetlb_shm(void) |
926 | { | 930 | { |
927 | return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group); | 931 | kgid_t shm_group; |
932 | shm_group = make_kgid(&init_user_ns, sysctl_hugetlb_shm_group); | ||
933 | return capable(CAP_IPC_LOCK) || in_group_p(shm_group); | ||
928 | } | 934 | } |
929 | 935 | ||
930 | struct file *hugetlb_file_setup(const char *name, unsigned long addr, | 936 | struct file *hugetlb_file_setup(const char *name, unsigned long addr, |
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c index f94cde4527e8..67ce52507d7d 100644 --- a/fs/isofs/inode.c +++ b/fs/isofs/inode.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/cdrom.h> | 21 | #include <linux/cdrom.h> |
22 | #include <linux/parser.h> | 22 | #include <linux/parser.h> |
23 | #include <linux/mpage.h> | 23 | #include <linux/mpage.h> |
24 | #include <linux/user_namespace.h> | ||
24 | 25 | ||
25 | #include "isofs.h" | 26 | #include "isofs.h" |
26 | #include "zisofs.h" | 27 | #include "zisofs.h" |
@@ -176,8 +177,8 @@ struct iso9660_options{ | |||
176 | unsigned int blocksize; | 177 | unsigned int blocksize; |
177 | umode_t fmode; | 178 | umode_t fmode; |
178 | umode_t dmode; | 179 | umode_t dmode; |
179 | gid_t gid; | 180 | kgid_t gid; |
180 | uid_t uid; | 181 | kuid_t uid; |
181 | char *iocharset; | 182 | char *iocharset; |
182 | /* LVE */ | 183 | /* LVE */ |
183 | s32 session; | 184 | s32 session; |
@@ -388,8 +389,8 @@ static int parse_options(char *options, struct iso9660_options *popt) | |||
388 | popt->fmode = popt->dmode = ISOFS_INVALID_MODE; | 389 | popt->fmode = popt->dmode = ISOFS_INVALID_MODE; |
389 | popt->uid_set = 0; | 390 | popt->uid_set = 0; |
390 | popt->gid_set = 0; | 391 | popt->gid_set = 0; |
391 | popt->gid = 0; | 392 | popt->gid = GLOBAL_ROOT_GID; |
392 | popt->uid = 0; | 393 | popt->uid = GLOBAL_ROOT_UID; |
393 | popt->iocharset = NULL; | 394 | popt->iocharset = NULL; |
394 | popt->utf8 = 0; | 395 | popt->utf8 = 0; |
395 | popt->overriderockperm = 0; | 396 | popt->overriderockperm = 0; |
@@ -465,13 +466,17 @@ static int parse_options(char *options, struct iso9660_options *popt) | |||
465 | case Opt_uid: | 466 | case Opt_uid: |
466 | if (match_int(&args[0], &option)) | 467 | if (match_int(&args[0], &option)) |
467 | return 0; | 468 | return 0; |
468 | popt->uid = option; | 469 | popt->uid = make_kuid(current_user_ns(), option); |
470 | if (!uid_valid(popt->uid)) | ||
471 | return 0; | ||
469 | popt->uid_set = 1; | 472 | popt->uid_set = 1; |
470 | break; | 473 | break; |
471 | case Opt_gid: | 474 | case Opt_gid: |
472 | if (match_int(&args[0], &option)) | 475 | if (match_int(&args[0], &option)) |
473 | return 0; | 476 | return 0; |
474 | popt->gid = option; | 477 | popt->gid = make_kgid(current_user_ns(), option); |
478 | if (!gid_valid(popt->gid)) | ||
479 | return 0; | ||
475 | popt->gid_set = 1; | 480 | popt->gid_set = 1; |
476 | break; | 481 | break; |
477 | case Opt_mode: | 482 | case Opt_mode: |
diff --git a/fs/isofs/isofs.h b/fs/isofs/isofs.h index 3620ad1ea9bc..99167238518d 100644 --- a/fs/isofs/isofs.h +++ b/fs/isofs/isofs.h | |||
@@ -52,8 +52,8 @@ struct isofs_sb_info { | |||
52 | 52 | ||
53 | umode_t s_fmode; | 53 | umode_t s_fmode; |
54 | umode_t s_dmode; | 54 | umode_t s_dmode; |
55 | gid_t s_gid; | 55 | kgid_t s_gid; |
56 | uid_t s_uid; | 56 | kuid_t s_uid; |
57 | struct nls_table *s_nls_iocharset; /* Native language support table */ | 57 | struct nls_table *s_nls_iocharset; /* Native language support table */ |
58 | }; | 58 | }; |
59 | 59 | ||
diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c index 70e79d0c756a..c0bf42472e40 100644 --- a/fs/isofs/rock.c +++ b/fs/isofs/rock.c | |||
@@ -364,8 +364,8 @@ repeat: | |||
364 | case SIG('P', 'X'): | 364 | case SIG('P', 'X'): |
365 | inode->i_mode = isonum_733(rr->u.PX.mode); | 365 | inode->i_mode = isonum_733(rr->u.PX.mode); |
366 | set_nlink(inode, isonum_733(rr->u.PX.n_links)); | 366 | set_nlink(inode, isonum_733(rr->u.PX.n_links)); |
367 | inode->i_uid = isonum_733(rr->u.PX.uid); | 367 | i_uid_write(inode, isonum_733(rr->u.PX.uid)); |
368 | inode->i_gid = isonum_733(rr->u.PX.gid); | 368 | i_gid_write(inode, isonum_733(rr->u.PX.gid)); |
369 | break; | 369 | break; |
370 | case SIG('P', 'N'): | 370 | case SIG('P', 'N'): |
371 | { | 371 | { |
diff --git a/fs/jffs2/acl.c b/fs/jffs2/acl.c index 922f146e4235..223283c30111 100644 --- a/fs/jffs2/acl.c +++ b/fs/jffs2/acl.c | |||
@@ -94,15 +94,23 @@ static struct posix_acl *jffs2_acl_from_medium(void *value, size_t size) | |||
94 | case ACL_MASK: | 94 | case ACL_MASK: |
95 | case ACL_OTHER: | 95 | case ACL_OTHER: |
96 | value += sizeof(struct jffs2_acl_entry_short); | 96 | value += sizeof(struct jffs2_acl_entry_short); |
97 | acl->a_entries[i].e_id = ACL_UNDEFINED_ID; | ||
98 | break; | 97 | break; |
99 | 98 | ||
100 | case ACL_USER: | 99 | case ACL_USER: |
100 | value += sizeof(struct jffs2_acl_entry); | ||
101 | if (value > end) | ||
102 | goto fail; | ||
103 | acl->a_entries[i].e_uid = | ||
104 | make_kuid(&init_user_ns, | ||
105 | je32_to_cpu(entry->e_id)); | ||
106 | break; | ||
101 | case ACL_GROUP: | 107 | case ACL_GROUP: |
102 | value += sizeof(struct jffs2_acl_entry); | 108 | value += sizeof(struct jffs2_acl_entry); |
103 | if (value > end) | 109 | if (value > end) |
104 | goto fail; | 110 | goto fail; |
105 | acl->a_entries[i].e_id = je32_to_cpu(entry->e_id); | 111 | acl->a_entries[i].e_gid = |
112 | make_kgid(&init_user_ns, | ||
113 | je32_to_cpu(entry->e_id)); | ||
106 | break; | 114 | break; |
107 | 115 | ||
108 | default: | 116 | default: |
@@ -131,13 +139,19 @@ static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size) | |||
131 | header->a_version = cpu_to_je32(JFFS2_ACL_VERSION); | 139 | header->a_version = cpu_to_je32(JFFS2_ACL_VERSION); |
132 | e = header + 1; | 140 | e = header + 1; |
133 | for (i=0; i < acl->a_count; i++) { | 141 | for (i=0; i < acl->a_count; i++) { |
142 | const struct posix_acl_entry *acl_e = &acl->a_entries[i]; | ||
134 | entry = e; | 143 | entry = e; |
135 | entry->e_tag = cpu_to_je16(acl->a_entries[i].e_tag); | 144 | entry->e_tag = cpu_to_je16(acl_e->e_tag); |
136 | entry->e_perm = cpu_to_je16(acl->a_entries[i].e_perm); | 145 | entry->e_perm = cpu_to_je16(acl_e->e_perm); |
137 | switch(acl->a_entries[i].e_tag) { | 146 | switch(acl_e->e_tag) { |
138 | case ACL_USER: | 147 | case ACL_USER: |
148 | entry->e_id = cpu_to_je32( | ||
149 | from_kuid(&init_user_ns, acl_e->e_uid)); | ||
150 | e += sizeof(struct jffs2_acl_entry); | ||
151 | break; | ||
139 | case ACL_GROUP: | 152 | case ACL_GROUP: |
140 | entry->e_id = cpu_to_je32(acl->a_entries[i].e_id); | 153 | entry->e_id = cpu_to_je32( |
154 | from_kgid(&init_user_ns, acl_e->e_gid)); | ||
141 | e += sizeof(struct jffs2_acl_entry); | 155 | e += sizeof(struct jffs2_acl_entry); |
142 | break; | 156 | break; |
143 | 157 | ||
@@ -363,7 +377,7 @@ static int jffs2_acl_getxattr(struct dentry *dentry, const char *name, | |||
363 | return PTR_ERR(acl); | 377 | return PTR_ERR(acl); |
364 | if (!acl) | 378 | if (!acl) |
365 | return -ENODATA; | 379 | return -ENODATA; |
366 | rc = posix_acl_to_xattr(acl, buffer, size); | 380 | rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
367 | posix_acl_release(acl); | 381 | posix_acl_release(acl); |
368 | 382 | ||
369 | return rc; | 383 | return rc; |
@@ -381,7 +395,7 @@ static int jffs2_acl_setxattr(struct dentry *dentry, const char *name, | |||
381 | return -EPERM; | 395 | return -EPERM; |
382 | 396 | ||
383 | if (value) { | 397 | if (value) { |
384 | acl = posix_acl_from_xattr(value, size); | 398 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
385 | if (IS_ERR(acl)) | 399 | if (IS_ERR(acl)) |
386 | return PTR_ERR(acl); | 400 | return PTR_ERR(acl); |
387 | if (acl) { | 401 | if (acl) { |
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c index db3889ba8818..60ef3fb707ff 100644 --- a/fs/jffs2/file.c +++ b/fs/jffs2/file.c | |||
@@ -175,8 +175,8 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping, | |||
175 | ri.ino = cpu_to_je32(f->inocache->ino); | 175 | ri.ino = cpu_to_je32(f->inocache->ino); |
176 | ri.version = cpu_to_je32(++f->highest_version); | 176 | ri.version = cpu_to_je32(++f->highest_version); |
177 | ri.mode = cpu_to_jemode(inode->i_mode); | 177 | ri.mode = cpu_to_jemode(inode->i_mode); |
178 | ri.uid = cpu_to_je16(inode->i_uid); | 178 | ri.uid = cpu_to_je16(i_uid_read(inode)); |
179 | ri.gid = cpu_to_je16(inode->i_gid); | 179 | ri.gid = cpu_to_je16(i_gid_read(inode)); |
180 | ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs)); | 180 | ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs)); |
181 | ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds()); | 181 | ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds()); |
182 | ri.offset = cpu_to_je32(inode->i_size); | 182 | ri.offset = cpu_to_je32(inode->i_size); |
@@ -283,8 +283,8 @@ static int jffs2_write_end(struct file *filp, struct address_space *mapping, | |||
283 | /* Set the fields that the generic jffs2_write_inode_range() code can't find */ | 283 | /* Set the fields that the generic jffs2_write_inode_range() code can't find */ |
284 | ri->ino = cpu_to_je32(inode->i_ino); | 284 | ri->ino = cpu_to_je32(inode->i_ino); |
285 | ri->mode = cpu_to_jemode(inode->i_mode); | 285 | ri->mode = cpu_to_jemode(inode->i_mode); |
286 | ri->uid = cpu_to_je16(inode->i_uid); | 286 | ri->uid = cpu_to_je16(i_uid_read(inode)); |
287 | ri->gid = cpu_to_je16(inode->i_gid); | 287 | ri->gid = cpu_to_je16(i_gid_read(inode)); |
288 | ri->isize = cpu_to_je32((uint32_t)inode->i_size); | 288 | ri->isize = cpu_to_je32((uint32_t)inode->i_size); |
289 | ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds()); | 289 | ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds()); |
290 | 290 | ||
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 3d3092eda811..fe3c0527545f 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c | |||
@@ -99,8 +99,10 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) | |||
99 | ri->ino = cpu_to_je32(inode->i_ino); | 99 | ri->ino = cpu_to_je32(inode->i_ino); |
100 | ri->version = cpu_to_je32(++f->highest_version); | 100 | ri->version = cpu_to_je32(++f->highest_version); |
101 | 101 | ||
102 | ri->uid = cpu_to_je16((ivalid & ATTR_UID)?iattr->ia_uid:inode->i_uid); | 102 | ri->uid = cpu_to_je16((ivalid & ATTR_UID)? |
103 | ri->gid = cpu_to_je16((ivalid & ATTR_GID)?iattr->ia_gid:inode->i_gid); | 103 | from_kuid(&init_user_ns, iattr->ia_uid):i_uid_read(inode)); |
104 | ri->gid = cpu_to_je16((ivalid & ATTR_GID)? | ||
105 | from_kgid(&init_user_ns, iattr->ia_gid):i_gid_read(inode)); | ||
104 | 106 | ||
105 | if (ivalid & ATTR_MODE) | 107 | if (ivalid & ATTR_MODE) |
106 | ri->mode = cpu_to_jemode(iattr->ia_mode); | 108 | ri->mode = cpu_to_jemode(iattr->ia_mode); |
@@ -147,8 +149,8 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr) | |||
147 | inode->i_ctime = ITIME(je32_to_cpu(ri->ctime)); | 149 | inode->i_ctime = ITIME(je32_to_cpu(ri->ctime)); |
148 | inode->i_mtime = ITIME(je32_to_cpu(ri->mtime)); | 150 | inode->i_mtime = ITIME(je32_to_cpu(ri->mtime)); |
149 | inode->i_mode = jemode_to_cpu(ri->mode); | 151 | inode->i_mode = jemode_to_cpu(ri->mode); |
150 | inode->i_uid = je16_to_cpu(ri->uid); | 152 | i_uid_write(inode, je16_to_cpu(ri->uid)); |
151 | inode->i_gid = je16_to_cpu(ri->gid); | 153 | i_gid_write(inode, je16_to_cpu(ri->gid)); |
152 | 154 | ||
153 | 155 | ||
154 | old_metadata = f->metadata; | 156 | old_metadata = f->metadata; |
@@ -276,8 +278,8 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino) | |||
276 | return ERR_PTR(ret); | 278 | return ERR_PTR(ret); |
277 | } | 279 | } |
278 | inode->i_mode = jemode_to_cpu(latest_node.mode); | 280 | inode->i_mode = jemode_to_cpu(latest_node.mode); |
279 | inode->i_uid = je16_to_cpu(latest_node.uid); | 281 | i_uid_write(inode, je16_to_cpu(latest_node.uid)); |
280 | inode->i_gid = je16_to_cpu(latest_node.gid); | 282 | i_gid_write(inode, je16_to_cpu(latest_node.gid)); |
281 | inode->i_size = je32_to_cpu(latest_node.isize); | 283 | inode->i_size = je32_to_cpu(latest_node.isize); |
282 | inode->i_atime = ITIME(je32_to_cpu(latest_node.atime)); | 284 | inode->i_atime = ITIME(je32_to_cpu(latest_node.atime)); |
283 | inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime)); | 285 | inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime)); |
@@ -440,14 +442,14 @@ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_r | |||
440 | 442 | ||
441 | memset(ri, 0, sizeof(*ri)); | 443 | memset(ri, 0, sizeof(*ri)); |
442 | /* Set OS-specific defaults for new inodes */ | 444 | /* Set OS-specific defaults for new inodes */ |
443 | ri->uid = cpu_to_je16(current_fsuid()); | 445 | ri->uid = cpu_to_je16(from_kuid(&init_user_ns, current_fsuid())); |
444 | 446 | ||
445 | if (dir_i->i_mode & S_ISGID) { | 447 | if (dir_i->i_mode & S_ISGID) { |
446 | ri->gid = cpu_to_je16(dir_i->i_gid); | 448 | ri->gid = cpu_to_je16(i_gid_read(dir_i)); |
447 | if (S_ISDIR(mode)) | 449 | if (S_ISDIR(mode)) |
448 | mode |= S_ISGID; | 450 | mode |= S_ISGID; |
449 | } else { | 451 | } else { |
450 | ri->gid = cpu_to_je16(current_fsgid()); | 452 | ri->gid = cpu_to_je16(from_kgid(&init_user_ns, current_fsgid())); |
451 | } | 453 | } |
452 | 454 | ||
453 | /* POSIX ACLs have to be processed now, at least partly. | 455 | /* POSIX ACLs have to be processed now, at least partly. |
@@ -467,8 +469,8 @@ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_r | |||
467 | set_nlink(inode, 1); | 469 | set_nlink(inode, 1); |
468 | inode->i_ino = je32_to_cpu(ri->ino); | 470 | inode->i_ino = je32_to_cpu(ri->ino); |
469 | inode->i_mode = jemode_to_cpu(ri->mode); | 471 | inode->i_mode = jemode_to_cpu(ri->mode); |
470 | inode->i_gid = je16_to_cpu(ri->gid); | 472 | i_gid_write(inode, je16_to_cpu(ri->gid)); |
471 | inode->i_uid = je16_to_cpu(ri->uid); | 473 | i_uid_write(inode, je16_to_cpu(ri->uid)); |
472 | inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; | 474 | inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; |
473 | ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime)); | 475 | ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime)); |
474 | 476 | ||
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h index bcd983d7e7f9..d200a9b8fd5e 100644 --- a/fs/jffs2/os-linux.h +++ b/fs/jffs2/os-linux.h | |||
@@ -27,8 +27,8 @@ struct kvec; | |||
27 | 27 | ||
28 | #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) | 28 | #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) |
29 | #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) | 29 | #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) |
30 | #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid) | 30 | #define JFFS2_F_I_UID(f) (i_uid_read(OFNI_EDONI_2SFFJ(f))) |
31 | #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid) | 31 | #define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f))) |
32 | #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev) | 32 | #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev) |
33 | 33 | ||
34 | #define ITIME(sec) ((struct timespec){sec, 0}) | 34 | #define ITIME(sec) ((struct timespec){sec, 0}) |
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c index 45559dc3ea2f..d254d6d35995 100644 --- a/fs/jfs/acl.c +++ b/fs/jfs/acl.c | |||
@@ -64,7 +64,7 @@ struct posix_acl *jfs_get_acl(struct inode *inode, int type) | |||
64 | else | 64 | else |
65 | acl = ERR_PTR(size); | 65 | acl = ERR_PTR(size); |
66 | } else { | 66 | } else { |
67 | acl = posix_acl_from_xattr(value, size); | 67 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
68 | } | 68 | } |
69 | kfree(value); | 69 | kfree(value); |
70 | if (!IS_ERR(acl)) | 70 | if (!IS_ERR(acl)) |
@@ -100,7 +100,7 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int type, | |||
100 | value = kmalloc(size, GFP_KERNEL); | 100 | value = kmalloc(size, GFP_KERNEL); |
101 | if (!value) | 101 | if (!value) |
102 | return -ENOMEM; | 102 | return -ENOMEM; |
103 | rc = posix_acl_to_xattr(acl, value, size); | 103 | rc = posix_acl_to_xattr(&init_user_ns, acl, value, size); |
104 | if (rc < 0) | 104 | if (rc < 0) |
105 | goto out; | 105 | goto out; |
106 | } | 106 | } |
diff --git a/fs/jfs/file.c b/fs/jfs/file.c index 844f9460cb11..9d3afd157f99 100644 --- a/fs/jfs/file.c +++ b/fs/jfs/file.c | |||
@@ -108,8 +108,8 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
108 | 108 | ||
109 | if (is_quota_modification(inode, iattr)) | 109 | if (is_quota_modification(inode, iattr)) |
110 | dquot_initialize(inode); | 110 | dquot_initialize(inode); |
111 | if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) || | 111 | if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) || |
112 | (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) { | 112 | (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) { |
113 | rc = dquot_transfer(inode, iattr); | 113 | rc = dquot_transfer(inode, iattr); |
114 | if (rc) | 114 | if (rc) |
115 | return rc; | 115 | return rc; |
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c index 1b6f15f191b3..6ba4006e011b 100644 --- a/fs/jfs/jfs_imap.c +++ b/fs/jfs/jfs_imap.c | |||
@@ -3078,15 +3078,15 @@ static int copy_from_dinode(struct dinode * dip, struct inode *ip) | |||
3078 | } | 3078 | } |
3079 | set_nlink(ip, le32_to_cpu(dip->di_nlink)); | 3079 | set_nlink(ip, le32_to_cpu(dip->di_nlink)); |
3080 | 3080 | ||
3081 | jfs_ip->saved_uid = le32_to_cpu(dip->di_uid); | 3081 | jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid)); |
3082 | if (sbi->uid == -1) | 3082 | if (!uid_valid(sbi->uid)) |
3083 | ip->i_uid = jfs_ip->saved_uid; | 3083 | ip->i_uid = jfs_ip->saved_uid; |
3084 | else { | 3084 | else { |
3085 | ip->i_uid = sbi->uid; | 3085 | ip->i_uid = sbi->uid; |
3086 | } | 3086 | } |
3087 | 3087 | ||
3088 | jfs_ip->saved_gid = le32_to_cpu(dip->di_gid); | 3088 | jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid)); |
3089 | if (sbi->gid == -1) | 3089 | if (!gid_valid(sbi->gid)) |
3090 | ip->i_gid = jfs_ip->saved_gid; | 3090 | ip->i_gid = jfs_ip->saved_gid; |
3091 | else { | 3091 | else { |
3092 | ip->i_gid = sbi->gid; | 3092 | ip->i_gid = sbi->gid; |
@@ -3150,14 +3150,16 @@ static void copy_to_dinode(struct dinode * dip, struct inode *ip) | |||
3150 | dip->di_size = cpu_to_le64(ip->i_size); | 3150 | dip->di_size = cpu_to_le64(ip->i_size); |
3151 | dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); | 3151 | dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); |
3152 | dip->di_nlink = cpu_to_le32(ip->i_nlink); | 3152 | dip->di_nlink = cpu_to_le32(ip->i_nlink); |
3153 | if (sbi->uid == -1) | 3153 | if (!uid_valid(sbi->uid)) |
3154 | dip->di_uid = cpu_to_le32(ip->i_uid); | 3154 | dip->di_uid = cpu_to_le32(i_uid_read(ip)); |
3155 | else | 3155 | else |
3156 | dip->di_uid = cpu_to_le32(jfs_ip->saved_uid); | 3156 | dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns, |
3157 | if (sbi->gid == -1) | 3157 | jfs_ip->saved_uid)); |
3158 | dip->di_gid = cpu_to_le32(ip->i_gid); | 3158 | if (!gid_valid(sbi->gid)) |
3159 | dip->di_gid = cpu_to_le32(i_gid_read(ip)); | ||
3159 | else | 3160 | else |
3160 | dip->di_gid = cpu_to_le32(jfs_ip->saved_gid); | 3161 | dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns, |
3162 | jfs_ip->saved_gid)); | ||
3161 | jfs_get_inode_flags(jfs_ip); | 3163 | jfs_get_inode_flags(jfs_ip); |
3162 | /* | 3164 | /* |
3163 | * mode2 is only needed for storing the higher order bits. | 3165 | * mode2 is only needed for storing the higher order bits. |
diff --git a/fs/jfs/jfs_incore.h b/fs/jfs/jfs_incore.h index 584a4a1a6e81..680605d7bf15 100644 --- a/fs/jfs/jfs_incore.h +++ b/fs/jfs/jfs_incore.h | |||
@@ -38,8 +38,8 @@ | |||
38 | struct jfs_inode_info { | 38 | struct jfs_inode_info { |
39 | int fileset; /* fileset number (always 16)*/ | 39 | int fileset; /* fileset number (always 16)*/ |
40 | uint mode2; /* jfs-specific mode */ | 40 | uint mode2; /* jfs-specific mode */ |
41 | uint saved_uid; /* saved for uid mount option */ | 41 | kuid_t saved_uid; /* saved for uid mount option */ |
42 | uint saved_gid; /* saved for gid mount option */ | 42 | kgid_t saved_gid; /* saved for gid mount option */ |
43 | pxd_t ixpxd; /* inode extent descriptor */ | 43 | pxd_t ixpxd; /* inode extent descriptor */ |
44 | dxd_t acl; /* dxd describing acl */ | 44 | dxd_t acl; /* dxd describing acl */ |
45 | dxd_t ea; /* dxd describing ea */ | 45 | dxd_t ea; /* dxd describing ea */ |
@@ -192,8 +192,8 @@ struct jfs_sb_info { | |||
192 | uint state; /* mount/recovery state */ | 192 | uint state; /* mount/recovery state */ |
193 | unsigned long flag; /* mount time flags */ | 193 | unsigned long flag; /* mount time flags */ |
194 | uint p_state; /* state prior to going no integrity */ | 194 | uint p_state; /* state prior to going no integrity */ |
195 | uint uid; /* uid to override on-disk uid */ | 195 | kuid_t uid; /* uid to override on-disk uid */ |
196 | uint gid; /* gid to override on-disk gid */ | 196 | kgid_t gid; /* gid to override on-disk gid */ |
197 | uint umask; /* umask to override on-disk umask */ | 197 | uint umask; /* umask to override on-disk umask */ |
198 | }; | 198 | }; |
199 | 199 | ||
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 3735347fd5f6..efdf8835dfca 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
@@ -321,13 +321,19 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, | |||
321 | case Opt_uid: | 321 | case Opt_uid: |
322 | { | 322 | { |
323 | char *uid = args[0].from; | 323 | char *uid = args[0].from; |
324 | sbi->uid = simple_strtoul(uid, &uid, 0); | 324 | uid_t val = simple_strtoul(uid, &uid, 0); |
325 | sbi->uid = make_kuid(current_user_ns(), val); | ||
326 | if (!uid_valid(sbi->uid)) | ||
327 | goto cleanup; | ||
325 | break; | 328 | break; |
326 | } | 329 | } |
327 | case Opt_gid: | 330 | case Opt_gid: |
328 | { | 331 | { |
329 | char *gid = args[0].from; | 332 | char *gid = args[0].from; |
330 | sbi->gid = simple_strtoul(gid, &gid, 0); | 333 | gid_t val = simple_strtoul(gid, &gid, 0); |
334 | sbi->gid = make_kgid(current_user_ns(), val); | ||
335 | if (!gid_valid(sbi->gid)) | ||
336 | goto cleanup; | ||
331 | break; | 337 | break; |
332 | } | 338 | } |
333 | case Opt_umask: | 339 | case Opt_umask: |
@@ -443,7 +449,9 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |||
443 | sb->s_fs_info = sbi; | 449 | sb->s_fs_info = sbi; |
444 | sb->s_max_links = JFS_LINK_MAX; | 450 | sb->s_max_links = JFS_LINK_MAX; |
445 | sbi->sb = sb; | 451 | sbi->sb = sb; |
446 | sbi->uid = sbi->gid = sbi->umask = -1; | 452 | sbi->uid = INVALID_UID; |
453 | sbi->gid = INVALID_GID; | ||
454 | sbi->umask = -1; | ||
447 | 455 | ||
448 | /* initialize the mount flag and determine the default error handler */ | 456 | /* initialize the mount flag and determine the default error handler */ |
449 | flag = JFS_ERR_REMOUNT_RO; | 457 | flag = JFS_ERR_REMOUNT_RO; |
@@ -617,10 +625,10 @@ static int jfs_show_options(struct seq_file *seq, struct dentry *root) | |||
617 | { | 625 | { |
618 | struct jfs_sb_info *sbi = JFS_SBI(root->d_sb); | 626 | struct jfs_sb_info *sbi = JFS_SBI(root->d_sb); |
619 | 627 | ||
620 | if (sbi->uid != -1) | 628 | if (uid_valid(sbi->uid)) |
621 | seq_printf(seq, ",uid=%d", sbi->uid); | 629 | seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid)); |
622 | if (sbi->gid != -1) | 630 | if (gid_valid(sbi->gid)) |
623 | seq_printf(seq, ",gid=%d", sbi->gid); | 631 | seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid)); |
624 | if (sbi->umask != -1) | 632 | if (sbi->umask != -1) |
625 | seq_printf(seq, ",umask=%03o", sbi->umask); | 633 | seq_printf(seq, ",umask=%03o", sbi->umask); |
626 | if (sbi->flag & JFS_NOINTEGRITY) | 634 | if (sbi->flag & JFS_NOINTEGRITY) |
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c index 26683e15b3ac..42d67f9757bf 100644 --- a/fs/jfs/xattr.c +++ b/fs/jfs/xattr.c | |||
@@ -685,7 +685,7 @@ static int can_set_system_xattr(struct inode *inode, const char *name, | |||
685 | * POSIX_ACL_XATTR_ACCESS is tied to i_mode | 685 | * POSIX_ACL_XATTR_ACCESS is tied to i_mode |
686 | */ | 686 | */ |
687 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) { | 687 | if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) { |
688 | acl = posix_acl_from_xattr(value, value_len); | 688 | acl = posix_acl_from_xattr(&init_user_ns, value, value_len); |
689 | if (IS_ERR(acl)) { | 689 | if (IS_ERR(acl)) { |
690 | rc = PTR_ERR(acl); | 690 | rc = PTR_ERR(acl); |
691 | printk(KERN_ERR "posix_acl_from_xattr returned %d\n", | 691 | printk(KERN_ERR "posix_acl_from_xattr returned %d\n", |
@@ -710,7 +710,7 @@ static int can_set_system_xattr(struct inode *inode, const char *name, | |||
710 | 710 | ||
711 | return 0; | 711 | return 0; |
712 | } else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) { | 712 | } else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) { |
713 | acl = posix_acl_from_xattr(value, value_len); | 713 | acl = posix_acl_from_xattr(&init_user_ns, value, value_len); |
714 | if (IS_ERR(acl)) { | 714 | if (IS_ERR(acl)) { |
715 | rc = PTR_ERR(acl); | 715 | rc = PTR_ERR(acl); |
716 | printk(KERN_ERR "posix_acl_from_xattr returned %d\n", | 716 | printk(KERN_ERR "posix_acl_from_xattr returned %d\n", |
diff --git a/fs/libfs.c b/fs/libfs.c index a74cb1725ac6..7cc37ca19cd8 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -874,7 +874,7 @@ struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid, | |||
874 | EXPORT_SYMBOL_GPL(generic_fh_to_dentry); | 874 | EXPORT_SYMBOL_GPL(generic_fh_to_dentry); |
875 | 875 | ||
876 | /** | 876 | /** |
877 | * generic_fh_to_dentry - generic helper for the fh_to_parent export operation | 877 | * generic_fh_to_parent - generic helper for the fh_to_parent export operation |
878 | * @sb: filesystem to do the file handle conversion on | 878 | * @sb: filesystem to do the file handle conversion on |
879 | * @fid: file handle to convert | 879 | * @fid: file handle to convert |
880 | * @fh_len: length of the file handle in bytes | 880 | * @fh_len: length of the file handle in bytes |
diff --git a/fs/logfs/inode.c b/fs/logfs/inode.c index 121bba2cf6f2..adb90116d36b 100644 --- a/fs/logfs/inode.c +++ b/fs/logfs/inode.c | |||
@@ -208,8 +208,8 @@ static void logfs_init_inode(struct super_block *sb, struct inode *inode) | |||
208 | li->li_height = 0; | 208 | li->li_height = 0; |
209 | li->li_used_bytes = 0; | 209 | li->li_used_bytes = 0; |
210 | li->li_block = NULL; | 210 | li->li_block = NULL; |
211 | inode->i_uid = 0; | 211 | i_uid_write(inode, 0); |
212 | inode->i_gid = 0; | 212 | i_gid_write(inode, 0); |
213 | inode->i_size = 0; | 213 | inode->i_size = 0; |
214 | inode->i_blocks = 0; | 214 | inode->i_blocks = 0; |
215 | inode->i_ctime = CURRENT_TIME; | 215 | inode->i_ctime = CURRENT_TIME; |
diff --git a/fs/logfs/readwrite.c b/fs/logfs/readwrite.c index 5be0abef603d..e1a3b6bf6324 100644 --- a/fs/logfs/readwrite.c +++ b/fs/logfs/readwrite.c | |||
@@ -119,8 +119,8 @@ static void logfs_disk_to_inode(struct logfs_disk_inode *di, struct inode*inode) | |||
119 | inode->i_mode = be16_to_cpu(di->di_mode); | 119 | inode->i_mode = be16_to_cpu(di->di_mode); |
120 | li->li_height = di->di_height; | 120 | li->li_height = di->di_height; |
121 | li->li_flags = be32_to_cpu(di->di_flags); | 121 | li->li_flags = be32_to_cpu(di->di_flags); |
122 | inode->i_uid = be32_to_cpu(di->di_uid); | 122 | i_uid_write(inode, be32_to_cpu(di->di_uid)); |
123 | inode->i_gid = be32_to_cpu(di->di_gid); | 123 | i_gid_write(inode, be32_to_cpu(di->di_gid)); |
124 | inode->i_size = be64_to_cpu(di->di_size); | 124 | inode->i_size = be64_to_cpu(di->di_size); |
125 | logfs_set_blocks(inode, be64_to_cpu(di->di_used_bytes)); | 125 | logfs_set_blocks(inode, be64_to_cpu(di->di_used_bytes)); |
126 | inode->i_atime = be64_to_timespec(di->di_atime); | 126 | inode->i_atime = be64_to_timespec(di->di_atime); |
@@ -156,8 +156,8 @@ static void logfs_inode_to_disk(struct inode *inode, struct logfs_disk_inode*di) | |||
156 | di->di_height = li->li_height; | 156 | di->di_height = li->li_height; |
157 | di->di_pad = 0; | 157 | di->di_pad = 0; |
158 | di->di_flags = cpu_to_be32(li->li_flags); | 158 | di->di_flags = cpu_to_be32(li->li_flags); |
159 | di->di_uid = cpu_to_be32(inode->i_uid); | 159 | di->di_uid = cpu_to_be32(i_uid_read(inode)); |
160 | di->di_gid = cpu_to_be32(inode->i_gid); | 160 | di->di_gid = cpu_to_be32(i_gid_read(inode)); |
161 | di->di_size = cpu_to_be64(i_size_read(inode)); | 161 | di->di_size = cpu_to_be64(i_size_read(inode)); |
162 | di->di_used_bytes = cpu_to_be64(li->li_used_bytes); | 162 | di->di_used_bytes = cpu_to_be64(li->li_used_bytes); |
163 | di->di_atime = timespec_to_be64(inode->i_atime); | 163 | di->di_atime = timespec_to_be64(inode->i_atime); |
diff --git a/fs/minix/inode.c b/fs/minix/inode.c index dc8d3629c20a..4fc5f8ab1c44 100644 --- a/fs/minix/inode.c +++ b/fs/minix/inode.c | |||
@@ -465,8 +465,8 @@ static struct inode *V1_minix_iget(struct inode *inode) | |||
465 | return ERR_PTR(-EIO); | 465 | return ERR_PTR(-EIO); |
466 | } | 466 | } |
467 | inode->i_mode = raw_inode->i_mode; | 467 | inode->i_mode = raw_inode->i_mode; |
468 | inode->i_uid = (uid_t)raw_inode->i_uid; | 468 | i_uid_write(inode, raw_inode->i_uid); |
469 | inode->i_gid = (gid_t)raw_inode->i_gid; | 469 | i_gid_write(inode, raw_inode->i_gid); |
470 | set_nlink(inode, raw_inode->i_nlinks); | 470 | set_nlink(inode, raw_inode->i_nlinks); |
471 | inode->i_size = raw_inode->i_size; | 471 | inode->i_size = raw_inode->i_size; |
472 | inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time; | 472 | inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time; |
@@ -498,8 +498,8 @@ static struct inode *V2_minix_iget(struct inode *inode) | |||
498 | return ERR_PTR(-EIO); | 498 | return ERR_PTR(-EIO); |
499 | } | 499 | } |
500 | inode->i_mode = raw_inode->i_mode; | 500 | inode->i_mode = raw_inode->i_mode; |
501 | inode->i_uid = (uid_t)raw_inode->i_uid; | 501 | i_uid_write(inode, raw_inode->i_uid); |
502 | inode->i_gid = (gid_t)raw_inode->i_gid; | 502 | i_gid_write(inode, raw_inode->i_gid); |
503 | set_nlink(inode, raw_inode->i_nlinks); | 503 | set_nlink(inode, raw_inode->i_nlinks); |
504 | inode->i_size = raw_inode->i_size; | 504 | inode->i_size = raw_inode->i_size; |
505 | inode->i_mtime.tv_sec = raw_inode->i_mtime; | 505 | inode->i_mtime.tv_sec = raw_inode->i_mtime; |
@@ -550,8 +550,8 @@ static struct buffer_head * V1_minix_update_inode(struct inode * inode) | |||
550 | if (!raw_inode) | 550 | if (!raw_inode) |
551 | return NULL; | 551 | return NULL; |
552 | raw_inode->i_mode = inode->i_mode; | 552 | raw_inode->i_mode = inode->i_mode; |
553 | raw_inode->i_uid = fs_high2lowuid(inode->i_uid); | 553 | raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode)); |
554 | raw_inode->i_gid = fs_high2lowgid(inode->i_gid); | 554 | raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode)); |
555 | raw_inode->i_nlinks = inode->i_nlink; | 555 | raw_inode->i_nlinks = inode->i_nlink; |
556 | raw_inode->i_size = inode->i_size; | 556 | raw_inode->i_size = inode->i_size; |
557 | raw_inode->i_time = inode->i_mtime.tv_sec; | 557 | raw_inode->i_time = inode->i_mtime.tv_sec; |
@@ -577,8 +577,8 @@ static struct buffer_head * V2_minix_update_inode(struct inode * inode) | |||
577 | if (!raw_inode) | 577 | if (!raw_inode) |
578 | return NULL; | 578 | return NULL; |
579 | raw_inode->i_mode = inode->i_mode; | 579 | raw_inode->i_mode = inode->i_mode; |
580 | raw_inode->i_uid = fs_high2lowuid(inode->i_uid); | 580 | raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode)); |
581 | raw_inode->i_gid = fs_high2lowgid(inode->i_gid); | 581 | raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode)); |
582 | raw_inode->i_nlinks = inode->i_nlink; | 582 | raw_inode->i_nlinks = inode->i_nlink; |
583 | raw_inode->i_size = inode->i_size; | 583 | raw_inode->i_size = inode->i_size; |
584 | raw_inode->i_mtime = inode->i_mtime.tv_sec; | 584 | raw_inode->i_mtime = inode->i_mtime.tv_sec; |
diff --git a/fs/namei.c b/fs/namei.c index e1c7072c7afa..aa30d19e9edd 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -680,7 +680,7 @@ static inline int may_follow_link(struct path *link, struct nameidata *nd) | |||
680 | 680 | ||
681 | /* Allowed if owner and follower match. */ | 681 | /* Allowed if owner and follower match. */ |
682 | inode = link->dentry->d_inode; | 682 | inode = link->dentry->d_inode; |
683 | if (current_cred()->fsuid == inode->i_uid) | 683 | if (uid_eq(current_cred()->fsuid, inode->i_uid)) |
684 | return 0; | 684 | return 0; |
685 | 685 | ||
686 | /* Allowed if parent directory not sticky and world-writable. */ | 686 | /* Allowed if parent directory not sticky and world-writable. */ |
@@ -689,7 +689,7 @@ static inline int may_follow_link(struct path *link, struct nameidata *nd) | |||
689 | return 0; | 689 | return 0; |
690 | 690 | ||
691 | /* Allowed if parent directory and link owner match. */ | 691 | /* Allowed if parent directory and link owner match. */ |
692 | if (parent->i_uid == inode->i_uid) | 692 | if (uid_eq(parent->i_uid, inode->i_uid)) |
693 | return 0; | 693 | return 0; |
694 | 694 | ||
695 | path_put_conditional(link, nd); | 695 | path_put_conditional(link, nd); |
@@ -759,7 +759,7 @@ static int may_linkat(struct path *link) | |||
759 | /* Source inode owner (or CAP_FOWNER) can hardlink all they like, | 759 | /* Source inode owner (or CAP_FOWNER) can hardlink all they like, |
760 | * otherwise, it must be a safe source. | 760 | * otherwise, it must be a safe source. |
761 | */ | 761 | */ |
762 | if (cred->fsuid == inode->i_uid || safe_hardlink_source(inode) || | 762 | if (uid_eq(cred->fsuid, inode->i_uid) || safe_hardlink_source(inode) || |
763 | capable(CAP_FOWNER)) | 763 | capable(CAP_FOWNER)) |
764 | return 0; | 764 | return 0; |
765 | 765 | ||
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c index 0c62c55b25d7..d7e9fe77188a 100644 --- a/fs/ncpfs/inode.c +++ b/fs/ncpfs/inode.c | |||
@@ -319,11 +319,11 @@ static void ncp_stop_tasks(struct ncp_server *server) { | |||
319 | release_sock(sk); | 319 | release_sock(sk); |
320 | del_timer_sync(&server->timeout_tm); | 320 | del_timer_sync(&server->timeout_tm); |
321 | 321 | ||
322 | flush_work_sync(&server->rcv.tq); | 322 | flush_work(&server->rcv.tq); |
323 | if (sk->sk_socket->type == SOCK_STREAM) | 323 | if (sk->sk_socket->type == SOCK_STREAM) |
324 | flush_work_sync(&server->tx.tq); | 324 | flush_work(&server->tx.tq); |
325 | else | 325 | else |
326 | flush_work_sync(&server->timeout_tq); | 326 | flush_work(&server->timeout_tq); |
327 | } | 327 | } |
328 | 328 | ||
329 | static int ncp_show_options(struct seq_file *seq, struct dentry *root) | 329 | static int ncp_show_options(struct seq_file *seq, struct dentry *root) |
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c index e4498dc351a8..4a1aafba6a20 100644 --- a/fs/nfs/nfs3acl.c +++ b/fs/nfs/nfs3acl.c | |||
@@ -70,7 +70,7 @@ ssize_t nfs3_getxattr(struct dentry *dentry, const char *name, | |||
70 | if (type == ACL_TYPE_ACCESS && acl->a_count == 0) | 70 | if (type == ACL_TYPE_ACCESS && acl->a_count == 0) |
71 | error = -ENODATA; | 71 | error = -ENODATA; |
72 | else | 72 | else |
73 | error = posix_acl_to_xattr(acl, buffer, size); | 73 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
74 | posix_acl_release(acl); | 74 | posix_acl_release(acl); |
75 | } else | 75 | } else |
76 | error = -ENODATA; | 76 | error = -ENODATA; |
@@ -92,7 +92,7 @@ int nfs3_setxattr(struct dentry *dentry, const char *name, | |||
92 | else | 92 | else |
93 | return -EOPNOTSUPP; | 93 | return -EOPNOTSUPP; |
94 | 94 | ||
95 | acl = posix_acl_from_xattr(value, size); | 95 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
96 | if (IS_ERR(acl)) | 96 | if (IS_ERR(acl)) |
97 | return PTR_ERR(acl); | 97 | return PTR_ERR(acl); |
98 | error = nfs3_proc_setacl(inode, type, acl); | 98 | error = nfs3_proc_setacl(inode, type, acl); |
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c index 6930bec91bca..1720d32ffa54 100644 --- a/fs/nfs/nfs4renewd.c +++ b/fs/nfs/nfs4renewd.c | |||
@@ -117,8 +117,7 @@ nfs4_schedule_state_renewal(struct nfs_client *clp) | |||
117 | timeout = 5 * HZ; | 117 | timeout = 5 * HZ; |
118 | dprintk("%s: requeueing work. Lease period = %ld\n", | 118 | dprintk("%s: requeueing work. Lease period = %ld\n", |
119 | __func__, (timeout + HZ - 1) / HZ); | 119 | __func__, (timeout + HZ - 1) / HZ); |
120 | cancel_delayed_work(&clp->cl_renewd); | 120 | mod_delayed_work(system_wq, &clp->cl_renewd, timeout); |
121 | schedule_delayed_work(&clp->cl_renewd, timeout); | ||
122 | set_bit(NFS_CS_RENEWD, &clp->cl_res_state); | 121 | set_bit(NFS_CS_RENEWD, &clp->cl_res_state); |
123 | spin_unlock(&clp->cl_lock); | 122 | spin_unlock(&clp->cl_lock); |
124 | } | 123 | } |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index b8eda700584b..d2c7f5db0847 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -1537,7 +1537,7 @@ static int nfs_parse_mount_options(char *raw, | |||
1537 | 1537 | ||
1538 | /* | 1538 | /* |
1539 | * verify that any proto=/mountproto= options match the address | 1539 | * verify that any proto=/mountproto= options match the address |
1540 | * familiies in the addr=/mountaddr= options. | 1540 | * families in the addr=/mountaddr= options. |
1541 | */ | 1541 | */ |
1542 | if (protofamily != AF_UNSPEC && | 1542 | if (protofamily != AF_UNSPEC && |
1543 | protofamily != mnt->nfs_server.address.ss_family) | 1543 | protofamily != mnt->nfs_server.address.ss_family) |
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index a9269f142cc4..3f67b8e12251 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c | |||
@@ -480,7 +480,7 @@ set_nfsv4_acl_one(struct dentry *dentry, struct posix_acl *pacl, char *key) | |||
480 | if (buf == NULL) | 480 | if (buf == NULL) |
481 | goto out; | 481 | goto out; |
482 | 482 | ||
483 | len = posix_acl_to_xattr(pacl, buf, buflen); | 483 | len = posix_acl_to_xattr(&init_user_ns, pacl, buf, buflen); |
484 | if (len < 0) { | 484 | if (len < 0) { |
485 | error = len; | 485 | error = len; |
486 | goto out; | 486 | goto out; |
@@ -549,7 +549,7 @@ _get_posix_acl(struct dentry *dentry, char *key) | |||
549 | if (buflen <= 0) | 549 | if (buflen <= 0) |
550 | return ERR_PTR(buflen); | 550 | return ERR_PTR(buflen); |
551 | 551 | ||
552 | pacl = posix_acl_from_xattr(buf, buflen); | 552 | pacl = posix_acl_from_xattr(&init_user_ns, buf, buflen); |
553 | kfree(buf); | 553 | kfree(buf); |
554 | return pacl; | 554 | return pacl; |
555 | } | 555 | } |
@@ -2264,7 +2264,7 @@ nfsd_get_posix_acl(struct svc_fh *fhp, int type) | |||
2264 | if (size < 0) | 2264 | if (size < 0) |
2265 | return ERR_PTR(size); | 2265 | return ERR_PTR(size); |
2266 | 2266 | ||
2267 | acl = posix_acl_from_xattr(value, size); | 2267 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
2268 | kfree(value); | 2268 | kfree(value); |
2269 | return acl; | 2269 | return acl; |
2270 | } | 2270 | } |
@@ -2297,7 +2297,7 @@ nfsd_set_posix_acl(struct svc_fh *fhp, int type, struct posix_acl *acl) | |||
2297 | value = kmalloc(size, GFP_KERNEL); | 2297 | value = kmalloc(size, GFP_KERNEL); |
2298 | if (!value) | 2298 | if (!value) |
2299 | return -ENOMEM; | 2299 | return -ENOMEM; |
2300 | error = posix_acl_to_xattr(acl, value, size); | 2300 | error = posix_acl_to_xattr(&init_user_ns, acl, value, size); |
2301 | if (error < 0) | 2301 | if (error < 0) |
2302 | goto getout; | 2302 | goto getout; |
2303 | size = error; | 2303 | size = error; |
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 6e2c3db976b2..4d31d2cca7fd 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c | |||
@@ -401,8 +401,8 @@ int nilfs_read_inode_common(struct inode *inode, | |||
401 | int err; | 401 | int err; |
402 | 402 | ||
403 | inode->i_mode = le16_to_cpu(raw_inode->i_mode); | 403 | inode->i_mode = le16_to_cpu(raw_inode->i_mode); |
404 | inode->i_uid = (uid_t)le32_to_cpu(raw_inode->i_uid); | 404 | i_uid_write(inode, le32_to_cpu(raw_inode->i_uid)); |
405 | inode->i_gid = (gid_t)le32_to_cpu(raw_inode->i_gid); | 405 | i_gid_write(inode, le32_to_cpu(raw_inode->i_gid)); |
406 | set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); | 406 | set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); |
407 | inode->i_size = le64_to_cpu(raw_inode->i_size); | 407 | inode->i_size = le64_to_cpu(raw_inode->i_size); |
408 | inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime); | 408 | inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime); |
@@ -590,8 +590,8 @@ void nilfs_write_inode_common(struct inode *inode, | |||
590 | struct nilfs_inode_info *ii = NILFS_I(inode); | 590 | struct nilfs_inode_info *ii = NILFS_I(inode); |
591 | 591 | ||
592 | raw_inode->i_mode = cpu_to_le16(inode->i_mode); | 592 | raw_inode->i_mode = cpu_to_le16(inode->i_mode); |
593 | raw_inode->i_uid = cpu_to_le32(inode->i_uid); | 593 | raw_inode->i_uid = cpu_to_le32(i_uid_read(inode)); |
594 | raw_inode->i_gid = cpu_to_le32(inode->i_gid); | 594 | raw_inode->i_gid = cpu_to_le32(i_gid_read(inode)); |
595 | raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); | 595 | raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); |
596 | raw_inode->i_size = cpu_to_le64(inode->i_size); | 596 | raw_inode->i_size = cpu_to_le64(inode->i_size); |
597 | raw_inode->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); | 597 | raw_inode->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec); |
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index c6dbd3db6ca8..1d27331e6fc9 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c | |||
@@ -2124,7 +2124,8 @@ int ntfs_read_inode_mount(struct inode *vi) | |||
2124 | * ntfs_read_inode() will have set up the default ones. | 2124 | * ntfs_read_inode() will have set up the default ones. |
2125 | */ | 2125 | */ |
2126 | /* Set uid and gid to root. */ | 2126 | /* Set uid and gid to root. */ |
2127 | vi->i_uid = vi->i_gid = 0; | 2127 | vi->i_uid = GLOBAL_ROOT_UID; |
2128 | vi->i_gid = GLOBAL_ROOT_GID; | ||
2128 | /* Regular file. No access for anyone. */ | 2129 | /* Regular file. No access for anyone. */ |
2129 | vi->i_mode = S_IFREG; | 2130 | vi->i_mode = S_IFREG; |
2130 | /* No VFS initiated operations allowed for $MFT. */ | 2131 | /* No VFS initiated operations allowed for $MFT. */ |
@@ -2312,8 +2313,8 @@ int ntfs_show_options(struct seq_file *sf, struct dentry *root) | |||
2312 | ntfs_volume *vol = NTFS_SB(root->d_sb); | 2313 | ntfs_volume *vol = NTFS_SB(root->d_sb); |
2313 | int i; | 2314 | int i; |
2314 | 2315 | ||
2315 | seq_printf(sf, ",uid=%i", vol->uid); | 2316 | seq_printf(sf, ",uid=%i", from_kuid_munged(&init_user_ns, vol->uid)); |
2316 | seq_printf(sf, ",gid=%i", vol->gid); | 2317 | seq_printf(sf, ",gid=%i", from_kgid_munged(&init_user_ns, vol->gid)); |
2317 | if (vol->fmask == vol->dmask) | 2318 | if (vol->fmask == vol->dmask) |
2318 | seq_printf(sf, ",umask=0%o", vol->fmask); | 2319 | seq_printf(sf, ",umask=0%o", vol->fmask); |
2319 | else { | 2320 | else { |
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index fe08d4afa106..4a8289f8b16c 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c | |||
@@ -102,8 +102,8 @@ static bool parse_options(ntfs_volume *vol, char *opt) | |||
102 | char *p, *v, *ov; | 102 | char *p, *v, *ov; |
103 | static char *utf8 = "utf8"; | 103 | static char *utf8 = "utf8"; |
104 | int errors = 0, sloppy = 0; | 104 | int errors = 0, sloppy = 0; |
105 | uid_t uid = (uid_t)-1; | 105 | kuid_t uid = INVALID_UID; |
106 | gid_t gid = (gid_t)-1; | 106 | kgid_t gid = INVALID_GID; |
107 | umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; | 107 | umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; |
108 | int mft_zone_multiplier = -1, on_errors = -1; | 108 | int mft_zone_multiplier = -1, on_errors = -1; |
109 | int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; | 109 | int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; |
@@ -128,6 +128,30 @@ static bool parse_options(ntfs_volume *vol, char *opt) | |||
128 | if (*v) \ | 128 | if (*v) \ |
129 | goto needs_val; \ | 129 | goto needs_val; \ |
130 | } | 130 | } |
131 | #define NTFS_GETOPT_UID(option, variable) \ | ||
132 | if (!strcmp(p, option)) { \ | ||
133 | uid_t uid_value; \ | ||
134 | if (!v || !*v) \ | ||
135 | goto needs_arg; \ | ||
136 | uid_value = simple_strtoul(ov = v, &v, 0); \ | ||
137 | if (*v) \ | ||
138 | goto needs_val; \ | ||
139 | variable = make_kuid(current_user_ns(), uid_value); \ | ||
140 | if (!uid_valid(variable)) \ | ||
141 | goto needs_val; \ | ||
142 | } | ||
143 | #define NTFS_GETOPT_GID(option, variable) \ | ||
144 | if (!strcmp(p, option)) { \ | ||
145 | gid_t gid_value; \ | ||
146 | if (!v || !*v) \ | ||
147 | goto needs_arg; \ | ||
148 | gid_value = simple_strtoul(ov = v, &v, 0); \ | ||
149 | if (*v) \ | ||
150 | goto needs_val; \ | ||
151 | variable = make_kgid(current_user_ns(), gid_value); \ | ||
152 | if (!gid_valid(variable)) \ | ||
153 | goto needs_val; \ | ||
154 | } | ||
131 | #define NTFS_GETOPT_OCTAL(option, variable) \ | 155 | #define NTFS_GETOPT_OCTAL(option, variable) \ |
132 | if (!strcmp(p, option)) { \ | 156 | if (!strcmp(p, option)) { \ |
133 | if (!v || !*v) \ | 157 | if (!v || !*v) \ |
@@ -165,8 +189,8 @@ static bool parse_options(ntfs_volume *vol, char *opt) | |||
165 | while ((p = strsep(&opt, ","))) { | 189 | while ((p = strsep(&opt, ","))) { |
166 | if ((v = strchr(p, '='))) | 190 | if ((v = strchr(p, '='))) |
167 | *v++ = 0; | 191 | *v++ = 0; |
168 | NTFS_GETOPT("uid", uid) | 192 | NTFS_GETOPT_UID("uid", uid) |
169 | else NTFS_GETOPT("gid", gid) | 193 | else NTFS_GETOPT_GID("gid", gid) |
170 | else NTFS_GETOPT_OCTAL("umask", fmask = dmask) | 194 | else NTFS_GETOPT_OCTAL("umask", fmask = dmask) |
171 | else NTFS_GETOPT_OCTAL("fmask", fmask) | 195 | else NTFS_GETOPT_OCTAL("fmask", fmask) |
172 | else NTFS_GETOPT_OCTAL("dmask", dmask) | 196 | else NTFS_GETOPT_OCTAL("dmask", dmask) |
@@ -283,9 +307,9 @@ no_mount_options: | |||
283 | vol->on_errors = on_errors; | 307 | vol->on_errors = on_errors; |
284 | if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) | 308 | if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) |
285 | vol->on_errors |= ON_ERRORS_CONTINUE; | 309 | vol->on_errors |= ON_ERRORS_CONTINUE; |
286 | if (uid != (uid_t)-1) | 310 | if (uid_valid(uid)) |
287 | vol->uid = uid; | 311 | vol->uid = uid; |
288 | if (gid != (gid_t)-1) | 312 | if (gid_valid(gid)) |
289 | vol->gid = gid; | 313 | vol->gid = gid; |
290 | if (fmask != (umode_t)-1) | 314 | if (fmask != (umode_t)-1) |
291 | vol->fmask = fmask; | 315 | vol->fmask = fmask; |
@@ -1023,7 +1047,8 @@ static bool load_and_init_mft_mirror(ntfs_volume *vol) | |||
1023 | * ntfs_read_inode() will have set up the default ones. | 1047 | * ntfs_read_inode() will have set up the default ones. |
1024 | */ | 1048 | */ |
1025 | /* Set uid and gid to root. */ | 1049 | /* Set uid and gid to root. */ |
1026 | tmp_ino->i_uid = tmp_ino->i_gid = 0; | 1050 | tmp_ino->i_uid = GLOBAL_ROOT_UID; |
1051 | tmp_ino->i_gid = GLOBAL_ROOT_GID; | ||
1027 | /* Regular file. No access for anyone. */ | 1052 | /* Regular file. No access for anyone. */ |
1028 | tmp_ino->i_mode = S_IFREG; | 1053 | tmp_ino->i_mode = S_IFREG; |
1029 | /* No VFS initiated operations allowed for $MFTMirr. */ | 1054 | /* No VFS initiated operations allowed for $MFTMirr. */ |
diff --git a/fs/ntfs/volume.h b/fs/ntfs/volume.h index 15e3ba8d521a..4f579b02bc76 100644 --- a/fs/ntfs/volume.h +++ b/fs/ntfs/volume.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #define _LINUX_NTFS_VOLUME_H | 25 | #define _LINUX_NTFS_VOLUME_H |
26 | 26 | ||
27 | #include <linux/rwsem.h> | 27 | #include <linux/rwsem.h> |
28 | #include <linux/uidgid.h> | ||
28 | 29 | ||
29 | #include "types.h" | 30 | #include "types.h" |
30 | #include "layout.h" | 31 | #include "layout.h" |
@@ -46,8 +47,8 @@ typedef struct { | |||
46 | sized blocks on the device. */ | 47 | sized blocks on the device. */ |
47 | /* Configuration provided by user at mount time. */ | 48 | /* Configuration provided by user at mount time. */ |
48 | unsigned long flags; /* Miscellaneous flags, see below. */ | 49 | unsigned long flags; /* Miscellaneous flags, see below. */ |
49 | uid_t uid; /* uid that files will be mounted as. */ | 50 | kuid_t uid; /* uid that files will be mounted as. */ |
50 | gid_t gid; /* gid that files will be mounted as. */ | 51 | kgid_t gid; /* gid that files will be mounted as. */ |
51 | umode_t fmask; /* The mask for file permissions. */ | 52 | umode_t fmask; /* The mask for file permissions. */ |
52 | umode_t dmask; /* The mask for directory | 53 | umode_t dmask; /* The mask for directory |
53 | permissions. */ | 54 | permissions. */ |
diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c index a7219075b4de..260b16281fc3 100644 --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c | |||
@@ -452,7 +452,7 @@ static int ocfs2_xattr_get_acl(struct dentry *dentry, const char *name, | |||
452 | return PTR_ERR(acl); | 452 | return PTR_ERR(acl); |
453 | if (acl == NULL) | 453 | if (acl == NULL) |
454 | return -ENODATA; | 454 | return -ENODATA; |
455 | ret = posix_acl_to_xattr(acl, buffer, size); | 455 | ret = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
456 | posix_acl_release(acl); | 456 | posix_acl_release(acl); |
457 | 457 | ||
458 | return ret; | 458 | return ret; |
@@ -475,7 +475,7 @@ static int ocfs2_xattr_set_acl(struct dentry *dentry, const char *name, | |||
475 | return -EPERM; | 475 | return -EPERM; |
476 | 476 | ||
477 | if (value) { | 477 | if (value) { |
478 | acl = posix_acl_from_xattr(value, size); | 478 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
479 | if (IS_ERR(acl)) | 479 | if (IS_ERR(acl)) |
480 | return PTR_ERR(acl); | 480 | return PTR_ERR(acl); |
481 | else if (acl) { | 481 | else if (acl) { |
diff --git a/fs/ocfs2/cluster/quorum.c b/fs/ocfs2/cluster/quorum.c index 8f9cea1597af..c19897d0fe14 100644 --- a/fs/ocfs2/cluster/quorum.c +++ b/fs/ocfs2/cluster/quorum.c | |||
@@ -327,5 +327,5 @@ void o2quo_exit(void) | |||
327 | { | 327 | { |
328 | struct o2quo_state *qs = &o2quo_state; | 328 | struct o2quo_state *qs = &o2quo_state; |
329 | 329 | ||
330 | flush_work_sync(&qs->qs_work); | 330 | flush_work(&qs->qs_work); |
331 | } | 331 | } |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 46a1f6d75104..5a4ee77cec51 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -1184,8 +1184,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) | |||
1184 | if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid | 1184 | if (attr->ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid |
1185 | && OCFS2_HAS_RO_COMPAT_FEATURE(sb, | 1185 | && OCFS2_HAS_RO_COMPAT_FEATURE(sb, |
1186 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | 1186 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { |
1187 | transfer_to[USRQUOTA] = dqget(sb, attr->ia_uid, | 1187 | transfer_to[USRQUOTA] = dqget(sb, make_kqid_uid(attr->ia_uid)); |
1188 | USRQUOTA); | ||
1189 | if (!transfer_to[USRQUOTA]) { | 1188 | if (!transfer_to[USRQUOTA]) { |
1190 | status = -ESRCH; | 1189 | status = -ESRCH; |
1191 | goto bail_unlock; | 1190 | goto bail_unlock; |
@@ -1194,8 +1193,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) | |||
1194 | if (attr->ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid | 1193 | if (attr->ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid |
1195 | && OCFS2_HAS_RO_COMPAT_FEATURE(sb, | 1194 | && OCFS2_HAS_RO_COMPAT_FEATURE(sb, |
1196 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | 1195 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { |
1197 | transfer_to[GRPQUOTA] = dqget(sb, attr->ia_gid, | 1196 | transfer_to[GRPQUOTA] = dqget(sb, make_kqid_gid(attr->ia_gid)); |
1198 | GRPQUOTA); | ||
1199 | if (!transfer_to[GRPQUOTA]) { | 1197 | if (!transfer_to[GRPQUOTA]) { |
1200 | status = -ESRCH; | 1198 | status = -ESRCH; |
1201 | goto bail_unlock; | 1199 | goto bail_unlock; |
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index 0a86e302655f..332a281f217e 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c | |||
@@ -95,7 +95,7 @@ static void ocfs2_global_mem2diskdqb(void *dp, struct dquot *dquot) | |||
95 | struct ocfs2_global_disk_dqblk *d = dp; | 95 | struct ocfs2_global_disk_dqblk *d = dp; |
96 | struct mem_dqblk *m = &dquot->dq_dqb; | 96 | struct mem_dqblk *m = &dquot->dq_dqb; |
97 | 97 | ||
98 | d->dqb_id = cpu_to_le32(dquot->dq_id); | 98 | d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id)); |
99 | d->dqb_use_count = cpu_to_le32(OCFS2_DQUOT(dquot)->dq_use_count); | 99 | d->dqb_use_count = cpu_to_le32(OCFS2_DQUOT(dquot)->dq_use_count); |
100 | d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit); | 100 | d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit); |
101 | d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit); | 101 | d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit); |
@@ -112,11 +112,14 @@ static int ocfs2_global_is_id(void *dp, struct dquot *dquot) | |||
112 | { | 112 | { |
113 | struct ocfs2_global_disk_dqblk *d = dp; | 113 | struct ocfs2_global_disk_dqblk *d = dp; |
114 | struct ocfs2_mem_dqinfo *oinfo = | 114 | struct ocfs2_mem_dqinfo *oinfo = |
115 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 115 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
116 | 116 | ||
117 | if (qtree_entry_unused(&oinfo->dqi_gi, dp)) | 117 | if (qtree_entry_unused(&oinfo->dqi_gi, dp)) |
118 | return 0; | 118 | return 0; |
119 | return le32_to_cpu(d->dqb_id) == dquot->dq_id; | 119 | |
120 | return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type, | ||
121 | le32_to_cpu(d->dqb_id)), | ||
122 | dquot->dq_id); | ||
120 | } | 123 | } |
121 | 124 | ||
122 | struct qtree_fmt_operations ocfs2_global_ops = { | 125 | struct qtree_fmt_operations ocfs2_global_ops = { |
@@ -475,7 +478,7 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing) | |||
475 | { | 478 | { |
476 | int err, err2; | 479 | int err, err2; |
477 | struct super_block *sb = dquot->dq_sb; | 480 | struct super_block *sb = dquot->dq_sb; |
478 | int type = dquot->dq_type; | 481 | int type = dquot->dq_id.type; |
479 | struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; | 482 | struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; |
480 | struct ocfs2_global_disk_dqblk dqblk; | 483 | struct ocfs2_global_disk_dqblk dqblk; |
481 | s64 spacechange, inodechange; | 484 | s64 spacechange, inodechange; |
@@ -504,7 +507,8 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing) | |||
504 | olditime = dquot->dq_dqb.dqb_itime; | 507 | olditime = dquot->dq_dqb.dqb_itime; |
505 | oldbtime = dquot->dq_dqb.dqb_btime; | 508 | oldbtime = dquot->dq_dqb.dqb_btime; |
506 | ocfs2_global_disk2memdqb(dquot, &dqblk); | 509 | ocfs2_global_disk2memdqb(dquot, &dqblk); |
507 | trace_ocfs2_sync_dquot(dquot->dq_id, dquot->dq_dqb.dqb_curspace, | 510 | trace_ocfs2_sync_dquot(from_kqid(&init_user_ns, dquot->dq_id), |
511 | dquot->dq_dqb.dqb_curspace, | ||
508 | (long long)spacechange, | 512 | (long long)spacechange, |
509 | dquot->dq_dqb.dqb_curinodes, | 513 | dquot->dq_dqb.dqb_curinodes, |
510 | (long long)inodechange); | 514 | (long long)inodechange); |
@@ -555,8 +559,8 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing) | |||
555 | err = ocfs2_qinfo_lock(info, freeing); | 559 | err = ocfs2_qinfo_lock(info, freeing); |
556 | if (err < 0) { | 560 | if (err < 0) { |
557 | mlog(ML_ERROR, "Failed to lock quota info, losing quota write" | 561 | mlog(ML_ERROR, "Failed to lock quota info, losing quota write" |
558 | " (type=%d, id=%u)\n", dquot->dq_type, | 562 | " (type=%d, id=%u)\n", dquot->dq_id.type, |
559 | (unsigned)dquot->dq_id); | 563 | (unsigned)from_kqid(&init_user_ns, dquot->dq_id)); |
560 | goto out; | 564 | goto out; |
561 | } | 565 | } |
562 | if (freeing) | 566 | if (freeing) |
@@ -591,9 +595,10 @@ static int ocfs2_sync_dquot_helper(struct dquot *dquot, unsigned long type) | |||
591 | struct ocfs2_super *osb = OCFS2_SB(sb); | 595 | struct ocfs2_super *osb = OCFS2_SB(sb); |
592 | int status = 0; | 596 | int status = 0; |
593 | 597 | ||
594 | trace_ocfs2_sync_dquot_helper(dquot->dq_id, dquot->dq_type, | 598 | trace_ocfs2_sync_dquot_helper(from_kqid(&init_user_ns, dquot->dq_id), |
599 | dquot->dq_id.type, | ||
595 | type, sb->s_id); | 600 | type, sb->s_id); |
596 | if (type != dquot->dq_type) | 601 | if (type != dquot->dq_id.type) |
597 | goto out; | 602 | goto out; |
598 | status = ocfs2_lock_global_qf(oinfo, 1); | 603 | status = ocfs2_lock_global_qf(oinfo, 1); |
599 | if (status < 0) | 604 | if (status < 0) |
@@ -643,7 +648,8 @@ static int ocfs2_write_dquot(struct dquot *dquot) | |||
643 | struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb); | 648 | struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb); |
644 | int status = 0; | 649 | int status = 0; |
645 | 650 | ||
646 | trace_ocfs2_write_dquot(dquot->dq_id, dquot->dq_type); | 651 | trace_ocfs2_write_dquot(from_kqid(&init_user_ns, dquot->dq_id), |
652 | dquot->dq_id.type); | ||
647 | 653 | ||
648 | handle = ocfs2_start_trans(osb, OCFS2_QWRITE_CREDITS); | 654 | handle = ocfs2_start_trans(osb, OCFS2_QWRITE_CREDITS); |
649 | if (IS_ERR(handle)) { | 655 | if (IS_ERR(handle)) { |
@@ -677,11 +683,12 @@ static int ocfs2_release_dquot(struct dquot *dquot) | |||
677 | { | 683 | { |
678 | handle_t *handle; | 684 | handle_t *handle; |
679 | struct ocfs2_mem_dqinfo *oinfo = | 685 | struct ocfs2_mem_dqinfo *oinfo = |
680 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 686 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
681 | struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb); | 687 | struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb); |
682 | int status = 0; | 688 | int status = 0; |
683 | 689 | ||
684 | trace_ocfs2_release_dquot(dquot->dq_id, dquot->dq_type); | 690 | trace_ocfs2_release_dquot(from_kqid(&init_user_ns, dquot->dq_id), |
691 | dquot->dq_id.type); | ||
685 | 692 | ||
686 | mutex_lock(&dquot->dq_lock); | 693 | mutex_lock(&dquot->dq_lock); |
687 | /* Check whether we are not racing with some other dqget() */ | 694 | /* Check whether we are not racing with some other dqget() */ |
@@ -691,7 +698,7 @@ static int ocfs2_release_dquot(struct dquot *dquot) | |||
691 | if (status < 0) | 698 | if (status < 0) |
692 | goto out; | 699 | goto out; |
693 | handle = ocfs2_start_trans(osb, | 700 | handle = ocfs2_start_trans(osb, |
694 | ocfs2_calc_qdel_credits(dquot->dq_sb, dquot->dq_type)); | 701 | ocfs2_calc_qdel_credits(dquot->dq_sb, dquot->dq_id.type)); |
695 | if (IS_ERR(handle)) { | 702 | if (IS_ERR(handle)) { |
696 | status = PTR_ERR(handle); | 703 | status = PTR_ERR(handle); |
697 | mlog_errno(status); | 704 | mlog_errno(status); |
@@ -733,13 +740,14 @@ static int ocfs2_acquire_dquot(struct dquot *dquot) | |||
733 | int ex = 0; | 740 | int ex = 0; |
734 | struct super_block *sb = dquot->dq_sb; | 741 | struct super_block *sb = dquot->dq_sb; |
735 | struct ocfs2_super *osb = OCFS2_SB(sb); | 742 | struct ocfs2_super *osb = OCFS2_SB(sb); |
736 | int type = dquot->dq_type; | 743 | int type = dquot->dq_id.type; |
737 | struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; | 744 | struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; |
738 | struct inode *gqinode = info->dqi_gqinode; | 745 | struct inode *gqinode = info->dqi_gqinode; |
739 | int need_alloc = ocfs2_global_qinit_alloc(sb, type); | 746 | int need_alloc = ocfs2_global_qinit_alloc(sb, type); |
740 | handle_t *handle; | 747 | handle_t *handle; |
741 | 748 | ||
742 | trace_ocfs2_acquire_dquot(dquot->dq_id, type); | 749 | trace_ocfs2_acquire_dquot(from_kqid(&init_user_ns, dquot->dq_id), |
750 | type); | ||
743 | mutex_lock(&dquot->dq_lock); | 751 | mutex_lock(&dquot->dq_lock); |
744 | /* | 752 | /* |
745 | * We need an exclusive lock, because we're going to update use count | 753 | * We need an exclusive lock, because we're going to update use count |
@@ -821,12 +829,13 @@ static int ocfs2_mark_dquot_dirty(struct dquot *dquot) | |||
821 | int sync = 0; | 829 | int sync = 0; |
822 | int status; | 830 | int status; |
823 | struct super_block *sb = dquot->dq_sb; | 831 | struct super_block *sb = dquot->dq_sb; |
824 | int type = dquot->dq_type; | 832 | int type = dquot->dq_id.type; |
825 | struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv; | 833 | struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv; |
826 | handle_t *handle; | 834 | handle_t *handle; |
827 | struct ocfs2_super *osb = OCFS2_SB(sb); | 835 | struct ocfs2_super *osb = OCFS2_SB(sb); |
828 | 836 | ||
829 | trace_ocfs2_mark_dquot_dirty(dquot->dq_id, type); | 837 | trace_ocfs2_mark_dquot_dirty(from_kqid(&init_user_ns, dquot->dq_id), |
838 | type); | ||
830 | 839 | ||
831 | /* In case user set some limits, sync dquot immediately to global | 840 | /* In case user set some limits, sync dquot immediately to global |
832 | * quota file so that information propagates quicker */ | 841 | * quota file so that information propagates quicker */ |
diff --git a/fs/ocfs2/quota_local.c b/fs/ocfs2/quota_local.c index f100bf70a906..27fe7ee4874c 100644 --- a/fs/ocfs2/quota_local.c +++ b/fs/ocfs2/quota_local.c | |||
@@ -501,7 +501,9 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode, | |||
501 | } | 501 | } |
502 | dqblk = (struct ocfs2_local_disk_dqblk *)(qbh->b_data + | 502 | dqblk = (struct ocfs2_local_disk_dqblk *)(qbh->b_data + |
503 | ol_dqblk_block_off(sb, chunk, bit)); | 503 | ol_dqblk_block_off(sb, chunk, bit)); |
504 | dquot = dqget(sb, le64_to_cpu(dqblk->dqb_id), type); | 504 | dquot = dqget(sb, |
505 | make_kqid(&init_user_ns, type, | ||
506 | le64_to_cpu(dqblk->dqb_id))); | ||
505 | if (!dquot) { | 507 | if (!dquot) { |
506 | status = -EIO; | 508 | status = -EIO; |
507 | mlog(ML_ERROR, "Failed to get quota structure " | 509 | mlog(ML_ERROR, "Failed to get quota structure " |
@@ -881,7 +883,8 @@ static void olq_set_dquot(struct buffer_head *bh, void *private) | |||
881 | dqblk = (struct ocfs2_local_disk_dqblk *)(bh->b_data | 883 | dqblk = (struct ocfs2_local_disk_dqblk *)(bh->b_data |
882 | + ol_dqblk_block_offset(sb, od->dq_local_off)); | 884 | + ol_dqblk_block_offset(sb, od->dq_local_off)); |
883 | 885 | ||
884 | dqblk->dqb_id = cpu_to_le64(od->dq_dquot.dq_id); | 886 | dqblk->dqb_id = cpu_to_le64(from_kqid(&init_user_ns, |
887 | od->dq_dquot.dq_id)); | ||
885 | spin_lock(&dq_data_lock); | 888 | spin_lock(&dq_data_lock); |
886 | dqblk->dqb_spacemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curspace - | 889 | dqblk->dqb_spacemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curspace - |
887 | od->dq_origspace); | 890 | od->dq_origspace); |
@@ -891,7 +894,7 @@ static void olq_set_dquot(struct buffer_head *bh, void *private) | |||
891 | trace_olq_set_dquot( | 894 | trace_olq_set_dquot( |
892 | (unsigned long long)le64_to_cpu(dqblk->dqb_spacemod), | 895 | (unsigned long long)le64_to_cpu(dqblk->dqb_spacemod), |
893 | (unsigned long long)le64_to_cpu(dqblk->dqb_inodemod), | 896 | (unsigned long long)le64_to_cpu(dqblk->dqb_inodemod), |
894 | od->dq_dquot.dq_id); | 897 | from_kqid(&init_user_ns, od->dq_dquot.dq_id)); |
895 | } | 898 | } |
896 | 899 | ||
897 | /* Write dquot to local quota file */ | 900 | /* Write dquot to local quota file */ |
@@ -900,7 +903,7 @@ int ocfs2_local_write_dquot(struct dquot *dquot) | |||
900 | struct super_block *sb = dquot->dq_sb; | 903 | struct super_block *sb = dquot->dq_sb; |
901 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); | 904 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); |
902 | struct buffer_head *bh; | 905 | struct buffer_head *bh; |
903 | struct inode *lqinode = sb_dqopt(sb)->files[dquot->dq_type]; | 906 | struct inode *lqinode = sb_dqopt(sb)->files[dquot->dq_id.type]; |
904 | int status; | 907 | int status; |
905 | 908 | ||
906 | status = ocfs2_read_quota_phys_block(lqinode, od->dq_local_phys_blk, | 909 | status = ocfs2_read_quota_phys_block(lqinode, od->dq_local_phys_blk, |
@@ -1221,7 +1224,7 @@ static void olq_alloc_dquot(struct buffer_head *bh, void *private) | |||
1221 | int ocfs2_create_local_dquot(struct dquot *dquot) | 1224 | int ocfs2_create_local_dquot(struct dquot *dquot) |
1222 | { | 1225 | { |
1223 | struct super_block *sb = dquot->dq_sb; | 1226 | struct super_block *sb = dquot->dq_sb; |
1224 | int type = dquot->dq_type; | 1227 | int type = dquot->dq_id.type; |
1225 | struct inode *lqinode = sb_dqopt(sb)->files[type]; | 1228 | struct inode *lqinode = sb_dqopt(sb)->files[type]; |
1226 | struct ocfs2_quota_chunk *chunk; | 1229 | struct ocfs2_quota_chunk *chunk; |
1227 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); | 1230 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); |
@@ -1275,7 +1278,7 @@ out: | |||
1275 | int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot) | 1278 | int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot) |
1276 | { | 1279 | { |
1277 | int status; | 1280 | int status; |
1278 | int type = dquot->dq_type; | 1281 | int type = dquot->dq_id.type; |
1279 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); | 1282 | struct ocfs2_dquot *od = OCFS2_DQUOT(dquot); |
1280 | struct super_block *sb = dquot->dq_sb; | 1283 | struct super_block *sb = dquot->dq_sb; |
1281 | struct ocfs2_local_disk_chunk *dchunk; | 1284 | struct ocfs2_local_disk_chunk *dchunk; |
diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c index e6213b3725d1..25d715c7c87a 100644 --- a/fs/omfs/inode.c +++ b/fs/omfs/inode.c | |||
@@ -391,12 +391,16 @@ static int parse_options(char *options, struct omfs_sb_info *sbi) | |||
391 | case Opt_uid: | 391 | case Opt_uid: |
392 | if (match_int(&args[0], &option)) | 392 | if (match_int(&args[0], &option)) |
393 | return 0; | 393 | return 0; |
394 | sbi->s_uid = option; | 394 | sbi->s_uid = make_kuid(current_user_ns(), option); |
395 | if (!uid_valid(sbi->s_uid)) | ||
396 | return 0; | ||
395 | break; | 397 | break; |
396 | case Opt_gid: | 398 | case Opt_gid: |
397 | if (match_int(&args[0], &option)) | 399 | if (match_int(&args[0], &option)) |
398 | return 0; | 400 | return 0; |
399 | sbi->s_gid = option; | 401 | sbi->s_gid = make_kgid(current_user_ns(), option); |
402 | if (!gid_valid(sbi->s_gid)) | ||
403 | return 0; | ||
400 | break; | 404 | break; |
401 | case Opt_umask: | 405 | case Opt_umask: |
402 | if (match_octal(&args[0], &option)) | 406 | if (match_octal(&args[0], &option)) |
diff --git a/fs/omfs/omfs.h b/fs/omfs/omfs.h index 8941f12c6b01..f0f8bc75e609 100644 --- a/fs/omfs/omfs.h +++ b/fs/omfs/omfs.h | |||
@@ -19,8 +19,8 @@ struct omfs_sb_info { | |||
19 | unsigned long **s_imap; | 19 | unsigned long **s_imap; |
20 | int s_imap_size; | 20 | int s_imap_size; |
21 | struct mutex s_bitmap_lock; | 21 | struct mutex s_bitmap_lock; |
22 | int s_uid; | 22 | kuid_t s_uid; |
23 | int s_gid; | 23 | kgid_t s_gid; |
24 | int s_dmask; | 24 | int s_dmask; |
25 | int s_fmask; | 25 | int s_fmask; |
26 | }; | 26 | }; |
@@ -531,7 +531,7 @@ static int chown_common(struct path *path, uid_t user, gid_t group) | |||
531 | newattrs.ia_valid |= | 531 | newattrs.ia_valid |= |
532 | ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV; | 532 | ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV; |
533 | mutex_lock(&inode->i_mutex); | 533 | mutex_lock(&inode->i_mutex); |
534 | error = security_path_chown(path, user, group); | 534 | error = security_path_chown(path, uid, gid); |
535 | if (!error) | 535 | if (!error) |
536 | error = notify_change(path->dentry, &newattrs); | 536 | error = notify_change(path->dentry, &newattrs); |
537 | mutex_unlock(&inode->i_mutex); | 537 | mutex_unlock(&inode->i_mutex); |
diff --git a/fs/posix_acl.c b/fs/posix_acl.c index 5e325a42e33d..8bd2135b7f82 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c | |||
@@ -78,7 +78,8 @@ posix_acl_valid(const struct posix_acl *acl) | |||
78 | { | 78 | { |
79 | const struct posix_acl_entry *pa, *pe; | 79 | const struct posix_acl_entry *pa, *pe; |
80 | int state = ACL_USER_OBJ; | 80 | int state = ACL_USER_OBJ; |
81 | unsigned int id = 0; /* keep gcc happy */ | 81 | kuid_t prev_uid = INVALID_UID; |
82 | kgid_t prev_gid = INVALID_GID; | ||
82 | int needs_mask = 0; | 83 | int needs_mask = 0; |
83 | 84 | ||
84 | FOREACH_ACL_ENTRY(pa, acl, pe) { | 85 | FOREACH_ACL_ENTRY(pa, acl, pe) { |
@@ -87,7 +88,6 @@ posix_acl_valid(const struct posix_acl *acl) | |||
87 | switch (pa->e_tag) { | 88 | switch (pa->e_tag) { |
88 | case ACL_USER_OBJ: | 89 | case ACL_USER_OBJ: |
89 | if (state == ACL_USER_OBJ) { | 90 | if (state == ACL_USER_OBJ) { |
90 | id = 0; | ||
91 | state = ACL_USER; | 91 | state = ACL_USER; |
92 | break; | 92 | break; |
93 | } | 93 | } |
@@ -96,16 +96,17 @@ posix_acl_valid(const struct posix_acl *acl) | |||
96 | case ACL_USER: | 96 | case ACL_USER: |
97 | if (state != ACL_USER) | 97 | if (state != ACL_USER) |
98 | return -EINVAL; | 98 | return -EINVAL; |
99 | if (pa->e_id == ACL_UNDEFINED_ID || | 99 | if (!uid_valid(pa->e_uid)) |
100 | pa->e_id < id) | ||
101 | return -EINVAL; | 100 | return -EINVAL; |
102 | id = pa->e_id + 1; | 101 | if (uid_valid(prev_uid) && |
102 | uid_lte(pa->e_uid, prev_uid)) | ||
103 | return -EINVAL; | ||
104 | prev_uid = pa->e_uid; | ||
103 | needs_mask = 1; | 105 | needs_mask = 1; |
104 | break; | 106 | break; |
105 | 107 | ||
106 | case ACL_GROUP_OBJ: | 108 | case ACL_GROUP_OBJ: |
107 | if (state == ACL_USER) { | 109 | if (state == ACL_USER) { |
108 | id = 0; | ||
109 | state = ACL_GROUP; | 110 | state = ACL_GROUP; |
110 | break; | 111 | break; |
111 | } | 112 | } |
@@ -114,10 +115,12 @@ posix_acl_valid(const struct posix_acl *acl) | |||
114 | case ACL_GROUP: | 115 | case ACL_GROUP: |
115 | if (state != ACL_GROUP) | 116 | if (state != ACL_GROUP) |
116 | return -EINVAL; | 117 | return -EINVAL; |
117 | if (pa->e_id == ACL_UNDEFINED_ID || | 118 | if (!gid_valid(pa->e_gid)) |
118 | pa->e_id < id) | 119 | return -EINVAL; |
120 | if (gid_valid(prev_gid) && | ||
121 | gid_lte(pa->e_gid, prev_gid)) | ||
119 | return -EINVAL; | 122 | return -EINVAL; |
120 | id = pa->e_id + 1; | 123 | prev_gid = pa->e_gid; |
121 | needs_mask = 1; | 124 | needs_mask = 1; |
122 | break; | 125 | break; |
123 | 126 | ||
@@ -195,15 +198,12 @@ posix_acl_from_mode(umode_t mode, gfp_t flags) | |||
195 | return ERR_PTR(-ENOMEM); | 198 | return ERR_PTR(-ENOMEM); |
196 | 199 | ||
197 | acl->a_entries[0].e_tag = ACL_USER_OBJ; | 200 | acl->a_entries[0].e_tag = ACL_USER_OBJ; |
198 | acl->a_entries[0].e_id = ACL_UNDEFINED_ID; | ||
199 | acl->a_entries[0].e_perm = (mode & S_IRWXU) >> 6; | 201 | acl->a_entries[0].e_perm = (mode & S_IRWXU) >> 6; |
200 | 202 | ||
201 | acl->a_entries[1].e_tag = ACL_GROUP_OBJ; | 203 | acl->a_entries[1].e_tag = ACL_GROUP_OBJ; |
202 | acl->a_entries[1].e_id = ACL_UNDEFINED_ID; | ||
203 | acl->a_entries[1].e_perm = (mode & S_IRWXG) >> 3; | 204 | acl->a_entries[1].e_perm = (mode & S_IRWXG) >> 3; |
204 | 205 | ||
205 | acl->a_entries[2].e_tag = ACL_OTHER; | 206 | acl->a_entries[2].e_tag = ACL_OTHER; |
206 | acl->a_entries[2].e_id = ACL_UNDEFINED_ID; | ||
207 | acl->a_entries[2].e_perm = (mode & S_IRWXO); | 207 | acl->a_entries[2].e_perm = (mode & S_IRWXO); |
208 | return acl; | 208 | return acl; |
209 | } | 209 | } |
@@ -224,11 +224,11 @@ posix_acl_permission(struct inode *inode, const struct posix_acl *acl, int want) | |||
224 | switch(pa->e_tag) { | 224 | switch(pa->e_tag) { |
225 | case ACL_USER_OBJ: | 225 | case ACL_USER_OBJ: |
226 | /* (May have been checked already) */ | 226 | /* (May have been checked already) */ |
227 | if (inode->i_uid == current_fsuid()) | 227 | if (uid_eq(inode->i_uid, current_fsuid())) |
228 | goto check_perm; | 228 | goto check_perm; |
229 | break; | 229 | break; |
230 | case ACL_USER: | 230 | case ACL_USER: |
231 | if (pa->e_id == current_fsuid()) | 231 | if (uid_eq(pa->e_uid, current_fsuid())) |
232 | goto mask; | 232 | goto mask; |
233 | break; | 233 | break; |
234 | case ACL_GROUP_OBJ: | 234 | case ACL_GROUP_OBJ: |
@@ -239,7 +239,7 @@ posix_acl_permission(struct inode *inode, const struct posix_acl *acl, int want) | |||
239 | } | 239 | } |
240 | break; | 240 | break; |
241 | case ACL_GROUP: | 241 | case ACL_GROUP: |
242 | if (in_group_p(pa->e_id)) { | 242 | if (in_group_p(pa->e_gid)) { |
243 | found = 1; | 243 | found = 1; |
244 | if ((pa->e_perm & want) == want) | 244 | if ((pa->e_perm & want) == want) |
245 | goto mask; | 245 | goto mask; |
diff --git a/fs/proc/base.c b/fs/proc/base.c index df18db61d6d8..d295af993677 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -1088,7 +1088,8 @@ static ssize_t proc_loginuid_read(struct file * file, char __user * buf, | |||
1088 | if (!task) | 1088 | if (!task) |
1089 | return -ESRCH; | 1089 | return -ESRCH; |
1090 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", | 1090 | length = scnprintf(tmpbuf, TMPBUFLEN, "%u", |
1091 | audit_get_loginuid(task)); | 1091 | from_kuid(file->f_cred->user_ns, |
1092 | audit_get_loginuid(task))); | ||
1092 | put_task_struct(task); | 1093 | put_task_struct(task); |
1093 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); | 1094 | return simple_read_from_buffer(buf, count, ppos, tmpbuf, length); |
1094 | } | 1095 | } |
@@ -1100,6 +1101,7 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, | |||
1100 | char *page, *tmp; | 1101 | char *page, *tmp; |
1101 | ssize_t length; | 1102 | ssize_t length; |
1102 | uid_t loginuid; | 1103 | uid_t loginuid; |
1104 | kuid_t kloginuid; | ||
1103 | 1105 | ||
1104 | rcu_read_lock(); | 1106 | rcu_read_lock(); |
1105 | if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) { | 1107 | if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) { |
@@ -1129,7 +1131,13 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, | |||
1129 | goto out_free_page; | 1131 | goto out_free_page; |
1130 | 1132 | ||
1131 | } | 1133 | } |
1132 | length = audit_set_loginuid(loginuid); | 1134 | kloginuid = make_kuid(file->f_cred->user_ns, loginuid); |
1135 | if (!uid_valid(kloginuid)) { | ||
1136 | length = -EINVAL; | ||
1137 | goto out_free_page; | ||
1138 | } | ||
1139 | |||
1140 | length = audit_set_loginuid(kloginuid); | ||
1133 | if (likely(length == 0)) | 1141 | if (likely(length == 0)) |
1134 | length = count; | 1142 | length = count; |
1135 | 1143 | ||
@@ -2588,6 +2596,11 @@ static int proc_gid_map_open(struct inode *inode, struct file *file) | |||
2588 | return proc_id_map_open(inode, file, &proc_gid_seq_operations); | 2596 | return proc_id_map_open(inode, file, &proc_gid_seq_operations); |
2589 | } | 2597 | } |
2590 | 2598 | ||
2599 | static int proc_projid_map_open(struct inode *inode, struct file *file) | ||
2600 | { | ||
2601 | return proc_id_map_open(inode, file, &proc_projid_seq_operations); | ||
2602 | } | ||
2603 | |||
2591 | static const struct file_operations proc_uid_map_operations = { | 2604 | static const struct file_operations proc_uid_map_operations = { |
2592 | .open = proc_uid_map_open, | 2605 | .open = proc_uid_map_open, |
2593 | .write = proc_uid_map_write, | 2606 | .write = proc_uid_map_write, |
@@ -2603,6 +2616,14 @@ static const struct file_operations proc_gid_map_operations = { | |||
2603 | .llseek = seq_lseek, | 2616 | .llseek = seq_lseek, |
2604 | .release = proc_id_map_release, | 2617 | .release = proc_id_map_release, |
2605 | }; | 2618 | }; |
2619 | |||
2620 | static const struct file_operations proc_projid_map_operations = { | ||
2621 | .open = proc_projid_map_open, | ||
2622 | .write = proc_projid_map_write, | ||
2623 | .read = seq_read, | ||
2624 | .llseek = seq_lseek, | ||
2625 | .release = proc_id_map_release, | ||
2626 | }; | ||
2606 | #endif /* CONFIG_USER_NS */ | 2627 | #endif /* CONFIG_USER_NS */ |
2607 | 2628 | ||
2608 | static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns, | 2629 | static int proc_pid_personality(struct seq_file *m, struct pid_namespace *ns, |
@@ -2710,6 +2731,7 @@ static const struct pid_entry tgid_base_stuff[] = { | |||
2710 | #ifdef CONFIG_USER_NS | 2731 | #ifdef CONFIG_USER_NS |
2711 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), | 2732 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), |
2712 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), | 2733 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), |
2734 | REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations), | ||
2713 | #endif | 2735 | #endif |
2714 | }; | 2736 | }; |
2715 | 2737 | ||
@@ -3073,6 +3095,7 @@ static const struct pid_entry tid_base_stuff[] = { | |||
3073 | #ifdef CONFIG_USER_NS | 3095 | #ifdef CONFIG_USER_NS |
3074 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), | 3096 | REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations), |
3075 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), | 3097 | REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations), |
3098 | REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations), | ||
3076 | #endif | 3099 | #endif |
3077 | }; | 3100 | }; |
3078 | 3101 | ||
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c index 9534b4f76579..43098bb5723a 100644 --- a/fs/qnx4/inode.c +++ b/fs/qnx4/inode.c | |||
@@ -312,8 +312,8 @@ struct inode *qnx4_iget(struct super_block *sb, unsigned long ino) | |||
312 | (ino % QNX4_INODES_PER_BLOCK); | 312 | (ino % QNX4_INODES_PER_BLOCK); |
313 | 313 | ||
314 | inode->i_mode = le16_to_cpu(raw_inode->di_mode); | 314 | inode->i_mode = le16_to_cpu(raw_inode->di_mode); |
315 | inode->i_uid = (uid_t)le16_to_cpu(raw_inode->di_uid); | 315 | i_uid_write(inode, (uid_t)le16_to_cpu(raw_inode->di_uid)); |
316 | inode->i_gid = (gid_t)le16_to_cpu(raw_inode->di_gid); | 316 | i_gid_write(inode, (gid_t)le16_to_cpu(raw_inode->di_gid)); |
317 | set_nlink(inode, le16_to_cpu(raw_inode->di_nlink)); | 317 | set_nlink(inode, le16_to_cpu(raw_inode->di_nlink)); |
318 | inode->i_size = le32_to_cpu(raw_inode->di_size); | 318 | inode->i_size = le32_to_cpu(raw_inode->di_size); |
319 | inode->i_mtime.tv_sec = le32_to_cpu(raw_inode->di_mtime); | 319 | inode->i_mtime.tv_sec = le32_to_cpu(raw_inode->di_mtime); |
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c index 1b37fff7b5ff..b6addf560483 100644 --- a/fs/qnx6/inode.c +++ b/fs/qnx6/inode.c | |||
@@ -574,8 +574,8 @@ struct inode *qnx6_iget(struct super_block *sb, unsigned ino) | |||
574 | raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs; | 574 | raw_inode = ((struct qnx6_inode_entry *)page_address(page)) + offs; |
575 | 575 | ||
576 | inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode); | 576 | inode->i_mode = fs16_to_cpu(sbi, raw_inode->di_mode); |
577 | inode->i_uid = (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid); | 577 | i_uid_write(inode, (uid_t)fs32_to_cpu(sbi, raw_inode->di_uid)); |
578 | inode->i_gid = (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid); | 578 | i_gid_write(inode, (gid_t)fs32_to_cpu(sbi, raw_inode->di_gid)); |
579 | inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size); | 579 | inode->i_size = fs64_to_cpu(sbi, raw_inode->di_size); |
580 | inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_mtime); | 580 | inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->di_mtime); |
581 | inode->i_mtime.tv_nsec = 0; | 581 | inode->i_mtime.tv_nsec = 0; |
diff --git a/fs/quota/Makefile b/fs/quota/Makefile index 5f9e9e276af0..c66c37cdaa39 100644 --- a/fs/quota/Makefile +++ b/fs/quota/Makefile | |||
@@ -2,6 +2,6 @@ obj-$(CONFIG_QUOTA) += dquot.o | |||
2 | obj-$(CONFIG_QFMT_V1) += quota_v1.o | 2 | obj-$(CONFIG_QFMT_V1) += quota_v1.o |
3 | obj-$(CONFIG_QFMT_V2) += quota_v2.o | 3 | obj-$(CONFIG_QFMT_V2) += quota_v2.o |
4 | obj-$(CONFIG_QUOTA_TREE) += quota_tree.o | 4 | obj-$(CONFIG_QUOTA_TREE) += quota_tree.o |
5 | obj-$(CONFIG_QUOTACTL) += quota.o | 5 | obj-$(CONFIG_QUOTACTL) += quota.o kqid.o |
6 | obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o | 6 | obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o |
7 | obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o | 7 | obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o |
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index c495a3055e2a..557a9c20a215 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c | |||
@@ -253,8 +253,10 @@ static qsize_t inode_get_rsv_space(struct inode *inode); | |||
253 | static void __dquot_initialize(struct inode *inode, int type); | 253 | static void __dquot_initialize(struct inode *inode, int type); |
254 | 254 | ||
255 | static inline unsigned int | 255 | static inline unsigned int |
256 | hashfn(const struct super_block *sb, unsigned int id, int type) | 256 | hashfn(const struct super_block *sb, struct kqid qid) |
257 | { | 257 | { |
258 | unsigned int id = from_kqid(&init_user_ns, qid); | ||
259 | int type = qid.type; | ||
258 | unsigned long tmp; | 260 | unsigned long tmp; |
259 | 261 | ||
260 | tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type); | 262 | tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type); |
@@ -267,7 +269,7 @@ hashfn(const struct super_block *sb, unsigned int id, int type) | |||
267 | static inline void insert_dquot_hash(struct dquot *dquot) | 269 | static inline void insert_dquot_hash(struct dquot *dquot) |
268 | { | 270 | { |
269 | struct hlist_head *head; | 271 | struct hlist_head *head; |
270 | head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type); | 272 | head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id); |
271 | hlist_add_head(&dquot->dq_hash, head); | 273 | hlist_add_head(&dquot->dq_hash, head); |
272 | } | 274 | } |
273 | 275 | ||
@@ -277,15 +279,14 @@ static inline void remove_dquot_hash(struct dquot *dquot) | |||
277 | } | 279 | } |
278 | 280 | ||
279 | static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, | 281 | static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, |
280 | unsigned int id, int type) | 282 | struct kqid qid) |
281 | { | 283 | { |
282 | struct hlist_node *node; | 284 | struct hlist_node *node; |
283 | struct dquot *dquot; | 285 | struct dquot *dquot; |
284 | 286 | ||
285 | hlist_for_each (node, dquot_hash+hashent) { | 287 | hlist_for_each (node, dquot_hash+hashent) { |
286 | dquot = hlist_entry(node, struct dquot, dq_hash); | 288 | dquot = hlist_entry(node, struct dquot, dq_hash); |
287 | if (dquot->dq_sb == sb && dquot->dq_id == id && | 289 | if (dquot->dq_sb == sb && qid_eq(dquot->dq_id, qid)) |
288 | dquot->dq_type == type) | ||
289 | return dquot; | 290 | return dquot; |
290 | } | 291 | } |
291 | return NULL; | 292 | return NULL; |
@@ -351,7 +352,7 @@ int dquot_mark_dquot_dirty(struct dquot *dquot) | |||
351 | spin_lock(&dq_list_lock); | 352 | spin_lock(&dq_list_lock); |
352 | if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) { | 353 | if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) { |
353 | list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)-> | 354 | list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)-> |
354 | info[dquot->dq_type].dqi_dirty_list); | 355 | info[dquot->dq_id.type].dqi_dirty_list); |
355 | ret = 0; | 356 | ret = 0; |
356 | } | 357 | } |
357 | spin_unlock(&dq_list_lock); | 358 | spin_unlock(&dq_list_lock); |
@@ -410,17 +411,17 @@ int dquot_acquire(struct dquot *dquot) | |||
410 | mutex_lock(&dquot->dq_lock); | 411 | mutex_lock(&dquot->dq_lock); |
411 | mutex_lock(&dqopt->dqio_mutex); | 412 | mutex_lock(&dqopt->dqio_mutex); |
412 | if (!test_bit(DQ_READ_B, &dquot->dq_flags)) | 413 | if (!test_bit(DQ_READ_B, &dquot->dq_flags)) |
413 | ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot); | 414 | ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); |
414 | if (ret < 0) | 415 | if (ret < 0) |
415 | goto out_iolock; | 416 | goto out_iolock; |
416 | set_bit(DQ_READ_B, &dquot->dq_flags); | 417 | set_bit(DQ_READ_B, &dquot->dq_flags); |
417 | /* Instantiate dquot if needed */ | 418 | /* Instantiate dquot if needed */ |
418 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { | 419 | if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { |
419 | ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); | 420 | ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); |
420 | /* Write the info if needed */ | 421 | /* Write the info if needed */ |
421 | if (info_dirty(&dqopt->info[dquot->dq_type])) { | 422 | if (info_dirty(&dqopt->info[dquot->dq_id.type])) { |
422 | ret2 = dqopt->ops[dquot->dq_type]->write_file_info( | 423 | ret2 = dqopt->ops[dquot->dq_id.type]->write_file_info( |
423 | dquot->dq_sb, dquot->dq_type); | 424 | dquot->dq_sb, dquot->dq_id.type); |
424 | } | 425 | } |
425 | if (ret < 0) | 426 | if (ret < 0) |
426 | goto out_iolock; | 427 | goto out_iolock; |
@@ -455,7 +456,7 @@ int dquot_commit(struct dquot *dquot) | |||
455 | /* Inactive dquot can be only if there was error during read/init | 456 | /* Inactive dquot can be only if there was error during read/init |
456 | * => we have better not writing it */ | 457 | * => we have better not writing it */ |
457 | if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) | 458 | if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) |
458 | ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); | 459 | ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); |
459 | else | 460 | else |
460 | ret = -EIO; | 461 | ret = -EIO; |
461 | out_sem: | 462 | out_sem: |
@@ -477,12 +478,12 @@ int dquot_release(struct dquot *dquot) | |||
477 | if (atomic_read(&dquot->dq_count) > 1) | 478 | if (atomic_read(&dquot->dq_count) > 1) |
478 | goto out_dqlock; | 479 | goto out_dqlock; |
479 | mutex_lock(&dqopt->dqio_mutex); | 480 | mutex_lock(&dqopt->dqio_mutex); |
480 | if (dqopt->ops[dquot->dq_type]->release_dqblk) { | 481 | if (dqopt->ops[dquot->dq_id.type]->release_dqblk) { |
481 | ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot); | 482 | ret = dqopt->ops[dquot->dq_id.type]->release_dqblk(dquot); |
482 | /* Write the info */ | 483 | /* Write the info */ |
483 | if (info_dirty(&dqopt->info[dquot->dq_type])) { | 484 | if (info_dirty(&dqopt->info[dquot->dq_id.type])) { |
484 | ret2 = dqopt->ops[dquot->dq_type]->write_file_info( | 485 | ret2 = dqopt->ops[dquot->dq_id.type]->write_file_info( |
485 | dquot->dq_sb, dquot->dq_type); | 486 | dquot->dq_sb, dquot->dq_id.type); |
486 | } | 487 | } |
487 | if (ret >= 0) | 488 | if (ret >= 0) |
488 | ret = ret2; | 489 | ret = ret2; |
@@ -521,7 +522,7 @@ restart: | |||
521 | list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) { | 522 | list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) { |
522 | if (dquot->dq_sb != sb) | 523 | if (dquot->dq_sb != sb) |
523 | continue; | 524 | continue; |
524 | if (dquot->dq_type != type) | 525 | if (dquot->dq_id.type != type) |
525 | continue; | 526 | continue; |
526 | /* Wait for dquot users */ | 527 | /* Wait for dquot users */ |
527 | if (atomic_read(&dquot->dq_count)) { | 528 | if (atomic_read(&dquot->dq_count)) { |
@@ -741,7 +742,8 @@ void dqput(struct dquot *dquot) | |||
741 | #ifdef CONFIG_QUOTA_DEBUG | 742 | #ifdef CONFIG_QUOTA_DEBUG |
742 | if (!atomic_read(&dquot->dq_count)) { | 743 | if (!atomic_read(&dquot->dq_count)) { |
743 | quota_error(dquot->dq_sb, "trying to free free dquot of %s %d", | 744 | quota_error(dquot->dq_sb, "trying to free free dquot of %s %d", |
744 | quotatypes[dquot->dq_type], dquot->dq_id); | 745 | quotatypes[dquot->dq_id.type], |
746 | from_kqid(&init_user_ns, dquot->dq_id)); | ||
745 | BUG(); | 747 | BUG(); |
746 | } | 748 | } |
747 | #endif | 749 | #endif |
@@ -752,7 +754,7 @@ we_slept: | |||
752 | /* We have more than one user... nothing to do */ | 754 | /* We have more than one user... nothing to do */ |
753 | atomic_dec(&dquot->dq_count); | 755 | atomic_dec(&dquot->dq_count); |
754 | /* Releasing dquot during quotaoff phase? */ | 756 | /* Releasing dquot during quotaoff phase? */ |
755 | if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_type) && | 757 | if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_id.type) && |
756 | atomic_read(&dquot->dq_count) == 1) | 758 | atomic_read(&dquot->dq_count) == 1) |
757 | wake_up(&dquot->dq_wait_unused); | 759 | wake_up(&dquot->dq_wait_unused); |
758 | spin_unlock(&dq_list_lock); | 760 | spin_unlock(&dq_list_lock); |
@@ -815,7 +817,7 @@ static struct dquot *get_empty_dquot(struct super_block *sb, int type) | |||
815 | INIT_LIST_HEAD(&dquot->dq_dirty); | 817 | INIT_LIST_HEAD(&dquot->dq_dirty); |
816 | init_waitqueue_head(&dquot->dq_wait_unused); | 818 | init_waitqueue_head(&dquot->dq_wait_unused); |
817 | dquot->dq_sb = sb; | 819 | dquot->dq_sb = sb; |
818 | dquot->dq_type = type; | 820 | dquot->dq_id = make_kqid_invalid(type); |
819 | atomic_set(&dquot->dq_count, 1); | 821 | atomic_set(&dquot->dq_count, 1); |
820 | 822 | ||
821 | return dquot; | 823 | return dquot; |
@@ -829,35 +831,35 @@ static struct dquot *get_empty_dquot(struct super_block *sb, int type) | |||
829 | * a) checking for quota flags under dq_list_lock and | 831 | * a) checking for quota flags under dq_list_lock and |
830 | * b) getting a reference to dquot before we release dq_list_lock | 832 | * b) getting a reference to dquot before we release dq_list_lock |
831 | */ | 833 | */ |
832 | struct dquot *dqget(struct super_block *sb, unsigned int id, int type) | 834 | struct dquot *dqget(struct super_block *sb, struct kqid qid) |
833 | { | 835 | { |
834 | unsigned int hashent = hashfn(sb, id, type); | 836 | unsigned int hashent = hashfn(sb, qid); |
835 | struct dquot *dquot = NULL, *empty = NULL; | 837 | struct dquot *dquot = NULL, *empty = NULL; |
836 | 838 | ||
837 | if (!sb_has_quota_active(sb, type)) | 839 | if (!sb_has_quota_active(sb, qid.type)) |
838 | return NULL; | 840 | return NULL; |
839 | we_slept: | 841 | we_slept: |
840 | spin_lock(&dq_list_lock); | 842 | spin_lock(&dq_list_lock); |
841 | spin_lock(&dq_state_lock); | 843 | spin_lock(&dq_state_lock); |
842 | if (!sb_has_quota_active(sb, type)) { | 844 | if (!sb_has_quota_active(sb, qid.type)) { |
843 | spin_unlock(&dq_state_lock); | 845 | spin_unlock(&dq_state_lock); |
844 | spin_unlock(&dq_list_lock); | 846 | spin_unlock(&dq_list_lock); |
845 | goto out; | 847 | goto out; |
846 | } | 848 | } |
847 | spin_unlock(&dq_state_lock); | 849 | spin_unlock(&dq_state_lock); |
848 | 850 | ||
849 | dquot = find_dquot(hashent, sb, id, type); | 851 | dquot = find_dquot(hashent, sb, qid); |
850 | if (!dquot) { | 852 | if (!dquot) { |
851 | if (!empty) { | 853 | if (!empty) { |
852 | spin_unlock(&dq_list_lock); | 854 | spin_unlock(&dq_list_lock); |
853 | empty = get_empty_dquot(sb, type); | 855 | empty = get_empty_dquot(sb, qid.type); |
854 | if (!empty) | 856 | if (!empty) |
855 | schedule(); /* Try to wait for a moment... */ | 857 | schedule(); /* Try to wait for a moment... */ |
856 | goto we_slept; | 858 | goto we_slept; |
857 | } | 859 | } |
858 | dquot = empty; | 860 | dquot = empty; |
859 | empty = NULL; | 861 | empty = NULL; |
860 | dquot->dq_id = id; | 862 | dquot->dq_id = qid; |
861 | /* all dquots go on the inuse_list */ | 863 | /* all dquots go on the inuse_list */ |
862 | put_inuse(dquot); | 864 | put_inuse(dquot); |
863 | /* hash it first so it can be found */ | 865 | /* hash it first so it can be found */ |
@@ -1129,8 +1131,7 @@ static void dquot_decr_space(struct dquot *dquot, qsize_t number) | |||
1129 | 1131 | ||
1130 | struct dquot_warn { | 1132 | struct dquot_warn { |
1131 | struct super_block *w_sb; | 1133 | struct super_block *w_sb; |
1132 | qid_t w_dq_id; | 1134 | struct kqid w_dq_id; |
1133 | short w_dq_type; | ||
1134 | short w_type; | 1135 | short w_type; |
1135 | }; | 1136 | }; |
1136 | 1137 | ||
@@ -1154,11 +1155,11 @@ static int need_print_warning(struct dquot_warn *warn) | |||
1154 | if (!flag_print_warnings) | 1155 | if (!flag_print_warnings) |
1155 | return 0; | 1156 | return 0; |
1156 | 1157 | ||
1157 | switch (warn->w_dq_type) { | 1158 | switch (warn->w_dq_id.type) { |
1158 | case USRQUOTA: | 1159 | case USRQUOTA: |
1159 | return current_fsuid() == warn->w_dq_id; | 1160 | return uid_eq(current_fsuid(), warn->w_dq_id.uid); |
1160 | case GRPQUOTA: | 1161 | case GRPQUOTA: |
1161 | return in_group_p(warn->w_dq_id); | 1162 | return in_group_p(warn->w_dq_id.gid); |
1162 | } | 1163 | } |
1163 | return 0; | 1164 | return 0; |
1164 | } | 1165 | } |
@@ -1184,7 +1185,7 @@ static void print_warning(struct dquot_warn *warn) | |||
1184 | tty_write_message(tty, ": warning, "); | 1185 | tty_write_message(tty, ": warning, "); |
1185 | else | 1186 | else |
1186 | tty_write_message(tty, ": write failed, "); | 1187 | tty_write_message(tty, ": write failed, "); |
1187 | tty_write_message(tty, quotatypes[warn->w_dq_type]); | 1188 | tty_write_message(tty, quotatypes[warn->w_dq_id.type]); |
1188 | switch (warntype) { | 1189 | switch (warntype) { |
1189 | case QUOTA_NL_IHARDWARN: | 1190 | case QUOTA_NL_IHARDWARN: |
1190 | msg = " file limit reached.\r\n"; | 1191 | msg = " file limit reached.\r\n"; |
@@ -1218,7 +1219,6 @@ static void prepare_warning(struct dquot_warn *warn, struct dquot *dquot, | |||
1218 | warn->w_type = warntype; | 1219 | warn->w_type = warntype; |
1219 | warn->w_sb = dquot->dq_sb; | 1220 | warn->w_sb = dquot->dq_sb; |
1220 | warn->w_dq_id = dquot->dq_id; | 1221 | warn->w_dq_id = dquot->dq_id; |
1221 | warn->w_dq_type = dquot->dq_type; | ||
1222 | } | 1222 | } |
1223 | 1223 | ||
1224 | /* | 1224 | /* |
@@ -1236,14 +1236,14 @@ static void flush_warnings(struct dquot_warn *warn) | |||
1236 | #ifdef CONFIG_PRINT_QUOTA_WARNING | 1236 | #ifdef CONFIG_PRINT_QUOTA_WARNING |
1237 | print_warning(&warn[i]); | 1237 | print_warning(&warn[i]); |
1238 | #endif | 1238 | #endif |
1239 | quota_send_warning(warn[i].w_dq_type, warn[i].w_dq_id, | 1239 | quota_send_warning(warn[i].w_dq_id, |
1240 | warn[i].w_sb->s_dev, warn[i].w_type); | 1240 | warn[i].w_sb->s_dev, warn[i].w_type); |
1241 | } | 1241 | } |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | static int ignore_hardlimit(struct dquot *dquot) | 1244 | static int ignore_hardlimit(struct dquot *dquot) |
1245 | { | 1245 | { |
1246 | struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; | 1246 | struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type]; |
1247 | 1247 | ||
1248 | return capable(CAP_SYS_RESOURCE) && | 1248 | return capable(CAP_SYS_RESOURCE) && |
1249 | (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || | 1249 | (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || |
@@ -1256,7 +1256,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, | |||
1256 | { | 1256 | { |
1257 | qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes; | 1257 | qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes; |
1258 | 1258 | ||
1259 | if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || | 1259 | if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_id.type) || |
1260 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) | 1260 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
1261 | return 0; | 1261 | return 0; |
1262 | 1262 | ||
@@ -1281,7 +1281,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, | |||
1281 | dquot->dq_dqb.dqb_itime == 0) { | 1281 | dquot->dq_dqb.dqb_itime == 0) { |
1282 | prepare_warning(warn, dquot, QUOTA_NL_ISOFTWARN); | 1282 | prepare_warning(warn, dquot, QUOTA_NL_ISOFTWARN); |
1283 | dquot->dq_dqb.dqb_itime = get_seconds() + | 1283 | dquot->dq_dqb.dqb_itime = get_seconds() + |
1284 | sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; | 1284 | sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type].dqi_igrace; |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | return 0; | 1287 | return 0; |
@@ -1294,7 +1294,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, | |||
1294 | qsize_t tspace; | 1294 | qsize_t tspace; |
1295 | struct super_block *sb = dquot->dq_sb; | 1295 | struct super_block *sb = dquot->dq_sb; |
1296 | 1296 | ||
1297 | if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) || | 1297 | if (!sb_has_quota_limits_enabled(sb, dquot->dq_id.type) || |
1298 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) | 1298 | test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
1299 | return 0; | 1299 | return 0; |
1300 | 1300 | ||
@@ -1325,7 +1325,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, | |||
1325 | if (!prealloc) { | 1325 | if (!prealloc) { |
1326 | prepare_warning(warn, dquot, QUOTA_NL_BSOFTWARN); | 1326 | prepare_warning(warn, dquot, QUOTA_NL_BSOFTWARN); |
1327 | dquot->dq_dqb.dqb_btime = get_seconds() + | 1327 | dquot->dq_dqb.dqb_btime = get_seconds() + |
1328 | sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace; | 1328 | sb_dqopt(sb)->info[dquot->dq_id.type].dqi_bgrace; |
1329 | } | 1329 | } |
1330 | else | 1330 | else |
1331 | /* | 1331 | /* |
@@ -1344,7 +1344,7 @@ static int info_idq_free(struct dquot *dquot, qsize_t inodes) | |||
1344 | 1344 | ||
1345 | if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || | 1345 | if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || |
1346 | dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit || | 1346 | dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit || |
1347 | !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type)) | 1347 | !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_id.type)) |
1348 | return QUOTA_NL_NOWARN; | 1348 | return QUOTA_NL_NOWARN; |
1349 | 1349 | ||
1350 | newinodes = dquot->dq_dqb.dqb_curinodes - inodes; | 1350 | newinodes = dquot->dq_dqb.dqb_curinodes - inodes; |
@@ -1390,7 +1390,6 @@ static int dquot_active(const struct inode *inode) | |||
1390 | */ | 1390 | */ |
1391 | static void __dquot_initialize(struct inode *inode, int type) | 1391 | static void __dquot_initialize(struct inode *inode, int type) |
1392 | { | 1392 | { |
1393 | unsigned int id = 0; | ||
1394 | int cnt; | 1393 | int cnt; |
1395 | struct dquot *got[MAXQUOTAS]; | 1394 | struct dquot *got[MAXQUOTAS]; |
1396 | struct super_block *sb = inode->i_sb; | 1395 | struct super_block *sb = inode->i_sb; |
@@ -1403,18 +1402,19 @@ static void __dquot_initialize(struct inode *inode, int type) | |||
1403 | 1402 | ||
1404 | /* First get references to structures we might need. */ | 1403 | /* First get references to structures we might need. */ |
1405 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | 1404 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
1405 | struct kqid qid; | ||
1406 | got[cnt] = NULL; | 1406 | got[cnt] = NULL; |
1407 | if (type != -1 && cnt != type) | 1407 | if (type != -1 && cnt != type) |
1408 | continue; | 1408 | continue; |
1409 | switch (cnt) { | 1409 | switch (cnt) { |
1410 | case USRQUOTA: | 1410 | case USRQUOTA: |
1411 | id = inode->i_uid; | 1411 | qid = make_kqid_uid(inode->i_uid); |
1412 | break; | 1412 | break; |
1413 | case GRPQUOTA: | 1413 | case GRPQUOTA: |
1414 | id = inode->i_gid; | 1414 | qid = make_kqid_gid(inode->i_gid); |
1415 | break; | 1415 | break; |
1416 | } | 1416 | } |
1417 | got[cnt] = dqget(sb, id, cnt); | 1417 | got[cnt] = dqget(sb, qid); |
1418 | } | 1418 | } |
1419 | 1419 | ||
1420 | down_write(&sb_dqopt(sb)->dqptr_sem); | 1420 | down_write(&sb_dqopt(sb)->dqptr_sem); |
@@ -1897,10 +1897,10 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) | |||
1897 | if (!dquot_active(inode)) | 1897 | if (!dquot_active(inode)) |
1898 | return 0; | 1898 | return 0; |
1899 | 1899 | ||
1900 | if (iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) | 1900 | if (iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) |
1901 | transfer_to[USRQUOTA] = dqget(sb, iattr->ia_uid, USRQUOTA); | 1901 | transfer_to[USRQUOTA] = dqget(sb, make_kqid_uid(iattr->ia_uid)); |
1902 | if (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) | 1902 | if (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) |
1903 | transfer_to[GRPQUOTA] = dqget(sb, iattr->ia_gid, GRPQUOTA); | 1903 | transfer_to[GRPQUOTA] = dqget(sb, make_kqid_gid(iattr->ia_gid)); |
1904 | 1904 | ||
1905 | ret = __dquot_transfer(inode, transfer_to); | 1905 | ret = __dquot_transfer(inode, transfer_to); |
1906 | dqput_all(transfer_to); | 1906 | dqput_all(transfer_to); |
@@ -2360,9 +2360,9 @@ static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di) | |||
2360 | 2360 | ||
2361 | memset(di, 0, sizeof(*di)); | 2361 | memset(di, 0, sizeof(*di)); |
2362 | di->d_version = FS_DQUOT_VERSION; | 2362 | di->d_version = FS_DQUOT_VERSION; |
2363 | di->d_flags = dquot->dq_type == USRQUOTA ? | 2363 | di->d_flags = dquot->dq_id.type == USRQUOTA ? |
2364 | FS_USER_QUOTA : FS_GROUP_QUOTA; | 2364 | FS_USER_QUOTA : FS_GROUP_QUOTA; |
2365 | di->d_id = dquot->dq_id; | 2365 | di->d_id = from_kqid_munged(current_user_ns(), dquot->dq_id); |
2366 | 2366 | ||
2367 | spin_lock(&dq_data_lock); | 2367 | spin_lock(&dq_data_lock); |
2368 | di->d_blk_hardlimit = stoqb(dm->dqb_bhardlimit); | 2368 | di->d_blk_hardlimit = stoqb(dm->dqb_bhardlimit); |
@@ -2376,12 +2376,12 @@ static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di) | |||
2376 | spin_unlock(&dq_data_lock); | 2376 | spin_unlock(&dq_data_lock); |
2377 | } | 2377 | } |
2378 | 2378 | ||
2379 | int dquot_get_dqblk(struct super_block *sb, int type, qid_t id, | 2379 | int dquot_get_dqblk(struct super_block *sb, struct kqid qid, |
2380 | struct fs_disk_quota *di) | 2380 | struct fs_disk_quota *di) |
2381 | { | 2381 | { |
2382 | struct dquot *dquot; | 2382 | struct dquot *dquot; |
2383 | 2383 | ||
2384 | dquot = dqget(sb, id, type); | 2384 | dquot = dqget(sb, qid); |
2385 | if (!dquot) | 2385 | if (!dquot) |
2386 | return -ESRCH; | 2386 | return -ESRCH; |
2387 | do_get_dqblk(dquot, di); | 2387 | do_get_dqblk(dquot, di); |
@@ -2401,7 +2401,7 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di) | |||
2401 | { | 2401 | { |
2402 | struct mem_dqblk *dm = &dquot->dq_dqb; | 2402 | struct mem_dqblk *dm = &dquot->dq_dqb; |
2403 | int check_blim = 0, check_ilim = 0; | 2403 | int check_blim = 0, check_ilim = 0; |
2404 | struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; | 2404 | struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type]; |
2405 | 2405 | ||
2406 | if (di->d_fieldmask & ~VFS_FS_DQ_MASK) | 2406 | if (di->d_fieldmask & ~VFS_FS_DQ_MASK) |
2407 | return -EINVAL; | 2407 | return -EINVAL; |
@@ -2488,13 +2488,13 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di) | |||
2488 | return 0; | 2488 | return 0; |
2489 | } | 2489 | } |
2490 | 2490 | ||
2491 | int dquot_set_dqblk(struct super_block *sb, int type, qid_t id, | 2491 | int dquot_set_dqblk(struct super_block *sb, struct kqid qid, |
2492 | struct fs_disk_quota *di) | 2492 | struct fs_disk_quota *di) |
2493 | { | 2493 | { |
2494 | struct dquot *dquot; | 2494 | struct dquot *dquot; |
2495 | int rc; | 2495 | int rc; |
2496 | 2496 | ||
2497 | dquot = dqget(sb, id, type); | 2497 | dquot = dqget(sb, qid); |
2498 | if (!dquot) { | 2498 | if (!dquot) { |
2499 | rc = -ESRCH; | 2499 | rc = -ESRCH; |
2500 | goto out; | 2500 | goto out; |
diff --git a/fs/quota/kqid.c b/fs/quota/kqid.c new file mode 100644 index 000000000000..2f97b0e2c501 --- /dev/null +++ b/fs/quota/kqid.c | |||
@@ -0,0 +1,132 @@ | |||
1 | #include <linux/fs.h> | ||
2 | #include <linux/quota.h> | ||
3 | #include <linux/export.h> | ||
4 | |||
5 | /** | ||
6 | * qid_eq - Test to see if to kquid values are the same | ||
7 | * @left: A qid value | ||
8 | * @right: Another quid value | ||
9 | * | ||
10 | * Return true if the two qid values are equal and false otherwise. | ||
11 | */ | ||
12 | bool qid_eq(struct kqid left, struct kqid right) | ||
13 | { | ||
14 | if (left.type != right.type) | ||
15 | return false; | ||
16 | switch(left.type) { | ||
17 | case USRQUOTA: | ||
18 | return uid_eq(left.uid, right.uid); | ||
19 | case GRPQUOTA: | ||
20 | return gid_eq(left.gid, right.gid); | ||
21 | case PRJQUOTA: | ||
22 | return projid_eq(left.projid, right.projid); | ||
23 | default: | ||
24 | BUG(); | ||
25 | } | ||
26 | } | ||
27 | EXPORT_SYMBOL(qid_eq); | ||
28 | |||
29 | /** | ||
30 | * qid_lt - Test to see if one qid value is less than another | ||
31 | * @left: The possibly lesser qid value | ||
32 | * @right: The possibly greater qid value | ||
33 | * | ||
34 | * Return true if left is less than right and false otherwise. | ||
35 | */ | ||
36 | bool qid_lt(struct kqid left, struct kqid right) | ||
37 | { | ||
38 | if (left.type < right.type) | ||
39 | return true; | ||
40 | if (left.type > right.type) | ||
41 | return false; | ||
42 | switch (left.type) { | ||
43 | case USRQUOTA: | ||
44 | return uid_lt(left.uid, right.uid); | ||
45 | case GRPQUOTA: | ||
46 | return gid_lt(left.gid, right.gid); | ||
47 | case PRJQUOTA: | ||
48 | return projid_lt(left.projid, right.projid); | ||
49 | default: | ||
50 | BUG(); | ||
51 | } | ||
52 | } | ||
53 | EXPORT_SYMBOL(qid_lt); | ||
54 | |||
55 | /** | ||
56 | * from_kqid - Create a qid from a kqid user-namespace pair. | ||
57 | * @targ: The user namespace we want a qid in. | ||
58 | * @kuid: The kernel internal quota identifier to start with. | ||
59 | * | ||
60 | * Map @kqid into the user-namespace specified by @targ and | ||
61 | * return the resulting qid. | ||
62 | * | ||
63 | * There is always a mapping into the initial user_namespace. | ||
64 | * | ||
65 | * If @kqid has no mapping in @targ (qid_t)-1 is returned. | ||
66 | */ | ||
67 | qid_t from_kqid(struct user_namespace *targ, struct kqid kqid) | ||
68 | { | ||
69 | switch (kqid.type) { | ||
70 | case USRQUOTA: | ||
71 | return from_kuid(targ, kqid.uid); | ||
72 | case GRPQUOTA: | ||
73 | return from_kgid(targ, kqid.gid); | ||
74 | case PRJQUOTA: | ||
75 | return from_kprojid(targ, kqid.projid); | ||
76 | default: | ||
77 | BUG(); | ||
78 | } | ||
79 | } | ||
80 | EXPORT_SYMBOL(from_kqid); | ||
81 | |||
82 | /** | ||
83 | * from_kqid_munged - Create a qid from a kqid user-namespace pair. | ||
84 | * @targ: The user namespace we want a qid in. | ||
85 | * @kqid: The kernel internal quota identifier to start with. | ||
86 | * | ||
87 | * Map @kqid into the user-namespace specified by @targ and | ||
88 | * return the resulting qid. | ||
89 | * | ||
90 | * There is always a mapping into the initial user_namespace. | ||
91 | * | ||
92 | * Unlike from_kqid from_kqid_munged never fails and always | ||
93 | * returns a valid projid. This makes from_kqid_munged | ||
94 | * appropriate for use in places where failing to provide | ||
95 | * a qid_t is not a good option. | ||
96 | * | ||
97 | * If @kqid has no mapping in @targ the kqid.type specific | ||
98 | * overflow identifier is returned. | ||
99 | */ | ||
100 | qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid) | ||
101 | { | ||
102 | switch (kqid.type) { | ||
103 | case USRQUOTA: | ||
104 | return from_kuid_munged(targ, kqid.uid); | ||
105 | case GRPQUOTA: | ||
106 | return from_kgid_munged(targ, kqid.gid); | ||
107 | case PRJQUOTA: | ||
108 | return from_kprojid_munged(targ, kqid.projid); | ||
109 | default: | ||
110 | BUG(); | ||
111 | } | ||
112 | } | ||
113 | EXPORT_SYMBOL(from_kqid_munged); | ||
114 | |||
115 | /** | ||
116 | * qid_valid - Report if a valid value is stored in a kqid. | ||
117 | * @qid: The kernel internal quota identifier to test. | ||
118 | */ | ||
119 | bool qid_valid(struct kqid qid) | ||
120 | { | ||
121 | switch (qid.type) { | ||
122 | case USRQUOTA: | ||
123 | return uid_valid(qid.uid); | ||
124 | case GRPQUOTA: | ||
125 | return gid_valid(qid.gid); | ||
126 | case PRJQUOTA: | ||
127 | return projid_valid(qid.projid); | ||
128 | default: | ||
129 | BUG(); | ||
130 | } | ||
131 | } | ||
132 | EXPORT_SYMBOL(qid_valid); | ||
diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c index d67908b407d9..16e8abb7709b 100644 --- a/fs/quota/netlink.c +++ b/fs/quota/netlink.c | |||
@@ -30,7 +30,7 @@ static struct genl_family quota_genl_family = { | |||
30 | * | 30 | * |
31 | */ | 31 | */ |
32 | 32 | ||
33 | void quota_send_warning(short type, unsigned int id, dev_t dev, | 33 | void quota_send_warning(struct kqid qid, dev_t dev, |
34 | const char warntype) | 34 | const char warntype) |
35 | { | 35 | { |
36 | static atomic_t seq; | 36 | static atomic_t seq; |
@@ -56,10 +56,11 @@ void quota_send_warning(short type, unsigned int id, dev_t dev, | |||
56 | "VFS: Cannot store netlink header in quota warning.\n"); | 56 | "VFS: Cannot store netlink header in quota warning.\n"); |
57 | goto err_out; | 57 | goto err_out; |
58 | } | 58 | } |
59 | ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, type); | 59 | ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, qid.type); |
60 | if (ret) | 60 | if (ret) |
61 | goto attr_err_out; | 61 | goto attr_err_out; |
62 | ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, id); | 62 | ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, |
63 | from_kqid_munged(&init_user_ns, qid)); | ||
63 | if (ret) | 64 | if (ret) |
64 | goto attr_err_out; | 65 | goto attr_err_out; |
65 | ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype); | 66 | ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype); |
@@ -71,7 +72,8 @@ void quota_send_warning(short type, unsigned int id, dev_t dev, | |||
71 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev)); | 72 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev)); |
72 | if (ret) | 73 | if (ret) |
73 | goto attr_err_out; | 74 | goto attr_err_out; |
74 | ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid()); | 75 | ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, |
76 | from_kuid_munged(&init_user_ns, current_uid())); | ||
75 | if (ret) | 77 | if (ret) |
76 | goto attr_err_out; | 78 | goto attr_err_out; |
77 | genlmsg_end(skb, msg_head); | 79 | genlmsg_end(skb, msg_head); |
diff --git a/fs/quota/quota.c b/fs/quota/quota.c index 6f155788cbc6..ff0135d6bc51 100644 --- a/fs/quota/quota.c +++ b/fs/quota/quota.c | |||
@@ -32,8 +32,8 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd, | |||
32 | /* allow to query information for dquots we "own" */ | 32 | /* allow to query information for dquots we "own" */ |
33 | case Q_GETQUOTA: | 33 | case Q_GETQUOTA: |
34 | case Q_XGETQUOTA: | 34 | case Q_XGETQUOTA: |
35 | if ((type == USRQUOTA && current_euid() == id) || | 35 | if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) || |
36 | (type == GRPQUOTA && in_egroup_p(id))) | 36 | (type == GRPQUOTA && in_egroup_p(make_kgid(current_user_ns(), id)))) |
37 | break; | 37 | break; |
38 | /*FALLTHROUGH*/ | 38 | /*FALLTHROUGH*/ |
39 | default: | 39 | default: |
@@ -130,13 +130,17 @@ static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src) | |||
130 | static int quota_getquota(struct super_block *sb, int type, qid_t id, | 130 | static int quota_getquota(struct super_block *sb, int type, qid_t id, |
131 | void __user *addr) | 131 | void __user *addr) |
132 | { | 132 | { |
133 | struct kqid qid; | ||
133 | struct fs_disk_quota fdq; | 134 | struct fs_disk_quota fdq; |
134 | struct if_dqblk idq; | 135 | struct if_dqblk idq; |
135 | int ret; | 136 | int ret; |
136 | 137 | ||
137 | if (!sb->s_qcop->get_dqblk) | 138 | if (!sb->s_qcop->get_dqblk) |
138 | return -ENOSYS; | 139 | return -ENOSYS; |
139 | ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq); | 140 | qid = make_kqid(current_user_ns(), type, id); |
141 | if (!qid_valid(qid)) | ||
142 | return -EINVAL; | ||
143 | ret = sb->s_qcop->get_dqblk(sb, qid, &fdq); | ||
140 | if (ret) | 144 | if (ret) |
141 | return ret; | 145 | return ret; |
142 | copy_to_if_dqblk(&idq, &fdq); | 146 | copy_to_if_dqblk(&idq, &fdq); |
@@ -176,13 +180,17 @@ static int quota_setquota(struct super_block *sb, int type, qid_t id, | |||
176 | { | 180 | { |
177 | struct fs_disk_quota fdq; | 181 | struct fs_disk_quota fdq; |
178 | struct if_dqblk idq; | 182 | struct if_dqblk idq; |
183 | struct kqid qid; | ||
179 | 184 | ||
180 | if (copy_from_user(&idq, addr, sizeof(idq))) | 185 | if (copy_from_user(&idq, addr, sizeof(idq))) |
181 | return -EFAULT; | 186 | return -EFAULT; |
182 | if (!sb->s_qcop->set_dqblk) | 187 | if (!sb->s_qcop->set_dqblk) |
183 | return -ENOSYS; | 188 | return -ENOSYS; |
189 | qid = make_kqid(current_user_ns(), type, id); | ||
190 | if (!qid_valid(qid)) | ||
191 | return -EINVAL; | ||
184 | copy_from_if_dqblk(&fdq, &idq); | 192 | copy_from_if_dqblk(&fdq, &idq); |
185 | return sb->s_qcop->set_dqblk(sb, type, id, &fdq); | 193 | return sb->s_qcop->set_dqblk(sb, qid, &fdq); |
186 | } | 194 | } |
187 | 195 | ||
188 | static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr) | 196 | static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr) |
@@ -213,23 +221,31 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id, | |||
213 | void __user *addr) | 221 | void __user *addr) |
214 | { | 222 | { |
215 | struct fs_disk_quota fdq; | 223 | struct fs_disk_quota fdq; |
224 | struct kqid qid; | ||
216 | 225 | ||
217 | if (copy_from_user(&fdq, addr, sizeof(fdq))) | 226 | if (copy_from_user(&fdq, addr, sizeof(fdq))) |
218 | return -EFAULT; | 227 | return -EFAULT; |
219 | if (!sb->s_qcop->set_dqblk) | 228 | if (!sb->s_qcop->set_dqblk) |
220 | return -ENOSYS; | 229 | return -ENOSYS; |
221 | return sb->s_qcop->set_dqblk(sb, type, id, &fdq); | 230 | qid = make_kqid(current_user_ns(), type, id); |
231 | if (!qid_valid(qid)) | ||
232 | return -EINVAL; | ||
233 | return sb->s_qcop->set_dqblk(sb, qid, &fdq); | ||
222 | } | 234 | } |
223 | 235 | ||
224 | static int quota_getxquota(struct super_block *sb, int type, qid_t id, | 236 | static int quota_getxquota(struct super_block *sb, int type, qid_t id, |
225 | void __user *addr) | 237 | void __user *addr) |
226 | { | 238 | { |
227 | struct fs_disk_quota fdq; | 239 | struct fs_disk_quota fdq; |
240 | struct kqid qid; | ||
228 | int ret; | 241 | int ret; |
229 | 242 | ||
230 | if (!sb->s_qcop->get_dqblk) | 243 | if (!sb->s_qcop->get_dqblk) |
231 | return -ENOSYS; | 244 | return -ENOSYS; |
232 | ret = sb->s_qcop->get_dqblk(sb, type, id, &fdq); | 245 | qid = make_kqid(current_user_ns(), type, id); |
246 | if (!qid_valid(qid)) | ||
247 | return -EINVAL; | ||
248 | ret = sb->s_qcop->get_dqblk(sb, qid, &fdq); | ||
233 | if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) | 249 | if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) |
234 | return -EFAULT; | 250 | return -EFAULT; |
235 | return ret; | 251 | return ret; |
diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c index e41c1becf096..d65877fbe8f4 100644 --- a/fs/quota/quota_tree.c +++ b/fs/quota/quota_tree.c | |||
@@ -22,9 +22,10 @@ MODULE_LICENSE("GPL"); | |||
22 | 22 | ||
23 | #define __QUOTA_QT_PARANOIA | 23 | #define __QUOTA_QT_PARANOIA |
24 | 24 | ||
25 | static int get_index(struct qtree_mem_dqinfo *info, qid_t id, int depth) | 25 | static int get_index(struct qtree_mem_dqinfo *info, struct kqid qid, int depth) |
26 | { | 26 | { |
27 | unsigned int epb = info->dqi_usable_bs >> 2; | 27 | unsigned int epb = info->dqi_usable_bs >> 2; |
28 | qid_t id = from_kqid(&init_user_ns, qid); | ||
28 | 29 | ||
29 | depth = info->dqi_qtree_depth - depth - 1; | 30 | depth = info->dqi_qtree_depth - depth - 1; |
30 | while (depth--) | 31 | while (depth--) |
@@ -244,7 +245,7 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info, | |||
244 | /* This is enough as the block is already zeroed and the entry | 245 | /* This is enough as the block is already zeroed and the entry |
245 | * list is empty... */ | 246 | * list is empty... */ |
246 | info->dqi_free_entry = blk; | 247 | info->dqi_free_entry = blk; |
247 | mark_info_dirty(dquot->dq_sb, dquot->dq_type); | 248 | mark_info_dirty(dquot->dq_sb, dquot->dq_id.type); |
248 | } | 249 | } |
249 | /* Block will be full? */ | 250 | /* Block will be full? */ |
250 | if (le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) { | 251 | if (le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) { |
@@ -357,7 +358,7 @@ static inline int dq_insert_tree(struct qtree_mem_dqinfo *info, | |||
357 | */ | 358 | */ |
358 | int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) | 359 | int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) |
359 | { | 360 | { |
360 | int type = dquot->dq_type; | 361 | int type = dquot->dq_id.type; |
361 | struct super_block *sb = dquot->dq_sb; | 362 | struct super_block *sb = dquot->dq_sb; |
362 | ssize_t ret; | 363 | ssize_t ret; |
363 | char *ddquot = getdqbuf(info->dqi_entry_size); | 364 | char *ddquot = getdqbuf(info->dqi_entry_size); |
@@ -538,8 +539,9 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info, | |||
538 | ddquot += info->dqi_entry_size; | 539 | ddquot += info->dqi_entry_size; |
539 | } | 540 | } |
540 | if (i == qtree_dqstr_in_blk(info)) { | 541 | if (i == qtree_dqstr_in_blk(info)) { |
541 | quota_error(dquot->dq_sb, "Quota for id %u referenced " | 542 | quota_error(dquot->dq_sb, |
542 | "but not present", dquot->dq_id); | 543 | "Quota for id %u referenced but not present", |
544 | from_kqid(&init_user_ns, dquot->dq_id)); | ||
543 | ret = -EIO; | 545 | ret = -EIO; |
544 | goto out_buf; | 546 | goto out_buf; |
545 | } else { | 547 | } else { |
@@ -589,7 +591,7 @@ static inline loff_t find_dqentry(struct qtree_mem_dqinfo *info, | |||
589 | 591 | ||
590 | int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) | 592 | int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) |
591 | { | 593 | { |
592 | int type = dquot->dq_type; | 594 | int type = dquot->dq_id.type; |
593 | struct super_block *sb = dquot->dq_sb; | 595 | struct super_block *sb = dquot->dq_sb; |
594 | loff_t offset; | 596 | loff_t offset; |
595 | char *ddquot; | 597 | char *ddquot; |
@@ -607,8 +609,10 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) | |||
607 | offset = find_dqentry(info, dquot); | 609 | offset = find_dqentry(info, dquot); |
608 | if (offset <= 0) { /* Entry not present? */ | 610 | if (offset <= 0) { /* Entry not present? */ |
609 | if (offset < 0) | 611 | if (offset < 0) |
610 | quota_error(sb, "Can't read quota structure " | 612 | quota_error(sb,"Can't read quota structure " |
611 | "for id %u", dquot->dq_id); | 613 | "for id %u", |
614 | from_kqid(&init_user_ns, | ||
615 | dquot->dq_id)); | ||
612 | dquot->dq_off = 0; | 616 | dquot->dq_off = 0; |
613 | set_bit(DQ_FAKE_B, &dquot->dq_flags); | 617 | set_bit(DQ_FAKE_B, &dquot->dq_flags); |
614 | memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); | 618 | memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); |
@@ -626,7 +630,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) | |||
626 | if (ret >= 0) | 630 | if (ret >= 0) |
627 | ret = -EIO; | 631 | ret = -EIO; |
628 | quota_error(sb, "Error while reading quota structure for id %u", | 632 | quota_error(sb, "Error while reading quota structure for id %u", |
629 | dquot->dq_id); | 633 | from_kqid(&init_user_ns, dquot->dq_id)); |
630 | set_bit(DQ_FAKE_B, &dquot->dq_flags); | 634 | set_bit(DQ_FAKE_B, &dquot->dq_flags); |
631 | memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); | 635 | memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); |
632 | kfree(ddquot); | 636 | kfree(ddquot); |
diff --git a/fs/quota/quota_v1.c b/fs/quota/quota_v1.c index 34b37a67bb16..469c6848b322 100644 --- a/fs/quota/quota_v1.c +++ b/fs/quota/quota_v1.c | |||
@@ -54,7 +54,7 @@ static void v1_mem2disk_dqblk(struct v1_disk_dqblk *d, struct mem_dqblk *m) | |||
54 | 54 | ||
55 | static int v1_read_dqblk(struct dquot *dquot) | 55 | static int v1_read_dqblk(struct dquot *dquot) |
56 | { | 56 | { |
57 | int type = dquot->dq_type; | 57 | int type = dquot->dq_id.type; |
58 | struct v1_disk_dqblk dqblk; | 58 | struct v1_disk_dqblk dqblk; |
59 | 59 | ||
60 | if (!sb_dqopt(dquot->dq_sb)->files[type]) | 60 | if (!sb_dqopt(dquot->dq_sb)->files[type]) |
@@ -63,7 +63,8 @@ static int v1_read_dqblk(struct dquot *dquot) | |||
63 | /* Set structure to 0s in case read fails/is after end of file */ | 63 | /* Set structure to 0s in case read fails/is after end of file */ |
64 | memset(&dqblk, 0, sizeof(struct v1_disk_dqblk)); | 64 | memset(&dqblk, 0, sizeof(struct v1_disk_dqblk)); |
65 | dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk, | 65 | dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk, |
66 | sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id)); | 66 | sizeof(struct v1_disk_dqblk), |
67 | v1_dqoff(from_kqid(&init_user_ns, dquot->dq_id))); | ||
67 | 68 | ||
68 | v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk); | 69 | v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk); |
69 | if (dquot->dq_dqb.dqb_bhardlimit == 0 && | 70 | if (dquot->dq_dqb.dqb_bhardlimit == 0 && |
@@ -78,12 +79,13 @@ static int v1_read_dqblk(struct dquot *dquot) | |||
78 | 79 | ||
79 | static int v1_commit_dqblk(struct dquot *dquot) | 80 | static int v1_commit_dqblk(struct dquot *dquot) |
80 | { | 81 | { |
81 | short type = dquot->dq_type; | 82 | short type = dquot->dq_id.type; |
82 | ssize_t ret; | 83 | ssize_t ret; |
83 | struct v1_disk_dqblk dqblk; | 84 | struct v1_disk_dqblk dqblk; |
84 | 85 | ||
85 | v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb); | 86 | v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb); |
86 | if (dquot->dq_id == 0) { | 87 | if (((type == USRQUOTA) && uid_eq(dquot->dq_id.uid, GLOBAL_ROOT_UID)) || |
88 | ((type == GRPQUOTA) && gid_eq(dquot->dq_id.gid, GLOBAL_ROOT_GID))) { | ||
87 | dqblk.dqb_btime = | 89 | dqblk.dqb_btime = |
88 | sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace; | 90 | sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace; |
89 | dqblk.dqb_itime = | 91 | dqblk.dqb_itime = |
@@ -93,7 +95,7 @@ static int v1_commit_dqblk(struct dquot *dquot) | |||
93 | if (sb_dqopt(dquot->dq_sb)->files[type]) | 95 | if (sb_dqopt(dquot->dq_sb)->files[type]) |
94 | ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, | 96 | ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, |
95 | (char *)&dqblk, sizeof(struct v1_disk_dqblk), | 97 | (char *)&dqblk, sizeof(struct v1_disk_dqblk), |
96 | v1_dqoff(dquot->dq_id)); | 98 | v1_dqoff(from_kqid(&init_user_ns, dquot->dq_id))); |
97 | if (ret != sizeof(struct v1_disk_dqblk)) { | 99 | if (ret != sizeof(struct v1_disk_dqblk)) { |
98 | quota_error(dquot->dq_sb, "dquota write failed"); | 100 | quota_error(dquot->dq_sb, "dquota write failed"); |
99 | if (ret >= 0) | 101 | if (ret >= 0) |
diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c index f1ab3604db5a..02751ec695c5 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c | |||
@@ -196,7 +196,7 @@ static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot) | |||
196 | struct v2r0_disk_dqblk *d = dp; | 196 | struct v2r0_disk_dqblk *d = dp; |
197 | struct mem_dqblk *m = &dquot->dq_dqb; | 197 | struct mem_dqblk *m = &dquot->dq_dqb; |
198 | struct qtree_mem_dqinfo *info = | 198 | struct qtree_mem_dqinfo *info = |
199 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 199 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
200 | 200 | ||
201 | d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit); | 201 | d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit); |
202 | d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit); | 202 | d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit); |
@@ -206,7 +206,7 @@ static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot) | |||
206 | d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit)); | 206 | d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit)); |
207 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); | 207 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); |
208 | d->dqb_btime = cpu_to_le64(m->dqb_btime); | 208 | d->dqb_btime = cpu_to_le64(m->dqb_btime); |
209 | d->dqb_id = cpu_to_le32(dquot->dq_id); | 209 | d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id)); |
210 | if (qtree_entry_unused(info, dp)) | 210 | if (qtree_entry_unused(info, dp)) |
211 | d->dqb_itime = cpu_to_le64(1); | 211 | d->dqb_itime = cpu_to_le64(1); |
212 | } | 212 | } |
@@ -215,11 +215,13 @@ static int v2r0_is_id(void *dp, struct dquot *dquot) | |||
215 | { | 215 | { |
216 | struct v2r0_disk_dqblk *d = dp; | 216 | struct v2r0_disk_dqblk *d = dp; |
217 | struct qtree_mem_dqinfo *info = | 217 | struct qtree_mem_dqinfo *info = |
218 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 218 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
219 | 219 | ||
220 | if (qtree_entry_unused(info, dp)) | 220 | if (qtree_entry_unused(info, dp)) |
221 | return 0; | 221 | return 0; |
222 | return le32_to_cpu(d->dqb_id) == dquot->dq_id; | 222 | return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type, |
223 | le32_to_cpu(d->dqb_id)), | ||
224 | dquot->dq_id); | ||
223 | } | 225 | } |
224 | 226 | ||
225 | static void v2r1_disk2memdqb(struct dquot *dquot, void *dp) | 227 | static void v2r1_disk2memdqb(struct dquot *dquot, void *dp) |
@@ -247,7 +249,7 @@ static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot) | |||
247 | struct v2r1_disk_dqblk *d = dp; | 249 | struct v2r1_disk_dqblk *d = dp; |
248 | struct mem_dqblk *m = &dquot->dq_dqb; | 250 | struct mem_dqblk *m = &dquot->dq_dqb; |
249 | struct qtree_mem_dqinfo *info = | 251 | struct qtree_mem_dqinfo *info = |
250 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 252 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
251 | 253 | ||
252 | d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit); | 254 | d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit); |
253 | d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit); | 255 | d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit); |
@@ -257,7 +259,7 @@ static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot) | |||
257 | d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit)); | 259 | d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit)); |
258 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); | 260 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); |
259 | d->dqb_btime = cpu_to_le64(m->dqb_btime); | 261 | d->dqb_btime = cpu_to_le64(m->dqb_btime); |
260 | d->dqb_id = cpu_to_le32(dquot->dq_id); | 262 | d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id)); |
261 | if (qtree_entry_unused(info, dp)) | 263 | if (qtree_entry_unused(info, dp)) |
262 | d->dqb_itime = cpu_to_le64(1); | 264 | d->dqb_itime = cpu_to_le64(1); |
263 | } | 265 | } |
@@ -266,26 +268,28 @@ static int v2r1_is_id(void *dp, struct dquot *dquot) | |||
266 | { | 268 | { |
267 | struct v2r1_disk_dqblk *d = dp; | 269 | struct v2r1_disk_dqblk *d = dp; |
268 | struct qtree_mem_dqinfo *info = | 270 | struct qtree_mem_dqinfo *info = |
269 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 271 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
270 | 272 | ||
271 | if (qtree_entry_unused(info, dp)) | 273 | if (qtree_entry_unused(info, dp)) |
272 | return 0; | 274 | return 0; |
273 | return le32_to_cpu(d->dqb_id) == dquot->dq_id; | 275 | return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type, |
276 | le32_to_cpu(d->dqb_id)), | ||
277 | dquot->dq_id); | ||
274 | } | 278 | } |
275 | 279 | ||
276 | static int v2_read_dquot(struct dquot *dquot) | 280 | static int v2_read_dquot(struct dquot *dquot) |
277 | { | 281 | { |
278 | return qtree_read_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv, dquot); | 282 | return qtree_read_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
279 | } | 283 | } |
280 | 284 | ||
281 | static int v2_write_dquot(struct dquot *dquot) | 285 | static int v2_write_dquot(struct dquot *dquot) |
282 | { | 286 | { |
283 | return qtree_write_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv, dquot); | 287 | return qtree_write_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
284 | } | 288 | } |
285 | 289 | ||
286 | static int v2_release_dquot(struct dquot *dquot) | 290 | static int v2_release_dquot(struct dquot *dquot) |
287 | { | 291 | { |
288 | return qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv, dquot); | 292 | return qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
289 | } | 293 | } |
290 | 294 | ||
291 | static int v2_free_file_info(struct super_block *sb, int type) | 295 | static int v2_free_file_info(struct super_block *sb, int type) |
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index 855da58db145..46485557cdc6 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c | |||
@@ -1155,8 +1155,8 @@ static void init_inode(struct inode *inode, struct treepath *path) | |||
1155 | set_inode_sd_version(inode, STAT_DATA_V1); | 1155 | set_inode_sd_version(inode, STAT_DATA_V1); |
1156 | inode->i_mode = sd_v1_mode(sd); | 1156 | inode->i_mode = sd_v1_mode(sd); |
1157 | set_nlink(inode, sd_v1_nlink(sd)); | 1157 | set_nlink(inode, sd_v1_nlink(sd)); |
1158 | inode->i_uid = sd_v1_uid(sd); | 1158 | i_uid_write(inode, sd_v1_uid(sd)); |
1159 | inode->i_gid = sd_v1_gid(sd); | 1159 | i_gid_write(inode, sd_v1_gid(sd)); |
1160 | inode->i_size = sd_v1_size(sd); | 1160 | inode->i_size = sd_v1_size(sd); |
1161 | inode->i_atime.tv_sec = sd_v1_atime(sd); | 1161 | inode->i_atime.tv_sec = sd_v1_atime(sd); |
1162 | inode->i_mtime.tv_sec = sd_v1_mtime(sd); | 1162 | inode->i_mtime.tv_sec = sd_v1_mtime(sd); |
@@ -1200,9 +1200,9 @@ static void init_inode(struct inode *inode, struct treepath *path) | |||
1200 | 1200 | ||
1201 | inode->i_mode = sd_v2_mode(sd); | 1201 | inode->i_mode = sd_v2_mode(sd); |
1202 | set_nlink(inode, sd_v2_nlink(sd)); | 1202 | set_nlink(inode, sd_v2_nlink(sd)); |
1203 | inode->i_uid = sd_v2_uid(sd); | 1203 | i_uid_write(inode, sd_v2_uid(sd)); |
1204 | inode->i_size = sd_v2_size(sd); | 1204 | inode->i_size = sd_v2_size(sd); |
1205 | inode->i_gid = sd_v2_gid(sd); | 1205 | i_gid_write(inode, sd_v2_gid(sd)); |
1206 | inode->i_mtime.tv_sec = sd_v2_mtime(sd); | 1206 | inode->i_mtime.tv_sec = sd_v2_mtime(sd); |
1207 | inode->i_atime.tv_sec = sd_v2_atime(sd); | 1207 | inode->i_atime.tv_sec = sd_v2_atime(sd); |
1208 | inode->i_ctime.tv_sec = sd_v2_ctime(sd); | 1208 | inode->i_ctime.tv_sec = sd_v2_ctime(sd); |
@@ -1258,9 +1258,9 @@ static void inode2sd(void *sd, struct inode *inode, loff_t size) | |||
1258 | 1258 | ||
1259 | set_sd_v2_mode(sd_v2, inode->i_mode); | 1259 | set_sd_v2_mode(sd_v2, inode->i_mode); |
1260 | set_sd_v2_nlink(sd_v2, inode->i_nlink); | 1260 | set_sd_v2_nlink(sd_v2, inode->i_nlink); |
1261 | set_sd_v2_uid(sd_v2, inode->i_uid); | 1261 | set_sd_v2_uid(sd_v2, i_uid_read(inode)); |
1262 | set_sd_v2_size(sd_v2, size); | 1262 | set_sd_v2_size(sd_v2, size); |
1263 | set_sd_v2_gid(sd_v2, inode->i_gid); | 1263 | set_sd_v2_gid(sd_v2, i_gid_read(inode)); |
1264 | set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec); | 1264 | set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec); |
1265 | set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec); | 1265 | set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec); |
1266 | set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec); | 1266 | set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec); |
@@ -1280,8 +1280,8 @@ static void inode2sd_v1(void *sd, struct inode *inode, loff_t size) | |||
1280 | struct stat_data_v1 *sd_v1 = (struct stat_data_v1 *)sd; | 1280 | struct stat_data_v1 *sd_v1 = (struct stat_data_v1 *)sd; |
1281 | 1281 | ||
1282 | set_sd_v1_mode(sd_v1, inode->i_mode); | 1282 | set_sd_v1_mode(sd_v1, inode->i_mode); |
1283 | set_sd_v1_uid(sd_v1, inode->i_uid); | 1283 | set_sd_v1_uid(sd_v1, i_uid_read(inode)); |
1284 | set_sd_v1_gid(sd_v1, inode->i_gid); | 1284 | set_sd_v1_gid(sd_v1, i_gid_read(inode)); |
1285 | set_sd_v1_nlink(sd_v1, inode->i_nlink); | 1285 | set_sd_v1_nlink(sd_v1, inode->i_nlink); |
1286 | set_sd_v1_size(sd_v1, size); | 1286 | set_sd_v1_size(sd_v1, size); |
1287 | set_sd_v1_atime(sd_v1, inode->i_atime.tv_sec); | 1287 | set_sd_v1_atime(sd_v1, inode->i_atime.tv_sec); |
@@ -1869,7 +1869,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th, | |||
1869 | goto out_bad_inode; | 1869 | goto out_bad_inode; |
1870 | } | 1870 | } |
1871 | if (old_format_only(sb)) { | 1871 | if (old_format_only(sb)) { |
1872 | if (inode->i_uid & ~0xffff || inode->i_gid & ~0xffff) { | 1872 | if (i_uid_read(inode) & ~0xffff || i_gid_read(inode) & ~0xffff) { |
1873 | pathrelse(&path_to_key); | 1873 | pathrelse(&path_to_key); |
1874 | /* i_uid or i_gid is too big to be stored in stat data v3.5 */ | 1874 | /* i_uid or i_gid is too big to be stored in stat data v3.5 */ |
1875 | err = -EINVAL; | 1875 | err = -EINVAL; |
@@ -3140,16 +3140,16 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3140 | } | 3140 | } |
3141 | } | 3141 | } |
3142 | 3142 | ||
3143 | if ((((attr->ia_valid & ATTR_UID) && (attr->ia_uid & ~0xffff)) || | 3143 | if ((((attr->ia_valid & ATTR_UID) && (from_kuid(&init_user_ns, attr->ia_uid) & ~0xffff)) || |
3144 | ((attr->ia_valid & ATTR_GID) && (attr->ia_gid & ~0xffff))) && | 3144 | ((attr->ia_valid & ATTR_GID) && (from_kgid(&init_user_ns, attr->ia_gid) & ~0xffff))) && |
3145 | (get_inode_sd_version(inode) == STAT_DATA_V1)) { | 3145 | (get_inode_sd_version(inode) == STAT_DATA_V1)) { |
3146 | /* stat data of format v3.5 has 16 bit uid and gid */ | 3146 | /* stat data of format v3.5 has 16 bit uid and gid */ |
3147 | error = -EINVAL; | 3147 | error = -EINVAL; |
3148 | goto out; | 3148 | goto out; |
3149 | } | 3149 | } |
3150 | 3150 | ||
3151 | if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || | 3151 | if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) || |
3152 | (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) { | 3152 | (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) { |
3153 | struct reiserfs_transaction_handle th; | 3153 | struct reiserfs_transaction_handle th; |
3154 | int jbegin_count = | 3154 | int jbegin_count = |
3155 | 2 * | 3155 | 2 * |
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c index 44474f9b990d..d7c01ef64eda 100644 --- a/fs/reiserfs/xattr_acl.c +++ b/fs/reiserfs/xattr_acl.c | |||
@@ -30,7 +30,7 @@ posix_acl_set(struct dentry *dentry, const char *name, const void *value, | |||
30 | return -EPERM; | 30 | return -EPERM; |
31 | 31 | ||
32 | if (value) { | 32 | if (value) { |
33 | acl = posix_acl_from_xattr(value, size); | 33 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
34 | if (IS_ERR(acl)) { | 34 | if (IS_ERR(acl)) { |
35 | return PTR_ERR(acl); | 35 | return PTR_ERR(acl); |
36 | } else if (acl) { | 36 | } else if (acl) { |
@@ -77,7 +77,7 @@ posix_acl_get(struct dentry *dentry, const char *name, void *buffer, | |||
77 | return PTR_ERR(acl); | 77 | return PTR_ERR(acl); |
78 | if (acl == NULL) | 78 | if (acl == NULL) |
79 | return -ENODATA; | 79 | return -ENODATA; |
80 | error = posix_acl_to_xattr(acl, buffer, size); | 80 | error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
81 | posix_acl_release(acl); | 81 | posix_acl_release(acl); |
82 | 82 | ||
83 | return error; | 83 | return error; |
@@ -121,15 +121,23 @@ static struct posix_acl *posix_acl_from_disk(const void *value, size_t size) | |||
121 | case ACL_OTHER: | 121 | case ACL_OTHER: |
122 | value = (char *)value + | 122 | value = (char *)value + |
123 | sizeof(reiserfs_acl_entry_short); | 123 | sizeof(reiserfs_acl_entry_short); |
124 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; | ||
125 | break; | 124 | break; |
126 | 125 | ||
127 | case ACL_USER: | 126 | case ACL_USER: |
127 | value = (char *)value + sizeof(reiserfs_acl_entry); | ||
128 | if ((char *)value > end) | ||
129 | goto fail; | ||
130 | acl->a_entries[n].e_uid = | ||
131 | make_kuid(&init_user_ns, | ||
132 | le32_to_cpu(entry->e_id)); | ||
133 | break; | ||
128 | case ACL_GROUP: | 134 | case ACL_GROUP: |
129 | value = (char *)value + sizeof(reiserfs_acl_entry); | 135 | value = (char *)value + sizeof(reiserfs_acl_entry); |
130 | if ((char *)value > end) | 136 | if ((char *)value > end) |
131 | goto fail; | 137 | goto fail; |
132 | acl->a_entries[n].e_id = le32_to_cpu(entry->e_id); | 138 | acl->a_entries[n].e_gid = |
139 | make_kgid(&init_user_ns, | ||
140 | le32_to_cpu(entry->e_id)); | ||
133 | break; | 141 | break; |
134 | 142 | ||
135 | default: | 143 | default: |
@@ -164,13 +172,19 @@ static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size) | |||
164 | ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION); | 172 | ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION); |
165 | e = (char *)ext_acl + sizeof(reiserfs_acl_header); | 173 | e = (char *)ext_acl + sizeof(reiserfs_acl_header); |
166 | for (n = 0; n < acl->a_count; n++) { | 174 | for (n = 0; n < acl->a_count; n++) { |
175 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; | ||
167 | reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e; | 176 | reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e; |
168 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 177 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); |
169 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 178 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); |
170 | switch (acl->a_entries[n].e_tag) { | 179 | switch (acl->a_entries[n].e_tag) { |
171 | case ACL_USER: | 180 | case ACL_USER: |
181 | entry->e_id = cpu_to_le32( | ||
182 | from_kuid(&init_user_ns, acl_e->e_uid)); | ||
183 | e += sizeof(reiserfs_acl_entry); | ||
184 | break; | ||
172 | case ACL_GROUP: | 185 | case ACL_GROUP: |
173 | entry->e_id = cpu_to_le32(acl->a_entries[n].e_id); | 186 | entry->e_id = cpu_to_le32( |
187 | from_kgid(&init_user_ns, acl_e->e_gid)); | ||
174 | e += sizeof(reiserfs_acl_entry); | 188 | e += sizeof(reiserfs_acl_entry); |
175 | break; | 189 | break; |
176 | 190 | ||
diff --git a/fs/seq_file.c b/fs/seq_file.c index 14cf9de1dbe1..99dffab4c4e4 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/export.h> | 9 | #include <linux/export.h> |
10 | #include <linux/seq_file.h> | 10 | #include <linux/seq_file.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/cred.h> | ||
12 | 13 | ||
13 | #include <asm/uaccess.h> | 14 | #include <asm/uaccess.h> |
14 | #include <asm/page.h> | 15 | #include <asm/page.h> |
@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op) | |||
56 | memset(p, 0, sizeof(*p)); | 57 | memset(p, 0, sizeof(*p)); |
57 | mutex_init(&p->lock); | 58 | mutex_init(&p->lock); |
58 | p->op = op; | 59 | p->op = op; |
60 | #ifdef CONFIG_USER_NS | ||
61 | p->user_ns = file->f_cred->user_ns; | ||
62 | #endif | ||
59 | 63 | ||
60 | /* | 64 | /* |
61 | * Wrappers around seq_open(e.g. swaps_open) need to be | 65 | * Wrappers around seq_open(e.g. swaps_open) need to be |
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c index 81afbccfa843..a1ce5ce60632 100644 --- a/fs/squashfs/inode.c +++ b/fs/squashfs/inode.c | |||
@@ -56,16 +56,20 @@ | |||
56 | static int squashfs_new_inode(struct super_block *sb, struct inode *inode, | 56 | static int squashfs_new_inode(struct super_block *sb, struct inode *inode, |
57 | struct squashfs_base_inode *sqsh_ino) | 57 | struct squashfs_base_inode *sqsh_ino) |
58 | { | 58 | { |
59 | uid_t i_uid; | ||
60 | gid_t i_gid; | ||
59 | int err; | 61 | int err; |
60 | 62 | ||
61 | err = squashfs_get_id(sb, le16_to_cpu(sqsh_ino->uid), &inode->i_uid); | 63 | err = squashfs_get_id(sb, le16_to_cpu(sqsh_ino->uid), &i_uid); |
62 | if (err) | 64 | if (err) |
63 | return err; | 65 | return err; |
64 | 66 | ||
65 | err = squashfs_get_id(sb, le16_to_cpu(sqsh_ino->guid), &inode->i_gid); | 67 | err = squashfs_get_id(sb, le16_to_cpu(sqsh_ino->guid), &i_gid); |
66 | if (err) | 68 | if (err) |
67 | return err; | 69 | return err; |
68 | 70 | ||
71 | i_uid_write(inode, i_uid); | ||
72 | i_gid_write(inode, i_gid); | ||
69 | inode->i_ino = le32_to_cpu(sqsh_ino->inode_number); | 73 | inode->i_ino = le32_to_cpu(sqsh_ino->inode_number); |
70 | inode->i_mtime.tv_sec = le32_to_cpu(sqsh_ino->mtime); | 74 | inode->i_mtime.tv_sec = le32_to_cpu(sqsh_ino->mtime); |
71 | inode->i_atime.tv_sec = inode->i_mtime.tv_sec; | 75 | inode->i_atime.tv_sec = inode->i_mtime.tv_sec; |
@@ -326,7 +326,7 @@ SYSCALL_DEFINE3(readlink, const char __user *, path, char __user *, buf, | |||
326 | 326 | ||
327 | 327 | ||
328 | /* ---------- LFS-64 ----------- */ | 328 | /* ---------- LFS-64 ----------- */ |
329 | #ifdef __ARCH_WANT_STAT64 | 329 | #if defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_COMPAT_STAT64) |
330 | 330 | ||
331 | #ifndef INIT_STRUCT_STAT64_PADDING | 331 | #ifndef INIT_STRUCT_STAT64_PADDING |
332 | # define INIT_STRUCT_STAT64_PADDING(st) memset(&st, 0, sizeof(st)) | 332 | # define INIT_STRUCT_STAT64_PADDING(st) memset(&st, 0, sizeof(st)) |
@@ -415,7 +415,7 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename, | |||
415 | return error; | 415 | return error; |
416 | return cp_new_stat64(&stat, statbuf); | 416 | return cp_new_stat64(&stat, statbuf); |
417 | } | 417 | } |
418 | #endif /* __ARCH_WANT_STAT64 */ | 418 | #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ |
419 | 419 | ||
420 | /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ | 420 | /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ |
421 | void __inode_add_bytes(struct inode *inode, loff_t bytes) | 421 | void __inode_add_bytes(struct inode *inode, loff_t bytes) |
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c index a7ac78f8e67a..3c9eb5624f5e 100644 --- a/fs/sysfs/symlink.c +++ b/fs/sysfs/symlink.c | |||
@@ -113,7 +113,7 @@ int sysfs_create_link(struct kobject *kobj, struct kobject *target, | |||
113 | * @target: object we're pointing to. | 113 | * @target: object we're pointing to. |
114 | * @name: name of the symlink. | 114 | * @name: name of the symlink. |
115 | * | 115 | * |
116 | * This function does the same as sysf_create_link(), but it | 116 | * This function does the same as sysfs_create_link(), but it |
117 | * doesn't warn if the link already exists. | 117 | * doesn't warn if the link already exists. |
118 | */ | 118 | */ |
119 | int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, | 119 | int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, |
diff --git a/fs/sysv/inode.c b/fs/sysv/inode.c index 0d0c50bd3321..d33e506c1eac 100644 --- a/fs/sysv/inode.c +++ b/fs/sysv/inode.c | |||
@@ -202,8 +202,8 @@ struct inode *sysv_iget(struct super_block *sb, unsigned int ino) | |||
202 | } | 202 | } |
203 | /* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */ | 203 | /* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */ |
204 | inode->i_mode = fs16_to_cpu(sbi, raw_inode->i_mode); | 204 | inode->i_mode = fs16_to_cpu(sbi, raw_inode->i_mode); |
205 | inode->i_uid = (uid_t)fs16_to_cpu(sbi, raw_inode->i_uid); | 205 | i_uid_write(inode, (uid_t)fs16_to_cpu(sbi, raw_inode->i_uid)); |
206 | inode->i_gid = (gid_t)fs16_to_cpu(sbi, raw_inode->i_gid); | 206 | i_gid_write(inode, (gid_t)fs16_to_cpu(sbi, raw_inode->i_gid)); |
207 | set_nlink(inode, fs16_to_cpu(sbi, raw_inode->i_nlink)); | 207 | set_nlink(inode, fs16_to_cpu(sbi, raw_inode->i_nlink)); |
208 | inode->i_size = fs32_to_cpu(sbi, raw_inode->i_size); | 208 | inode->i_size = fs32_to_cpu(sbi, raw_inode->i_size); |
209 | inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->i_atime); | 209 | inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->i_atime); |
@@ -256,8 +256,8 @@ static int __sysv_write_inode(struct inode *inode, int wait) | |||
256 | } | 256 | } |
257 | 257 | ||
258 | raw_inode->i_mode = cpu_to_fs16(sbi, inode->i_mode); | 258 | raw_inode->i_mode = cpu_to_fs16(sbi, inode->i_mode); |
259 | raw_inode->i_uid = cpu_to_fs16(sbi, fs_high2lowuid(inode->i_uid)); | 259 | raw_inode->i_uid = cpu_to_fs16(sbi, fs_high2lowuid(i_uid_read(inode))); |
260 | raw_inode->i_gid = cpu_to_fs16(sbi, fs_high2lowgid(inode->i_gid)); | 260 | raw_inode->i_gid = cpu_to_fs16(sbi, fs_high2lowgid(i_gid_read(inode))); |
261 | raw_inode->i_nlink = cpu_to_fs16(sbi, inode->i_nlink); | 261 | raw_inode->i_nlink = cpu_to_fs16(sbi, inode->i_nlink); |
262 | raw_inode->i_size = cpu_to_fs32(sbi, inode->i_size); | 262 | raw_inode->i_size = cpu_to_fs32(sbi, inode->i_size); |
263 | raw_inode->i_atime = cpu_to_fs32(sbi, inode->i_atime.tv_sec); | 263 | raw_inode->i_atime = cpu_to_fs32(sbi, inode->i_atime.tv_sec); |
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c index bc4f94b28706..969489e478bc 100644 --- a/fs/ubifs/budget.c +++ b/fs/ubifs/budget.c | |||
@@ -272,8 +272,8 @@ long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs) | |||
272 | */ | 272 | */ |
273 | static int can_use_rp(struct ubifs_info *c) | 273 | static int can_use_rp(struct ubifs_info *c) |
274 | { | 274 | { |
275 | if (current_fsuid() == c->rp_uid || capable(CAP_SYS_RESOURCE) || | 275 | if (uid_eq(current_fsuid(), c->rp_uid) || capable(CAP_SYS_RESOURCE) || |
276 | (c->rp_gid != 0 && in_group_p(c->rp_gid))) | 276 | (!gid_eq(c->rp_gid, GLOBAL_ROOT_GID) && in_group_p(c->rp_gid))) |
277 | return 1; | 277 | return 1; |
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index bb3167257aab..340d1afc1302 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
@@ -243,8 +243,8 @@ void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode) | |||
243 | printk(KERN_ERR "\tsize %llu\n", | 243 | printk(KERN_ERR "\tsize %llu\n", |
244 | (unsigned long long)i_size_read(inode)); | 244 | (unsigned long long)i_size_read(inode)); |
245 | printk(KERN_ERR "\tnlink %u\n", inode->i_nlink); | 245 | printk(KERN_ERR "\tnlink %u\n", inode->i_nlink); |
246 | printk(KERN_ERR "\tuid %u\n", (unsigned int)inode->i_uid); | 246 | printk(KERN_ERR "\tuid %u\n", (unsigned int)i_uid_read(inode)); |
247 | printk(KERN_ERR "\tgid %u\n", (unsigned int)inode->i_gid); | 247 | printk(KERN_ERR "\tgid %u\n", (unsigned int)i_gid_read(inode)); |
248 | printk(KERN_ERR "\tatime %u.%u\n", | 248 | printk(KERN_ERR "\tatime %u.%u\n", |
249 | (unsigned int)inode->i_atime.tv_sec, | 249 | (unsigned int)inode->i_atime.tv_sec, |
250 | (unsigned int)inode->i_atime.tv_nsec); | 250 | (unsigned int)inode->i_atime.tv_nsec); |
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 12c0f154ca83..afaad07f3b29 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -469,8 +469,8 @@ static void pack_inode(struct ubifs_info *c, struct ubifs_ino_node *ino, | |||
469 | ino->ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); | 469 | ino->ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec); |
470 | ino->mtime_sec = cpu_to_le64(inode->i_mtime.tv_sec); | 470 | ino->mtime_sec = cpu_to_le64(inode->i_mtime.tv_sec); |
471 | ino->mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); | 471 | ino->mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); |
472 | ino->uid = cpu_to_le32(inode->i_uid); | 472 | ino->uid = cpu_to_le32(i_uid_read(inode)); |
473 | ino->gid = cpu_to_le32(inode->i_gid); | 473 | ino->gid = cpu_to_le32(i_gid_read(inode)); |
474 | ino->mode = cpu_to_le32(inode->i_mode); | 474 | ino->mode = cpu_to_le32(inode->i_mode); |
475 | ino->flags = cpu_to_le32(ui->flags); | 475 | ino->flags = cpu_to_le32(ui->flags); |
476 | ino->size = cpu_to_le64(ui->ui_size); | 476 | ino->size = cpu_to_le64(ui->ui_size); |
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index 15e2fc5aa60b..52c21f4190f6 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c | |||
@@ -611,8 +611,8 @@ int ubifs_read_superblock(struct ubifs_info *c) | |||
611 | c->fanout = le32_to_cpu(sup->fanout); | 611 | c->fanout = le32_to_cpu(sup->fanout); |
612 | c->lsave_cnt = le32_to_cpu(sup->lsave_cnt); | 612 | c->lsave_cnt = le32_to_cpu(sup->lsave_cnt); |
613 | c->rp_size = le64_to_cpu(sup->rp_size); | 613 | c->rp_size = le64_to_cpu(sup->rp_size); |
614 | c->rp_uid = le32_to_cpu(sup->rp_uid); | 614 | c->rp_uid = make_kuid(&init_user_ns, le32_to_cpu(sup->rp_uid)); |
615 | c->rp_gid = le32_to_cpu(sup->rp_gid); | 615 | c->rp_gid = make_kgid(&init_user_ns, le32_to_cpu(sup->rp_gid)); |
616 | sup_flags = le32_to_cpu(sup->flags); | 616 | sup_flags = le32_to_cpu(sup->flags); |
617 | if (!c->mount_opts.override_compr) | 617 | if (!c->mount_opts.override_compr) |
618 | c->default_compr = le16_to_cpu(sup->default_compr); | 618 | c->default_compr = le16_to_cpu(sup->default_compr); |
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 36e09ca9130b..49825427a0e8 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
@@ -130,8 +130,8 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum) | |||
130 | 130 | ||
131 | inode->i_flags |= (S_NOCMTIME | S_NOATIME); | 131 | inode->i_flags |= (S_NOCMTIME | S_NOATIME); |
132 | set_nlink(inode, le32_to_cpu(ino->nlink)); | 132 | set_nlink(inode, le32_to_cpu(ino->nlink)); |
133 | inode->i_uid = le32_to_cpu(ino->uid); | 133 | i_uid_write(inode, le32_to_cpu(ino->uid)); |
134 | inode->i_gid = le32_to_cpu(ino->gid); | 134 | i_gid_write(inode, le32_to_cpu(ino->gid)); |
135 | inode->i_atime.tv_sec = (int64_t)le64_to_cpu(ino->atime_sec); | 135 | inode->i_atime.tv_sec = (int64_t)le64_to_cpu(ino->atime_sec); |
136 | inode->i_atime.tv_nsec = le32_to_cpu(ino->atime_nsec); | 136 | inode->i_atime.tv_nsec = le32_to_cpu(ino->atime_nsec); |
137 | inode->i_mtime.tv_sec = (int64_t)le64_to_cpu(ino->mtime_sec); | 137 | inode->i_mtime.tv_sec = (int64_t)le64_to_cpu(ino->mtime_sec); |
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 1e5a08623d11..64f2367c2f4c 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -1426,8 +1426,8 @@ struct ubifs_info { | |||
1426 | 1426 | ||
1427 | long long rp_size; | 1427 | long long rp_size; |
1428 | long long report_rp_size; | 1428 | long long report_rp_size; |
1429 | uid_t rp_uid; | 1429 | kuid_t rp_uid; |
1430 | gid_t rp_gid; | 1430 | kgid_t rp_gid; |
1431 | 1431 | ||
1432 | /* The below fields are used only during mounting and re-mounting */ | 1432 | /* The below fields are used only during mounting and re-mounting */ |
1433 | unsigned int empty:1; | 1433 | unsigned int empty:1; |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index aa233469b3c1..287ef9f587b7 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
@@ -1312,14 +1312,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | read_lock(&sbi->s_cred_lock); | 1314 | read_lock(&sbi->s_cred_lock); |
1315 | inode->i_uid = le32_to_cpu(fe->uid); | 1315 | i_uid_write(inode, le32_to_cpu(fe->uid)); |
1316 | if (inode->i_uid == -1 || | 1316 | if (!uid_valid(inode->i_uid) || |
1317 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) || | 1317 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) || |
1318 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET)) | 1318 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET)) |
1319 | inode->i_uid = UDF_SB(inode->i_sb)->s_uid; | 1319 | inode->i_uid = UDF_SB(inode->i_sb)->s_uid; |
1320 | 1320 | ||
1321 | inode->i_gid = le32_to_cpu(fe->gid); | 1321 | i_gid_write(inode, le32_to_cpu(fe->gid)); |
1322 | if (inode->i_gid == -1 || | 1322 | if (!gid_valid(inode->i_gid) || |
1323 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) || | 1323 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) || |
1324 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET)) | 1324 | UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET)) |
1325 | inode->i_gid = UDF_SB(inode->i_sb)->s_gid; | 1325 | inode->i_gid = UDF_SB(inode->i_sb)->s_gid; |
@@ -1542,12 +1542,12 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1542 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) | 1542 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) |
1543 | fe->uid = cpu_to_le32(-1); | 1543 | fe->uid = cpu_to_le32(-1); |
1544 | else | 1544 | else |
1545 | fe->uid = cpu_to_le32(inode->i_uid); | 1545 | fe->uid = cpu_to_le32(i_uid_read(inode)); |
1546 | 1546 | ||
1547 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) | 1547 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) |
1548 | fe->gid = cpu_to_le32(-1); | 1548 | fe->gid = cpu_to_le32(-1); |
1549 | else | 1549 | else |
1550 | fe->gid = cpu_to_le32(inode->i_gid); | 1550 | fe->gid = cpu_to_le32(i_gid_read(inode)); |
1551 | 1551 | ||
1552 | udfperms = ((inode->i_mode & S_IRWXO)) | | 1552 | udfperms = ((inode->i_mode & S_IRWXO)) | |
1553 | ((inode->i_mode & S_IRWXG) << 2) | | 1553 | ((inode->i_mode & S_IRWXG) << 2) | |
diff --git a/fs/udf/super.c b/fs/udf/super.c index b8d27642ab06..d44fb568abe1 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c | |||
@@ -204,8 +204,8 @@ struct udf_options { | |||
204 | unsigned int rootdir; | 204 | unsigned int rootdir; |
205 | unsigned int flags; | 205 | unsigned int flags; |
206 | umode_t umask; | 206 | umode_t umask; |
207 | gid_t gid; | 207 | kgid_t gid; |
208 | uid_t uid; | 208 | kuid_t uid; |
209 | umode_t fmode; | 209 | umode_t fmode; |
210 | umode_t dmode; | 210 | umode_t dmode; |
211 | struct nls_table *nls_map; | 211 | struct nls_table *nls_map; |
@@ -340,9 +340,9 @@ static int udf_show_options(struct seq_file *seq, struct dentry *root) | |||
340 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE)) | 340 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE)) |
341 | seq_puts(seq, ",gid=ignore"); | 341 | seq_puts(seq, ",gid=ignore"); |
342 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET)) | 342 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET)) |
343 | seq_printf(seq, ",uid=%u", sbi->s_uid); | 343 | seq_printf(seq, ",uid=%u", from_kuid(&init_user_ns, sbi->s_uid)); |
344 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET)) | 344 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET)) |
345 | seq_printf(seq, ",gid=%u", sbi->s_gid); | 345 | seq_printf(seq, ",gid=%u", from_kgid(&init_user_ns, sbi->s_gid)); |
346 | if (sbi->s_umask != 0) | 346 | if (sbi->s_umask != 0) |
347 | seq_printf(seq, ",umask=%ho", sbi->s_umask); | 347 | seq_printf(seq, ",umask=%ho", sbi->s_umask); |
348 | if (sbi->s_fmode != UDF_INVALID_MODE) | 348 | if (sbi->s_fmode != UDF_INVALID_MODE) |
@@ -521,13 +521,17 @@ static int udf_parse_options(char *options, struct udf_options *uopt, | |||
521 | case Opt_gid: | 521 | case Opt_gid: |
522 | if (match_int(args, &option)) | 522 | if (match_int(args, &option)) |
523 | return 0; | 523 | return 0; |
524 | uopt->gid = option; | 524 | uopt->gid = make_kgid(current_user_ns(), option); |
525 | if (!gid_valid(uopt->gid)) | ||
526 | return 0; | ||
525 | uopt->flags |= (1 << UDF_FLAG_GID_SET); | 527 | uopt->flags |= (1 << UDF_FLAG_GID_SET); |
526 | break; | 528 | break; |
527 | case Opt_uid: | 529 | case Opt_uid: |
528 | if (match_int(args, &option)) | 530 | if (match_int(args, &option)) |
529 | return 0; | 531 | return 0; |
530 | uopt->uid = option; | 532 | uopt->uid = make_kuid(current_user_ns(), option); |
533 | if (!uid_valid(uopt->uid)) | ||
534 | return 0; | ||
531 | uopt->flags |= (1 << UDF_FLAG_UID_SET); | 535 | uopt->flags |= (1 << UDF_FLAG_UID_SET); |
532 | break; | 536 | break; |
533 | case Opt_umask: | 537 | case Opt_umask: |
@@ -1939,8 +1943,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
1939 | struct udf_sb_info *sbi; | 1943 | struct udf_sb_info *sbi; |
1940 | 1944 | ||
1941 | uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT); | 1945 | uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT); |
1942 | uopt.uid = -1; | 1946 | uopt.uid = INVALID_UID; |
1943 | uopt.gid = -1; | 1947 | uopt.gid = INVALID_GID; |
1944 | uopt.umask = 0; | 1948 | uopt.umask = 0; |
1945 | uopt.fmode = UDF_INVALID_MODE; | 1949 | uopt.fmode = UDF_INVALID_MODE; |
1946 | uopt.dmode = UDF_INVALID_MODE; | 1950 | uopt.dmode = UDF_INVALID_MODE; |
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h index 42ad69ac9576..5f027227f085 100644 --- a/fs/udf/udf_sb.h +++ b/fs/udf/udf_sb.h | |||
@@ -128,8 +128,8 @@ struct udf_sb_info { | |||
128 | 128 | ||
129 | /* Default permissions */ | 129 | /* Default permissions */ |
130 | umode_t s_umask; | 130 | umode_t s_umask; |
131 | gid_t s_gid; | 131 | kgid_t s_gid; |
132 | uid_t s_uid; | 132 | kuid_t s_uid; |
133 | umode_t s_fmode; | 133 | umode_t s_fmode; |
134 | umode_t s_dmode; | 134 | umode_t s_dmode; |
135 | /* Lock protecting consistency of above permission settings */ | 135 | /* Lock protecting consistency of above permission settings */ |
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c index dd7c89d8a1c1..eb6d0b7dc879 100644 --- a/fs/ufs/inode.c +++ b/fs/ufs/inode.c | |||
@@ -597,8 +597,8 @@ static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode) | |||
597 | /* | 597 | /* |
598 | * Linux now has 32-bit uid and gid, so we can support EFT. | 598 | * Linux now has 32-bit uid and gid, so we can support EFT. |
599 | */ | 599 | */ |
600 | inode->i_uid = ufs_get_inode_uid(sb, ufs_inode); | 600 | i_uid_write(inode, ufs_get_inode_uid(sb, ufs_inode)); |
601 | inode->i_gid = ufs_get_inode_gid(sb, ufs_inode); | 601 | i_gid_write(inode, ufs_get_inode_gid(sb, ufs_inode)); |
602 | 602 | ||
603 | inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size); | 603 | inode->i_size = fs64_to_cpu(sb, ufs_inode->ui_size); |
604 | inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec); | 604 | inode->i_atime.tv_sec = fs32_to_cpu(sb, ufs_inode->ui_atime.tv_sec); |
@@ -645,8 +645,8 @@ static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode) | |||
645 | /* | 645 | /* |
646 | * Linux now has 32-bit uid and gid, so we can support EFT. | 646 | * Linux now has 32-bit uid and gid, so we can support EFT. |
647 | */ | 647 | */ |
648 | inode->i_uid = fs32_to_cpu(sb, ufs2_inode->ui_uid); | 648 | i_uid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_uid)); |
649 | inode->i_gid = fs32_to_cpu(sb, ufs2_inode->ui_gid); | 649 | i_gid_write(inode, fs32_to_cpu(sb, ufs2_inode->ui_gid)); |
650 | 650 | ||
651 | inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size); | 651 | inode->i_size = fs64_to_cpu(sb, ufs2_inode->ui_size); |
652 | inode->i_atime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_atime); | 652 | inode->i_atime.tv_sec = fs64_to_cpu(sb, ufs2_inode->ui_atime); |
@@ -745,8 +745,8 @@ static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode) | |||
745 | ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); | 745 | ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); |
746 | ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink); | 746 | ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink); |
747 | 747 | ||
748 | ufs_set_inode_uid(sb, ufs_inode, inode->i_uid); | 748 | ufs_set_inode_uid(sb, ufs_inode, i_uid_read(inode)); |
749 | ufs_set_inode_gid(sb, ufs_inode, inode->i_gid); | 749 | ufs_set_inode_gid(sb, ufs_inode, i_gid_read(inode)); |
750 | 750 | ||
751 | ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size); | 751 | ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size); |
752 | ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb, inode->i_atime.tv_sec); | 752 | ufs_inode->ui_atime.tv_sec = cpu_to_fs32(sb, inode->i_atime.tv_sec); |
@@ -789,8 +789,8 @@ static void ufs2_update_inode(struct inode *inode, struct ufs2_inode *ufs_inode) | |||
789 | ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); | 789 | ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); |
790 | ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink); | 790 | ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink); |
791 | 791 | ||
792 | ufs_inode->ui_uid = cpu_to_fs32(sb, inode->i_uid); | 792 | ufs_inode->ui_uid = cpu_to_fs32(sb, i_uid_read(inode)); |
793 | ufs_inode->ui_gid = cpu_to_fs32(sb, inode->i_gid); | 793 | ufs_inode->ui_gid = cpu_to_fs32(sb, i_gid_read(inode)); |
794 | 794 | ||
795 | ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size); | 795 | ufs_inode->ui_size = cpu_to_fs64(sb, inode->i_size); |
796 | ufs_inode->ui_atime = cpu_to_fs64(sb, inode->i_atime.tv_sec); | 796 | ufs_inode->ui_atime = cpu_to_fs64(sb, inode->i_atime.tv_sec); |
diff --git a/fs/xattr.c b/fs/xattr.c index 14a7e2544fe3..ca15fbd391c8 100644 --- a/fs/xattr.c +++ b/fs/xattr.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/fsnotify.h> | 20 | #include <linux/fsnotify.h> |
21 | #include <linux/audit.h> | 21 | #include <linux/audit.h> |
22 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
23 | #include <linux/posix_acl_xattr.h> | ||
23 | 24 | ||
24 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
25 | 26 | ||
@@ -347,6 +348,9 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, | |||
347 | error = -EFAULT; | 348 | error = -EFAULT; |
348 | goto out; | 349 | goto out; |
349 | } | 350 | } |
351 | if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) || | ||
352 | (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) | ||
353 | posix_acl_fix_xattr_from_user(kvalue, size); | ||
350 | } | 354 | } |
351 | 355 | ||
352 | error = vfs_setxattr(d, kname, kvalue, size, flags); | 356 | error = vfs_setxattr(d, kname, kvalue, size, flags); |
@@ -448,6 +452,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, | |||
448 | 452 | ||
449 | error = vfs_getxattr(d, kname, kvalue, size); | 453 | error = vfs_getxattr(d, kname, kvalue, size); |
450 | if (error > 0) { | 454 | if (error > 0) { |
455 | if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) || | ||
456 | (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)) | ||
457 | posix_acl_fix_xattr_to_user(kvalue, size); | ||
451 | if (size && copy_to_user(value, kvalue, error)) | 458 | if (size && copy_to_user(value, kvalue, error)) |
452 | error = -EFAULT; | 459 | error = -EFAULT; |
453 | } else if (error == -ERANGE && size >= XATTR_SIZE_MAX) { | 460 | } else if (error == -ERANGE && size >= XATTR_SIZE_MAX) { |
@@ -783,3 +790,183 @@ EXPORT_SYMBOL(generic_getxattr); | |||
783 | EXPORT_SYMBOL(generic_listxattr); | 790 | EXPORT_SYMBOL(generic_listxattr); |
784 | EXPORT_SYMBOL(generic_setxattr); | 791 | EXPORT_SYMBOL(generic_setxattr); |
785 | EXPORT_SYMBOL(generic_removexattr); | 792 | EXPORT_SYMBOL(generic_removexattr); |
793 | |||
794 | /* | ||
795 | * Allocate new xattr and copy in the value; but leave the name to callers. | ||
796 | */ | ||
797 | struct simple_xattr *simple_xattr_alloc(const void *value, size_t size) | ||
798 | { | ||
799 | struct simple_xattr *new_xattr; | ||
800 | size_t len; | ||
801 | |||
802 | /* wrap around? */ | ||
803 | len = sizeof(*new_xattr) + size; | ||
804 | if (len <= sizeof(*new_xattr)) | ||
805 | return NULL; | ||
806 | |||
807 | new_xattr = kmalloc(len, GFP_KERNEL); | ||
808 | if (!new_xattr) | ||
809 | return NULL; | ||
810 | |||
811 | new_xattr->size = size; | ||
812 | memcpy(new_xattr->value, value, size); | ||
813 | return new_xattr; | ||
814 | } | ||
815 | |||
816 | /* | ||
817 | * xattr GET operation for in-memory/pseudo filesystems | ||
818 | */ | ||
819 | int simple_xattr_get(struct simple_xattrs *xattrs, const char *name, | ||
820 | void *buffer, size_t size) | ||
821 | { | ||
822 | struct simple_xattr *xattr; | ||
823 | int ret = -ENODATA; | ||
824 | |||
825 | spin_lock(&xattrs->lock); | ||
826 | list_for_each_entry(xattr, &xattrs->head, list) { | ||
827 | if (strcmp(name, xattr->name)) | ||
828 | continue; | ||
829 | |||
830 | ret = xattr->size; | ||
831 | if (buffer) { | ||
832 | if (size < xattr->size) | ||
833 | ret = -ERANGE; | ||
834 | else | ||
835 | memcpy(buffer, xattr->value, xattr->size); | ||
836 | } | ||
837 | break; | ||
838 | } | ||
839 | spin_unlock(&xattrs->lock); | ||
840 | return ret; | ||
841 | } | ||
842 | |||
843 | static int __simple_xattr_set(struct simple_xattrs *xattrs, const char *name, | ||
844 | const void *value, size_t size, int flags) | ||
845 | { | ||
846 | struct simple_xattr *xattr; | ||
847 | struct simple_xattr *uninitialized_var(new_xattr); | ||
848 | int err = 0; | ||
849 | |||
850 | /* value == NULL means remove */ | ||
851 | if (value) { | ||
852 | new_xattr = simple_xattr_alloc(value, size); | ||
853 | if (!new_xattr) | ||
854 | return -ENOMEM; | ||
855 | |||
856 | new_xattr->name = kstrdup(name, GFP_KERNEL); | ||
857 | if (!new_xattr->name) { | ||
858 | kfree(new_xattr); | ||
859 | return -ENOMEM; | ||
860 | } | ||
861 | } | ||
862 | |||
863 | spin_lock(&xattrs->lock); | ||
864 | list_for_each_entry(xattr, &xattrs->head, list) { | ||
865 | if (!strcmp(name, xattr->name)) { | ||
866 | if (flags & XATTR_CREATE) { | ||
867 | xattr = new_xattr; | ||
868 | err = -EEXIST; | ||
869 | } else if (new_xattr) { | ||
870 | list_replace(&xattr->list, &new_xattr->list); | ||
871 | } else { | ||
872 | list_del(&xattr->list); | ||
873 | } | ||
874 | goto out; | ||
875 | } | ||
876 | } | ||
877 | if (flags & XATTR_REPLACE) { | ||
878 | xattr = new_xattr; | ||
879 | err = -ENODATA; | ||
880 | } else { | ||
881 | list_add(&new_xattr->list, &xattrs->head); | ||
882 | xattr = NULL; | ||
883 | } | ||
884 | out: | ||
885 | spin_unlock(&xattrs->lock); | ||
886 | if (xattr) { | ||
887 | kfree(xattr->name); | ||
888 | kfree(xattr); | ||
889 | } | ||
890 | return err; | ||
891 | |||
892 | } | ||
893 | |||
894 | /** | ||
895 | * simple_xattr_set - xattr SET operation for in-memory/pseudo filesystems | ||
896 | * @xattrs: target simple_xattr list | ||
897 | * @name: name of the new extended attribute | ||
898 | * @value: value of the new xattr. If %NULL, will remove the attribute | ||
899 | * @size: size of the new xattr | ||
900 | * @flags: %XATTR_{CREATE|REPLACE} | ||
901 | * | ||
902 | * %XATTR_CREATE is set, the xattr shouldn't exist already; otherwise fails | ||
903 | * with -EEXIST. If %XATTR_REPLACE is set, the xattr should exist; | ||
904 | * otherwise, fails with -ENODATA. | ||
905 | * | ||
906 | * Returns 0 on success, -errno on failure. | ||
907 | */ | ||
908 | int simple_xattr_set(struct simple_xattrs *xattrs, const char *name, | ||
909 | const void *value, size_t size, int flags) | ||
910 | { | ||
911 | if (size == 0) | ||
912 | value = ""; /* empty EA, do not remove */ | ||
913 | return __simple_xattr_set(xattrs, name, value, size, flags); | ||
914 | } | ||
915 | |||
916 | /* | ||
917 | * xattr REMOVE operation for in-memory/pseudo filesystems | ||
918 | */ | ||
919 | int simple_xattr_remove(struct simple_xattrs *xattrs, const char *name) | ||
920 | { | ||
921 | return __simple_xattr_set(xattrs, name, NULL, 0, XATTR_REPLACE); | ||
922 | } | ||
923 | |||
924 | static bool xattr_is_trusted(const char *name) | ||
925 | { | ||
926 | return !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN); | ||
927 | } | ||
928 | |||
929 | /* | ||
930 | * xattr LIST operation for in-memory/pseudo filesystems | ||
931 | */ | ||
932 | ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer, | ||
933 | size_t size) | ||
934 | { | ||
935 | bool trusted = capable(CAP_SYS_ADMIN); | ||
936 | struct simple_xattr *xattr; | ||
937 | size_t used = 0; | ||
938 | |||
939 | spin_lock(&xattrs->lock); | ||
940 | list_for_each_entry(xattr, &xattrs->head, list) { | ||
941 | size_t len; | ||
942 | |||
943 | /* skip "trusted." attributes for unprivileged callers */ | ||
944 | if (!trusted && xattr_is_trusted(xattr->name)) | ||
945 | continue; | ||
946 | |||
947 | len = strlen(xattr->name) + 1; | ||
948 | used += len; | ||
949 | if (buffer) { | ||
950 | if (size < used) { | ||
951 | used = -ERANGE; | ||
952 | break; | ||
953 | } | ||
954 | memcpy(buffer, xattr->name, len); | ||
955 | buffer += len; | ||
956 | } | ||
957 | } | ||
958 | spin_unlock(&xattrs->lock); | ||
959 | |||
960 | return used; | ||
961 | } | ||
962 | |||
963 | /* | ||
964 | * Adds an extended attribute to the list | ||
965 | */ | ||
966 | void simple_xattr_list_add(struct simple_xattrs *xattrs, | ||
967 | struct simple_xattr *new_xattr) | ||
968 | { | ||
969 | spin_lock(&xattrs->lock); | ||
970 | list_add(&new_xattr->list, &xattrs->head); | ||
971 | spin_unlock(&xattrs->lock); | ||
972 | } | ||
diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c index 69d06b07b169..11efd830b5f5 100644 --- a/fs/xattr_acl.c +++ b/fs/xattr_acl.c | |||
@@ -9,13 +9,72 @@ | |||
9 | #include <linux/fs.h> | 9 | #include <linux/fs.h> |
10 | #include <linux/posix_acl_xattr.h> | 10 | #include <linux/posix_acl_xattr.h> |
11 | #include <linux/gfp.h> | 11 | #include <linux/gfp.h> |
12 | #include <linux/user_namespace.h> | ||
12 | 13 | ||
14 | /* | ||
15 | * Fix up the uids and gids in posix acl extended attributes in place. | ||
16 | */ | ||
17 | static void posix_acl_fix_xattr_userns( | ||
18 | struct user_namespace *to, struct user_namespace *from, | ||
19 | void *value, size_t size) | ||
20 | { | ||
21 | posix_acl_xattr_header *header = (posix_acl_xattr_header *)value; | ||
22 | posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end; | ||
23 | int count; | ||
24 | kuid_t uid; | ||
25 | kgid_t gid; | ||
26 | |||
27 | if (!value) | ||
28 | return; | ||
29 | if (size < sizeof(posix_acl_xattr_header)) | ||
30 | return; | ||
31 | if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION)) | ||
32 | return; | ||
33 | |||
34 | count = posix_acl_xattr_count(size); | ||
35 | if (count < 0) | ||
36 | return; | ||
37 | if (count == 0) | ||
38 | return; | ||
39 | |||
40 | for (end = entry + count; entry != end; entry++) { | ||
41 | switch(le16_to_cpu(entry->e_tag)) { | ||
42 | case ACL_USER: | ||
43 | uid = make_kuid(from, le32_to_cpu(entry->e_id)); | ||
44 | entry->e_id = cpu_to_le32(from_kuid(to, uid)); | ||
45 | break; | ||
46 | case ACL_GROUP: | ||
47 | gid = make_kgid(from, le32_to_cpu(entry->e_id)); | ||
48 | entry->e_id = cpu_to_le32(from_kuid(to, uid)); | ||
49 | break; | ||
50 | default: | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void posix_acl_fix_xattr_from_user(void *value, size_t size) | ||
57 | { | ||
58 | struct user_namespace *user_ns = current_user_ns(); | ||
59 | if (user_ns == &init_user_ns) | ||
60 | return; | ||
61 | posix_acl_fix_xattr_userns(&init_user_ns, user_ns, value, size); | ||
62 | } | ||
63 | |||
64 | void posix_acl_fix_xattr_to_user(void *value, size_t size) | ||
65 | { | ||
66 | struct user_namespace *user_ns = current_user_ns(); | ||
67 | if (user_ns == &init_user_ns) | ||
68 | return; | ||
69 | posix_acl_fix_xattr_userns(user_ns, &init_user_ns, value, size); | ||
70 | } | ||
13 | 71 | ||
14 | /* | 72 | /* |
15 | * Convert from extended attribute to in-memory representation. | 73 | * Convert from extended attribute to in-memory representation. |
16 | */ | 74 | */ |
17 | struct posix_acl * | 75 | struct posix_acl * |
18 | posix_acl_from_xattr(const void *value, size_t size) | 76 | posix_acl_from_xattr(struct user_namespace *user_ns, |
77 | const void *value, size_t size) | ||
19 | { | 78 | { |
20 | posix_acl_xattr_header *header = (posix_acl_xattr_header *)value; | 79 | posix_acl_xattr_header *header = (posix_acl_xattr_header *)value; |
21 | posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end; | 80 | posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end; |
@@ -50,12 +109,21 @@ posix_acl_from_xattr(const void *value, size_t size) | |||
50 | case ACL_GROUP_OBJ: | 109 | case ACL_GROUP_OBJ: |
51 | case ACL_MASK: | 110 | case ACL_MASK: |
52 | case ACL_OTHER: | 111 | case ACL_OTHER: |
53 | acl_e->e_id = ACL_UNDEFINED_ID; | ||
54 | break; | 112 | break; |
55 | 113 | ||
56 | case ACL_USER: | 114 | case ACL_USER: |
115 | acl_e->e_uid = | ||
116 | make_kuid(user_ns, | ||
117 | le32_to_cpu(entry->e_id)); | ||
118 | if (!uid_valid(acl_e->e_uid)) | ||
119 | goto fail; | ||
120 | break; | ||
57 | case ACL_GROUP: | 121 | case ACL_GROUP: |
58 | acl_e->e_id = le32_to_cpu(entry->e_id); | 122 | acl_e->e_gid = |
123 | make_kgid(user_ns, | ||
124 | le32_to_cpu(entry->e_id)); | ||
125 | if (!gid_valid(acl_e->e_gid)) | ||
126 | goto fail; | ||
59 | break; | 127 | break; |
60 | 128 | ||
61 | default: | 129 | default: |
@@ -74,7 +142,8 @@ EXPORT_SYMBOL (posix_acl_from_xattr); | |||
74 | * Convert from in-memory to extended attribute representation. | 142 | * Convert from in-memory to extended attribute representation. |
75 | */ | 143 | */ |
76 | int | 144 | int |
77 | posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) | 145 | posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl, |
146 | void *buffer, size_t size) | ||
78 | { | 147 | { |
79 | posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer; | 148 | posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer; |
80 | posix_acl_xattr_entry *ext_entry = ext_acl->a_entries; | 149 | posix_acl_xattr_entry *ext_entry = ext_acl->a_entries; |
@@ -89,9 +158,22 @@ posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) | |||
89 | ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); | 158 | ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
90 | 159 | ||
91 | for (n=0; n < acl->a_count; n++, ext_entry++) { | 160 | for (n=0; n < acl->a_count; n++, ext_entry++) { |
92 | ext_entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 161 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; |
93 | ext_entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 162 | ext_entry->e_tag = cpu_to_le16(acl_e->e_tag); |
94 | ext_entry->e_id = cpu_to_le32(acl->a_entries[n].e_id); | 163 | ext_entry->e_perm = cpu_to_le16(acl_e->e_perm); |
164 | switch(acl_e->e_tag) { | ||
165 | case ACL_USER: | ||
166 | ext_entry->e_id = | ||
167 | cpu_to_le32(from_kuid(user_ns, acl_e->e_uid)); | ||
168 | break; | ||
169 | case ACL_GROUP: | ||
170 | ext_entry->e_id = | ||
171 | cpu_to_le32(from_kgid(user_ns, acl_e->e_gid)); | ||
172 | break; | ||
173 | default: | ||
174 | ext_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID); | ||
175 | break; | ||
176 | } | ||
95 | } | 177 | } |
96 | return real_size; | 178 | return real_size; |
97 | } | 179 | } |
diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c index ac702a6eab9b..1d32f1d52763 100644 --- a/fs/xfs/xfs_acl.c +++ b/fs/xfs/xfs_acl.c | |||
@@ -337,7 +337,7 @@ xfs_xattr_acl_get(struct dentry *dentry, const char *name, | |||
337 | if (acl == NULL) | 337 | if (acl == NULL) |
338 | return -ENODATA; | 338 | return -ENODATA; |
339 | 339 | ||
340 | error = posix_acl_to_xattr(acl, value, size); | 340 | error = posix_acl_to_xattr(&init_user_ns, acl, value, size); |
341 | posix_acl_release(acl); | 341 | posix_acl_release(acl); |
342 | 342 | ||
343 | return error; | 343 | return error; |
@@ -361,7 +361,7 @@ xfs_xattr_acl_set(struct dentry *dentry, const char *name, | |||
361 | if (!value) | 361 | if (!value) |
362 | goto set_acl; | 362 | goto set_acl; |
363 | 363 | ||
364 | acl = posix_acl_from_xattr(value, size); | 364 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
365 | if (!acl) { | 365 | if (!acl) { |
366 | /* | 366 | /* |
367 | * acl_set_file(3) may request that we set default ACLs with | 367 | * acl_set_file(3) may request that we set default ACLs with |
diff --git a/fs/xfs/xfs_quotaops.c b/fs/xfs/xfs_quotaops.c index fed504fc2999..71926d630527 100644 --- a/fs/xfs/xfs_quotaops.c +++ b/fs/xfs/xfs_quotaops.c | |||
@@ -97,8 +97,7 @@ xfs_fs_set_xstate( | |||
97 | STATIC int | 97 | STATIC int |
98 | xfs_fs_get_dqblk( | 98 | xfs_fs_get_dqblk( |
99 | struct super_block *sb, | 99 | struct super_block *sb, |
100 | int type, | 100 | struct kqid qid, |
101 | qid_t id, | ||
102 | struct fs_disk_quota *fdq) | 101 | struct fs_disk_quota *fdq) |
103 | { | 102 | { |
104 | struct xfs_mount *mp = XFS_M(sb); | 103 | struct xfs_mount *mp = XFS_M(sb); |
@@ -108,14 +107,14 @@ xfs_fs_get_dqblk( | |||
108 | if (!XFS_IS_QUOTA_ON(mp)) | 107 | if (!XFS_IS_QUOTA_ON(mp)) |
109 | return -ESRCH; | 108 | return -ESRCH; |
110 | 109 | ||
111 | return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq); | 110 | return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), |
111 | xfs_quota_type(qid.type), fdq); | ||
112 | } | 112 | } |
113 | 113 | ||
114 | STATIC int | 114 | STATIC int |
115 | xfs_fs_set_dqblk( | 115 | xfs_fs_set_dqblk( |
116 | struct super_block *sb, | 116 | struct super_block *sb, |
117 | int type, | 117 | struct kqid qid, |
118 | qid_t id, | ||
119 | struct fs_disk_quota *fdq) | 118 | struct fs_disk_quota *fdq) |
120 | { | 119 | { |
121 | struct xfs_mount *mp = XFS_M(sb); | 120 | struct xfs_mount *mp = XFS_M(sb); |
@@ -127,7 +126,8 @@ xfs_fs_set_dqblk( | |||
127 | if (!XFS_IS_QUOTA_ON(mp)) | 126 | if (!XFS_IS_QUOTA_ON(mp)) |
128 | return -ESRCH; | 127 | return -ESRCH; |
129 | 128 | ||
130 | return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq); | 129 | return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
130 | xfs_quota_type(qid.type), fdq); | ||
131 | } | 131 | } |
132 | 132 | ||
133 | const struct quotactl_ops xfs_quotactl_operations = { | 133 | const struct quotactl_ops xfs_quotactl_operations = { |
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 83d36e473d2f..e0fd2734189e 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c | |||
@@ -954,7 +954,7 @@ xfs_fs_sync_fs( | |||
954 | * We schedule xfssyncd now (now that the disk is | 954 | * We schedule xfssyncd now (now that the disk is |
955 | * active) instead of later (when it might not be). | 955 | * active) instead of later (when it might not be). |
956 | */ | 956 | */ |
957 | flush_delayed_work_sync(&mp->m_sync_work); | 957 | flush_delayed_work(&mp->m_sync_work); |
958 | } | 958 | } |
959 | 959 | ||
960 | return 0; | 960 | return 0; |
diff --git a/fs/xfs/xfs_sync.c b/fs/xfs/xfs_sync.c index 96548176db80..9500caf15acf 100644 --- a/fs/xfs/xfs_sync.c +++ b/fs/xfs/xfs_sync.c | |||
@@ -475,7 +475,7 @@ xfs_flush_inodes( | |||
475 | struct xfs_mount *mp = ip->i_mount; | 475 | struct xfs_mount *mp = ip->i_mount; |
476 | 476 | ||
477 | queue_work(xfs_syncd_wq, &mp->m_flush_work); | 477 | queue_work(xfs_syncd_wq, &mp->m_flush_work); |
478 | flush_work_sync(&mp->m_flush_work); | 478 | flush_work(&mp->m_flush_work); |
479 | } | 479 | } |
480 | 480 | ||
481 | STATIC void | 481 | STATIC void |
diff --git a/fs/xfs/xfs_trans_dquot.c b/fs/xfs/xfs_trans_dquot.c index bcb60542fcf1..0c7fa54f309e 100644 --- a/fs/xfs/xfs_trans_dquot.c +++ b/fs/xfs/xfs_trans_dquot.c | |||
@@ -578,9 +578,11 @@ xfs_quota_warn( | |||
578 | /* no warnings for project quotas - we just return ENOSPC later */ | 578 | /* no warnings for project quotas - we just return ENOSPC later */ |
579 | if (dqp->dq_flags & XFS_DQ_PROJ) | 579 | if (dqp->dq_flags & XFS_DQ_PROJ) |
580 | return; | 580 | return; |
581 | quota_send_warning((dqp->dq_flags & XFS_DQ_USER) ? USRQUOTA : GRPQUOTA, | 581 | quota_send_warning(make_kqid(&init_user_ns, |
582 | be32_to_cpu(dqp->q_core.d_id), mp->m_super->s_dev, | 582 | (dqp->dq_flags & XFS_DQ_USER) ? |
583 | type); | 583 | USRQUOTA : GRPQUOTA, |
584 | be32_to_cpu(dqp->q_core.d_id)), | ||
585 | mp->m_super->s_dev, type); | ||
584 | } | 586 | } |
585 | 587 | ||
586 | /* | 588 | /* |