aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorStanislav Kinsbursky <skinsbursky@parallels.com>2011-12-26 07:43:23 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-01-31 18:20:24 -0500
commit766347bec3490111e1c4482af7c7394868c2aed1 (patch)
treeafc06a17ceb7e7f1f0e119ec21e0102063b6992a /net
parentefc46bf2b2893132e07628ad8c06e915f3281fdc (diff)
SUNRPC: replace inode lock with pipe lock for RPC PipeFS operations
Currenly, inode i_lock is used to provide concurrent access to SUNPRC PipeFS pipes. It looks redundant, since now other use of inode is present in most of these places and thus can be easely replaced, which will allow to remove most of inode references from PipeFS code. This is a first step towards to removing PipeFS inode references from kernel code other than PipeFS itself. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net')
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c57
-rw-r--r--net/sunrpc/rpc_pipe.c38
2 files changed, 47 insertions, 48 deletions
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index affa631ac1ab..a0844f92a447 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -112,7 +112,7 @@ gss_put_ctx(struct gss_cl_ctx *ctx)
112/* gss_cred_set_ctx: 112/* gss_cred_set_ctx:
113 * called by gss_upcall_callback and gss_create_upcall in order 113 * called by gss_upcall_callback and gss_create_upcall in order
114 * to set the gss context. The actual exchange of an old context 114 * to set the gss context. The actual exchange of an old context
115 * and a new one is protected by the inode->i_lock. 115 * and a new one is protected by the rpci->lock.
116 */ 116 */
117static void 117static void
118gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx) 118gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
@@ -316,17 +316,16 @@ static inline struct gss_upcall_msg *
316gss_add_msg(struct gss_upcall_msg *gss_msg) 316gss_add_msg(struct gss_upcall_msg *gss_msg)
317{ 317{
318 struct rpc_inode *rpci = gss_msg->inode; 318 struct rpc_inode *rpci = gss_msg->inode;
319 struct inode *inode = &rpci->vfs_inode;
320 struct gss_upcall_msg *old; 319 struct gss_upcall_msg *old;
321 320
322 spin_lock(&inode->i_lock); 321 spin_lock(&rpci->lock);
323 old = __gss_find_upcall(rpci, gss_msg->uid); 322 old = __gss_find_upcall(rpci, gss_msg->uid);
324 if (old == NULL) { 323 if (old == NULL) {
325 atomic_inc(&gss_msg->count); 324 atomic_inc(&gss_msg->count);
326 list_add(&gss_msg->list, &rpci->in_downcall); 325 list_add(&gss_msg->list, &rpci->in_downcall);
327 } else 326 } else
328 gss_msg = old; 327 gss_msg = old;
329 spin_unlock(&inode->i_lock); 328 spin_unlock(&rpci->lock);
330 return gss_msg; 329 return gss_msg;
331} 330}
332 331
@@ -342,14 +341,14 @@ __gss_unhash_msg(struct gss_upcall_msg *gss_msg)
342static void 341static void
343gss_unhash_msg(struct gss_upcall_msg *gss_msg) 342gss_unhash_msg(struct gss_upcall_msg *gss_msg)
344{ 343{
345 struct inode *inode = &gss_msg->inode->vfs_inode; 344 struct rpc_inode *rpci = gss_msg->inode;
346 345
347 if (list_empty(&gss_msg->list)) 346 if (list_empty(&gss_msg->list))
348 return; 347 return;
349 spin_lock(&inode->i_lock); 348 spin_lock(&rpci->lock);
350 if (!list_empty(&gss_msg->list)) 349 if (!list_empty(&gss_msg->list))
351 __gss_unhash_msg(gss_msg); 350 __gss_unhash_msg(gss_msg);
352 spin_unlock(&inode->i_lock); 351 spin_unlock(&rpci->lock);
353} 352}
354 353
355static void 354static void
@@ -376,11 +375,11 @@ gss_upcall_callback(struct rpc_task *task)
376 struct gss_cred *gss_cred = container_of(task->tk_rqstp->rq_cred, 375 struct gss_cred *gss_cred = container_of(task->tk_rqstp->rq_cred,
377 struct gss_cred, gc_base); 376 struct gss_cred, gc_base);
378 struct gss_upcall_msg *gss_msg = gss_cred->gc_upcall; 377 struct gss_upcall_msg *gss_msg = gss_cred->gc_upcall;
379 struct inode *inode = &gss_msg->inode->vfs_inode; 378 struct rpc_inode *rpci = gss_msg->inode;
380 379
381 spin_lock(&inode->i_lock); 380 spin_lock(&rpci->lock);
382 gss_handle_downcall_result(gss_cred, gss_msg); 381 gss_handle_downcall_result(gss_cred, gss_msg);
383 spin_unlock(&inode->i_lock); 382 spin_unlock(&rpci->lock);
384 task->tk_status = gss_msg->msg.errno; 383 task->tk_status = gss_msg->msg.errno;
385 gss_release_msg(gss_msg); 384 gss_release_msg(gss_msg);
386} 385}
@@ -506,7 +505,7 @@ gss_refresh_upcall(struct rpc_task *task)
506 struct gss_cred *gss_cred = container_of(cred, 505 struct gss_cred *gss_cred = container_of(cred,
507 struct gss_cred, gc_base); 506 struct gss_cred, gc_base);
508 struct gss_upcall_msg *gss_msg; 507 struct gss_upcall_msg *gss_msg;
509 struct inode *inode; 508 struct rpc_inode *rpci;
510 int err = 0; 509 int err = 0;
511 510
512 dprintk("RPC: %5u gss_refresh_upcall for uid %u\n", task->tk_pid, 511 dprintk("RPC: %5u gss_refresh_upcall for uid %u\n", task->tk_pid,
@@ -524,8 +523,8 @@ gss_refresh_upcall(struct rpc_task *task)
524 err = PTR_ERR(gss_msg); 523 err = PTR_ERR(gss_msg);
525 goto out; 524 goto out;
526 } 525 }
527 inode = &gss_msg->inode->vfs_inode; 526 rpci = gss_msg->inode;
528 spin_lock(&inode->i_lock); 527 spin_lock(&rpci->lock);
529 if (gss_cred->gc_upcall != NULL) 528 if (gss_cred->gc_upcall != NULL)
530 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL); 529 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL);
531 else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) { 530 else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) {
@@ -538,7 +537,7 @@ gss_refresh_upcall(struct rpc_task *task)
538 gss_handle_downcall_result(gss_cred, gss_msg); 537 gss_handle_downcall_result(gss_cred, gss_msg);
539 err = gss_msg->msg.errno; 538 err = gss_msg->msg.errno;
540 } 539 }
541 spin_unlock(&inode->i_lock); 540 spin_unlock(&rpci->lock);
542 gss_release_msg(gss_msg); 541 gss_release_msg(gss_msg);
543out: 542out:
544 dprintk("RPC: %5u gss_refresh_upcall for uid %u result %d\n", 543 dprintk("RPC: %5u gss_refresh_upcall for uid %u result %d\n",
@@ -549,7 +548,7 @@ out:
549static inline int 548static inline int
550gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred) 549gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)
551{ 550{
552 struct inode *inode; 551 struct rpc_inode *rpci;
553 struct rpc_cred *cred = &gss_cred->gc_base; 552 struct rpc_cred *cred = &gss_cred->gc_base;
554 struct gss_upcall_msg *gss_msg; 553 struct gss_upcall_msg *gss_msg;
555 DEFINE_WAIT(wait); 554 DEFINE_WAIT(wait);
@@ -573,14 +572,14 @@ retry:
573 err = PTR_ERR(gss_msg); 572 err = PTR_ERR(gss_msg);
574 goto out; 573 goto out;
575 } 574 }
576 inode = &gss_msg->inode->vfs_inode; 575 rpci = gss_msg->inode;
577 for (;;) { 576 for (;;) {
578 prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_KILLABLE); 577 prepare_to_wait(&gss_msg->waitqueue, &wait, TASK_KILLABLE);
579 spin_lock(&inode->i_lock); 578 spin_lock(&rpci->lock);
580 if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) { 579 if (gss_msg->ctx != NULL || gss_msg->msg.errno < 0) {
581 break; 580 break;
582 } 581 }
583 spin_unlock(&inode->i_lock); 582 spin_unlock(&rpci->lock);
584 if (fatal_signal_pending(current)) { 583 if (fatal_signal_pending(current)) {
585 err = -ERESTARTSYS; 584 err = -ERESTARTSYS;
586 goto out_intr; 585 goto out_intr;
@@ -591,7 +590,7 @@ retry:
591 gss_cred_set_ctx(cred, gss_msg->ctx); 590 gss_cred_set_ctx(cred, gss_msg->ctx);
592 else 591 else
593 err = gss_msg->msg.errno; 592 err = gss_msg->msg.errno;
594 spin_unlock(&inode->i_lock); 593 spin_unlock(&rpci->lock);
595out_intr: 594out_intr:
596 finish_wait(&gss_msg->waitqueue, &wait); 595 finish_wait(&gss_msg->waitqueue, &wait);
597 gss_release_msg(gss_msg); 596 gss_release_msg(gss_msg);
@@ -609,7 +608,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
609 const void *p, *end; 608 const void *p, *end;
610 void *buf; 609 void *buf;
611 struct gss_upcall_msg *gss_msg; 610 struct gss_upcall_msg *gss_msg;
612 struct inode *inode = filp->f_path.dentry->d_inode; 611 struct rpc_inode *rpci = RPC_I(filp->f_dentry->d_inode);
613 struct gss_cl_ctx *ctx; 612 struct gss_cl_ctx *ctx;
614 uid_t uid; 613 uid_t uid;
615 ssize_t err = -EFBIG; 614 ssize_t err = -EFBIG;
@@ -639,14 +638,14 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
639 638
640 err = -ENOENT; 639 err = -ENOENT;
641 /* Find a matching upcall */ 640 /* Find a matching upcall */
642 spin_lock(&inode->i_lock); 641 spin_lock(&rpci->lock);
643 gss_msg = __gss_find_upcall(RPC_I(inode), uid); 642 gss_msg = __gss_find_upcall(rpci, uid);
644 if (gss_msg == NULL) { 643 if (gss_msg == NULL) {
645 spin_unlock(&inode->i_lock); 644 spin_unlock(&rpci->lock);
646 goto err_put_ctx; 645 goto err_put_ctx;
647 } 646 }
648 list_del_init(&gss_msg->list); 647 list_del_init(&gss_msg->list);
649 spin_unlock(&inode->i_lock); 648 spin_unlock(&rpci->lock);
650 649
651 p = gss_fill_context(p, end, ctx, gss_msg->auth->mech); 650 p = gss_fill_context(p, end, ctx, gss_msg->auth->mech);
652 if (IS_ERR(p)) { 651 if (IS_ERR(p)) {
@@ -674,9 +673,9 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
674 err = mlen; 673 err = mlen;
675 674
676err_release_msg: 675err_release_msg:
677 spin_lock(&inode->i_lock); 676 spin_lock(&rpci->lock);
678 __gss_unhash_msg(gss_msg); 677 __gss_unhash_msg(gss_msg);
679 spin_unlock(&inode->i_lock); 678 spin_unlock(&rpci->lock);
680 gss_release_msg(gss_msg); 679 gss_release_msg(gss_msg);
681err_put_ctx: 680err_put_ctx:
682 gss_put_ctx(ctx); 681 gss_put_ctx(ctx);
@@ -726,7 +725,7 @@ gss_pipe_release(struct inode *inode)
726 struct gss_upcall_msg *gss_msg; 725 struct gss_upcall_msg *gss_msg;
727 726
728restart: 727restart:
729 spin_lock(&inode->i_lock); 728 spin_lock(&rpci->lock);
730 list_for_each_entry(gss_msg, &rpci->in_downcall, list) { 729 list_for_each_entry(gss_msg, &rpci->in_downcall, list) {
731 730
732 if (!list_empty(&gss_msg->msg.list)) 731 if (!list_empty(&gss_msg->msg.list))
@@ -734,11 +733,11 @@ restart:
734 gss_msg->msg.errno = -EPIPE; 733 gss_msg->msg.errno = -EPIPE;
735 atomic_inc(&gss_msg->count); 734 atomic_inc(&gss_msg->count);
736 __gss_unhash_msg(gss_msg); 735 __gss_unhash_msg(gss_msg);
737 spin_unlock(&inode->i_lock); 736 spin_unlock(&rpci->lock);
738 gss_release_msg(gss_msg); 737 gss_release_msg(gss_msg);
739 goto restart; 738 goto restart;
740 } 739 }
741 spin_unlock(&inode->i_lock); 740 spin_unlock(&rpci->lock);
742 741
743 put_pipe_version(); 742 put_pipe_version();
744} 743}
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 9a881138fead..16d9b9a701a4 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -83,12 +83,11 @@ rpc_timeout_upcall_queue(struct work_struct *work)
83 LIST_HEAD(free_list); 83 LIST_HEAD(free_list);
84 struct rpc_inode *rpci = 84 struct rpc_inode *rpci =
85 container_of(work, struct rpc_inode, queue_timeout.work); 85 container_of(work, struct rpc_inode, queue_timeout.work);
86 struct inode *inode = &rpci->vfs_inode;
87 void (*destroy_msg)(struct rpc_pipe_msg *); 86 void (*destroy_msg)(struct rpc_pipe_msg *);
88 87
89 spin_lock(&inode->i_lock); 88 spin_lock(&rpci->lock);
90 if (rpci->ops == NULL) { 89 if (rpci->ops == NULL) {
91 spin_unlock(&inode->i_lock); 90 spin_unlock(&rpci->lock);
92 return; 91 return;
93 } 92 }
94 destroy_msg = rpci->ops->destroy_msg; 93 destroy_msg = rpci->ops->destroy_msg;
@@ -96,7 +95,7 @@ rpc_timeout_upcall_queue(struct work_struct *work)
96 list_splice_init(&rpci->pipe, &free_list); 95 list_splice_init(&rpci->pipe, &free_list);
97 rpci->pipelen = 0; 96 rpci->pipelen = 0;
98 } 97 }
99 spin_unlock(&inode->i_lock); 98 spin_unlock(&rpci->lock);
100 rpc_purge_list(rpci, &free_list, destroy_msg, -ETIMEDOUT); 99 rpc_purge_list(rpci, &free_list, destroy_msg, -ETIMEDOUT);
101} 100}
102 101
@@ -136,7 +135,7 @@ rpc_queue_upcall(struct inode *inode, struct rpc_pipe_msg *msg)
136 struct rpc_inode *rpci = RPC_I(inode); 135 struct rpc_inode *rpci = RPC_I(inode);
137 int res = -EPIPE; 136 int res = -EPIPE;
138 137
139 spin_lock(&inode->i_lock); 138 spin_lock(&rpci->lock);
140 if (rpci->ops == NULL) 139 if (rpci->ops == NULL)
141 goto out; 140 goto out;
142 if (rpci->nreaders) { 141 if (rpci->nreaders) {
@@ -153,7 +152,7 @@ rpc_queue_upcall(struct inode *inode, struct rpc_pipe_msg *msg)
153 res = 0; 152 res = 0;
154 } 153 }
155out: 154out:
156 spin_unlock(&inode->i_lock); 155 spin_unlock(&rpci->lock);
157 wake_up(&rpci->waitq); 156 wake_up(&rpci->waitq);
158 return res; 157 return res;
159} 158}
@@ -176,14 +175,14 @@ rpc_close_pipes(struct inode *inode)
176 ops = rpci->ops; 175 ops = rpci->ops;
177 if (ops != NULL) { 176 if (ops != NULL) {
178 LIST_HEAD(free_list); 177 LIST_HEAD(free_list);
179 spin_lock(&inode->i_lock); 178 spin_lock(&rpci->lock);
180 need_release = rpci->nreaders != 0 || rpci->nwriters != 0; 179 need_release = rpci->nreaders != 0 || rpci->nwriters != 0;
181 rpci->nreaders = 0; 180 rpci->nreaders = 0;
182 list_splice_init(&rpci->in_upcall, &free_list); 181 list_splice_init(&rpci->in_upcall, &free_list);
183 list_splice_init(&rpci->pipe, &free_list); 182 list_splice_init(&rpci->pipe, &free_list);
184 rpci->pipelen = 0; 183 rpci->pipelen = 0;
185 rpci->ops = NULL; 184 rpci->ops = NULL;
186 spin_unlock(&inode->i_lock); 185 spin_unlock(&rpci->lock);
187 rpc_purge_list(rpci, &free_list, ops->destroy_msg, -EPIPE); 186 rpc_purge_list(rpci, &free_list, ops->destroy_msg, -EPIPE);
188 rpci->nwriters = 0; 187 rpci->nwriters = 0;
189 if (need_release && ops->release_pipe) 188 if (need_release && ops->release_pipe)
@@ -255,10 +254,10 @@ rpc_pipe_release(struct inode *inode, struct file *filp)
255 goto out; 254 goto out;
256 msg = filp->private_data; 255 msg = filp->private_data;
257 if (msg != NULL) { 256 if (msg != NULL) {
258 spin_lock(&inode->i_lock); 257 spin_lock(&rpci->lock);
259 msg->errno = -EAGAIN; 258 msg->errno = -EAGAIN;
260 list_del_init(&msg->list); 259 list_del_init(&msg->list);
261 spin_unlock(&inode->i_lock); 260 spin_unlock(&rpci->lock);
262 rpci->ops->destroy_msg(msg); 261 rpci->ops->destroy_msg(msg);
263 } 262 }
264 if (filp->f_mode & FMODE_WRITE) 263 if (filp->f_mode & FMODE_WRITE)
@@ -267,10 +266,10 @@ rpc_pipe_release(struct inode *inode, struct file *filp)
267 rpci->nreaders --; 266 rpci->nreaders --;
268 if (rpci->nreaders == 0) { 267 if (rpci->nreaders == 0) {
269 LIST_HEAD(free_list); 268 LIST_HEAD(free_list);
270 spin_lock(&inode->i_lock); 269 spin_lock(&rpci->lock);
271 list_splice_init(&rpci->pipe, &free_list); 270 list_splice_init(&rpci->pipe, &free_list);
272 rpci->pipelen = 0; 271 rpci->pipelen = 0;
273 spin_unlock(&inode->i_lock); 272 spin_unlock(&rpci->lock);
274 rpc_purge_list(rpci, &free_list, 273 rpc_purge_list(rpci, &free_list,
275 rpci->ops->destroy_msg, -EAGAIN); 274 rpci->ops->destroy_msg, -EAGAIN);
276 } 275 }
@@ -298,7 +297,7 @@ rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
298 } 297 }
299 msg = filp->private_data; 298 msg = filp->private_data;
300 if (msg == NULL) { 299 if (msg == NULL) {
301 spin_lock(&inode->i_lock); 300 spin_lock(&rpci->lock);
302 if (!list_empty(&rpci->pipe)) { 301 if (!list_empty(&rpci->pipe)) {
303 msg = list_entry(rpci->pipe.next, 302 msg = list_entry(rpci->pipe.next,
304 struct rpc_pipe_msg, 303 struct rpc_pipe_msg,
@@ -308,7 +307,7 @@ rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
308 filp->private_data = msg; 307 filp->private_data = msg;
309 msg->copied = 0; 308 msg->copied = 0;
310 } 309 }
311 spin_unlock(&inode->i_lock); 310 spin_unlock(&rpci->lock);
312 if (msg == NULL) 311 if (msg == NULL)
313 goto out_unlock; 312 goto out_unlock;
314 } 313 }
@@ -316,9 +315,9 @@ rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
316 res = rpci->ops->upcall(filp, msg, buf, len); 315 res = rpci->ops->upcall(filp, msg, buf, len);
317 if (res < 0 || msg->len == msg->copied) { 316 if (res < 0 || msg->len == msg->copied) {
318 filp->private_data = NULL; 317 filp->private_data = NULL;
319 spin_lock(&inode->i_lock); 318 spin_lock(&rpci->lock);
320 list_del_init(&msg->list); 319 list_del_init(&msg->list);
321 spin_unlock(&inode->i_lock); 320 spin_unlock(&rpci->lock);
322 rpci->ops->destroy_msg(msg); 321 rpci->ops->destroy_msg(msg);
323 } 322 }
324out_unlock: 323out_unlock:
@@ -367,9 +366,9 @@ rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
367 366
368 switch (cmd) { 367 switch (cmd) {
369 case FIONREAD: 368 case FIONREAD:
370 spin_lock(&inode->i_lock); 369 spin_lock(&rpci->lock);
371 if (rpci->ops == NULL) { 370 if (rpci->ops == NULL) {
372 spin_unlock(&inode->i_lock); 371 spin_unlock(&rpci->lock);
373 return -EPIPE; 372 return -EPIPE;
374 } 373 }
375 len = rpci->pipelen; 374 len = rpci->pipelen;
@@ -378,7 +377,7 @@ rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
378 msg = filp->private_data; 377 msg = filp->private_data;
379 len += msg->len - msg->copied; 378 len += msg->len - msg->copied;
380 } 379 }
381 spin_unlock(&inode->i_lock); 380 spin_unlock(&rpci->lock);
382 return put_user(len, (int __user *)arg); 381 return put_user(len, (int __user *)arg);
383 default: 382 default:
384 return -EINVAL; 383 return -EINVAL;
@@ -1153,6 +1152,7 @@ init_once(void *foo)
1153 INIT_DELAYED_WORK(&rpci->queue_timeout, 1152 INIT_DELAYED_WORK(&rpci->queue_timeout,
1154 rpc_timeout_upcall_queue); 1153 rpc_timeout_upcall_queue);
1155 rpci->ops = NULL; 1154 rpci->ops = NULL;
1155 spin_lock_init(&rpci->lock);
1156} 1156}
1157 1157
1158int register_rpc_pipefs(void) 1158int register_rpc_pipefs(void)