diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/aio.c | 26 | ||||
-rw-r--r-- | fs/exec.c | 12 | ||||
-rw-r--r-- | fs/locks.c | 42 | ||||
-rw-r--r-- | fs/namei.c | 95 | ||||
-rw-r--r-- | fs/nfs/delegation.c | 6 | ||||
-rw-r--r-- | fs/nfs/delegation.h | 16 | ||||
-rw-r--r-- | fs/nfs/dir.c | 44 | ||||
-rw-r--r-- | fs/nfs/file.c | 30 | ||||
-rw-r--r-- | fs/nfs/inode.c | 17 | ||||
-rw-r--r-- | fs/nfs/nfs3proc.c | 2 | ||||
-rw-r--r-- | fs/nfs/nfs4_fs.h | 53 | ||||
-rw-r--r-- | fs/nfs/nfs4proc.c | 577 | ||||
-rw-r--r-- | fs/nfs/nfs4state.c | 165 | ||||
-rw-r--r-- | fs/nfs/nfs4xdr.c | 62 | ||||
-rw-r--r-- | fs/nfs/proc.c | 2 | ||||
-rw-r--r-- | fs/open.c | 79 | ||||
-rw-r--r-- | fs/proc/base.c | 12 | ||||
-rw-r--r-- | fs/proc/nommu.c | 1 |
18 files changed, 824 insertions, 417 deletions
@@ -398,7 +398,7 @@ static struct kiocb fastcall *__aio_get_req(struct kioctx *ctx) | |||
398 | if (unlikely(!req)) | 398 | if (unlikely(!req)) |
399 | return NULL; | 399 | return NULL; |
400 | 400 | ||
401 | req->ki_flags = 1 << KIF_LOCKED; | 401 | req->ki_flags = 0; |
402 | req->ki_users = 2; | 402 | req->ki_users = 2; |
403 | req->ki_key = 0; | 403 | req->ki_key = 0; |
404 | req->ki_ctx = ctx; | 404 | req->ki_ctx = ctx; |
@@ -547,25 +547,6 @@ struct kioctx *lookup_ioctx(unsigned long ctx_id) | |||
547 | return ioctx; | 547 | return ioctx; |
548 | } | 548 | } |
549 | 549 | ||
550 | static int lock_kiocb_action(void *param) | ||
551 | { | ||
552 | schedule(); | ||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | static inline void lock_kiocb(struct kiocb *iocb) | ||
557 | { | ||
558 | wait_on_bit_lock(&iocb->ki_flags, KIF_LOCKED, lock_kiocb_action, | ||
559 | TASK_UNINTERRUPTIBLE); | ||
560 | } | ||
561 | |||
562 | static inline void unlock_kiocb(struct kiocb *iocb) | ||
563 | { | ||
564 | kiocbClearLocked(iocb); | ||
565 | smp_mb__after_clear_bit(); | ||
566 | wake_up_bit(&iocb->ki_flags, KIF_LOCKED); | ||
567 | } | ||
568 | |||
569 | /* | 550 | /* |
570 | * use_mm | 551 | * use_mm |
571 | * Makes the calling kernel thread take on the specified | 552 | * Makes the calling kernel thread take on the specified |
@@ -796,9 +777,7 @@ static int __aio_run_iocbs(struct kioctx *ctx) | |||
796 | * Hold an extra reference while retrying i/o. | 777 | * Hold an extra reference while retrying i/o. |
797 | */ | 778 | */ |
798 | iocb->ki_users++; /* grab extra reference */ | 779 | iocb->ki_users++; /* grab extra reference */ |
799 | lock_kiocb(iocb); | ||
800 | aio_run_iocb(iocb); | 780 | aio_run_iocb(iocb); |
801 | unlock_kiocb(iocb); | ||
802 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ | 781 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ |
803 | put_ioctx(ctx); | 782 | put_ioctx(ctx); |
804 | } | 783 | } |
@@ -1542,7 +1521,6 @@ int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, | |||
1542 | 1521 | ||
1543 | spin_lock_irq(&ctx->ctx_lock); | 1522 | spin_lock_irq(&ctx->ctx_lock); |
1544 | aio_run_iocb(req); | 1523 | aio_run_iocb(req); |
1545 | unlock_kiocb(req); | ||
1546 | if (!list_empty(&ctx->run_list)) { | 1524 | if (!list_empty(&ctx->run_list)) { |
1547 | /* drain the run list */ | 1525 | /* drain the run list */ |
1548 | while (__aio_run_iocbs(ctx)) | 1526 | while (__aio_run_iocbs(ctx)) |
@@ -1674,7 +1652,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1674 | if (NULL != cancel) { | 1652 | if (NULL != cancel) { |
1675 | struct io_event tmp; | 1653 | struct io_event tmp; |
1676 | pr_debug("calling cancel\n"); | 1654 | pr_debug("calling cancel\n"); |
1677 | lock_kiocb(kiocb); | ||
1678 | memset(&tmp, 0, sizeof(tmp)); | 1655 | memset(&tmp, 0, sizeof(tmp)); |
1679 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; | 1656 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; |
1680 | tmp.data = kiocb->ki_user_data; | 1657 | tmp.data = kiocb->ki_user_data; |
@@ -1686,7 +1663,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1686 | if (copy_to_user(result, &tmp, sizeof(tmp))) | 1663 | if (copy_to_user(result, &tmp, sizeof(tmp))) |
1687 | ret = -EFAULT; | 1664 | ret = -EFAULT; |
1688 | } | 1665 | } |
1689 | unlock_kiocb(kiocb); | ||
1690 | } else | 1666 | } else |
1691 | ret = -EINVAL; | 1667 | ret = -EINVAL; |
1692 | 1668 | ||
@@ -126,8 +126,7 @@ asmlinkage long sys_uselib(const char __user * library) | |||
126 | struct nameidata nd; | 126 | struct nameidata nd; |
127 | int error; | 127 | int error; |
128 | 128 | ||
129 | nd.intent.open.flags = FMODE_READ; | 129 | error = __user_path_lookup_open(library, LOOKUP_FOLLOW, &nd, FMODE_READ); |
130 | error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); | ||
131 | if (error) | 130 | if (error) |
132 | goto out; | 131 | goto out; |
133 | 132 | ||
@@ -139,7 +138,7 @@ asmlinkage long sys_uselib(const char __user * library) | |||
139 | if (error) | 138 | if (error) |
140 | goto exit; | 139 | goto exit; |
141 | 140 | ||
142 | file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); | 141 | file = nameidata_to_filp(&nd, O_RDONLY); |
143 | error = PTR_ERR(file); | 142 | error = PTR_ERR(file); |
144 | if (IS_ERR(file)) | 143 | if (IS_ERR(file)) |
145 | goto out; | 144 | goto out; |
@@ -167,6 +166,7 @@ asmlinkage long sys_uselib(const char __user * library) | |||
167 | out: | 166 | out: |
168 | return error; | 167 | return error; |
169 | exit: | 168 | exit: |
169 | release_open_intent(&nd); | ||
170 | path_release(&nd); | 170 | path_release(&nd); |
171 | goto out; | 171 | goto out; |
172 | } | 172 | } |
@@ -490,8 +490,7 @@ struct file *open_exec(const char *name) | |||
490 | int err; | 490 | int err; |
491 | struct file *file; | 491 | struct file *file; |
492 | 492 | ||
493 | nd.intent.open.flags = FMODE_READ; | 493 | err = path_lookup_open(name, LOOKUP_FOLLOW, &nd, FMODE_READ); |
494 | err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); | ||
495 | file = ERR_PTR(err); | 494 | file = ERR_PTR(err); |
496 | 495 | ||
497 | if (!err) { | 496 | if (!err) { |
@@ -504,7 +503,7 @@ struct file *open_exec(const char *name) | |||
504 | err = -EACCES; | 503 | err = -EACCES; |
505 | file = ERR_PTR(err); | 504 | file = ERR_PTR(err); |
506 | if (!err) { | 505 | if (!err) { |
507 | file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); | 506 | file = nameidata_to_filp(&nd, O_RDONLY); |
508 | if (!IS_ERR(file)) { | 507 | if (!IS_ERR(file)) { |
509 | err = deny_write_access(file); | 508 | err = deny_write_access(file); |
510 | if (err) { | 509 | if (err) { |
@@ -516,6 +515,7 @@ out: | |||
516 | return file; | 515 | return file; |
517 | } | 516 | } |
518 | } | 517 | } |
518 | release_open_intent(&nd); | ||
519 | path_release(&nd); | 519 | path_release(&nd); |
520 | } | 520 | } |
521 | goto out; | 521 | goto out; |
diff --git a/fs/locks.c b/fs/locks.c index 7eb1d77b92..a1e8b22480 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -316,21 +316,22 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, | |||
316 | /* POSIX-1996 leaves the case l->l_len < 0 undefined; | 316 | /* POSIX-1996 leaves the case l->l_len < 0 undefined; |
317 | POSIX-2001 defines it. */ | 317 | POSIX-2001 defines it. */ |
318 | start += l->l_start; | 318 | start += l->l_start; |
319 | end = start + l->l_len - 1; | 319 | if (start < 0) |
320 | if (l->l_len < 0) { | 320 | return -EINVAL; |
321 | fl->fl_end = OFFSET_MAX; | ||
322 | if (l->l_len > 0) { | ||
323 | end = start + l->l_len - 1; | ||
324 | fl->fl_end = end; | ||
325 | } else if (l->l_len < 0) { | ||
321 | end = start - 1; | 326 | end = start - 1; |
327 | fl->fl_end = end; | ||
322 | start += l->l_len; | 328 | start += l->l_len; |
329 | if (start < 0) | ||
330 | return -EINVAL; | ||
323 | } | 331 | } |
324 | |||
325 | if (start < 0) | ||
326 | return -EINVAL; | ||
327 | if (l->l_len > 0 && end < 0) | ||
328 | return -EOVERFLOW; | ||
329 | |||
330 | fl->fl_start = start; /* we record the absolute position */ | 332 | fl->fl_start = start; /* we record the absolute position */ |
331 | fl->fl_end = end; | 333 | if (fl->fl_end < fl->fl_start) |
332 | if (l->l_len == 0) | 334 | return -EOVERFLOW; |
333 | fl->fl_end = OFFSET_MAX; | ||
334 | 335 | ||
335 | fl->fl_owner = current->files; | 336 | fl->fl_owner = current->files; |
336 | fl->fl_pid = current->tgid; | 337 | fl->fl_pid = current->tgid; |
@@ -362,14 +363,21 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, | |||
362 | return -EINVAL; | 363 | return -EINVAL; |
363 | } | 364 | } |
364 | 365 | ||
365 | if (((start += l->l_start) < 0) || (l->l_len < 0)) | 366 | start += l->l_start; |
367 | if (start < 0) | ||
366 | return -EINVAL; | 368 | return -EINVAL; |
367 | fl->fl_end = start + l->l_len - 1; | 369 | fl->fl_end = OFFSET_MAX; |
368 | if (l->l_len > 0 && fl->fl_end < 0) | 370 | if (l->l_len > 0) { |
369 | return -EOVERFLOW; | 371 | fl->fl_end = start + l->l_len - 1; |
372 | } else if (l->l_len < 0) { | ||
373 | fl->fl_end = start - 1; | ||
374 | start += l->l_len; | ||
375 | if (start < 0) | ||
376 | return -EINVAL; | ||
377 | } | ||
370 | fl->fl_start = start; /* we record the absolute position */ | 378 | fl->fl_start = start; /* we record the absolute position */ |
371 | if (l->l_len == 0) | 379 | if (fl->fl_end < fl->fl_start) |
372 | fl->fl_end = OFFSET_MAX; | 380 | return -EOVERFLOW; |
373 | 381 | ||
374 | fl->fl_owner = current->files; | 382 | fl->fl_owner = current->files; |
375 | fl->fl_pid = current->tgid; | 383 | fl->fl_pid = current->tgid; |
diff --git a/fs/namei.c b/fs/namei.c index aa62dbda93..aaaa810362 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/syscalls.h> | 28 | #include <linux/syscalls.h> |
29 | #include <linux/mount.h> | 29 | #include <linux/mount.h> |
30 | #include <linux/audit.h> | 30 | #include <linux/audit.h> |
31 | #include <linux/file.h> | ||
31 | #include <asm/namei.h> | 32 | #include <asm/namei.h> |
32 | #include <asm/uaccess.h> | 33 | #include <asm/uaccess.h> |
33 | 34 | ||
@@ -317,6 +318,18 @@ void path_release_on_umount(struct nameidata *nd) | |||
317 | mntput_no_expire(nd->mnt); | 318 | mntput_no_expire(nd->mnt); |
318 | } | 319 | } |
319 | 320 | ||
321 | /** | ||
322 | * release_open_intent - free up open intent resources | ||
323 | * @nd: pointer to nameidata | ||
324 | */ | ||
325 | void release_open_intent(struct nameidata *nd) | ||
326 | { | ||
327 | if (nd->intent.open.file->f_dentry == NULL) | ||
328 | put_filp(nd->intent.open.file); | ||
329 | else | ||
330 | fput(nd->intent.open.file); | ||
331 | } | ||
332 | |||
320 | /* | 333 | /* |
321 | * Internal lookup() using the new generic dcache. | 334 | * Internal lookup() using the new generic dcache. |
322 | * SMP-safe | 335 | * SMP-safe |
@@ -750,6 +763,7 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd) | |||
750 | struct qstr this; | 763 | struct qstr this; |
751 | unsigned int c; | 764 | unsigned int c; |
752 | 765 | ||
766 | nd->flags |= LOOKUP_CONTINUE; | ||
753 | err = exec_permission_lite(inode, nd); | 767 | err = exec_permission_lite(inode, nd); |
754 | if (err == -EAGAIN) { | 768 | if (err == -EAGAIN) { |
755 | err = permission(inode, MAY_EXEC, nd); | 769 | err = permission(inode, MAY_EXEC, nd); |
@@ -802,7 +816,6 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd) | |||
802 | if (err < 0) | 816 | if (err < 0) |
803 | break; | 817 | break; |
804 | } | 818 | } |
805 | nd->flags |= LOOKUP_CONTINUE; | ||
806 | /* This does the actual lookups.. */ | 819 | /* This does the actual lookups.. */ |
807 | err = do_lookup(nd, &this, &next); | 820 | err = do_lookup(nd, &this, &next); |
808 | if (err) | 821 | if (err) |
@@ -1052,6 +1065,70 @@ out: | |||
1052 | return retval; | 1065 | return retval; |
1053 | } | 1066 | } |
1054 | 1067 | ||
1068 | static int __path_lookup_intent_open(const char *name, unsigned int lookup_flags, | ||
1069 | struct nameidata *nd, int open_flags, int create_mode) | ||
1070 | { | ||
1071 | struct file *filp = get_empty_filp(); | ||
1072 | int err; | ||
1073 | |||
1074 | if (filp == NULL) | ||
1075 | return -ENFILE; | ||
1076 | nd->intent.open.file = filp; | ||
1077 | nd->intent.open.flags = open_flags; | ||
1078 | nd->intent.open.create_mode = create_mode; | ||
1079 | err = path_lookup(name, lookup_flags|LOOKUP_OPEN, nd); | ||
1080 | if (IS_ERR(nd->intent.open.file)) { | ||
1081 | if (err == 0) { | ||
1082 | err = PTR_ERR(nd->intent.open.file); | ||
1083 | path_release(nd); | ||
1084 | } | ||
1085 | } else if (err != 0) | ||
1086 | release_open_intent(nd); | ||
1087 | return err; | ||
1088 | } | ||
1089 | |||
1090 | /** | ||
1091 | * path_lookup_open - lookup a file path with open intent | ||
1092 | * @name: pointer to file name | ||
1093 | * @lookup_flags: lookup intent flags | ||
1094 | * @nd: pointer to nameidata | ||
1095 | * @open_flags: open intent flags | ||
1096 | */ | ||
1097 | int path_lookup_open(const char *name, unsigned int lookup_flags, | ||
1098 | struct nameidata *nd, int open_flags) | ||
1099 | { | ||
1100 | return __path_lookup_intent_open(name, lookup_flags, nd, | ||
1101 | open_flags, 0); | ||
1102 | } | ||
1103 | |||
1104 | /** | ||
1105 | * path_lookup_create - lookup a file path with open + create intent | ||
1106 | * @name: pointer to file name | ||
1107 | * @lookup_flags: lookup intent flags | ||
1108 | * @nd: pointer to nameidata | ||
1109 | * @open_flags: open intent flags | ||
1110 | * @create_mode: create intent flags | ||
1111 | */ | ||
1112 | int path_lookup_create(const char *name, unsigned int lookup_flags, | ||
1113 | struct nameidata *nd, int open_flags, int create_mode) | ||
1114 | { | ||
1115 | return __path_lookup_intent_open(name, lookup_flags|LOOKUP_CREATE, nd, | ||
1116 | open_flags, create_mode); | ||
1117 | } | ||
1118 | |||
1119 | int __user_path_lookup_open(const char __user *name, unsigned int lookup_flags, | ||
1120 | struct nameidata *nd, int open_flags) | ||
1121 | { | ||
1122 | char *tmp = getname(name); | ||
1123 | int err = PTR_ERR(tmp); | ||
1124 | |||
1125 | if (!IS_ERR(tmp)) { | ||
1126 | err = __path_lookup_intent_open(tmp, lookup_flags, nd, open_flags, 0); | ||
1127 | putname(tmp); | ||
1128 | } | ||
1129 | return err; | ||
1130 | } | ||
1131 | |||
1055 | /* | 1132 | /* |
1056 | * Restricted form of lookup. Doesn't follow links, single-component only, | 1133 | * Restricted form of lookup. Doesn't follow links, single-component only, |
1057 | * needs parent already locked. Doesn't follow mounts. | 1134 | * needs parent already locked. Doesn't follow mounts. |
@@ -1416,27 +1493,27 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) | |||
1416 | */ | 1493 | */ |
1417 | int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd) | 1494 | int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd) |
1418 | { | 1495 | { |
1419 | int acc_mode, error = 0; | 1496 | int acc_mode, error; |
1420 | struct path path; | 1497 | struct path path; |
1421 | struct dentry *dir; | 1498 | struct dentry *dir; |
1422 | int count = 0; | 1499 | int count = 0; |
1423 | 1500 | ||
1424 | acc_mode = ACC_MODE(flag); | 1501 | acc_mode = ACC_MODE(flag); |
1425 | 1502 | ||
1503 | /* O_TRUNC implies we need access checks for write permissions */ | ||
1504 | if (flag & O_TRUNC) | ||
1505 | acc_mode |= MAY_WRITE; | ||
1506 | |||
1426 | /* Allow the LSM permission hook to distinguish append | 1507 | /* Allow the LSM permission hook to distinguish append |
1427 | access from general write access. */ | 1508 | access from general write access. */ |
1428 | if (flag & O_APPEND) | 1509 | if (flag & O_APPEND) |
1429 | acc_mode |= MAY_APPEND; | 1510 | acc_mode |= MAY_APPEND; |
1430 | 1511 | ||
1431 | /* Fill in the open() intent data */ | ||
1432 | nd->intent.open.flags = flag; | ||
1433 | nd->intent.open.create_mode = mode; | ||
1434 | |||
1435 | /* | 1512 | /* |
1436 | * The simplest case - just a plain lookup. | 1513 | * The simplest case - just a plain lookup. |
1437 | */ | 1514 | */ |
1438 | if (!(flag & O_CREAT)) { | 1515 | if (!(flag & O_CREAT)) { |
1439 | error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd); | 1516 | error = path_lookup_open(pathname, lookup_flags(flag), nd, flag); |
1440 | if (error) | 1517 | if (error) |
1441 | return error; | 1518 | return error; |
1442 | goto ok; | 1519 | goto ok; |
@@ -1445,7 +1522,7 @@ int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd) | |||
1445 | /* | 1522 | /* |
1446 | * Create - we need to know the parent. | 1523 | * Create - we need to know the parent. |
1447 | */ | 1524 | */ |
1448 | error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd); | 1525 | error = path_lookup_create(pathname, LOOKUP_PARENT, nd, flag, mode); |
1449 | if (error) | 1526 | if (error) |
1450 | return error; | 1527 | return error; |
1451 | 1528 | ||
@@ -1520,6 +1597,8 @@ ok: | |||
1520 | exit_dput: | 1597 | exit_dput: |
1521 | dput_path(&path, nd); | 1598 | dput_path(&path, nd); |
1522 | exit: | 1599 | exit: |
1600 | if (!IS_ERR(nd->intent.open.file)) | ||
1601 | release_open_intent(nd); | ||
1523 | path_release(nd); | 1602 | path_release(nd); |
1524 | return error; | 1603 | return error; |
1525 | 1604 | ||
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index d7f7eb669d..44135af989 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c | |||
@@ -85,6 +85,10 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct | |||
85 | struct nfs_delegation *delegation; | 85 | struct nfs_delegation *delegation; |
86 | int status = 0; | 86 | int status = 0; |
87 | 87 | ||
88 | /* Ensure we first revalidate the attributes and page cache! */ | ||
89 | if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR))) | ||
90 | __nfs_revalidate_inode(NFS_SERVER(inode), inode); | ||
91 | |||
88 | delegation = nfs_alloc_delegation(); | 92 | delegation = nfs_alloc_delegation(); |
89 | if (delegation == NULL) | 93 | if (delegation == NULL) |
90 | return -ENOMEM; | 94 | return -ENOMEM; |
@@ -138,7 +142,7 @@ static void nfs_msync_inode(struct inode *inode) | |||
138 | /* | 142 | /* |
139 | * Basic procedure for returning a delegation to the server | 143 | * Basic procedure for returning a delegation to the server |
140 | */ | 144 | */ |
141 | int nfs_inode_return_delegation(struct inode *inode) | 145 | int __nfs_inode_return_delegation(struct inode *inode) |
142 | { | 146 | { |
143 | struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state; | 147 | struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state; |
144 | struct nfs_inode *nfsi = NFS_I(inode); | 148 | struct nfs_inode *nfsi = NFS_I(inode); |
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index 3f6c45a29d..8017846b56 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h | |||
@@ -25,7 +25,7 @@ struct nfs_delegation { | |||
25 | 25 | ||
26 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); | 26 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); |
27 | void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); | 27 | void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); |
28 | int nfs_inode_return_delegation(struct inode *inode); | 28 | int __nfs_inode_return_delegation(struct inode *inode); |
29 | int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid); | 29 | int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid); |
30 | 30 | ||
31 | struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle); | 31 | struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle); |
@@ -47,11 +47,25 @@ static inline int nfs_have_delegation(struct inode *inode, int flags) | |||
47 | return 1; | 47 | return 1; |
48 | return 0; | 48 | return 0; |
49 | } | 49 | } |
50 | |||
51 | static inline int nfs_inode_return_delegation(struct inode *inode) | ||
52 | { | ||
53 | int err = 0; | ||
54 | |||
55 | if (NFS_I(inode)->delegation != NULL) | ||
56 | err = __nfs_inode_return_delegation(inode); | ||
57 | return err; | ||
58 | } | ||
50 | #else | 59 | #else |
51 | static inline int nfs_have_delegation(struct inode *inode, int flags) | 60 | static inline int nfs_have_delegation(struct inode *inode, int flags) |
52 | { | 61 | { |
53 | return 0; | 62 | return 0; |
54 | } | 63 | } |
64 | |||
65 | static inline int nfs_inode_return_delegation(struct inode *inode) | ||
66 | { | ||
67 | return 0; | ||
68 | } | ||
55 | #endif | 69 | #endif |
56 | 70 | ||
57 | #endif | 71 | #endif |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index c70eabd6d1..eb50c19fc2 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -801,6 +801,7 @@ static int nfs_dentry_delete(struct dentry *dentry) | |||
801 | */ | 801 | */ |
802 | static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode) | 802 | static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode) |
803 | { | 803 | { |
804 | nfs_inode_return_delegation(inode); | ||
804 | if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { | 805 | if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { |
805 | lock_kernel(); | 806 | lock_kernel(); |
806 | inode->i_nlink--; | 807 | inode->i_nlink--; |
@@ -914,7 +915,6 @@ static int is_atomic_open(struct inode *dir, struct nameidata *nd) | |||
914 | static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 915 | static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
915 | { | 916 | { |
916 | struct dentry *res = NULL; | 917 | struct dentry *res = NULL; |
917 | struct inode *inode = NULL; | ||
918 | int error; | 918 | int error; |
919 | 919 | ||
920 | /* Check that we are indeed trying to open this file */ | 920 | /* Check that we are indeed trying to open this file */ |
@@ -928,8 +928,10 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
928 | dentry->d_op = NFS_PROTO(dir)->dentry_ops; | 928 | dentry->d_op = NFS_PROTO(dir)->dentry_ops; |
929 | 929 | ||
930 | /* Let vfs_create() deal with O_EXCL */ | 930 | /* Let vfs_create() deal with O_EXCL */ |
931 | if (nd->intent.open.flags & O_EXCL) | 931 | if (nd->intent.open.flags & O_EXCL) { |
932 | goto no_entry; | 932 | d_add(dentry, NULL); |
933 | goto out; | ||
934 | } | ||
933 | 935 | ||
934 | /* Open the file on the server */ | 936 | /* Open the file on the server */ |
935 | lock_kernel(); | 937 | lock_kernel(); |
@@ -943,32 +945,30 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
943 | 945 | ||
944 | if (nd->intent.open.flags & O_CREAT) { | 946 | if (nd->intent.open.flags & O_CREAT) { |
945 | nfs_begin_data_update(dir); | 947 | nfs_begin_data_update(dir); |
946 | inode = nfs4_atomic_open(dir, dentry, nd); | 948 | res = nfs4_atomic_open(dir, dentry, nd); |
947 | nfs_end_data_update(dir); | 949 | nfs_end_data_update(dir); |
948 | } else | 950 | } else |
949 | inode = nfs4_atomic_open(dir, dentry, nd); | 951 | res = nfs4_atomic_open(dir, dentry, nd); |
950 | unlock_kernel(); | 952 | unlock_kernel(); |
951 | if (IS_ERR(inode)) { | 953 | if (IS_ERR(res)) { |
952 | error = PTR_ERR(inode); | 954 | error = PTR_ERR(res); |
953 | switch (error) { | 955 | switch (error) { |
954 | /* Make a negative dentry */ | 956 | /* Make a negative dentry */ |
955 | case -ENOENT: | 957 | case -ENOENT: |
956 | inode = NULL; | 958 | res = NULL; |
957 | break; | 959 | goto out; |
958 | /* This turned out not to be a regular file */ | 960 | /* This turned out not to be a regular file */ |
961 | case -EISDIR: | ||
962 | case -ENOTDIR: | ||
963 | goto no_open; | ||
959 | case -ELOOP: | 964 | case -ELOOP: |
960 | if (!(nd->intent.open.flags & O_NOFOLLOW)) | 965 | if (!(nd->intent.open.flags & O_NOFOLLOW)) |
961 | goto no_open; | 966 | goto no_open; |
962 | /* case -EISDIR: */ | ||
963 | /* case -EINVAL: */ | 967 | /* case -EINVAL: */ |
964 | default: | 968 | default: |
965 | res = ERR_PTR(error); | ||
966 | goto out; | 969 | goto out; |
967 | } | 970 | } |
968 | } | 971 | } else if (res != NULL) |
969 | no_entry: | ||
970 | res = d_add_unique(dentry, inode); | ||
971 | if (res != NULL) | ||
972 | dentry = res; | 972 | dentry = res; |
973 | nfs_renew_times(dentry); | 973 | nfs_renew_times(dentry); |
974 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); | 974 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
@@ -1012,7 +1012,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
1012 | */ | 1012 | */ |
1013 | lock_kernel(); | 1013 | lock_kernel(); |
1014 | verifier = nfs_save_change_attribute(dir); | 1014 | verifier = nfs_save_change_attribute(dir); |
1015 | ret = nfs4_open_revalidate(dir, dentry, openflags); | 1015 | ret = nfs4_open_revalidate(dir, dentry, openflags, nd); |
1016 | if (!ret) | 1016 | if (!ret) |
1017 | nfs_set_verifier(dentry, verifier); | 1017 | nfs_set_verifier(dentry, verifier); |
1018 | unlock_kernel(); | 1018 | unlock_kernel(); |
@@ -1135,7 +1135,7 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode, | |||
1135 | 1135 | ||
1136 | lock_kernel(); | 1136 | lock_kernel(); |
1137 | nfs_begin_data_update(dir); | 1137 | nfs_begin_data_update(dir); |
1138 | error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags); | 1138 | error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, nd); |
1139 | nfs_end_data_update(dir); | 1139 | nfs_end_data_update(dir); |
1140 | if (error != 0) | 1140 | if (error != 0) |
1141 | goto out_err; | 1141 | goto out_err; |
@@ -1330,6 +1330,7 @@ static int nfs_safe_remove(struct dentry *dentry) | |||
1330 | 1330 | ||
1331 | nfs_begin_data_update(dir); | 1331 | nfs_begin_data_update(dir); |
1332 | if (inode != NULL) { | 1332 | if (inode != NULL) { |
1333 | nfs_inode_return_delegation(inode); | ||
1333 | nfs_begin_data_update(inode); | 1334 | nfs_begin_data_update(inode); |
1334 | error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); | 1335 | error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); |
1335 | /* The VFS may want to delete this inode */ | 1336 | /* The VFS may want to delete this inode */ |
@@ -1510,9 +1511,11 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1510 | */ | 1511 | */ |
1511 | if (!new_inode) | 1512 | if (!new_inode) |
1512 | goto go_ahead; | 1513 | goto go_ahead; |
1513 | if (S_ISDIR(new_inode->i_mode)) | 1514 | if (S_ISDIR(new_inode->i_mode)) { |
1514 | goto out; | 1515 | error = -EISDIR; |
1515 | else if (atomic_read(&new_dentry->d_count) > 2) { | 1516 | if (!S_ISDIR(old_inode->i_mode)) |
1517 | goto out; | ||
1518 | } else if (atomic_read(&new_dentry->d_count) > 2) { | ||
1516 | int err; | 1519 | int err; |
1517 | /* copy the target dentry's name */ | 1520 | /* copy the target dentry's name */ |
1518 | dentry = d_alloc(new_dentry->d_parent, | 1521 | dentry = d_alloc(new_dentry->d_parent, |
@@ -1548,6 +1551,7 @@ go_ahead: | |||
1548 | nfs_wb_all(old_inode); | 1551 | nfs_wb_all(old_inode); |
1549 | shrink_dcache_parent(old_dentry); | 1552 | shrink_dcache_parent(old_dentry); |
1550 | } | 1553 | } |
1554 | nfs_inode_return_delegation(old_inode); | ||
1551 | 1555 | ||
1552 | if (new_inode) | 1556 | if (new_inode) |
1553 | d_delete(new_dentry); | 1557 | d_delete(new_dentry); |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f6b9eda925..572d859348 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
@@ -137,7 +137,8 @@ static int nfs_revalidate_file(struct inode *inode, struct file *filp) | |||
137 | struct nfs_inode *nfsi = NFS_I(inode); | 137 | struct nfs_inode *nfsi = NFS_I(inode); |
138 | int retval = 0; | 138 | int retval = 0; |
139 | 139 | ||
140 | if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) || nfs_attribute_timeout(inode)) | 140 | if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR)) |
141 | || nfs_attribute_timeout(inode)) | ||
141 | retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode); | 142 | retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode); |
142 | nfs_revalidate_mapping(inode, filp->f_mapping); | 143 | nfs_revalidate_mapping(inode, filp->f_mapping); |
143 | return 0; | 144 | return 0; |
@@ -375,22 +376,31 @@ out_swapfile: | |||
375 | 376 | ||
376 | static int do_getlk(struct file *filp, int cmd, struct file_lock *fl) | 377 | static int do_getlk(struct file *filp, int cmd, struct file_lock *fl) |
377 | { | 378 | { |
379 | struct file_lock *cfl; | ||
378 | struct inode *inode = filp->f_mapping->host; | 380 | struct inode *inode = filp->f_mapping->host; |
379 | int status = 0; | 381 | int status = 0; |
380 | 382 | ||
381 | lock_kernel(); | 383 | lock_kernel(); |
382 | /* Use local locking if mounted with "-onolock" */ | 384 | /* Try local locking first */ |
383 | if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) | 385 | cfl = posix_test_lock(filp, fl); |
384 | status = NFS_PROTO(inode)->lock(filp, cmd, fl); | 386 | if (cfl != NULL) { |
385 | else { | 387 | locks_copy_lock(fl, cfl); |
386 | struct file_lock *cfl = posix_test_lock(filp, fl); | 388 | goto out; |
387 | |||
388 | fl->fl_type = F_UNLCK; | ||
389 | if (cfl != NULL) | ||
390 | memcpy(fl, cfl, sizeof(*fl)); | ||
391 | } | 389 | } |
390 | |||
391 | if (nfs_have_delegation(inode, FMODE_READ)) | ||
392 | goto out_noconflict; | ||
393 | |||
394 | if (NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM) | ||
395 | goto out_noconflict; | ||
396 | |||
397 | status = NFS_PROTO(inode)->lock(filp, cmd, fl); | ||
398 | out: | ||
392 | unlock_kernel(); | 399 | unlock_kernel(); |
393 | return status; | 400 | return status; |
401 | out_noconflict: | ||
402 | fl->fl_type = F_UNLCK; | ||
403 | goto out; | ||
394 | } | 404 | } |
395 | 405 | ||
396 | static int do_vfs_lock(struct file *file, struct file_lock *fl) | 406 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 358d8ef8c0..65d5ab45dd 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -853,6 +853,11 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
853 | filemap_fdatawait(inode->i_mapping); | 853 | filemap_fdatawait(inode->i_mapping); |
854 | nfs_wb_all(inode); | 854 | nfs_wb_all(inode); |
855 | } | 855 | } |
856 | /* | ||
857 | * Return any delegations if we're going to change ACLs | ||
858 | */ | ||
859 | if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) | ||
860 | nfs_inode_return_delegation(inode); | ||
856 | error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr); | 861 | error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr); |
857 | if (error == 0) | 862 | if (error == 0) |
858 | nfs_refresh_inode(inode, &fattr); | 863 | nfs_refresh_inode(inode, &fattr); |
@@ -909,12 +914,10 @@ static int nfs_wait_on_inode(struct inode *inode) | |||
909 | sigset_t oldmask; | 914 | sigset_t oldmask; |
910 | int error; | 915 | int error; |
911 | 916 | ||
912 | atomic_inc(&inode->i_count); | ||
913 | rpc_clnt_sigmask(clnt, &oldmask); | 917 | rpc_clnt_sigmask(clnt, &oldmask); |
914 | error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING, | 918 | error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING, |
915 | nfs_wait_schedule, TASK_INTERRUPTIBLE); | 919 | nfs_wait_schedule, TASK_INTERRUPTIBLE); |
916 | rpc_clnt_sigunmask(clnt, &oldmask); | 920 | rpc_clnt_sigunmask(clnt, &oldmask); |
917 | iput(inode); | ||
918 | 921 | ||
919 | return error; | 922 | return error; |
920 | } | 923 | } |
@@ -1258,10 +1261,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1258 | loff_t cur_size, new_isize; | 1261 | loff_t cur_size, new_isize; |
1259 | int data_unstable; | 1262 | int data_unstable; |
1260 | 1263 | ||
1261 | /* Do we hold a delegation? */ | ||
1262 | if (nfs_have_delegation(inode, FMODE_READ)) | ||
1263 | return 0; | ||
1264 | |||
1265 | spin_lock(&inode->i_lock); | 1264 | spin_lock(&inode->i_lock); |
1266 | 1265 | ||
1267 | /* Are we in the process of updating data on the server? */ | 1266 | /* Are we in the process of updating data on the server? */ |
@@ -1382,7 +1381,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr, unsign | |||
1382 | nfsi->read_cache_jiffies = fattr->timestamp; | 1381 | nfsi->read_cache_jiffies = fattr->timestamp; |
1383 | 1382 | ||
1384 | /* Are we racing with known updates of the metadata on the server? */ | 1383 | /* Are we racing with known updates of the metadata on the server? */ |
1385 | data_unstable = ! nfs_verify_change_attribute(inode, verifier); | 1384 | data_unstable = ! (nfs_verify_change_attribute(inode, verifier) || |
1385 | (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)); | ||
1386 | 1386 | ||
1387 | /* Check if our cached file size is stale */ | 1387 | /* Check if our cached file size is stale */ |
1388 | new_isize = nfs_size_to_loff_t(fattr->size); | 1388 | new_isize = nfs_size_to_loff_t(fattr->size); |
@@ -1676,8 +1676,7 @@ static void nfs4_clear_inode(struct inode *inode) | |||
1676 | struct nfs_inode *nfsi = NFS_I(inode); | 1676 | struct nfs_inode *nfsi = NFS_I(inode); |
1677 | 1677 | ||
1678 | /* If we are holding a delegation, return it! */ | 1678 | /* If we are holding a delegation, return it! */ |
1679 | if (nfsi->delegation != NULL) | 1679 | nfs_inode_return_delegation(inode); |
1680 | nfs_inode_return_delegation(inode); | ||
1681 | /* First call standard NFS clear_inode() code */ | 1680 | /* First call standard NFS clear_inode() code */ |
1682 | nfs_clear_inode(inode); | 1681 | nfs_clear_inode(inode); |
1683 | /* Now clear out any remaining state */ | 1682 | /* Now clear out any remaining state */ |
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c index edc9551404..df80477c5a 100644 --- a/fs/nfs/nfs3proc.c +++ b/fs/nfs/nfs3proc.c | |||
@@ -299,7 +299,7 @@ static int nfs3_proc_commit(struct nfs_write_data *cdata) | |||
299 | */ | 299 | */ |
300 | static int | 300 | static int |
301 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 301 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
302 | int flags) | 302 | int flags, struct nameidata *nd) |
303 | { | 303 | { |
304 | struct nfs_fh fhandle; | 304 | struct nfs_fh fhandle; |
305 | struct nfs_fattr fattr; | 305 | struct nfs_fattr fattr; |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index ec1a22d7b8..8a37881990 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
@@ -93,25 +93,50 @@ struct nfs4_client { | |||
93 | }; | 93 | }; |
94 | 94 | ||
95 | /* | 95 | /* |
96 | * struct rpc_sequence ensures that RPC calls are sent in the exact | ||
97 | * order that they appear on the list. | ||
98 | */ | ||
99 | struct rpc_sequence { | ||
100 | struct rpc_wait_queue wait; /* RPC call delay queue */ | ||
101 | spinlock_t lock; /* Protects the list */ | ||
102 | struct list_head list; /* Defines sequence of RPC calls */ | ||
103 | }; | ||
104 | |||
105 | #define NFS_SEQID_CONFIRMED 1 | ||
106 | struct nfs_seqid_counter { | ||
107 | struct rpc_sequence *sequence; | ||
108 | int flags; | ||
109 | u32 counter; | ||
110 | }; | ||
111 | |||
112 | struct nfs_seqid { | ||
113 | struct list_head list; | ||
114 | struct nfs_seqid_counter *sequence; | ||
115 | struct rpc_task *task; | ||
116 | }; | ||
117 | |||
118 | static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) | ||
119 | { | ||
120 | if (seqid_mutating_err(-status)) | ||
121 | seqid->flags |= NFS_SEQID_CONFIRMED; | ||
122 | } | ||
123 | |||
124 | /* | ||
96 | * NFS4 state_owners and lock_owners are simply labels for ordered | 125 | * NFS4 state_owners and lock_owners are simply labels for ordered |
97 | * sequences of RPC calls. Their sole purpose is to provide once-only | 126 | * sequences of RPC calls. Their sole purpose is to provide once-only |
98 | * semantics by allowing the server to identify replayed requests. | 127 | * semantics by allowing the server to identify replayed requests. |
99 | * | ||
100 | * The ->so_sema is held during all state_owner seqid-mutating operations: | ||
101 | * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize | ||
102 | * so_seqid. | ||
103 | */ | 128 | */ |
104 | struct nfs4_state_owner { | 129 | struct nfs4_state_owner { |
105 | struct list_head so_list; /* per-clientid list of state_owners */ | 130 | struct list_head so_list; /* per-clientid list of state_owners */ |
106 | struct nfs4_client *so_client; | 131 | struct nfs4_client *so_client; |
107 | u32 so_id; /* 32-bit identifier, unique */ | 132 | u32 so_id; /* 32-bit identifier, unique */ |
108 | struct semaphore so_sema; | ||
109 | u32 so_seqid; /* protected by so_sema */ | ||
110 | atomic_t so_count; | 133 | atomic_t so_count; |
111 | 134 | ||
112 | struct rpc_cred *so_cred; /* Associated cred */ | 135 | struct rpc_cred *so_cred; /* Associated cred */ |
113 | struct list_head so_states; | 136 | struct list_head so_states; |
114 | struct list_head so_delegations; | 137 | struct list_head so_delegations; |
138 | struct nfs_seqid_counter so_seqid; | ||
139 | struct rpc_sequence so_sequence; | ||
115 | }; | 140 | }; |
116 | 141 | ||
117 | /* | 142 | /* |
@@ -132,7 +157,7 @@ struct nfs4_lock_state { | |||
132 | fl_owner_t ls_owner; /* POSIX lock owner */ | 157 | fl_owner_t ls_owner; /* POSIX lock owner */ |
133 | #define NFS_LOCK_INITIALIZED 1 | 158 | #define NFS_LOCK_INITIALIZED 1 |
134 | int ls_flags; | 159 | int ls_flags; |
135 | u32 ls_seqid; | 160 | struct nfs_seqid_counter ls_seqid; |
136 | u32 ls_id; | 161 | u32 ls_id; |
137 | nfs4_stateid ls_stateid; | 162 | nfs4_stateid ls_stateid; |
138 | atomic_t ls_count; | 163 | atomic_t ls_count; |
@@ -153,7 +178,6 @@ struct nfs4_state { | |||
153 | struct inode *inode; /* Pointer to the inode */ | 178 | struct inode *inode; /* Pointer to the inode */ |
154 | 179 | ||
155 | unsigned long flags; /* Do we hold any locks? */ | 180 | unsigned long flags; /* Do we hold any locks? */ |
156 | struct semaphore lock_sema; /* Serializes file locking operations */ | ||
157 | spinlock_t state_lock; /* Protects the lock_states list */ | 181 | spinlock_t state_lock; /* Protects the lock_states list */ |
158 | 182 | ||
159 | nfs4_stateid stateid; | 183 | nfs4_stateid stateid; |
@@ -191,8 +215,8 @@ extern int nfs4_proc_setclientid_confirm(struct nfs4_client *); | |||
191 | extern int nfs4_proc_async_renew(struct nfs4_client *); | 215 | extern int nfs4_proc_async_renew(struct nfs4_client *); |
192 | extern int nfs4_proc_renew(struct nfs4_client *); | 216 | extern int nfs4_proc_renew(struct nfs4_client *); |
193 | extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode); | 217 | extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode); |
194 | extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); | 218 | extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *); |
195 | extern int nfs4_open_revalidate(struct inode *, struct dentry *, int); | 219 | extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); |
196 | 220 | ||
197 | extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops; | 221 | extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops; |
198 | extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops; | 222 | extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops; |
@@ -224,12 +248,17 @@ extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state | |||
224 | extern void nfs4_put_open_state(struct nfs4_state *); | 248 | extern void nfs4_put_open_state(struct nfs4_state *); |
225 | extern void nfs4_close_state(struct nfs4_state *, mode_t); | 249 | extern void nfs4_close_state(struct nfs4_state *, mode_t); |
226 | extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode); | 250 | extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode); |
227 | extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp); | ||
228 | extern void nfs4_schedule_state_recovery(struct nfs4_client *); | 251 | extern void nfs4_schedule_state_recovery(struct nfs4_client *); |
252 | extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); | ||
229 | extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); | 253 | extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); |
230 | extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls); | ||
231 | extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); | 254 | extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); |
232 | 255 | ||
256 | extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter); | ||
257 | extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); | ||
258 | extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); | ||
259 | extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); | ||
260 | extern void nfs_free_seqid(struct nfs_seqid *seqid); | ||
261 | |||
233 | extern const nfs4_stateid zero_stateid; | 262 | extern const nfs4_stateid zero_stateid; |
234 | 263 | ||
235 | /* nfs4xdr.c */ | 264 | /* nfs4xdr.c */ |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 9701ca8c94..ff378126cc 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/nfs_page.h> | 47 | #include <linux/nfs_page.h> |
48 | #include <linux/smp_lock.h> | 48 | #include <linux/smp_lock.h> |
49 | #include <linux/namei.h> | 49 | #include <linux/namei.h> |
50 | #include <linux/mount.h> | ||
50 | 51 | ||
51 | #include "nfs4_fs.h" | 52 | #include "nfs4_fs.h" |
52 | #include "delegation.h" | 53 | #include "delegation.h" |
@@ -56,10 +57,11 @@ | |||
56 | #define NFS4_POLL_RETRY_MIN (1*HZ) | 57 | #define NFS4_POLL_RETRY_MIN (1*HZ) |
57 | #define NFS4_POLL_RETRY_MAX (15*HZ) | 58 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
58 | 59 | ||
60 | static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid); | ||
59 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); | 61 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
60 | static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *); | 62 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *); |
61 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); | 63 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); |
62 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception); | 64 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception); |
63 | extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); | 65 | extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); |
64 | extern struct rpc_procinfo nfs4_procedures[]; | 66 | extern struct rpc_procinfo nfs4_procedures[]; |
65 | 67 | ||
@@ -189,6 +191,21 @@ static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinf | |||
189 | nfsi->change_attr = cinfo->after; | 191 | nfsi->change_attr = cinfo->after; |
190 | } | 192 | } |
191 | 193 | ||
194 | /* Helper for asynchronous RPC calls */ | ||
195 | static int nfs4_call_async(struct rpc_clnt *clnt, rpc_action tk_begin, | ||
196 | rpc_action tk_exit, void *calldata) | ||
197 | { | ||
198 | struct rpc_task *task; | ||
199 | |||
200 | if (!(task = rpc_new_task(clnt, tk_exit, RPC_TASK_ASYNC))) | ||
201 | return -ENOMEM; | ||
202 | |||
203 | task->tk_calldata = calldata; | ||
204 | task->tk_action = tk_begin; | ||
205 | rpc_execute(task); | ||
206 | return 0; | ||
207 | } | ||
208 | |||
192 | static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) | 209 | static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) |
193 | { | 210 | { |
194 | struct inode *inode = state->inode; | 211 | struct inode *inode = state->inode; |
@@ -209,7 +226,6 @@ static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, | |||
209 | /* | 226 | /* |
210 | * OPEN_RECLAIM: | 227 | * OPEN_RECLAIM: |
211 | * reclaim state on the server after a reboot. | 228 | * reclaim state on the server after a reboot. |
212 | * Assumes caller is holding the sp->so_sem | ||
213 | */ | 229 | */ |
214 | static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) | 230 | static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
215 | { | 231 | { |
@@ -218,7 +234,6 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st | |||
218 | struct nfs_delegation *delegation = NFS_I(inode)->delegation; | 234 | struct nfs_delegation *delegation = NFS_I(inode)->delegation; |
219 | struct nfs_openargs o_arg = { | 235 | struct nfs_openargs o_arg = { |
220 | .fh = NFS_FH(inode), | 236 | .fh = NFS_FH(inode), |
221 | .seqid = sp->so_seqid, | ||
222 | .id = sp->so_id, | 237 | .id = sp->so_id, |
223 | .open_flags = state->state, | 238 | .open_flags = state->state, |
224 | .clientid = server->nfs4_state->cl_clientid, | 239 | .clientid = server->nfs4_state->cl_clientid, |
@@ -245,8 +260,13 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st | |||
245 | } | 260 | } |
246 | o_arg.u.delegation_type = delegation->type; | 261 | o_arg.u.delegation_type = delegation->type; |
247 | } | 262 | } |
263 | o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); | ||
264 | if (o_arg.seqid == NULL) | ||
265 | return -ENOMEM; | ||
248 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 266 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); |
249 | nfs4_increment_seqid(status, sp); | 267 | /* Confirm the sequence as being established */ |
268 | nfs_confirm_seqid(&sp->so_seqid, status); | ||
269 | nfs_increment_open_seqid(status, o_arg.seqid); | ||
250 | if (status == 0) { | 270 | if (status == 0) { |
251 | memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid)); | 271 | memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid)); |
252 | if (o_res.delegation_type != 0) { | 272 | if (o_res.delegation_type != 0) { |
@@ -256,6 +276,7 @@ static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *st | |||
256 | nfs_async_inode_return_delegation(inode, &o_res.stateid); | 276 | nfs_async_inode_return_delegation(inode, &o_res.stateid); |
257 | } | 277 | } |
258 | } | 278 | } |
279 | nfs_free_seqid(o_arg.seqid); | ||
259 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 280 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
260 | /* Ensure we update the inode attributes */ | 281 | /* Ensure we update the inode attributes */ |
261 | NFS_CACHEINV(inode); | 282 | NFS_CACHEINV(inode); |
@@ -302,23 +323,35 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state | |||
302 | }; | 323 | }; |
303 | int status = 0; | 324 | int status = 0; |
304 | 325 | ||
305 | down(&sp->so_sema); | ||
306 | if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) | 326 | if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) |
307 | goto out; | 327 | goto out; |
308 | if (state->state == 0) | 328 | if (state->state == 0) |
309 | goto out; | 329 | goto out; |
310 | arg.seqid = sp->so_seqid; | 330 | arg.seqid = nfs_alloc_seqid(&sp->so_seqid); |
331 | status = -ENOMEM; | ||
332 | if (arg.seqid == NULL) | ||
333 | goto out; | ||
311 | arg.open_flags = state->state; | 334 | arg.open_flags = state->state; |
312 | memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data)); | 335 | memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data)); |
313 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 336 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); |
314 | nfs4_increment_seqid(status, sp); | 337 | nfs_increment_open_seqid(status, arg.seqid); |
338 | if (status != 0) | ||
339 | goto out_free; | ||
340 | if(res.rflags & NFS4_OPEN_RESULT_CONFIRM) { | ||
341 | status = _nfs4_proc_open_confirm(server->client, NFS_FH(inode), | ||
342 | sp, &res.stateid, arg.seqid); | ||
343 | if (status != 0) | ||
344 | goto out_free; | ||
345 | } | ||
346 | nfs_confirm_seqid(&sp->so_seqid, 0); | ||
315 | if (status >= 0) { | 347 | if (status >= 0) { |
316 | memcpy(state->stateid.data, res.stateid.data, | 348 | memcpy(state->stateid.data, res.stateid.data, |
317 | sizeof(state->stateid.data)); | 349 | sizeof(state->stateid.data)); |
318 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 350 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
319 | } | 351 | } |
352 | out_free: | ||
353 | nfs_free_seqid(arg.seqid); | ||
320 | out: | 354 | out: |
321 | up(&sp->so_sema); | ||
322 | dput(parent); | 355 | dput(parent); |
323 | return status; | 356 | return status; |
324 | } | 357 | } |
@@ -345,11 +378,11 @@ int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state) | |||
345 | return err; | 378 | return err; |
346 | } | 379 | } |
347 | 380 | ||
348 | static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid) | 381 | static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid) |
349 | { | 382 | { |
350 | struct nfs_open_confirmargs arg = { | 383 | struct nfs_open_confirmargs arg = { |
351 | .fh = fh, | 384 | .fh = fh, |
352 | .seqid = sp->so_seqid, | 385 | .seqid = seqid, |
353 | .stateid = *stateid, | 386 | .stateid = *stateid, |
354 | }; | 387 | }; |
355 | struct nfs_open_confirmres res; | 388 | struct nfs_open_confirmres res; |
@@ -362,7 +395,9 @@ static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nf | |||
362 | int status; | 395 | int status; |
363 | 396 | ||
364 | status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR); | 397 | status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR); |
365 | nfs4_increment_seqid(status, sp); | 398 | /* Confirm the sequence as being established */ |
399 | nfs_confirm_seqid(&sp->so_seqid, status); | ||
400 | nfs_increment_open_seqid(status, seqid); | ||
366 | if (status >= 0) | 401 | if (status >= 0) |
367 | memcpy(stateid, &res.stateid, sizeof(*stateid)); | 402 | memcpy(stateid, &res.stateid, sizeof(*stateid)); |
368 | return status; | 403 | return status; |
@@ -380,21 +415,37 @@ static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner *sp, stru | |||
380 | int status; | 415 | int status; |
381 | 416 | ||
382 | /* Update sequence id. The caller must serialize! */ | 417 | /* Update sequence id. The caller must serialize! */ |
383 | o_arg->seqid = sp->so_seqid; | ||
384 | o_arg->id = sp->so_id; | 418 | o_arg->id = sp->so_id; |
385 | o_arg->clientid = sp->so_client->cl_clientid; | 419 | o_arg->clientid = sp->so_client->cl_clientid; |
386 | 420 | ||
387 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 421 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); |
388 | nfs4_increment_seqid(status, sp); | 422 | if (status == 0) { |
423 | /* OPEN on anything except a regular file is disallowed in NFSv4 */ | ||
424 | switch (o_res->f_attr->mode & S_IFMT) { | ||
425 | case S_IFREG: | ||
426 | break; | ||
427 | case S_IFLNK: | ||
428 | status = -ELOOP; | ||
429 | break; | ||
430 | case S_IFDIR: | ||
431 | status = -EISDIR; | ||
432 | break; | ||
433 | default: | ||
434 | status = -ENOTDIR; | ||
435 | } | ||
436 | } | ||
437 | |||
438 | nfs_increment_open_seqid(status, o_arg->seqid); | ||
389 | if (status != 0) | 439 | if (status != 0) |
390 | goto out; | 440 | goto out; |
391 | update_changeattr(dir, &o_res->cinfo); | 441 | update_changeattr(dir, &o_res->cinfo); |
392 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 442 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
393 | status = _nfs4_proc_open_confirm(server->client, &o_res->fh, | 443 | status = _nfs4_proc_open_confirm(server->client, &o_res->fh, |
394 | sp, &o_res->stateid); | 444 | sp, &o_res->stateid, o_arg->seqid); |
395 | if (status != 0) | 445 | if (status != 0) |
396 | goto out; | 446 | goto out; |
397 | } | 447 | } |
448 | nfs_confirm_seqid(&sp->so_seqid, 0); | ||
398 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) | 449 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
399 | status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr); | 450 | status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr); |
400 | out: | 451 | out: |
@@ -465,6 +516,10 @@ static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st | |||
465 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 516 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
466 | goto out; | 517 | goto out; |
467 | } | 518 | } |
519 | o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); | ||
520 | status = -ENOMEM; | ||
521 | if (o_arg.seqid == NULL) | ||
522 | goto out; | ||
468 | status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); | 523 | status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); |
469 | if (status != 0) | 524 | if (status != 0) |
470 | goto out_nodeleg; | 525 | goto out_nodeleg; |
@@ -490,6 +545,7 @@ static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st | |||
490 | nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res); | 545 | nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res); |
491 | } | 546 | } |
492 | out_nodeleg: | 547 | out_nodeleg: |
548 | nfs_free_seqid(o_arg.seqid); | ||
493 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | 549 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
494 | out: | 550 | out: |
495 | dput(parent); | 551 | dput(parent); |
@@ -564,7 +620,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred | |||
564 | dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); | 620 | dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); |
565 | goto out_err; | 621 | goto out_err; |
566 | } | 622 | } |
567 | down(&sp->so_sema); | ||
568 | state = nfs4_get_open_state(inode, sp); | 623 | state = nfs4_get_open_state(inode, sp); |
569 | if (state == NULL) | 624 | if (state == NULL) |
570 | goto out_err; | 625 | goto out_err; |
@@ -589,7 +644,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred | |||
589 | set_bit(NFS_DELEGATED_STATE, &state->flags); | 644 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
590 | update_open_stateid(state, &delegation->stateid, open_flags); | 645 | update_open_stateid(state, &delegation->stateid, open_flags); |
591 | out_ok: | 646 | out_ok: |
592 | up(&sp->so_sema); | ||
593 | nfs4_put_state_owner(sp); | 647 | nfs4_put_state_owner(sp); |
594 | up_read(&nfsi->rwsem); | 648 | up_read(&nfsi->rwsem); |
595 | up_read(&clp->cl_sem); | 649 | up_read(&clp->cl_sem); |
@@ -600,11 +654,12 @@ out_err: | |||
600 | if (sp != NULL) { | 654 | if (sp != NULL) { |
601 | if (state != NULL) | 655 | if (state != NULL) |
602 | nfs4_put_open_state(state); | 656 | nfs4_put_open_state(state); |
603 | up(&sp->so_sema); | ||
604 | nfs4_put_state_owner(sp); | 657 | nfs4_put_state_owner(sp); |
605 | } | 658 | } |
606 | up_read(&nfsi->rwsem); | 659 | up_read(&nfsi->rwsem); |
607 | up_read(&clp->cl_sem); | 660 | up_read(&clp->cl_sem); |
661 | if (err != -EACCES) | ||
662 | nfs_inode_return_delegation(inode); | ||
608 | return err; | 663 | return err; |
609 | } | 664 | } |
610 | 665 | ||
@@ -665,8 +720,10 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st | |||
665 | } else | 720 | } else |
666 | o_arg.u.attrs = sattr; | 721 | o_arg.u.attrs = sattr; |
667 | /* Serialization for the sequence id */ | 722 | /* Serialization for the sequence id */ |
668 | down(&sp->so_sema); | ||
669 | 723 | ||
724 | o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); | ||
725 | if (o_arg.seqid == NULL) | ||
726 | return -ENOMEM; | ||
670 | status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); | 727 | status = _nfs4_proc_open(dir, sp, &o_arg, &o_res); |
671 | if (status != 0) | 728 | if (status != 0) |
672 | goto out_err; | 729 | goto out_err; |
@@ -681,7 +738,7 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st | |||
681 | update_open_stateid(state, &o_res.stateid, flags); | 738 | update_open_stateid(state, &o_res.stateid, flags); |
682 | if (o_res.delegation_type != 0) | 739 | if (o_res.delegation_type != 0) |
683 | nfs_inode_set_delegation(inode, cred, &o_res); | 740 | nfs_inode_set_delegation(inode, cred, &o_res); |
684 | up(&sp->so_sema); | 741 | nfs_free_seqid(o_arg.seqid); |
685 | nfs4_put_state_owner(sp); | 742 | nfs4_put_state_owner(sp); |
686 | up_read(&clp->cl_sem); | 743 | up_read(&clp->cl_sem); |
687 | *res = state; | 744 | *res = state; |
@@ -690,7 +747,7 @@ out_err: | |||
690 | if (sp != NULL) { | 747 | if (sp != NULL) { |
691 | if (state != NULL) | 748 | if (state != NULL) |
692 | nfs4_put_open_state(state); | 749 | nfs4_put_open_state(state); |
693 | up(&sp->so_sema); | 750 | nfs_free_seqid(o_arg.seqid); |
694 | nfs4_put_state_owner(sp); | 751 | nfs4_put_state_owner(sp); |
695 | } | 752 | } |
696 | /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ | 753 | /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ |
@@ -718,7 +775,7 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, | |||
718 | * It is actually a sign of a bug on the client or on the server. | 775 | * It is actually a sign of a bug on the client or on the server. |
719 | * | 776 | * |
720 | * If we receive a BAD_SEQID error in the particular case of | 777 | * If we receive a BAD_SEQID error in the particular case of |
721 | * doing an OPEN, we assume that nfs4_increment_seqid() will | 778 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
722 | * have unhashed the old state_owner for us, and that we can | 779 | * have unhashed the old state_owner for us, and that we can |
723 | * therefore safely retry using a new one. We should still warn | 780 | * therefore safely retry using a new one. We should still warn |
724 | * the user though... | 781 | * the user though... |
@@ -728,6 +785,16 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, | |||
728 | exception.retry = 1; | 785 | exception.retry = 1; |
729 | continue; | 786 | continue; |
730 | } | 787 | } |
788 | /* | ||
789 | * BAD_STATEID on OPEN means that the server cancelled our | ||
790 | * state before it received the OPEN_CONFIRM. | ||
791 | * Recover by retrying the request as per the discussion | ||
792 | * on Page 181 of RFC3530. | ||
793 | */ | ||
794 | if (status == -NFS4ERR_BAD_STATEID) { | ||
795 | exception.retry = 1; | ||
796 | continue; | ||
797 | } | ||
731 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), | 798 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
732 | status, &exception)); | 799 | status, &exception)); |
733 | } while (exception.retry); | 800 | } while (exception.retry); |
@@ -789,17 +856,27 @@ struct nfs4_closedata { | |||
789 | struct nfs_closeres res; | 856 | struct nfs_closeres res; |
790 | }; | 857 | }; |
791 | 858 | ||
859 | static void nfs4_free_closedata(struct nfs4_closedata *calldata) | ||
860 | { | ||
861 | struct nfs4_state *state = calldata->state; | ||
862 | struct nfs4_state_owner *sp = state->owner; | ||
863 | |||
864 | nfs4_put_open_state(calldata->state); | ||
865 | nfs_free_seqid(calldata->arg.seqid); | ||
866 | nfs4_put_state_owner(sp); | ||
867 | kfree(calldata); | ||
868 | } | ||
869 | |||
792 | static void nfs4_close_done(struct rpc_task *task) | 870 | static void nfs4_close_done(struct rpc_task *task) |
793 | { | 871 | { |
794 | struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata; | 872 | struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata; |
795 | struct nfs4_state *state = calldata->state; | 873 | struct nfs4_state *state = calldata->state; |
796 | struct nfs4_state_owner *sp = state->owner; | ||
797 | struct nfs_server *server = NFS_SERVER(calldata->inode); | 874 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
798 | 875 | ||
799 | /* hmm. we are done with the inode, and in the process of freeing | 876 | /* hmm. we are done with the inode, and in the process of freeing |
800 | * the state_owner. we keep this around to process errors | 877 | * the state_owner. we keep this around to process errors |
801 | */ | 878 | */ |
802 | nfs4_increment_seqid(task->tk_status, sp); | 879 | nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid); |
803 | switch (task->tk_status) { | 880 | switch (task->tk_status) { |
804 | case 0: | 881 | case 0: |
805 | memcpy(&state->stateid, &calldata->res.stateid, | 882 | memcpy(&state->stateid, &calldata->res.stateid, |
@@ -817,24 +894,46 @@ static void nfs4_close_done(struct rpc_task *task) | |||
817 | } | 894 | } |
818 | } | 895 | } |
819 | state->state = calldata->arg.open_flags; | 896 | state->state = calldata->arg.open_flags; |
820 | nfs4_put_open_state(state); | 897 | nfs4_free_closedata(calldata); |
821 | up(&sp->so_sema); | ||
822 | nfs4_put_state_owner(sp); | ||
823 | up_read(&server->nfs4_state->cl_sem); | ||
824 | kfree(calldata); | ||
825 | } | 898 | } |
826 | 899 | ||
827 | static inline int nfs4_close_call(struct rpc_clnt *clnt, struct nfs4_closedata *calldata) | 900 | static void nfs4_close_begin(struct rpc_task *task) |
828 | { | 901 | { |
902 | struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata; | ||
903 | struct nfs4_state *state = calldata->state; | ||
829 | struct rpc_message msg = { | 904 | struct rpc_message msg = { |
830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], | 905 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
831 | .rpc_argp = &calldata->arg, | 906 | .rpc_argp = &calldata->arg, |
832 | .rpc_resp = &calldata->res, | 907 | .rpc_resp = &calldata->res, |
833 | .rpc_cred = calldata->state->owner->so_cred, | 908 | .rpc_cred = state->owner->so_cred, |
834 | }; | 909 | }; |
835 | if (calldata->arg.open_flags != 0) | 910 | int mode = 0; |
911 | int status; | ||
912 | |||
913 | status = nfs_wait_on_sequence(calldata->arg.seqid, task); | ||
914 | if (status != 0) | ||
915 | return; | ||
916 | /* Don't reorder reads */ | ||
917 | smp_rmb(); | ||
918 | /* Recalculate the new open mode in case someone reopened the file | ||
919 | * while we were waiting in line to be scheduled. | ||
920 | */ | ||
921 | if (state->nreaders != 0) | ||
922 | mode |= FMODE_READ; | ||
923 | if (state->nwriters != 0) | ||
924 | mode |= FMODE_WRITE; | ||
925 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) | ||
926 | state->state = mode; | ||
927 | if (mode == state->state) { | ||
928 | nfs4_free_closedata(calldata); | ||
929 | task->tk_exit = NULL; | ||
930 | rpc_exit(task, 0); | ||
931 | return; | ||
932 | } | ||
933 | if (mode != 0) | ||
836 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; | 934 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
837 | return rpc_call_async(clnt, &msg, 0, nfs4_close_done, calldata); | 935 | calldata->arg.open_flags = mode; |
936 | rpc_call_setup(task, &msg, 0); | ||
838 | } | 937 | } |
839 | 938 | ||
840 | /* | 939 | /* |
@@ -851,39 +950,52 @@ static inline int nfs4_close_call(struct rpc_clnt *clnt, struct nfs4_closedata * | |||
851 | int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode) | 950 | int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode) |
852 | { | 951 | { |
853 | struct nfs4_closedata *calldata; | 952 | struct nfs4_closedata *calldata; |
854 | int status; | 953 | int status = -ENOMEM; |
855 | 954 | ||
856 | /* Tell caller we're done */ | 955 | calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); |
857 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | ||
858 | state->state = mode; | ||
859 | return 0; | ||
860 | } | ||
861 | calldata = (struct nfs4_closedata *)kmalloc(sizeof(*calldata), GFP_KERNEL); | ||
862 | if (calldata == NULL) | 956 | if (calldata == NULL) |
863 | return -ENOMEM; | 957 | goto out; |
864 | calldata->inode = inode; | 958 | calldata->inode = inode; |
865 | calldata->state = state; | 959 | calldata->state = state; |
866 | calldata->arg.fh = NFS_FH(inode); | 960 | calldata->arg.fh = NFS_FH(inode); |
961 | calldata->arg.stateid = &state->stateid; | ||
867 | /* Serialization for the sequence id */ | 962 | /* Serialization for the sequence id */ |
868 | calldata->arg.seqid = state->owner->so_seqid; | 963 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); |
869 | calldata->arg.open_flags = mode; | 964 | if (calldata->arg.seqid == NULL) |
870 | memcpy(&calldata->arg.stateid, &state->stateid, | 965 | goto out_free_calldata; |
871 | sizeof(calldata->arg.stateid)); | 966 | |
872 | status = nfs4_close_call(NFS_SERVER(inode)->client, calldata); | 967 | status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_close_begin, |
873 | /* | 968 | nfs4_close_done, calldata); |
874 | * Return -EINPROGRESS on success in order to indicate to the | 969 | if (status == 0) |
875 | * caller that an asynchronous RPC call has been launched, and | 970 | goto out; |
876 | * that it will release the semaphores on completion. | 971 | |
877 | */ | 972 | nfs_free_seqid(calldata->arg.seqid); |
878 | return (status == 0) ? -EINPROGRESS : status; | 973 | out_free_calldata: |
974 | kfree(calldata); | ||
975 | out: | ||
976 | return status; | ||
977 | } | ||
978 | |||
979 | static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state) | ||
980 | { | ||
981 | struct file *filp; | ||
982 | |||
983 | filp = lookup_instantiate_filp(nd, dentry, NULL); | ||
984 | if (!IS_ERR(filp)) { | ||
985 | struct nfs_open_context *ctx; | ||
986 | ctx = (struct nfs_open_context *)filp->private_data; | ||
987 | ctx->state = state; | ||
988 | } else | ||
989 | nfs4_close_state(state, nd->intent.open.flags); | ||
879 | } | 990 | } |
880 | 991 | ||
881 | struct inode * | 992 | struct dentry * |
882 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 993 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
883 | { | 994 | { |
884 | struct iattr attr; | 995 | struct iattr attr; |
885 | struct rpc_cred *cred; | 996 | struct rpc_cred *cred; |
886 | struct nfs4_state *state; | 997 | struct nfs4_state *state; |
998 | struct dentry *res; | ||
887 | 999 | ||
888 | if (nd->flags & LOOKUP_CREATE) { | 1000 | if (nd->flags & LOOKUP_CREATE) { |
889 | attr.ia_mode = nd->intent.open.create_mode; | 1001 | attr.ia_mode = nd->intent.open.create_mode; |
@@ -897,16 +1009,23 @@ nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | |||
897 | 1009 | ||
898 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); | 1010 | cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0); |
899 | if (IS_ERR(cred)) | 1011 | if (IS_ERR(cred)) |
900 | return (struct inode *)cred; | 1012 | return (struct dentry *)cred; |
901 | state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred); | 1013 | state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred); |
902 | put_rpccred(cred); | 1014 | put_rpccred(cred); |
903 | if (IS_ERR(state)) | 1015 | if (IS_ERR(state)) { |
904 | return (struct inode *)state; | 1016 | if (PTR_ERR(state) == -ENOENT) |
905 | return state->inode; | 1017 | d_add(dentry, NULL); |
1018 | return (struct dentry *)state; | ||
1019 | } | ||
1020 | res = d_add_unique(dentry, state->inode); | ||
1021 | if (res != NULL) | ||
1022 | dentry = res; | ||
1023 | nfs4_intent_set_file(nd, dentry, state); | ||
1024 | return res; | ||
906 | } | 1025 | } |
907 | 1026 | ||
908 | int | 1027 | int |
909 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags) | 1028 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
910 | { | 1029 | { |
911 | struct rpc_cred *cred; | 1030 | struct rpc_cred *cred; |
912 | struct nfs4_state *state; | 1031 | struct nfs4_state *state; |
@@ -919,18 +1038,30 @@ nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags) | |||
919 | if (IS_ERR(state)) | 1038 | if (IS_ERR(state)) |
920 | state = nfs4_do_open(dir, dentry, openflags, NULL, cred); | 1039 | state = nfs4_do_open(dir, dentry, openflags, NULL, cred); |
921 | put_rpccred(cred); | 1040 | put_rpccred(cred); |
922 | if (state == ERR_PTR(-ENOENT) && dentry->d_inode == 0) | 1041 | if (IS_ERR(state)) { |
923 | return 1; | 1042 | switch (PTR_ERR(state)) { |
924 | if (IS_ERR(state)) | 1043 | case -EPERM: |
925 | return 0; | 1044 | case -EACCES: |
1045 | case -EDQUOT: | ||
1046 | case -ENOSPC: | ||
1047 | case -EROFS: | ||
1048 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); | ||
1049 | return 1; | ||
1050 | case -ENOENT: | ||
1051 | if (dentry->d_inode == NULL) | ||
1052 | return 1; | ||
1053 | } | ||
1054 | goto out_drop; | ||
1055 | } | ||
926 | inode = state->inode; | 1056 | inode = state->inode; |
1057 | iput(inode); | ||
927 | if (inode == dentry->d_inode) { | 1058 | if (inode == dentry->d_inode) { |
928 | iput(inode); | 1059 | nfs4_intent_set_file(nd, dentry, state); |
929 | return 1; | 1060 | return 1; |
930 | } | 1061 | } |
931 | d_drop(dentry); | ||
932 | nfs4_close_state(state, openflags); | 1062 | nfs4_close_state(state, openflags); |
933 | iput(inode); | 1063 | out_drop: |
1064 | d_drop(dentry); | ||
934 | return 0; | 1065 | return 0; |
935 | } | 1066 | } |
936 | 1067 | ||
@@ -1431,7 +1562,7 @@ static int nfs4_proc_commit(struct nfs_write_data *cdata) | |||
1431 | 1562 | ||
1432 | static int | 1563 | static int |
1433 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 1564 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
1434 | int flags) | 1565 | int flags, struct nameidata *nd) |
1435 | { | 1566 | { |
1436 | struct nfs4_state *state; | 1567 | struct nfs4_state *state; |
1437 | struct rpc_cred *cred; | 1568 | struct rpc_cred *cred; |
@@ -1453,13 +1584,13 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | |||
1453 | struct nfs_fattr fattr; | 1584 | struct nfs_fattr fattr; |
1454 | status = nfs4_do_setattr(NFS_SERVER(dir), &fattr, | 1585 | status = nfs4_do_setattr(NFS_SERVER(dir), &fattr, |
1455 | NFS_FH(state->inode), sattr, state); | 1586 | NFS_FH(state->inode), sattr, state); |
1456 | if (status == 0) { | 1587 | if (status == 0) |
1457 | nfs_setattr_update_inode(state->inode, sattr); | 1588 | nfs_setattr_update_inode(state->inode, sattr); |
1458 | goto out; | 1589 | } |
1459 | } | 1590 | if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN)) |
1460 | } else if (flags != 0) | 1591 | nfs4_intent_set_file(nd, dentry, state); |
1461 | goto out; | 1592 | else |
1462 | nfs4_close_state(state, flags); | 1593 | nfs4_close_state(state, flags); |
1463 | out: | 1594 | out: |
1464 | return status; | 1595 | return status; |
1465 | } | 1596 | } |
@@ -2106,65 +2237,6 @@ nfs4_proc_renew(struct nfs4_client *clp) | |||
2106 | return 0; | 2237 | return 0; |
2107 | } | 2238 | } |
2108 | 2239 | ||
2109 | /* | ||
2110 | * We will need to arrange for the VFS layer to provide an atomic open. | ||
2111 | * Until then, this open method is prone to inefficiency and race conditions | ||
2112 | * due to the lookup, potential create, and open VFS calls from sys_open() | ||
2113 | * placed on the wire. | ||
2114 | */ | ||
2115 | static int | ||
2116 | nfs4_proc_file_open(struct inode *inode, struct file *filp) | ||
2117 | { | ||
2118 | struct dentry *dentry = filp->f_dentry; | ||
2119 | struct nfs_open_context *ctx; | ||
2120 | struct nfs4_state *state = NULL; | ||
2121 | struct rpc_cred *cred; | ||
2122 | int status = -ENOMEM; | ||
2123 | |||
2124 | dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n", | ||
2125 | (int)dentry->d_parent->d_name.len, | ||
2126 | dentry->d_parent->d_name.name, | ||
2127 | (int)dentry->d_name.len, dentry->d_name.name); | ||
2128 | |||
2129 | |||
2130 | /* Find our open stateid */ | ||
2131 | cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0); | ||
2132 | if (IS_ERR(cred)) | ||
2133 | return PTR_ERR(cred); | ||
2134 | ctx = alloc_nfs_open_context(dentry, cred); | ||
2135 | put_rpccred(cred); | ||
2136 | if (unlikely(ctx == NULL)) | ||
2137 | return -ENOMEM; | ||
2138 | status = -EIO; /* ERACE actually */ | ||
2139 | state = nfs4_find_state(inode, cred, filp->f_mode); | ||
2140 | if (unlikely(state == NULL)) | ||
2141 | goto no_state; | ||
2142 | ctx->state = state; | ||
2143 | nfs4_close_state(state, filp->f_mode); | ||
2144 | ctx->mode = filp->f_mode; | ||
2145 | nfs_file_set_open_context(filp, ctx); | ||
2146 | put_nfs_open_context(ctx); | ||
2147 | if (filp->f_mode & FMODE_WRITE) | ||
2148 | nfs_begin_data_update(inode); | ||
2149 | return 0; | ||
2150 | no_state: | ||
2151 | printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__); | ||
2152 | put_nfs_open_context(ctx); | ||
2153 | return status; | ||
2154 | } | ||
2155 | |||
2156 | /* | ||
2157 | * Release our state | ||
2158 | */ | ||
2159 | static int | ||
2160 | nfs4_proc_file_release(struct inode *inode, struct file *filp) | ||
2161 | { | ||
2162 | if (filp->f_mode & FMODE_WRITE) | ||
2163 | nfs_end_data_update(inode); | ||
2164 | nfs_file_clear_open_context(filp); | ||
2165 | return 0; | ||
2166 | } | ||
2167 | |||
2168 | static inline int nfs4_server_supports_acls(struct nfs_server *server) | 2240 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
2169 | { | 2241 | { |
2170 | return (server->caps & NFS_CAP_ACLS) | 2242 | return (server->caps & NFS_CAP_ACLS) |
@@ -2345,6 +2417,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen | |||
2345 | 2417 | ||
2346 | if (!nfs4_server_supports_acls(server)) | 2418 | if (!nfs4_server_supports_acls(server)) |
2347 | return -EOPNOTSUPP; | 2419 | return -EOPNOTSUPP; |
2420 | nfs_inode_return_delegation(inode); | ||
2348 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); | 2421 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
2349 | ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0); | 2422 | ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0); |
2350 | if (ret == 0) | 2423 | if (ret == 0) |
@@ -2353,7 +2426,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen | |||
2353 | } | 2426 | } |
2354 | 2427 | ||
2355 | static int | 2428 | static int |
2356 | nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server) | 2429 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server) |
2357 | { | 2430 | { |
2358 | struct nfs4_client *clp = server->nfs4_state; | 2431 | struct nfs4_client *clp = server->nfs4_state; |
2359 | 2432 | ||
@@ -2431,7 +2504,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) | |||
2431 | /* This is the error handling routine for processes that are allowed | 2504 | /* This is the error handling routine for processes that are allowed |
2432 | * to sleep. | 2505 | * to sleep. |
2433 | */ | 2506 | */ |
2434 | int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) | 2507 | int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
2435 | { | 2508 | { |
2436 | struct nfs4_client *clp = server->nfs4_state; | 2509 | struct nfs4_client *clp = server->nfs4_state; |
2437 | int ret = errorcode; | 2510 | int ret = errorcode; |
@@ -2632,7 +2705,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock | |||
2632 | 2705 | ||
2633 | down_read(&clp->cl_sem); | 2706 | down_read(&clp->cl_sem); |
2634 | nlo.clientid = clp->cl_clientid; | 2707 | nlo.clientid = clp->cl_clientid; |
2635 | down(&state->lock_sema); | ||
2636 | status = nfs4_set_lock_state(state, request); | 2708 | status = nfs4_set_lock_state(state, request); |
2637 | if (status != 0) | 2709 | if (status != 0) |
2638 | goto out; | 2710 | goto out; |
@@ -2659,7 +2731,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock | |||
2659 | status = 0; | 2731 | status = 0; |
2660 | } | 2732 | } |
2661 | out: | 2733 | out: |
2662 | up(&state->lock_sema); | ||
2663 | up_read(&clp->cl_sem); | 2734 | up_read(&clp->cl_sem); |
2664 | return status; | 2735 | return status; |
2665 | } | 2736 | } |
@@ -2696,79 +2767,149 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl) | |||
2696 | return res; | 2767 | return res; |
2697 | } | 2768 | } |
2698 | 2769 | ||
2699 | static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | 2770 | struct nfs4_unlockdata { |
2771 | struct nfs_lockargs arg; | ||
2772 | struct nfs_locku_opargs luargs; | ||
2773 | struct nfs_lockres res; | ||
2774 | struct nfs4_lock_state *lsp; | ||
2775 | struct nfs_open_context *ctx; | ||
2776 | atomic_t refcount; | ||
2777 | struct completion completion; | ||
2778 | }; | ||
2779 | |||
2780 | static void nfs4_locku_release_calldata(struct nfs4_unlockdata *calldata) | ||
2700 | { | 2781 | { |
2701 | struct inode *inode = state->inode; | 2782 | if (atomic_dec_and_test(&calldata->refcount)) { |
2702 | struct nfs_server *server = NFS_SERVER(inode); | 2783 | nfs_free_seqid(calldata->luargs.seqid); |
2703 | struct nfs4_client *clp = server->nfs4_state; | 2784 | nfs4_put_lock_state(calldata->lsp); |
2704 | struct nfs_lockargs arg = { | 2785 | put_nfs_open_context(calldata->ctx); |
2705 | .fh = NFS_FH(inode), | 2786 | kfree(calldata); |
2706 | .type = nfs4_lck_type(cmd, request), | 2787 | } |
2707 | .offset = request->fl_start, | 2788 | } |
2708 | .length = nfs4_lck_length(request), | 2789 | |
2709 | }; | 2790 | static void nfs4_locku_complete(struct nfs4_unlockdata *calldata) |
2710 | struct nfs_lockres res = { | 2791 | { |
2711 | .server = server, | 2792 | complete(&calldata->completion); |
2712 | }; | 2793 | nfs4_locku_release_calldata(calldata); |
2794 | } | ||
2795 | |||
2796 | static void nfs4_locku_done(struct rpc_task *task) | ||
2797 | { | ||
2798 | struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata; | ||
2799 | |||
2800 | nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid); | ||
2801 | switch (task->tk_status) { | ||
2802 | case 0: | ||
2803 | memcpy(calldata->lsp->ls_stateid.data, | ||
2804 | calldata->res.u.stateid.data, | ||
2805 | sizeof(calldata->lsp->ls_stateid.data)); | ||
2806 | break; | ||
2807 | case -NFS4ERR_STALE_STATEID: | ||
2808 | case -NFS4ERR_EXPIRED: | ||
2809 | nfs4_schedule_state_recovery(calldata->res.server->nfs4_state); | ||
2810 | break; | ||
2811 | default: | ||
2812 | if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) { | ||
2813 | rpc_restart_call(task); | ||
2814 | return; | ||
2815 | } | ||
2816 | } | ||
2817 | nfs4_locku_complete(calldata); | ||
2818 | } | ||
2819 | |||
2820 | static void nfs4_locku_begin(struct rpc_task *task) | ||
2821 | { | ||
2822 | struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata; | ||
2713 | struct rpc_message msg = { | 2823 | struct rpc_message msg = { |
2714 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], | 2824 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
2715 | .rpc_argp = &arg, | 2825 | .rpc_argp = &calldata->arg, |
2716 | .rpc_resp = &res, | 2826 | .rpc_resp = &calldata->res, |
2717 | .rpc_cred = state->owner->so_cred, | 2827 | .rpc_cred = calldata->lsp->ls_state->owner->so_cred, |
2718 | }; | 2828 | }; |
2829 | int status; | ||
2830 | |||
2831 | status = nfs_wait_on_sequence(calldata->luargs.seqid, task); | ||
2832 | if (status != 0) | ||
2833 | return; | ||
2834 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { | ||
2835 | nfs4_locku_complete(calldata); | ||
2836 | task->tk_exit = NULL; | ||
2837 | rpc_exit(task, 0); | ||
2838 | return; | ||
2839 | } | ||
2840 | rpc_call_setup(task, &msg, 0); | ||
2841 | } | ||
2842 | |||
2843 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | ||
2844 | { | ||
2845 | struct nfs4_unlockdata *calldata; | ||
2846 | struct inode *inode = state->inode; | ||
2847 | struct nfs_server *server = NFS_SERVER(inode); | ||
2719 | struct nfs4_lock_state *lsp; | 2848 | struct nfs4_lock_state *lsp; |
2720 | struct nfs_locku_opargs luargs; | ||
2721 | int status; | 2849 | int status; |
2722 | 2850 | ||
2723 | down_read(&clp->cl_sem); | ||
2724 | down(&state->lock_sema); | ||
2725 | status = nfs4_set_lock_state(state, request); | 2851 | status = nfs4_set_lock_state(state, request); |
2726 | if (status != 0) | 2852 | if (status != 0) |
2727 | goto out; | 2853 | return status; |
2728 | lsp = request->fl_u.nfs4_fl.owner; | 2854 | lsp = request->fl_u.nfs4_fl.owner; |
2729 | /* We might have lost the locks! */ | 2855 | /* We might have lost the locks! */ |
2730 | if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) | 2856 | if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) |
2731 | goto out; | 2857 | return 0; |
2732 | luargs.seqid = lsp->ls_seqid; | 2858 | calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); |
2733 | memcpy(&luargs.stateid, &lsp->ls_stateid, sizeof(luargs.stateid)); | 2859 | if (calldata == NULL) |
2734 | arg.u.locku = &luargs; | 2860 | return -ENOMEM; |
2735 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 2861 | calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
2736 | nfs4_increment_lock_seqid(status, lsp); | 2862 | if (calldata->luargs.seqid == NULL) { |
2737 | 2863 | kfree(calldata); | |
2738 | if (status == 0) | 2864 | return -ENOMEM; |
2739 | memcpy(&lsp->ls_stateid, &res.u.stateid, | 2865 | } |
2740 | sizeof(lsp->ls_stateid)); | 2866 | calldata->luargs.stateid = &lsp->ls_stateid; |
2741 | out: | 2867 | calldata->arg.fh = NFS_FH(inode); |
2742 | up(&state->lock_sema); | 2868 | calldata->arg.type = nfs4_lck_type(cmd, request); |
2869 | calldata->arg.offset = request->fl_start; | ||
2870 | calldata->arg.length = nfs4_lck_length(request); | ||
2871 | calldata->arg.u.locku = &calldata->luargs; | ||
2872 | calldata->res.server = server; | ||
2873 | calldata->lsp = lsp; | ||
2874 | atomic_inc(&lsp->ls_count); | ||
2875 | |||
2876 | /* Ensure we don't close file until we're done freeing locks! */ | ||
2877 | calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data); | ||
2878 | |||
2879 | atomic_set(&calldata->refcount, 2); | ||
2880 | init_completion(&calldata->completion); | ||
2881 | |||
2882 | status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_locku_begin, | ||
2883 | nfs4_locku_done, calldata); | ||
2743 | if (status == 0) | 2884 | if (status == 0) |
2744 | do_vfs_lock(request->fl_file, request); | 2885 | wait_for_completion_interruptible(&calldata->completion); |
2745 | up_read(&clp->cl_sem); | 2886 | do_vfs_lock(request->fl_file, request); |
2887 | nfs4_locku_release_calldata(calldata); | ||
2746 | return status; | 2888 | return status; |
2747 | } | 2889 | } |
2748 | 2890 | ||
2749 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | ||
2750 | { | ||
2751 | struct nfs4_exception exception = { }; | ||
2752 | int err; | ||
2753 | |||
2754 | do { | ||
2755 | err = nfs4_handle_exception(NFS_SERVER(state->inode), | ||
2756 | _nfs4_proc_unlck(state, cmd, request), | ||
2757 | &exception); | ||
2758 | } while (exception.retry); | ||
2759 | return err; | ||
2760 | } | ||
2761 | |||
2762 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim) | 2891 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim) |
2763 | { | 2892 | { |
2764 | struct inode *inode = state->inode; | 2893 | struct inode *inode = state->inode; |
2765 | struct nfs_server *server = NFS_SERVER(inode); | 2894 | struct nfs_server *server = NFS_SERVER(inode); |
2766 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; | 2895 | struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; |
2896 | struct nfs_lock_opargs largs = { | ||
2897 | .lock_stateid = &lsp->ls_stateid, | ||
2898 | .open_stateid = &state->stateid, | ||
2899 | .lock_owner = { | ||
2900 | .clientid = server->nfs4_state->cl_clientid, | ||
2901 | .id = lsp->ls_id, | ||
2902 | }, | ||
2903 | .reclaim = reclaim, | ||
2904 | }; | ||
2767 | struct nfs_lockargs arg = { | 2905 | struct nfs_lockargs arg = { |
2768 | .fh = NFS_FH(inode), | 2906 | .fh = NFS_FH(inode), |
2769 | .type = nfs4_lck_type(cmd, request), | 2907 | .type = nfs4_lck_type(cmd, request), |
2770 | .offset = request->fl_start, | 2908 | .offset = request->fl_start, |
2771 | .length = nfs4_lck_length(request), | 2909 | .length = nfs4_lck_length(request), |
2910 | .u = { | ||
2911 | .lock = &largs, | ||
2912 | }, | ||
2772 | }; | 2913 | }; |
2773 | struct nfs_lockres res = { | 2914 | struct nfs_lockres res = { |
2774 | .server = server, | 2915 | .server = server, |
@@ -2779,53 +2920,39 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r | |||
2779 | .rpc_resp = &res, | 2920 | .rpc_resp = &res, |
2780 | .rpc_cred = state->owner->so_cred, | 2921 | .rpc_cred = state->owner->so_cred, |
2781 | }; | 2922 | }; |
2782 | struct nfs_lock_opargs largs = { | 2923 | int status = -ENOMEM; |
2783 | .reclaim = reclaim, | ||
2784 | .new_lock_owner = 0, | ||
2785 | }; | ||
2786 | int status; | ||
2787 | 2924 | ||
2788 | if (!(lsp->ls_flags & NFS_LOCK_INITIALIZED)) { | 2925 | largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
2926 | if (largs.lock_seqid == NULL) | ||
2927 | return -ENOMEM; | ||
2928 | if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) { | ||
2789 | struct nfs4_state_owner *owner = state->owner; | 2929 | struct nfs4_state_owner *owner = state->owner; |
2790 | struct nfs_open_to_lock otl = { | 2930 | |
2791 | .lock_owner = { | 2931 | largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid); |
2792 | .clientid = server->nfs4_state->cl_clientid, | 2932 | if (largs.open_seqid == NULL) |
2793 | }, | 2933 | goto out; |
2794 | }; | ||
2795 | |||
2796 | otl.lock_seqid = lsp->ls_seqid; | ||
2797 | otl.lock_owner.id = lsp->ls_id; | ||
2798 | memcpy(&otl.open_stateid, &state->stateid, sizeof(otl.open_stateid)); | ||
2799 | largs.u.open_lock = &otl; | ||
2800 | largs.new_lock_owner = 1; | 2934 | largs.new_lock_owner = 1; |
2801 | arg.u.lock = &largs; | ||
2802 | down(&owner->so_sema); | ||
2803 | otl.open_seqid = owner->so_seqid; | ||
2804 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 2935 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); |
2805 | /* increment open_owner seqid on success, and | 2936 | /* increment open seqid on success, and seqid mutating errors */ |
2806 | * seqid mutating errors */ | 2937 | if (largs.new_lock_owner != 0) { |
2807 | nfs4_increment_seqid(status, owner); | 2938 | nfs_increment_open_seqid(status, largs.open_seqid); |
2808 | up(&owner->so_sema); | 2939 | if (status == 0) |
2809 | if (status == 0) { | 2940 | nfs_confirm_seqid(&lsp->ls_seqid, 0); |
2810 | lsp->ls_flags |= NFS_LOCK_INITIALIZED; | ||
2811 | lsp->ls_seqid++; | ||
2812 | } | 2941 | } |
2813 | } else { | 2942 | nfs_free_seqid(largs.open_seqid); |
2814 | struct nfs_exist_lock el = { | 2943 | } else |
2815 | .seqid = lsp->ls_seqid, | ||
2816 | }; | ||
2817 | memcpy(&el.stateid, &lsp->ls_stateid, sizeof(el.stateid)); | ||
2818 | largs.u.exist_lock = ⪙ | ||
2819 | arg.u.lock = &largs; | ||
2820 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); | 2944 | status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); |
2821 | /* increment seqid on success, and * seqid mutating errors*/ | 2945 | /* increment lock seqid on success, and seqid mutating errors*/ |
2822 | nfs4_increment_lock_seqid(status, lsp); | 2946 | nfs_increment_lock_seqid(status, largs.lock_seqid); |
2823 | } | ||
2824 | /* save the returned stateid. */ | 2947 | /* save the returned stateid. */ |
2825 | if (status == 0) | 2948 | if (status == 0) { |
2826 | memcpy(&lsp->ls_stateid, &res.u.stateid, sizeof(nfs4_stateid)); | 2949 | memcpy(lsp->ls_stateid.data, res.u.stateid.data, |
2827 | else if (status == -NFS4ERR_DENIED) | 2950 | sizeof(lsp->ls_stateid.data)); |
2951 | lsp->ls_flags |= NFS_LOCK_INITIALIZED; | ||
2952 | } else if (status == -NFS4ERR_DENIED) | ||
2828 | status = -EAGAIN; | 2953 | status = -EAGAIN; |
2954 | out: | ||
2955 | nfs_free_seqid(largs.lock_seqid); | ||
2829 | return status; | 2956 | return status; |
2830 | } | 2957 | } |
2831 | 2958 | ||
@@ -2865,11 +2992,9 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock | |||
2865 | int status; | 2992 | int status; |
2866 | 2993 | ||
2867 | down_read(&clp->cl_sem); | 2994 | down_read(&clp->cl_sem); |
2868 | down(&state->lock_sema); | ||
2869 | status = nfs4_set_lock_state(state, request); | 2995 | status = nfs4_set_lock_state(state, request); |
2870 | if (status == 0) | 2996 | if (status == 0) |
2871 | status = _nfs4_do_setlk(state, cmd, request, 0); | 2997 | status = _nfs4_do_setlk(state, cmd, request, 0); |
2872 | up(&state->lock_sema); | ||
2873 | if (status == 0) { | 2998 | if (status == 0) { |
2874 | /* Note: we always want to sleep here! */ | 2999 | /* Note: we always want to sleep here! */ |
2875 | request->fl_flags |= FL_SLEEP; | 3000 | request->fl_flags |= FL_SLEEP; |
@@ -3024,8 +3149,8 @@ struct nfs_rpc_ops nfs_v4_clientops = { | |||
3024 | .read_setup = nfs4_proc_read_setup, | 3149 | .read_setup = nfs4_proc_read_setup, |
3025 | .write_setup = nfs4_proc_write_setup, | 3150 | .write_setup = nfs4_proc_write_setup, |
3026 | .commit_setup = nfs4_proc_commit_setup, | 3151 | .commit_setup = nfs4_proc_commit_setup, |
3027 | .file_open = nfs4_proc_file_open, | 3152 | .file_open = nfs_open, |
3028 | .file_release = nfs4_proc_file_release, | 3153 | .file_release = nfs_release, |
3029 | .lock = nfs4_proc_lock, | 3154 | .lock = nfs4_proc_lock, |
3030 | .clear_acl_cache = nfs4_zap_acl_attr, | 3155 | .clear_acl_cache = nfs4_zap_acl_attr, |
3031 | }; | 3156 | }; |
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index afe587d82f..23834c8fb7 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c | |||
@@ -264,13 +264,15 @@ nfs4_alloc_state_owner(void) | |||
264 | { | 264 | { |
265 | struct nfs4_state_owner *sp; | 265 | struct nfs4_state_owner *sp; |
266 | 266 | ||
267 | sp = kmalloc(sizeof(*sp),GFP_KERNEL); | 267 | sp = kzalloc(sizeof(*sp),GFP_KERNEL); |
268 | if (!sp) | 268 | if (!sp) |
269 | return NULL; | 269 | return NULL; |
270 | init_MUTEX(&sp->so_sema); | ||
271 | sp->so_seqid = 0; /* arbitrary */ | ||
272 | INIT_LIST_HEAD(&sp->so_states); | 270 | INIT_LIST_HEAD(&sp->so_states); |
273 | INIT_LIST_HEAD(&sp->so_delegations); | 271 | INIT_LIST_HEAD(&sp->so_delegations); |
272 | rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); | ||
273 | sp->so_seqid.sequence = &sp->so_sequence; | ||
274 | spin_lock_init(&sp->so_sequence.lock); | ||
275 | INIT_LIST_HEAD(&sp->so_sequence.list); | ||
274 | atomic_set(&sp->so_count, 1); | 276 | atomic_set(&sp->so_count, 1); |
275 | return sp; | 277 | return sp; |
276 | } | 278 | } |
@@ -359,7 +361,6 @@ nfs4_alloc_open_state(void) | |||
359 | memset(state->stateid.data, 0, sizeof(state->stateid.data)); | 361 | memset(state->stateid.data, 0, sizeof(state->stateid.data)); |
360 | atomic_set(&state->count, 1); | 362 | atomic_set(&state->count, 1); |
361 | INIT_LIST_HEAD(&state->lock_states); | 363 | INIT_LIST_HEAD(&state->lock_states); |
362 | init_MUTEX(&state->lock_sema); | ||
363 | spin_lock_init(&state->state_lock); | 364 | spin_lock_init(&state->state_lock); |
364 | return state; | 365 | return state; |
365 | } | 366 | } |
@@ -441,7 +442,6 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) | |||
441 | state = __nfs4_find_state_byowner(inode, owner); | 442 | state = __nfs4_find_state_byowner(inode, owner); |
442 | if (state == NULL && new != NULL) { | 443 | if (state == NULL && new != NULL) { |
443 | state = new; | 444 | state = new; |
444 | /* Caller *must* be holding owner->so_sem */ | ||
445 | /* Note: The reclaim code dictates that we add stateless | 445 | /* Note: The reclaim code dictates that we add stateless |
446 | * and read-only stateids to the end of the list */ | 446 | * and read-only stateids to the end of the list */ |
447 | list_add_tail(&state->open_states, &owner->so_states); | 447 | list_add_tail(&state->open_states, &owner->so_states); |
@@ -461,7 +461,7 @@ out: | |||
461 | 461 | ||
462 | /* | 462 | /* |
463 | * Beware! Caller must be holding exactly one | 463 | * Beware! Caller must be holding exactly one |
464 | * reference to clp->cl_sem and owner->so_sema! | 464 | * reference to clp->cl_sem! |
465 | */ | 465 | */ |
466 | void nfs4_put_open_state(struct nfs4_state *state) | 466 | void nfs4_put_open_state(struct nfs4_state *state) |
467 | { | 467 | { |
@@ -481,19 +481,15 @@ void nfs4_put_open_state(struct nfs4_state *state) | |||
481 | } | 481 | } |
482 | 482 | ||
483 | /* | 483 | /* |
484 | * Beware! Caller must be holding no references to clp->cl_sem! | 484 | * Close the current file. |
485 | * of owner->so_sema! | ||
486 | */ | 485 | */ |
487 | void nfs4_close_state(struct nfs4_state *state, mode_t mode) | 486 | void nfs4_close_state(struct nfs4_state *state, mode_t mode) |
488 | { | 487 | { |
489 | struct inode *inode = state->inode; | 488 | struct inode *inode = state->inode; |
490 | struct nfs4_state_owner *owner = state->owner; | 489 | struct nfs4_state_owner *owner = state->owner; |
491 | struct nfs4_client *clp = owner->so_client; | ||
492 | int newstate; | 490 | int newstate; |
493 | 491 | ||
494 | atomic_inc(&owner->so_count); | 492 | atomic_inc(&owner->so_count); |
495 | down_read(&clp->cl_sem); | ||
496 | down(&owner->so_sema); | ||
497 | /* Protect against nfs4_find_state() */ | 493 | /* Protect against nfs4_find_state() */ |
498 | spin_lock(&inode->i_lock); | 494 | spin_lock(&inode->i_lock); |
499 | if (mode & FMODE_READ) | 495 | if (mode & FMODE_READ) |
@@ -515,14 +511,16 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode) | |||
515 | newstate |= FMODE_WRITE; | 511 | newstate |= FMODE_WRITE; |
516 | if (state->state == newstate) | 512 | if (state->state == newstate) |
517 | goto out; | 513 | goto out; |
518 | if (nfs4_do_close(inode, state, newstate) == -EINPROGRESS) | 514 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
515 | state->state = newstate; | ||
516 | goto out; | ||
517 | } | ||
518 | if (nfs4_do_close(inode, state, newstate) == 0) | ||
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | out: | 521 | out: |
522 | nfs4_put_open_state(state); | 522 | nfs4_put_open_state(state); |
523 | up(&owner->so_sema); | ||
524 | nfs4_put_state_owner(owner); | 523 | nfs4_put_state_owner(owner); |
525 | up_read(&clp->cl_sem); | ||
526 | } | 524 | } |
527 | 525 | ||
528 | /* | 526 | /* |
@@ -546,19 +544,16 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) | |||
546 | * Return a compatible lock_state. If no initialized lock_state structure | 544 | * Return a compatible lock_state. If no initialized lock_state structure |
547 | * exists, return an uninitialized one. | 545 | * exists, return an uninitialized one. |
548 | * | 546 | * |
549 | * The caller must be holding state->lock_sema | ||
550 | */ | 547 | */ |
551 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) | 548 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) |
552 | { | 549 | { |
553 | struct nfs4_lock_state *lsp; | 550 | struct nfs4_lock_state *lsp; |
554 | struct nfs4_client *clp = state->owner->so_client; | 551 | struct nfs4_client *clp = state->owner->so_client; |
555 | 552 | ||
556 | lsp = kmalloc(sizeof(*lsp), GFP_KERNEL); | 553 | lsp = kzalloc(sizeof(*lsp), GFP_KERNEL); |
557 | if (lsp == NULL) | 554 | if (lsp == NULL) |
558 | return NULL; | 555 | return NULL; |
559 | lsp->ls_flags = 0; | 556 | lsp->ls_seqid.sequence = &state->owner->so_sequence; |
560 | lsp->ls_seqid = 0; /* arbitrary */ | ||
561 | memset(lsp->ls_stateid.data, 0, sizeof(lsp->ls_stateid.data)); | ||
562 | atomic_set(&lsp->ls_count, 1); | 557 | atomic_set(&lsp->ls_count, 1); |
563 | lsp->ls_owner = fl_owner; | 558 | lsp->ls_owner = fl_owner; |
564 | spin_lock(&clp->cl_lock); | 559 | spin_lock(&clp->cl_lock); |
@@ -572,7 +567,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f | |||
572 | * Return a compatible lock_state. If no initialized lock_state structure | 567 | * Return a compatible lock_state. If no initialized lock_state structure |
573 | * exists, return an uninitialized one. | 568 | * exists, return an uninitialized one. |
574 | * | 569 | * |
575 | * The caller must be holding state->lock_sema and clp->cl_sem | 570 | * The caller must be holding clp->cl_sem |
576 | */ | 571 | */ |
577 | static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) | 572 | static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) |
578 | { | 573 | { |
@@ -605,7 +600,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_ | |||
605 | * Release reference to lock_state, and free it if we see that | 600 | * Release reference to lock_state, and free it if we see that |
606 | * it is no longer in use | 601 | * it is no longer in use |
607 | */ | 602 | */ |
608 | static void nfs4_put_lock_state(struct nfs4_lock_state *lsp) | 603 | void nfs4_put_lock_state(struct nfs4_lock_state *lsp) |
609 | { | 604 | { |
610 | struct nfs4_state *state; | 605 | struct nfs4_state *state; |
611 | 606 | ||
@@ -673,29 +668,98 @@ void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t f | |||
673 | nfs4_put_lock_state(lsp); | 668 | nfs4_put_lock_state(lsp); |
674 | } | 669 | } |
675 | 670 | ||
676 | /* | 671 | struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter) |
677 | * Called with state->lock_sema and clp->cl_sem held. | 672 | { |
678 | */ | 673 | struct rpc_sequence *sequence = counter->sequence; |
679 | void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *lsp) | 674 | struct nfs_seqid *new; |
675 | |||
676 | new = kmalloc(sizeof(*new), GFP_KERNEL); | ||
677 | if (new != NULL) { | ||
678 | new->sequence = counter; | ||
679 | new->task = NULL; | ||
680 | spin_lock(&sequence->lock); | ||
681 | list_add_tail(&new->list, &sequence->list); | ||
682 | spin_unlock(&sequence->lock); | ||
683 | } | ||
684 | return new; | ||
685 | } | ||
686 | |||
687 | void nfs_free_seqid(struct nfs_seqid *seqid) | ||
680 | { | 688 | { |
681 | if (status == NFS_OK || seqid_mutating_err(-status)) | 689 | struct rpc_sequence *sequence = seqid->sequence->sequence; |
682 | lsp->ls_seqid++; | 690 | struct rpc_task *next = NULL; |
691 | |||
692 | spin_lock(&sequence->lock); | ||
693 | list_del(&seqid->list); | ||
694 | if (!list_empty(&sequence->list)) { | ||
695 | next = list_entry(sequence->list.next, struct nfs_seqid, list)->task; | ||
696 | if (next) | ||
697 | rpc_wake_up_task(next); | ||
698 | } | ||
699 | spin_unlock(&sequence->lock); | ||
700 | kfree(seqid); | ||
683 | } | 701 | } |
684 | 702 | ||
685 | /* | 703 | /* |
686 | * Called with sp->so_sema and clp->cl_sem held. | 704 | * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or |
687 | * | 705 | * failed with a seqid incrementing error - |
688 | * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or | 706 | * see comments nfs_fs.h:seqid_mutating_error() |
689 | * failed with a seqid incrementing error - | 707 | */ |
690 | * see comments nfs_fs.h:seqid_mutating_error() | 708 | static inline void nfs_increment_seqid(int status, struct nfs_seqid *seqid) |
691 | */ | 709 | { |
692 | void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp) | 710 | switch (status) { |
693 | { | 711 | case 0: |
694 | if (status == NFS_OK || seqid_mutating_err(-status)) | 712 | break; |
695 | sp->so_seqid++; | 713 | case -NFS4ERR_BAD_SEQID: |
696 | /* If the server returns BAD_SEQID, unhash state_owner here */ | 714 | case -NFS4ERR_STALE_CLIENTID: |
697 | if (status == -NFS4ERR_BAD_SEQID) | 715 | case -NFS4ERR_STALE_STATEID: |
716 | case -NFS4ERR_BAD_STATEID: | ||
717 | case -NFS4ERR_BADXDR: | ||
718 | case -NFS4ERR_RESOURCE: | ||
719 | case -NFS4ERR_NOFILEHANDLE: | ||
720 | /* Non-seqid mutating errors */ | ||
721 | return; | ||
722 | }; | ||
723 | /* | ||
724 | * Note: no locking needed as we are guaranteed to be first | ||
725 | * on the sequence list | ||
726 | */ | ||
727 | seqid->sequence->counter++; | ||
728 | } | ||
729 | |||
730 | void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) | ||
731 | { | ||
732 | if (status == -NFS4ERR_BAD_SEQID) { | ||
733 | struct nfs4_state_owner *sp = container_of(seqid->sequence, | ||
734 | struct nfs4_state_owner, so_seqid); | ||
698 | nfs4_drop_state_owner(sp); | 735 | nfs4_drop_state_owner(sp); |
736 | } | ||
737 | return nfs_increment_seqid(status, seqid); | ||
738 | } | ||
739 | |||
740 | /* | ||
741 | * Increment the seqid if the LOCK/LOCKU succeeded, or | ||
742 | * failed with a seqid incrementing error - | ||
743 | * see comments nfs_fs.h:seqid_mutating_error() | ||
744 | */ | ||
745 | void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) | ||
746 | { | ||
747 | return nfs_increment_seqid(status, seqid); | ||
748 | } | ||
749 | |||
750 | int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) | ||
751 | { | ||
752 | struct rpc_sequence *sequence = seqid->sequence->sequence; | ||
753 | int status = 0; | ||
754 | |||
755 | spin_lock(&sequence->lock); | ||
756 | if (sequence->list.next != &seqid->list) { | ||
757 | seqid->task = task; | ||
758 | rpc_sleep_on(&sequence->wait, task, NULL, NULL); | ||
759 | status = -EAGAIN; | ||
760 | } | ||
761 | spin_unlock(&sequence->lock); | ||
762 | return status; | ||
699 | } | 763 | } |
700 | 764 | ||
701 | static int reclaimer(void *); | 765 | static int reclaimer(void *); |
@@ -791,8 +855,6 @@ static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct n | |||
791 | if (state->state == 0) | 855 | if (state->state == 0) |
792 | continue; | 856 | continue; |
793 | status = ops->recover_open(sp, state); | 857 | status = ops->recover_open(sp, state); |
794 | list_for_each_entry(lock, &state->lock_states, ls_locks) | ||
795 | lock->ls_flags &= ~NFS_LOCK_INITIALIZED; | ||
796 | if (status >= 0) { | 858 | if (status >= 0) { |
797 | status = nfs4_reclaim_locks(ops, state); | 859 | status = nfs4_reclaim_locks(ops, state); |
798 | if (status < 0) | 860 | if (status < 0) |
@@ -831,6 +893,26 @@ out_err: | |||
831 | return status; | 893 | return status; |
832 | } | 894 | } |
833 | 895 | ||
896 | static void nfs4_state_mark_reclaim(struct nfs4_client *clp) | ||
897 | { | ||
898 | struct nfs4_state_owner *sp; | ||
899 | struct nfs4_state *state; | ||
900 | struct nfs4_lock_state *lock; | ||
901 | |||
902 | /* Reset all sequence ids to zero */ | ||
903 | list_for_each_entry(sp, &clp->cl_state_owners, so_list) { | ||
904 | sp->so_seqid.counter = 0; | ||
905 | sp->so_seqid.flags = 0; | ||
906 | list_for_each_entry(state, &sp->so_states, open_states) { | ||
907 | list_for_each_entry(lock, &state->lock_states, ls_locks) { | ||
908 | lock->ls_seqid.counter = 0; | ||
909 | lock->ls_seqid.flags = 0; | ||
910 | lock->ls_flags &= ~NFS_LOCK_INITIALIZED; | ||
911 | } | ||
912 | } | ||
913 | } | ||
914 | } | ||
915 | |||
834 | static int reclaimer(void *ptr) | 916 | static int reclaimer(void *ptr) |
835 | { | 917 | { |
836 | struct reclaimer_args *args = (struct reclaimer_args *)ptr; | 918 | struct reclaimer_args *args = (struct reclaimer_args *)ptr; |
@@ -864,6 +946,7 @@ restart_loop: | |||
864 | default: | 946 | default: |
865 | ops = &nfs4_network_partition_recovery_ops; | 947 | ops = &nfs4_network_partition_recovery_ops; |
866 | }; | 948 | }; |
949 | nfs4_state_mark_reclaim(clp); | ||
867 | status = __nfs4_init_client(clp); | 950 | status = __nfs4_init_client(clp); |
868 | if (status) | 951 | if (status) |
869 | goto out_error; | 952 | goto out_error; |
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 6c564ef948..c5c75235c5 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
@@ -602,10 +602,10 @@ static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg) | |||
602 | { | 602 | { |
603 | uint32_t *p; | 603 | uint32_t *p; |
604 | 604 | ||
605 | RESERVE_SPACE(8+sizeof(arg->stateid.data)); | 605 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
606 | WRITE32(OP_CLOSE); | 606 | WRITE32(OP_CLOSE); |
607 | WRITE32(arg->seqid); | 607 | WRITE32(arg->seqid->sequence->counter); |
608 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); | 608 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
609 | 609 | ||
610 | return 0; | 610 | return 0; |
611 | } | 611 | } |
@@ -729,22 +729,18 @@ static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg) | |||
729 | WRITE64(arg->length); | 729 | WRITE64(arg->length); |
730 | WRITE32(opargs->new_lock_owner); | 730 | WRITE32(opargs->new_lock_owner); |
731 | if (opargs->new_lock_owner){ | 731 | if (opargs->new_lock_owner){ |
732 | struct nfs_open_to_lock *ol = opargs->u.open_lock; | ||
733 | |||
734 | RESERVE_SPACE(40); | 732 | RESERVE_SPACE(40); |
735 | WRITE32(ol->open_seqid); | 733 | WRITE32(opargs->open_seqid->sequence->counter); |
736 | WRITEMEM(&ol->open_stateid, sizeof(ol->open_stateid)); | 734 | WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data)); |
737 | WRITE32(ol->lock_seqid); | 735 | WRITE32(opargs->lock_seqid->sequence->counter); |
738 | WRITE64(ol->lock_owner.clientid); | 736 | WRITE64(opargs->lock_owner.clientid); |
739 | WRITE32(4); | 737 | WRITE32(4); |
740 | WRITE32(ol->lock_owner.id); | 738 | WRITE32(opargs->lock_owner.id); |
741 | } | 739 | } |
742 | else { | 740 | else { |
743 | struct nfs_exist_lock *el = opargs->u.exist_lock; | ||
744 | |||
745 | RESERVE_SPACE(20); | 741 | RESERVE_SPACE(20); |
746 | WRITEMEM(&el->stateid, sizeof(el->stateid)); | 742 | WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data)); |
747 | WRITE32(el->seqid); | 743 | WRITE32(opargs->lock_seqid->sequence->counter); |
748 | } | 744 | } |
749 | 745 | ||
750 | return 0; | 746 | return 0; |
@@ -775,8 +771,8 @@ static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg) | |||
775 | RESERVE_SPACE(44); | 771 | RESERVE_SPACE(44); |
776 | WRITE32(OP_LOCKU); | 772 | WRITE32(OP_LOCKU); |
777 | WRITE32(arg->type); | 773 | WRITE32(arg->type); |
778 | WRITE32(opargs->seqid); | 774 | WRITE32(opargs->seqid->sequence->counter); |
779 | WRITEMEM(&opargs->stateid, sizeof(opargs->stateid)); | 775 | WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data)); |
780 | WRITE64(arg->offset); | 776 | WRITE64(arg->offset); |
781 | WRITE64(arg->length); | 777 | WRITE64(arg->length); |
782 | 778 | ||
@@ -826,7 +822,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena | |||
826 | */ | 822 | */ |
827 | RESERVE_SPACE(8); | 823 | RESERVE_SPACE(8); |
828 | WRITE32(OP_OPEN); | 824 | WRITE32(OP_OPEN); |
829 | WRITE32(arg->seqid); | 825 | WRITE32(arg->seqid->sequence->counter); |
830 | encode_share_access(xdr, arg->open_flags); | 826 | encode_share_access(xdr, arg->open_flags); |
831 | RESERVE_SPACE(16); | 827 | RESERVE_SPACE(16); |
832 | WRITE64(arg->clientid); | 828 | WRITE64(arg->clientid); |
@@ -941,7 +937,7 @@ static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_con | |||
941 | RESERVE_SPACE(8+sizeof(arg->stateid.data)); | 937 | RESERVE_SPACE(8+sizeof(arg->stateid.data)); |
942 | WRITE32(OP_OPEN_CONFIRM); | 938 | WRITE32(OP_OPEN_CONFIRM); |
943 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); | 939 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); |
944 | WRITE32(arg->seqid); | 940 | WRITE32(arg->seqid->sequence->counter); |
945 | 941 | ||
946 | return 0; | 942 | return 0; |
947 | } | 943 | } |
@@ -950,10 +946,10 @@ static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closea | |||
950 | { | 946 | { |
951 | uint32_t *p; | 947 | uint32_t *p; |
952 | 948 | ||
953 | RESERVE_SPACE(8+sizeof(arg->stateid.data)); | 949 | RESERVE_SPACE(8+sizeof(arg->stateid->data)); |
954 | WRITE32(OP_OPEN_DOWNGRADE); | 950 | WRITE32(OP_OPEN_DOWNGRADE); |
955 | WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data)); | 951 | WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data)); |
956 | WRITE32(arg->seqid); | 952 | WRITE32(arg->seqid->sequence->counter); |
957 | encode_share_access(xdr, arg->open_flags); | 953 | encode_share_access(xdr, arg->open_flags); |
958 | return 0; | 954 | return 0; |
959 | } | 955 | } |
@@ -1437,6 +1433,9 @@ static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_opena | |||
1437 | }; | 1433 | }; |
1438 | int status; | 1434 | int status; |
1439 | 1435 | ||
1436 | status = nfs_wait_on_sequence(args->seqid, req->rq_task); | ||
1437 | if (status != 0) | ||
1438 | goto out; | ||
1440 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1439 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
1441 | encode_compound_hdr(&xdr, &hdr); | 1440 | encode_compound_hdr(&xdr, &hdr); |
1442 | status = encode_putfh(&xdr, args->fh); | 1441 | status = encode_putfh(&xdr, args->fh); |
@@ -1464,6 +1463,9 @@ static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct n | |||
1464 | }; | 1463 | }; |
1465 | int status; | 1464 | int status; |
1466 | 1465 | ||
1466 | status = nfs_wait_on_sequence(args->seqid, req->rq_task); | ||
1467 | if (status != 0) | ||
1468 | goto out; | ||
1467 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1469 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
1468 | encode_compound_hdr(&xdr, &hdr); | 1470 | encode_compound_hdr(&xdr, &hdr); |
1469 | status = encode_putfh(&xdr, args->fh); | 1471 | status = encode_putfh(&xdr, args->fh); |
@@ -1485,6 +1487,9 @@ static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nf | |||
1485 | }; | 1487 | }; |
1486 | int status; | 1488 | int status; |
1487 | 1489 | ||
1490 | status = nfs_wait_on_sequence(args->seqid, req->rq_task); | ||
1491 | if (status != 0) | ||
1492 | goto out; | ||
1488 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1493 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
1489 | encode_compound_hdr(&xdr, &hdr); | 1494 | encode_compound_hdr(&xdr, &hdr); |
1490 | status = encode_putfh(&xdr, args->fh); | 1495 | status = encode_putfh(&xdr, args->fh); |
@@ -1525,8 +1530,15 @@ static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_locka | |||
1525 | struct compound_hdr hdr = { | 1530 | struct compound_hdr hdr = { |
1526 | .nops = 2, | 1531 | .nops = 2, |
1527 | }; | 1532 | }; |
1533 | struct nfs_lock_opargs *opargs = args->u.lock; | ||
1528 | int status; | 1534 | int status; |
1529 | 1535 | ||
1536 | status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task); | ||
1537 | if (status != 0) | ||
1538 | goto out; | ||
1539 | /* Do we need to do an open_to_lock_owner? */ | ||
1540 | if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED) | ||
1541 | opargs->new_lock_owner = 0; | ||
1530 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1542 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
1531 | encode_compound_hdr(&xdr, &hdr); | 1543 | encode_compound_hdr(&xdr, &hdr); |
1532 | status = encode_putfh(&xdr, args->fh); | 1544 | status = encode_putfh(&xdr, args->fh); |
@@ -2890,8 +2902,8 @@ static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res) | |||
2890 | 2902 | ||
2891 | status = decode_op_hdr(xdr, OP_LOCK); | 2903 | status = decode_op_hdr(xdr, OP_LOCK); |
2892 | if (status == 0) { | 2904 | if (status == 0) { |
2893 | READ_BUF(sizeof(nfs4_stateid)); | 2905 | READ_BUF(sizeof(res->u.stateid.data)); |
2894 | COPYMEM(&res->u.stateid, sizeof(res->u.stateid)); | 2906 | COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data)); |
2895 | } else if (status == -NFS4ERR_DENIED) | 2907 | } else if (status == -NFS4ERR_DENIED) |
2896 | return decode_lock_denied(xdr, &res->u.denied); | 2908 | return decode_lock_denied(xdr, &res->u.denied); |
2897 | return status; | 2909 | return status; |
@@ -2913,8 +2925,8 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res) | |||
2913 | 2925 | ||
2914 | status = decode_op_hdr(xdr, OP_LOCKU); | 2926 | status = decode_op_hdr(xdr, OP_LOCKU); |
2915 | if (status == 0) { | 2927 | if (status == 0) { |
2916 | READ_BUF(sizeof(nfs4_stateid)); | 2928 | READ_BUF(sizeof(res->u.stateid.data)); |
2917 | COPYMEM(&res->u.stateid, sizeof(res->u.stateid)); | 2929 | COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data)); |
2918 | } | 2930 | } |
2919 | return status; | 2931 | return status; |
2920 | } | 2932 | } |
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c index be23c3fb92..8fef86523d 100644 --- a/fs/nfs/proc.c +++ b/fs/nfs/proc.c | |||
@@ -216,7 +216,7 @@ static int nfs_proc_write(struct nfs_write_data *wdata) | |||
216 | 216 | ||
217 | static int | 217 | static int |
218 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 218 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
219 | int flags) | 219 | int flags, struct nameidata *nd) |
220 | { | 220 | { |
221 | struct nfs_fh fhandle; | 221 | struct nfs_fh fhandle; |
222 | struct nfs_fattr fattr; | 222 | struct nfs_fattr fattr; |
@@ -739,7 +739,8 @@ asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group) | |||
739 | } | 739 | } |
740 | 740 | ||
741 | static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, | 741 | static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, |
742 | int flags, struct file *f) | 742 | int flags, struct file *f, |
743 | int (*open)(struct inode *, struct file *)) | ||
743 | { | 744 | { |
744 | struct inode *inode; | 745 | struct inode *inode; |
745 | int error; | 746 | int error; |
@@ -761,11 +762,14 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, | |||
761 | f->f_op = fops_get(inode->i_fop); | 762 | f->f_op = fops_get(inode->i_fop); |
762 | file_move(f, &inode->i_sb->s_files); | 763 | file_move(f, &inode->i_sb->s_files); |
763 | 764 | ||
764 | if (f->f_op && f->f_op->open) { | 765 | if (!open && f->f_op) |
765 | error = f->f_op->open(inode,f); | 766 | open = f->f_op->open; |
767 | if (open) { | ||
768 | error = open(inode, f); | ||
766 | if (error) | 769 | if (error) |
767 | goto cleanup_all; | 770 | goto cleanup_all; |
768 | } | 771 | } |
772 | |||
769 | f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); | 773 | f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); |
770 | 774 | ||
771 | file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); | 775 | file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); |
@@ -814,28 +818,75 @@ struct file *filp_open(const char * filename, int flags, int mode) | |||
814 | { | 818 | { |
815 | int namei_flags, error; | 819 | int namei_flags, error; |
816 | struct nameidata nd; | 820 | struct nameidata nd; |
817 | struct file *f; | ||
818 | 821 | ||
819 | namei_flags = flags; | 822 | namei_flags = flags; |
820 | if ((namei_flags+1) & O_ACCMODE) | 823 | if ((namei_flags+1) & O_ACCMODE) |
821 | namei_flags++; | 824 | namei_flags++; |
822 | if (namei_flags & O_TRUNC) | ||
823 | namei_flags |= 2; | ||
824 | |||
825 | error = -ENFILE; | ||
826 | f = get_empty_filp(); | ||
827 | if (f == NULL) | ||
828 | return ERR_PTR(error); | ||
829 | 825 | ||
830 | error = open_namei(filename, namei_flags, mode, &nd); | 826 | error = open_namei(filename, namei_flags, mode, &nd); |
831 | if (!error) | 827 | if (!error) |
832 | return __dentry_open(nd.dentry, nd.mnt, flags, f); | 828 | return nameidata_to_filp(&nd, flags); |
833 | 829 | ||
834 | put_filp(f); | ||
835 | return ERR_PTR(error); | 830 | return ERR_PTR(error); |
836 | } | 831 | } |
837 | EXPORT_SYMBOL(filp_open); | 832 | EXPORT_SYMBOL(filp_open); |
838 | 833 | ||
834 | /** | ||
835 | * lookup_instantiate_filp - instantiates the open intent filp | ||
836 | * @nd: pointer to nameidata | ||
837 | * @dentry: pointer to dentry | ||
838 | * @open: open callback | ||
839 | * | ||
840 | * Helper for filesystems that want to use lookup open intents and pass back | ||
841 | * a fully instantiated struct file to the caller. | ||
842 | * This function is meant to be called from within a filesystem's | ||
843 | * lookup method. | ||
844 | * Note that in case of error, nd->intent.open.file is destroyed, but the | ||
845 | * path information remains valid. | ||
846 | * If the open callback is set to NULL, then the standard f_op->open() | ||
847 | * filesystem callback is substituted. | ||
848 | */ | ||
849 | struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry, | ||
850 | int (*open)(struct inode *, struct file *)) | ||
851 | { | ||
852 | if (IS_ERR(nd->intent.open.file)) | ||
853 | goto out; | ||
854 | if (IS_ERR(dentry)) | ||
855 | goto out_err; | ||
856 | nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->mnt), | ||
857 | nd->intent.open.flags - 1, | ||
858 | nd->intent.open.file, | ||
859 | open); | ||
860 | out: | ||
861 | return nd->intent.open.file; | ||
862 | out_err: | ||
863 | release_open_intent(nd); | ||
864 | nd->intent.open.file = (struct file *)dentry; | ||
865 | goto out; | ||
866 | } | ||
867 | EXPORT_SYMBOL_GPL(lookup_instantiate_filp); | ||
868 | |||
869 | /** | ||
870 | * nameidata_to_filp - convert a nameidata to an open filp. | ||
871 | * @nd: pointer to nameidata | ||
872 | * @flags: open flags | ||
873 | * | ||
874 | * Note that this function destroys the original nameidata | ||
875 | */ | ||
876 | struct file *nameidata_to_filp(struct nameidata *nd, int flags) | ||
877 | { | ||
878 | struct file *filp; | ||
879 | |||
880 | /* Pick up the filp from the open intent */ | ||
881 | filp = nd->intent.open.file; | ||
882 | /* Has the filesystem initialised the file for us? */ | ||
883 | if (filp->f_dentry == NULL) | ||
884 | filp = __dentry_open(nd->dentry, nd->mnt, flags, filp, NULL); | ||
885 | else | ||
886 | path_release(nd); | ||
887 | return filp; | ||
888 | } | ||
889 | |||
839 | struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) | 890 | struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) |
840 | { | 891 | { |
841 | int error; | 892 | int error; |
@@ -846,7 +897,7 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) | |||
846 | if (f == NULL) | 897 | if (f == NULL) |
847 | return ERR_PTR(error); | 898 | return ERR_PTR(error); |
848 | 899 | ||
849 | return __dentry_open(dentry, mnt, flags, f); | 900 | return __dentry_open(dentry, mnt, flags, f, NULL); |
850 | } | 901 | } |
851 | EXPORT_SYMBOL(dentry_open); | 902 | EXPORT_SYMBOL(dentry_open); |
852 | 903 | ||
diff --git a/fs/proc/base.c b/fs/proc/base.c index 3b33f94020..a170450aad 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -103,7 +103,9 @@ enum pid_directory_inos { | |||
103 | PROC_TGID_NUMA_MAPS, | 103 | PROC_TGID_NUMA_MAPS, |
104 | PROC_TGID_MOUNTS, | 104 | PROC_TGID_MOUNTS, |
105 | PROC_TGID_WCHAN, | 105 | PROC_TGID_WCHAN, |
106 | #ifdef CONFIG_MMU | ||
106 | PROC_TGID_SMAPS, | 107 | PROC_TGID_SMAPS, |
108 | #endif | ||
107 | #ifdef CONFIG_SCHEDSTATS | 109 | #ifdef CONFIG_SCHEDSTATS |
108 | PROC_TGID_SCHEDSTAT, | 110 | PROC_TGID_SCHEDSTAT, |
109 | #endif | 111 | #endif |
@@ -141,7 +143,9 @@ enum pid_directory_inos { | |||
141 | PROC_TID_NUMA_MAPS, | 143 | PROC_TID_NUMA_MAPS, |
142 | PROC_TID_MOUNTS, | 144 | PROC_TID_MOUNTS, |
143 | PROC_TID_WCHAN, | 145 | PROC_TID_WCHAN, |
146 | #ifdef CONFIG_MMU | ||
144 | PROC_TID_SMAPS, | 147 | PROC_TID_SMAPS, |
148 | #endif | ||
145 | #ifdef CONFIG_SCHEDSTATS | 149 | #ifdef CONFIG_SCHEDSTATS |
146 | PROC_TID_SCHEDSTAT, | 150 | PROC_TID_SCHEDSTAT, |
147 | #endif | 151 | #endif |
@@ -195,7 +199,9 @@ static struct pid_entry tgid_base_stuff[] = { | |||
195 | E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO), | 199 | E(PROC_TGID_ROOT, "root", S_IFLNK|S_IRWXUGO), |
196 | E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO), | 200 | E(PROC_TGID_EXE, "exe", S_IFLNK|S_IRWXUGO), |
197 | E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO), | 201 | E(PROC_TGID_MOUNTS, "mounts", S_IFREG|S_IRUGO), |
202 | #ifdef CONFIG_MMU | ||
198 | E(PROC_TGID_SMAPS, "smaps", S_IFREG|S_IRUGO), | 203 | E(PROC_TGID_SMAPS, "smaps", S_IFREG|S_IRUGO), |
204 | #endif | ||
199 | #ifdef CONFIG_SECURITY | 205 | #ifdef CONFIG_SECURITY |
200 | E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), | 206 | E(PROC_TGID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), |
201 | #endif | 207 | #endif |
@@ -235,7 +241,9 @@ static struct pid_entry tid_base_stuff[] = { | |||
235 | E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO), | 241 | E(PROC_TID_ROOT, "root", S_IFLNK|S_IRWXUGO), |
236 | E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO), | 242 | E(PROC_TID_EXE, "exe", S_IFLNK|S_IRWXUGO), |
237 | E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO), | 243 | E(PROC_TID_MOUNTS, "mounts", S_IFREG|S_IRUGO), |
244 | #ifdef CONFIG_MMU | ||
238 | E(PROC_TID_SMAPS, "smaps", S_IFREG|S_IRUGO), | 245 | E(PROC_TID_SMAPS, "smaps", S_IFREG|S_IRUGO), |
246 | #endif | ||
239 | #ifdef CONFIG_SECURITY | 247 | #ifdef CONFIG_SECURITY |
240 | E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), | 248 | E(PROC_TID_ATTR, "attr", S_IFDIR|S_IRUGO|S_IXUGO), |
241 | #endif | 249 | #endif |
@@ -630,6 +638,7 @@ static struct file_operations proc_numa_maps_operations = { | |||
630 | }; | 638 | }; |
631 | #endif | 639 | #endif |
632 | 640 | ||
641 | #ifdef CONFIG_MMU | ||
633 | extern struct seq_operations proc_pid_smaps_op; | 642 | extern struct seq_operations proc_pid_smaps_op; |
634 | static int smaps_open(struct inode *inode, struct file *file) | 643 | static int smaps_open(struct inode *inode, struct file *file) |
635 | { | 644 | { |
@@ -648,6 +657,7 @@ static struct file_operations proc_smaps_operations = { | |||
648 | .llseek = seq_lseek, | 657 | .llseek = seq_lseek, |
649 | .release = seq_release, | 658 | .release = seq_release, |
650 | }; | 659 | }; |
660 | #endif | ||
651 | 661 | ||
652 | extern struct seq_operations mounts_op; | 662 | extern struct seq_operations mounts_op; |
653 | static int mounts_open(struct inode *inode, struct file *file) | 663 | static int mounts_open(struct inode *inode, struct file *file) |
@@ -1681,10 +1691,12 @@ static struct dentry *proc_pident_lookup(struct inode *dir, | |||
1681 | case PROC_TGID_MOUNTS: | 1691 | case PROC_TGID_MOUNTS: |
1682 | inode->i_fop = &proc_mounts_operations; | 1692 | inode->i_fop = &proc_mounts_operations; |
1683 | break; | 1693 | break; |
1694 | #ifdef CONFIG_MMU | ||
1684 | case PROC_TID_SMAPS: | 1695 | case PROC_TID_SMAPS: |
1685 | case PROC_TGID_SMAPS: | 1696 | case PROC_TGID_SMAPS: |
1686 | inode->i_fop = &proc_smaps_operations; | 1697 | inode->i_fop = &proc_smaps_operations; |
1687 | break; | 1698 | break; |
1699 | #endif | ||
1688 | #ifdef CONFIG_SECURITY | 1700 | #ifdef CONFIG_SECURITY |
1689 | case PROC_TID_ATTR: | 1701 | case PROC_TID_ATTR: |
1690 | inode->i_nlink = 2; | 1702 | inode->i_nlink = 2; |
diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c index f3bf016d5e..cff10ab1af 100644 --- a/fs/proc/nommu.c +++ b/fs/proc/nommu.c | |||
@@ -91,6 +91,7 @@ static void *nommu_vma_list_start(struct seq_file *m, loff_t *_pos) | |||
91 | next = _rb; | 91 | next = _rb; |
92 | break; | 92 | break; |
93 | } | 93 | } |
94 | pos--; | ||
94 | } | 95 | } |
95 | 96 | ||
96 | return next; | 97 | return next; |