blob: 5b3cc3f4bb391520da6186039887bdb158915c57 [file] [log] [blame]
Ricardo Labiaga85e174b2010-10-20 00:17:58 -04001/*
2 * pNFS functions to call and manage layout drivers.
3 *
4 * Copyright (c) 2002 [year of first publication]
5 * The Regents of the University of Michigan
6 * All Rights Reserved
7 *
8 * Dean Hildebrand <dhildebz@umich.edu>
9 *
10 * Permission is granted to use, copy, create derivative works, and
11 * redistribute this software and such derivative works for any purpose,
12 * so long as the name of the University of Michigan is not used in
13 * any advertising or publicity pertaining to the use or distribution
14 * of this software without specific, written prior authorization. If
15 * the above copyright notice or any other identification of the
16 * University of Michigan is included in any copy of any portion of
17 * this software, then the disclaimer below must also be included.
18 *
19 * This software is provided as is, without representation or warranty
20 * of any kind either express or implied, including without limitation
21 * the implied warranties of merchantability, fitness for a particular
22 * purpose, or noninfringement. The Regents of the University of
23 * Michigan shall not be liable for any damages, including special,
24 * indirect, incidental, or consequential damages, with respect to any
25 * claim arising out of or in connection with the use of the software,
26 * even if it has been or is hereafter advised of the possibility of
27 * such damages.
28 */
29
30#include <linux/nfs_fs.h>
Andy Adamson974cec82010-10-20 00:18:02 -040031#include "internal.h"
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040032#include "pnfs.h"
Andy Adamson64419a92011-03-01 01:34:16 +000033#include "iostat.h"
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040034
35#define NFSDBG_FACILITY NFSDBG_PNFS
36
Fred Isaman02c35fc2010-10-20 00:17:59 -040037/* Locking:
38 *
39 * pnfs_spinlock:
40 * protects pnfs_modules_tbl.
41 */
42static DEFINE_SPINLOCK(pnfs_spinlock);
43
44/*
45 * pnfs_modules_tbl holds all pnfs modules
46 */
47static LIST_HEAD(pnfs_modules_tbl);
48
49/* Return the registered pnfs layout driver module matching given id */
50static struct pnfs_layoutdriver_type *
51find_pnfs_driver_locked(u32 id)
52{
53 struct pnfs_layoutdriver_type *local;
54
55 list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid)
56 if (local->id == id)
57 goto out;
58 local = NULL;
59out:
60 dprintk("%s: Searching for id %u, found %p\n", __func__, id, local);
61 return local;
62}
63
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040064static struct pnfs_layoutdriver_type *
65find_pnfs_driver(u32 id)
66{
Fred Isaman02c35fc2010-10-20 00:17:59 -040067 struct pnfs_layoutdriver_type *local;
68
69 spin_lock(&pnfs_spinlock);
70 local = find_pnfs_driver_locked(id);
71 spin_unlock(&pnfs_spinlock);
72 return local;
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040073}
74
75void
76unset_pnfs_layoutdriver(struct nfs_server *nfss)
77{
Christoph Hellwigea8eecd2011-03-01 01:34:21 +000078 if (nfss->pnfs_curr_ld)
Fred Isaman02c35fc2010-10-20 00:17:59 -040079 module_put(nfss->pnfs_curr_ld->owner);
Ricardo Labiaga85e174b2010-10-20 00:17:58 -040080 nfss->pnfs_curr_ld = NULL;
81}
82
83/*
84 * Try to set the server's pnfs module to the pnfs layout type specified by id.
85 * Currently only one pNFS layout driver per filesystem is supported.
86 *
87 * @id layout type. Zero (illegal layout type) indicates pNFS not in use.
88 */
89void
90set_pnfs_layoutdriver(struct nfs_server *server, u32 id)
91{
92 struct pnfs_layoutdriver_type *ld_type = NULL;
93
94 if (id == 0)
95 goto out_no_driver;
96 if (!(server->nfs_client->cl_exchange_flags &
97 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
98 printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__,
99 id, server->nfs_client->cl_exchange_flags);
100 goto out_no_driver;
101 }
102 ld_type = find_pnfs_driver(id);
103 if (!ld_type) {
104 request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id);
105 ld_type = find_pnfs_driver(id);
106 if (!ld_type) {
107 dprintk("%s: No pNFS module found for %u.\n",
108 __func__, id);
109 goto out_no_driver;
110 }
111 }
Fred Isaman02c35fc2010-10-20 00:17:59 -0400112 if (!try_module_get(ld_type->owner)) {
113 dprintk("%s: Could not grab reference on module\n", __func__);
114 goto out_no_driver;
115 }
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400116 server->pnfs_curr_ld = ld_type;
Christoph Hellwigea8eecd2011-03-01 01:34:21 +0000117
Ricardo Labiaga85e174b2010-10-20 00:17:58 -0400118 dprintk("%s: pNFS module for %u set\n", __func__, id);
119 return;
120
121out_no_driver:
122 dprintk("%s: Using NFSv4 I/O\n", __func__);
123 server->pnfs_curr_ld = NULL;
124}
Fred Isaman02c35fc2010-10-20 00:17:59 -0400125
126int
127pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
128{
129 int status = -EINVAL;
130 struct pnfs_layoutdriver_type *tmp;
131
132 if (ld_type->id == 0) {
133 printk(KERN_ERR "%s id 0 is reserved\n", __func__);
134 return status;
135 }
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400136 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
137 printk(KERN_ERR "%s Layout driver must provide "
138 "alloc_lseg and free_lseg.\n", __func__);
139 return status;
140 }
Fred Isaman02c35fc2010-10-20 00:17:59 -0400141
142 spin_lock(&pnfs_spinlock);
143 tmp = find_pnfs_driver_locked(ld_type->id);
144 if (!tmp) {
145 list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl);
146 status = 0;
147 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
148 ld_type->name);
149 } else {
150 printk(KERN_ERR "%s Module with id %d already loaded!\n",
151 __func__, ld_type->id);
152 }
153 spin_unlock(&pnfs_spinlock);
154
155 return status;
156}
157EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver);
158
159void
160pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
161{
162 dprintk("%s Deregistering id:%u\n", __func__, ld_type->id);
163 spin_lock(&pnfs_spinlock);
164 list_del(&ld_type->pnfs_tblid);
165 spin_unlock(&pnfs_spinlock);
166}
167EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
Benny Halevye5e94012010-10-20 00:18:01 -0400168
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400169/*
170 * pNFS client layout cache
171 */
172
Fred Isamancc6e5342011-01-06 11:36:28 +0000173/* Need to hold i_lock if caller does not already hold reference */
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000174void
Fred Isamancc6e5342011-01-06 11:36:28 +0000175get_layout_hdr(struct pnfs_layout_hdr *lo)
Benny Halevye5e94012010-10-20 00:18:01 -0400176{
Fred Isamancc6e5342011-01-06 11:36:28 +0000177 atomic_inc(&lo->plh_refcount);
178}
179
Benny Halevy636fb9c2011-05-22 19:51:33 +0300180static struct pnfs_layout_hdr *
181pnfs_alloc_layout_hdr(struct inode *ino, gfp_t gfp_flags)
182{
183 struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld;
184 return ld->alloc_layout_hdr ? ld->alloc_layout_hdr(ino, gfp_flags) :
185 kzalloc(sizeof(struct pnfs_layout_hdr), gfp_flags);
186}
187
188static void
189pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo)
190{
191 struct pnfs_layoutdriver_type *ld = NFS_SERVER(lo->plh_inode)->pnfs_curr_ld;
192 return ld->alloc_layout_hdr ? ld->free_layout_hdr(lo) : kfree(lo);
193}
194
Fred Isamancc6e5342011-01-06 11:36:28 +0000195static void
196destroy_layout_hdr(struct pnfs_layout_hdr *lo)
197{
198 dprintk("%s: freeing layout cache %p\n", __func__, lo);
199 BUG_ON(!list_empty(&lo->plh_layouts));
200 NFS_I(lo->plh_inode)->layout = NULL;
Benny Halevy636fb9c2011-05-22 19:51:33 +0300201 pnfs_free_layout_hdr(lo);
Benny Halevye5e94012010-10-20 00:18:01 -0400202}
203
204static void
205put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
206{
Fred Isamancc6e5342011-01-06 11:36:28 +0000207 if (atomic_dec_and_test(&lo->plh_refcount))
208 destroy_layout_hdr(lo);
Benny Halevye5e94012010-10-20 00:18:01 -0400209}
210
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400211void
Fred Isamancc6e5342011-01-06 11:36:28 +0000212put_layout_hdr(struct pnfs_layout_hdr *lo)
Andy Adamson974cec82010-10-20 00:18:02 -0400213{
Fred Isamancc6e5342011-01-06 11:36:28 +0000214 struct inode *inode = lo->plh_inode;
215
216 if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
217 destroy_layout_hdr(lo);
218 spin_unlock(&inode->i_lock);
219 }
Andy Adamson974cec82010-10-20 00:18:02 -0400220}
221
222static void
223init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg)
224{
Fred Isaman566052c2011-01-06 11:36:20 +0000225 INIT_LIST_HEAD(&lseg->pls_list);
Fred Isaman4541d162011-01-06 11:36:23 +0000226 atomic_set(&lseg->pls_refcount, 1);
227 smp_mb();
228 set_bit(NFS_LSEG_VALID, &lseg->pls_flags);
Fred Isaman566052c2011-01-06 11:36:20 +0000229 lseg->pls_layout = lo;
Andy Adamson974cec82010-10-20 00:18:02 -0400230}
231
Fred Isaman4541d162011-01-06 11:36:23 +0000232static void free_lseg(struct pnfs_layout_segment *lseg)
Andy Adamson974cec82010-10-20 00:18:02 -0400233{
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000234 struct inode *ino = lseg->pls_layout->plh_inode;
Andy Adamson974cec82010-10-20 00:18:02 -0400235
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400236 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
Fred Isaman52fabd72011-01-06 11:36:18 +0000237 /* Matched by get_layout_hdr in pnfs_insert_layout */
Fred Isamancc6e5342011-01-06 11:36:28 +0000238 put_layout_hdr(NFS_I(ino)->layout);
Andy Adamson974cec82010-10-20 00:18:02 -0400239}
240
Fred Isamand684d2a2011-03-01 01:34:13 +0000241static void
242put_lseg_common(struct pnfs_layout_segment *lseg)
Andy Adamson974cec82010-10-20 00:18:02 -0400243{
Fred Isamand684d2a2011-03-01 01:34:13 +0000244 struct inode *inode = lseg->pls_layout->plh_inode;
245
Benny Halevyd20581a2011-05-22 19:52:03 +0300246 WARN_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
Fred Isamand684d2a2011-03-01 01:34:13 +0000247 list_del_init(&lseg->pls_list);
248 if (list_empty(&lseg->pls_layout->plh_segs)) {
249 set_bit(NFS_LAYOUT_DESTROYED, &lseg->pls_layout->plh_flags);
250 /* Matched by initial refcount set in alloc_init_layout_hdr */
251 put_layout_hdr_locked(lseg->pls_layout);
252 }
253 rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq);
254}
255
Fred Isamanbae724e2011-03-01 01:34:15 +0000256void
Fred Isamand684d2a2011-03-01 01:34:13 +0000257put_lseg(struct pnfs_layout_segment *lseg)
258{
259 struct inode *inode;
260
261 if (!lseg)
262 return;
263
Fred Isaman4541d162011-01-06 11:36:23 +0000264 dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
265 atomic_read(&lseg->pls_refcount),
266 test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
Fred Isamand684d2a2011-03-01 01:34:13 +0000267 inode = lseg->pls_layout->plh_inode;
268 if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) {
269 LIST_HEAD(free_me);
Andy Adamson974cec82010-10-20 00:18:02 -0400270
Fred Isamand684d2a2011-03-01 01:34:13 +0000271 put_lseg_common(lseg);
272 list_add(&lseg->pls_list, &free_me);
273 spin_unlock(&inode->i_lock);
274 pnfs_free_lseg_list(&free_me);
Fred Isaman4541d162011-01-06 11:36:23 +0000275 }
Andy Adamson974cec82010-10-20 00:18:02 -0400276}
Fred Isamane0c2b382011-03-23 13:27:53 +0000277EXPORT_SYMBOL_GPL(put_lseg);
Andy Adamson974cec82010-10-20 00:18:02 -0400278
Benny Halevyfb3296e2011-05-22 19:47:26 +0300279static inline u64
280end_offset(u64 start, u64 len)
Fred Isaman4541d162011-01-06 11:36:23 +0000281{
Benny Halevyfb3296e2011-05-22 19:47:26 +0300282 u64 end;
283
284 end = start + len;
285 return end >= start ? end : NFS4_MAX_UINT64;
286}
287
288/* last octet in a range */
289static inline u64
290last_byte_offset(u64 start, u64 len)
291{
292 u64 end;
293
294 BUG_ON(!len);
295 end = start + len;
296 return end > start ? end - 1 : NFS4_MAX_UINT64;
297}
298
299/*
300 * is l2 fully contained in l1?
301 * start1 end1
302 * [----------------------------------)
303 * start2 end2
304 * [----------------)
305 */
306static inline int
307lo_seg_contained(struct pnfs_layout_range *l1,
308 struct pnfs_layout_range *l2)
309{
310 u64 start1 = l1->offset;
311 u64 end1 = end_offset(start1, l1->length);
312 u64 start2 = l2->offset;
313 u64 end2 = end_offset(start2, l2->length);
314
315 return (start1 <= start2) && (end1 >= end2);
316}
317
318/*
319 * is l1 and l2 intersecting?
320 * start1 end1
321 * [----------------------------------)
322 * start2 end2
323 * [----------------)
324 */
325static inline int
326lo_seg_intersecting(struct pnfs_layout_range *l1,
327 struct pnfs_layout_range *l2)
328{
329 u64 start1 = l1->offset;
330 u64 end1 = end_offset(start1, l1->length);
331 u64 start2 = l2->offset;
332 u64 end2 = end_offset(start2, l2->length);
333
334 return (end1 == NFS4_MAX_UINT64 || end1 > start2) &&
335 (end2 == NFS4_MAX_UINT64 || end2 > start1);
336}
337
Fred Isaman4541d162011-01-06 11:36:23 +0000338static bool
Benny Halevy778b5502011-05-22 19:48:02 +0300339should_free_lseg(struct pnfs_layout_range *lseg_range,
340 struct pnfs_layout_range *recall_range)
Fred Isaman4541d162011-01-06 11:36:23 +0000341{
Benny Halevy778b5502011-05-22 19:48:02 +0300342 return (recall_range->iomode == IOMODE_ANY ||
343 lseg_range->iomode == recall_range->iomode) &&
344 lo_seg_intersecting(lseg_range, recall_range);
Fred Isaman4541d162011-01-06 11:36:23 +0000345}
346
347/* Returns 1 if lseg is removed from list, 0 otherwise */
348static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
349 struct list_head *tmp_list)
350{
351 int rv = 0;
352
353 if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) {
354 /* Remove the reference keeping the lseg in the
355 * list. It will now be removed when all
356 * outstanding io is finished.
357 */
Fred Isamand684d2a2011-03-01 01:34:13 +0000358 dprintk("%s: lseg %p ref %d\n", __func__, lseg,
359 atomic_read(&lseg->pls_refcount));
360 if (atomic_dec_and_test(&lseg->pls_refcount)) {
361 put_lseg_common(lseg);
362 list_add(&lseg->pls_list, tmp_list);
363 rv = 1;
364 }
Fred Isaman4541d162011-01-06 11:36:23 +0000365 }
366 return rv;
367}
368
369/* Returns count of number of matching invalid lsegs remaining in list
370 * after call.
371 */
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000372int
Fred Isaman4541d162011-01-06 11:36:23 +0000373mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
374 struct list_head *tmp_list,
Benny Halevy778b5502011-05-22 19:48:02 +0300375 struct pnfs_layout_range *recall_range)
Andy Adamson974cec82010-10-20 00:18:02 -0400376{
377 struct pnfs_layout_segment *lseg, *next;
Fred Isaman4541d162011-01-06 11:36:23 +0000378 int invalid = 0, removed = 0;
Andy Adamson974cec82010-10-20 00:18:02 -0400379
380 dprintk("%s:Begin lo %p\n", __func__, lo);
381
Fred Isaman38511722011-02-03 18:28:50 +0000382 if (list_empty(&lo->plh_segs)) {
383 if (!test_and_set_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags))
384 put_layout_hdr_locked(lo);
385 return 0;
386 }
Fred Isaman4541d162011-01-06 11:36:23 +0000387 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
Benny Halevy778b5502011-05-22 19:48:02 +0300388 if (!recall_range ||
389 should_free_lseg(&lseg->pls_range, recall_range)) {
Fred Isaman4541d162011-01-06 11:36:23 +0000390 dprintk("%s: freeing lseg %p iomode %d "
391 "offset %llu length %llu\n", __func__,
392 lseg, lseg->pls_range.iomode, lseg->pls_range.offset,
393 lseg->pls_range.length);
394 invalid++;
395 removed += mark_lseg_invalid(lseg, tmp_list);
396 }
397 dprintk("%s:Return %i\n", __func__, invalid - removed);
398 return invalid - removed;
Andy Adamson974cec82010-10-20 00:18:02 -0400399}
400
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000401/* note free_me must contain lsegs from a single layout_hdr */
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000402void
Fred Isaman4541d162011-01-06 11:36:23 +0000403pnfs_free_lseg_list(struct list_head *free_me)
Andy Adamson974cec82010-10-20 00:18:02 -0400404{
Fred Isaman4541d162011-01-06 11:36:23 +0000405 struct pnfs_layout_segment *lseg, *tmp;
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000406 struct pnfs_layout_hdr *lo;
Andy Adamson974cec82010-10-20 00:18:02 -0400407
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000408 if (list_empty(free_me))
409 return;
410
411 lo = list_first_entry(free_me, struct pnfs_layout_segment,
412 pls_list)->pls_layout;
413
414 if (test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) {
415 struct nfs_client *clp;
416
417 clp = NFS_SERVER(lo->plh_inode)->nfs_client;
418 spin_lock(&clp->cl_lock);
419 list_del_init(&lo->plh_layouts);
420 spin_unlock(&clp->cl_lock);
421 }
Fred Isaman4541d162011-01-06 11:36:23 +0000422 list_for_each_entry_safe(lseg, tmp, free_me, pls_list) {
Fred Isaman566052c2011-01-06 11:36:20 +0000423 list_del(&lseg->pls_list);
Fred Isaman4541d162011-01-06 11:36:23 +0000424 free_lseg(lseg);
Andy Adamson974cec82010-10-20 00:18:02 -0400425 }
426}
427
Benny Halevye5e94012010-10-20 00:18:01 -0400428void
429pnfs_destroy_layout(struct nfs_inode *nfsi)
430{
431 struct pnfs_layout_hdr *lo;
Andy Adamson974cec82010-10-20 00:18:02 -0400432 LIST_HEAD(tmp_list);
Benny Halevye5e94012010-10-20 00:18:01 -0400433
434 spin_lock(&nfsi->vfs_inode.i_lock);
435 lo = nfsi->layout;
436 if (lo) {
Fred Isaman38511722011-02-03 18:28:50 +0000437 lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */
Benny Halevy778b5502011-05-22 19:48:02 +0300438 mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
Benny Halevye5e94012010-10-20 00:18:01 -0400439 }
440 spin_unlock(&nfsi->vfs_inode.i_lock);
Andy Adamson974cec82010-10-20 00:18:02 -0400441 pnfs_free_lseg_list(&tmp_list);
Benny Halevye5e94012010-10-20 00:18:01 -0400442}
443
Andy Adamson974cec82010-10-20 00:18:02 -0400444/*
445 * Called by the state manger to remove all layouts established under an
446 * expired lease.
447 */
448void
449pnfs_destroy_all_layouts(struct nfs_client *clp)
450{
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400451 struct nfs_server *server;
Andy Adamson974cec82010-10-20 00:18:02 -0400452 struct pnfs_layout_hdr *lo;
453 LIST_HEAD(tmp_list);
454
Andy Adamsonc47abcf2011-06-15 17:52:40 -0400455 nfs4_deviceid_mark_client_invalid(clp);
456 nfs4_deviceid_purge_client(clp);
457
Andy Adamson974cec82010-10-20 00:18:02 -0400458 spin_lock(&clp->cl_lock);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400459 rcu_read_lock();
460 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
461 if (!list_empty(&server->layouts))
462 list_splice_init(&server->layouts, &tmp_list);
463 }
464 rcu_read_unlock();
Andy Adamson974cec82010-10-20 00:18:02 -0400465 spin_unlock(&clp->cl_lock);
466
467 while (!list_empty(&tmp_list)) {
468 lo = list_entry(tmp_list.next, struct pnfs_layout_hdr,
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000469 plh_layouts);
Andy Adamson974cec82010-10-20 00:18:02 -0400470 dprintk("%s freeing layout for inode %lu\n", __func__,
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000471 lo->plh_inode->i_ino);
Andy Adamson2887fe42011-05-11 01:19:58 -0400472 list_del_init(&lo->plh_layouts);
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000473 pnfs_destroy_layout(NFS_I(lo->plh_inode));
Andy Adamson974cec82010-10-20 00:18:02 -0400474 }
475}
476
Fred Isamanfd6002e2011-01-06 11:36:22 +0000477/* update lo->plh_stateid with new if is more recent */
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000478void
479pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
480 bool update_barrier)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400481{
Fred Isamanfd6002e2011-01-06 11:36:22 +0000482 u32 oldseq, newseq;
Andy Adamson974cec82010-10-20 00:18:02 -0400483
Fred Isamanfd6002e2011-01-06 11:36:22 +0000484 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
485 newseq = be32_to_cpu(new->stateid.seqid);
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000486 if ((int)(newseq - oldseq) > 0) {
Fred Isamanfd6002e2011-01-06 11:36:22 +0000487 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid));
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000488 if (update_barrier) {
489 u32 new_barrier = be32_to_cpu(new->stateid.seqid);
490
491 if ((int)(new_barrier - lo->plh_barrier))
492 lo->plh_barrier = new_barrier;
493 } else {
494 /* Because of wraparound, we want to keep the barrier
495 * "close" to the current seqids. It needs to be
496 * within 2**31 to count as "behind", so if it
497 * gets too near that limit, give us a litle leeway
498 * and bring it to within 2**30.
499 * NOTE - and yes, this is all unsigned arithmetic.
500 */
501 if (unlikely((newseq - lo->plh_barrier) > (3 << 29)))
502 lo->plh_barrier = newseq - (1 << 30);
503 }
504 }
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400505}
506
Fred Isamancf7d63f2011-01-06 11:36:25 +0000507/* lget is set to 1 if called from inside send_layoutget call chain */
508static bool
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000509pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
510 int lget)
Fred Isamancf7d63f2011-01-06 11:36:25 +0000511{
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000512 if ((stateid) &&
513 (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0)
514 return true;
Fred Isamanf7e89172011-01-06 11:36:32 +0000515 return lo->plh_block_lgets ||
Fred Isaman38511722011-02-03 18:28:50 +0000516 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
Fred Isamanf7e89172011-01-06 11:36:32 +0000517 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000518 (list_empty(&lo->plh_segs) &&
Fred Isamancf7d63f2011-01-06 11:36:25 +0000519 (atomic_read(&lo->plh_outstanding) > lget));
520}
521
Fred Isamanfd6002e2011-01-06 11:36:22 +0000522int
523pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
524 struct nfs4_state *open_state)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400525{
Fred Isamanfd6002e2011-01-06 11:36:22 +0000526 int status = 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400527
528 dprintk("--> %s\n", __func__);
Fred Isamanfd6002e2011-01-06 11:36:22 +0000529 spin_lock(&lo->plh_inode->i_lock);
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000530 if (pnfs_layoutgets_blocked(lo, NULL, 1)) {
Fred Isamancf7d63f2011-01-06 11:36:25 +0000531 status = -EAGAIN;
532 } else if (list_empty(&lo->plh_segs)) {
Fred Isamanfd6002e2011-01-06 11:36:22 +0000533 int seq;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400534
Fred Isamanfd6002e2011-01-06 11:36:22 +0000535 do {
536 seq = read_seqbegin(&open_state->seqlock);
537 memcpy(dst->data, open_state->stateid.data,
538 sizeof(open_state->stateid.data));
539 } while (read_seqretry(&open_state->seqlock, seq));
540 } else
541 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data));
542 spin_unlock(&lo->plh_inode->i_lock);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400543 dprintk("<-- %s\n", __func__);
Fred Isamanfd6002e2011-01-06 11:36:22 +0000544 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400545}
546
547/*
548* Get layout from server.
549* for now, assume that whole file layouts are requested.
550* arg->offset: 0
551* arg->length: all ones
552*/
Benny Halevye5e94012010-10-20 00:18:01 -0400553static struct pnfs_layout_segment *
554send_layoutget(struct pnfs_layout_hdr *lo,
555 struct nfs_open_context *ctx,
Benny Halevyfb3296e2011-05-22 19:47:26 +0300556 struct pnfs_layout_range *range,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400557 gfp_t gfp_flags)
Benny Halevye5e94012010-10-20 00:18:01 -0400558{
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000559 struct inode *ino = lo->plh_inode;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400560 struct nfs_server *server = NFS_SERVER(ino);
561 struct nfs4_layoutget *lgp;
562 struct pnfs_layout_segment *lseg = NULL;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400563 struct page **pages = NULL;
564 int i;
565 u32 max_resp_sz, max_pages;
Benny Halevye5e94012010-10-20 00:18:01 -0400566
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400567 dprintk("--> %s\n", __func__);
568
569 BUG_ON(ctx == NULL);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400570 lgp = kzalloc(sizeof(*lgp), gfp_flags);
Fred Isamancf7d63f2011-01-06 11:36:25 +0000571 if (lgp == NULL)
Andy Adamson974cec82010-10-20 00:18:02 -0400572 return NULL;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400573
574 /* allocate pages for xdr post processing */
575 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
576 max_pages = max_resp_sz >> PAGE_SHIFT;
577
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400578 pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400579 if (!pages)
580 goto out_err_free;
581
582 for (i = 0; i < max_pages; i++) {
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400583 pages[i] = alloc_page(gfp_flags);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400584 if (!pages[i])
585 goto out_err_free;
586 }
587
Benny Halevyfb3296e2011-05-22 19:47:26 +0300588 lgp->args.minlength = PAGE_CACHE_SIZE;
589 if (lgp->args.minlength > range->length)
590 lgp->args.minlength = range->length;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400591 lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
Benny Halevyfb3296e2011-05-22 19:47:26 +0300592 lgp->args.range = *range;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400593 lgp->args.type = server->pnfs_curr_ld->id;
594 lgp->args.inode = ino;
595 lgp->args.ctx = get_nfs_open_context(ctx);
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400596 lgp->args.layout.pages = pages;
597 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400598 lgp->lsegpp = &lseg;
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400599 lgp->gfp_flags = gfp_flags;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400600
601 /* Synchronously retrieve layout information from server and
602 * store in lseg.
603 */
604 nfs4_proc_layoutget(lgp);
605 if (!lseg) {
606 /* remember that LAYOUTGET failed and suspend trying */
Benny Halevyfb3296e2011-05-22 19:47:26 +0300607 set_bit(lo_fail_bit(range->iomode), &lo->plh_flags);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400608 }
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400609
610 /* free xdr pages */
611 for (i = 0; i < max_pages; i++)
612 __free_page(pages[i]);
613 kfree(pages);
614
Andy Adamson974cec82010-10-20 00:18:02 -0400615 return lseg;
Weston Andros Adamson35124a02011-03-24 16:48:21 -0400616
617out_err_free:
618 /* free any allocated xdr pages, lgp as it's not used */
619 if (pages) {
620 for (i = 0; i < max_pages; i++) {
621 if (!pages[i])
622 break;
623 __free_page(pages[i]);
624 }
625 kfree(pages);
626 }
627 kfree(lgp);
628 return NULL;
Andy Adamson974cec82010-10-20 00:18:02 -0400629}
630
Benny Halevycbe82602011-05-22 19:52:37 +0300631/* Initiates a LAYOUTRETURN(FILE) */
632int
633_pnfs_return_layout(struct inode *ino)
634{
635 struct pnfs_layout_hdr *lo = NULL;
636 struct nfs_inode *nfsi = NFS_I(ino);
637 LIST_HEAD(tmp_list);
638 struct nfs4_layoutreturn *lrp;
639 nfs4_stateid stateid;
640 int status = 0;
641
642 dprintk("--> %s\n", __func__);
643
644 spin_lock(&ino->i_lock);
645 lo = nfsi->layout;
Fred Isamana2e1d4f2011-06-13 18:54:53 -0400646 if (!lo) {
Benny Halevycbe82602011-05-22 19:52:37 +0300647 spin_unlock(&ino->i_lock);
Fred Isamana2e1d4f2011-06-13 18:54:53 -0400648 dprintk("%s: no layout to return\n", __func__);
649 return status;
Benny Halevycbe82602011-05-22 19:52:37 +0300650 }
651 stateid = nfsi->layout->plh_stateid;
652 /* Reference matched in nfs4_layoutreturn_release */
653 get_layout_hdr(lo);
Fred Isamanea0ded72011-06-15 12:31:02 -0400654 mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
655 lo->plh_block_lgets++;
Benny Halevycbe82602011-05-22 19:52:37 +0300656 spin_unlock(&ino->i_lock);
657 pnfs_free_lseg_list(&tmp_list);
658
659 WARN_ON(test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags));
660
661 lrp = kzalloc(sizeof(*lrp), GFP_KERNEL);
662 if (unlikely(lrp == NULL)) {
663 status = -ENOMEM;
Fred Isaman9e2dfdb2011-06-15 14:32:02 -0400664 set_bit(NFS_LAYOUT_RW_FAILED, &lo->plh_flags);
665 set_bit(NFS_LAYOUT_RO_FAILED, &lo->plh_flags);
Benny Halevy1ed3a852011-06-15 11:39:57 -0400666 put_layout_hdr(lo);
Benny Halevycbe82602011-05-22 19:52:37 +0300667 goto out;
668 }
669
670 lrp->args.stateid = stateid;
671 lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id;
672 lrp->args.inode = ino;
Trond Myklebusta56aaa02011-06-15 11:59:10 -0400673 lrp->args.layout = lo;
Benny Halevycbe82602011-05-22 19:52:37 +0300674 lrp->clp = NFS_SERVER(ino)->nfs_client;
675
676 status = nfs4_proc_layoutreturn(lrp);
677out:
678 dprintk("<-- %s status: %d\n", __func__, status);
679 return status;
680}
681
Fred Isamanf7e89172011-01-06 11:36:32 +0000682bool pnfs_roc(struct inode *ino)
683{
684 struct pnfs_layout_hdr *lo;
685 struct pnfs_layout_segment *lseg, *tmp;
686 LIST_HEAD(tmp_list);
687 bool found = false;
688
689 spin_lock(&ino->i_lock);
690 lo = NFS_I(ino)->layout;
691 if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) ||
692 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
693 goto out_nolayout;
694 list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list)
695 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
696 mark_lseg_invalid(lseg, &tmp_list);
697 found = true;
698 }
699 if (!found)
700 goto out_nolayout;
701 lo->plh_block_lgets++;
702 get_layout_hdr(lo); /* matched in pnfs_roc_release */
703 spin_unlock(&ino->i_lock);
704 pnfs_free_lseg_list(&tmp_list);
705 return true;
706
707out_nolayout:
708 spin_unlock(&ino->i_lock);
709 return false;
710}
711
712void pnfs_roc_release(struct inode *ino)
713{
714 struct pnfs_layout_hdr *lo;
715
716 spin_lock(&ino->i_lock);
717 lo = NFS_I(ino)->layout;
718 lo->plh_block_lgets--;
719 put_layout_hdr_locked(lo);
720 spin_unlock(&ino->i_lock);
721}
722
723void pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
724{
725 struct pnfs_layout_hdr *lo;
726
727 spin_lock(&ino->i_lock);
728 lo = NFS_I(ino)->layout;
729 if ((int)(barrier - lo->plh_barrier) > 0)
730 lo->plh_barrier = barrier;
731 spin_unlock(&ino->i_lock);
732}
733
734bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
735{
736 struct nfs_inode *nfsi = NFS_I(ino);
737 struct pnfs_layout_segment *lseg;
738 bool found = false;
739
740 spin_lock(&ino->i_lock);
741 list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
742 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
743 found = true;
744 break;
745 }
746 if (!found) {
747 struct pnfs_layout_hdr *lo = nfsi->layout;
748 u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid);
749
750 /* Since close does not return a layout stateid for use as
751 * a barrier, we choose the worst-case barrier.
752 */
753 *barrier = current_seqid + atomic_read(&lo->plh_outstanding);
754 }
755 spin_unlock(&ino->i_lock);
756 return found;
757}
758
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400759/*
760 * Compare two layout segments for sorting into layout cache.
761 * We want to preferentially return RW over RO layouts, so ensure those
762 * are seen first.
763 */
764static s64
Benny Halevyfb3296e2011-05-22 19:47:26 +0300765cmp_layout(struct pnfs_layout_range *l1,
766 struct pnfs_layout_range *l2)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400767{
Benny Halevyfb3296e2011-05-22 19:47:26 +0300768 s64 d;
769
770 /* high offset > low offset */
771 d = l1->offset - l2->offset;
772 if (d)
773 return d;
774
775 /* short length > long length */
776 d = l2->length - l1->length;
777 if (d)
778 return d;
779
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400780 /* read > read/write */
Benny Halevyfb3296e2011-05-22 19:47:26 +0300781 return (int)(l1->iomode == IOMODE_READ) - (int)(l2->iomode == IOMODE_READ);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400782}
783
Andy Adamson974cec82010-10-20 00:18:02 -0400784static void
785pnfs_insert_layout(struct pnfs_layout_hdr *lo,
786 struct pnfs_layout_segment *lseg)
787{
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400788 struct pnfs_layout_segment *lp;
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400789
Andy Adamson974cec82010-10-20 00:18:02 -0400790 dprintk("%s:Begin\n", __func__);
791
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000792 assert_spin_locked(&lo->plh_inode->i_lock);
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000793 list_for_each_entry(lp, &lo->plh_segs, pls_list) {
Benny Halevyfb3296e2011-05-22 19:47:26 +0300794 if (cmp_layout(&lseg->pls_range, &lp->pls_range) > 0)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400795 continue;
Fred Isaman566052c2011-01-06 11:36:20 +0000796 list_add_tail(&lseg->pls_list, &lp->pls_list);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400797 dprintk("%s: inserted lseg %p "
798 "iomode %d offset %llu length %llu before "
799 "lp %p iomode %d offset %llu length %llu\n",
Fred Isaman566052c2011-01-06 11:36:20 +0000800 __func__, lseg, lseg->pls_range.iomode,
801 lseg->pls_range.offset, lseg->pls_range.length,
802 lp, lp->pls_range.iomode, lp->pls_range.offset,
803 lp->pls_range.length);
Benny Halevyfb3296e2011-05-22 19:47:26 +0300804 goto out;
Andy Adamson974cec82010-10-20 00:18:02 -0400805 }
Benny Halevyfb3296e2011-05-22 19:47:26 +0300806 list_add_tail(&lseg->pls_list, &lo->plh_segs);
807 dprintk("%s: inserted lseg %p "
808 "iomode %d offset %llu length %llu at tail\n",
809 __func__, lseg, lseg->pls_range.iomode,
810 lseg->pls_range.offset, lseg->pls_range.length);
811out:
Fred Isamancc6e5342011-01-06 11:36:28 +0000812 get_layout_hdr(lo);
Andy Adamson974cec82010-10-20 00:18:02 -0400813
814 dprintk("%s:Return\n", __func__);
Benny Halevye5e94012010-10-20 00:18:01 -0400815}
816
817static struct pnfs_layout_hdr *
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400818alloc_init_layout_hdr(struct inode *ino, gfp_t gfp_flags)
Benny Halevye5e94012010-10-20 00:18:01 -0400819{
820 struct pnfs_layout_hdr *lo;
821
Benny Halevy636fb9c2011-05-22 19:51:33 +0300822 lo = pnfs_alloc_layout_hdr(ino, gfp_flags);
Benny Halevye5e94012010-10-20 00:18:01 -0400823 if (!lo)
824 return NULL;
Fred Isamancc6e5342011-01-06 11:36:28 +0000825 atomic_set(&lo->plh_refcount, 1);
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000826 INIT_LIST_HEAD(&lo->plh_layouts);
827 INIT_LIST_HEAD(&lo->plh_segs);
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000828 INIT_LIST_HEAD(&lo->plh_bulk_recall);
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000829 lo->plh_inode = ino;
Benny Halevye5e94012010-10-20 00:18:01 -0400830 return lo;
831}
832
833static struct pnfs_layout_hdr *
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400834pnfs_find_alloc_layout(struct inode *ino, gfp_t gfp_flags)
Benny Halevye5e94012010-10-20 00:18:01 -0400835{
836 struct nfs_inode *nfsi = NFS_I(ino);
837 struct pnfs_layout_hdr *new = NULL;
838
839 dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout);
840
841 assert_spin_locked(&ino->i_lock);
Fred Isaman4541d162011-01-06 11:36:23 +0000842 if (nfsi->layout) {
843 if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags))
844 return NULL;
845 else
846 return nfsi->layout;
847 }
Benny Halevye5e94012010-10-20 00:18:01 -0400848 spin_unlock(&ino->i_lock);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400849 new = alloc_init_layout_hdr(ino, gfp_flags);
Benny Halevye5e94012010-10-20 00:18:01 -0400850 spin_lock(&ino->i_lock);
851
852 if (likely(nfsi->layout == NULL)) /* Won the race? */
853 nfsi->layout = new;
854 else
Benny Halevy636fb9c2011-05-22 19:51:33 +0300855 pnfs_free_layout_hdr(new);
Benny Halevye5e94012010-10-20 00:18:01 -0400856 return nfsi->layout;
857}
858
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400859/*
860 * iomode matching rules:
861 * iomode lseg match
862 * ----- ----- -----
863 * ANY READ true
864 * ANY RW true
865 * RW READ false
866 * RW RW true
867 * READ READ true
868 * READ RW true
869 */
870static int
Benny Halevyfb3296e2011-05-22 19:47:26 +0300871is_matching_lseg(struct pnfs_layout_range *ls_range,
872 struct pnfs_layout_range *range)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400873{
Benny Halevyfb3296e2011-05-22 19:47:26 +0300874 struct pnfs_layout_range range1;
875
876 if ((range->iomode == IOMODE_RW &&
877 ls_range->iomode != IOMODE_RW) ||
878 !lo_seg_intersecting(ls_range, range))
879 return 0;
880
881 /* range1 covers only the first byte in the range */
882 range1 = *range;
883 range1.length = 1;
884 return lo_seg_contained(ls_range, &range1);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400885}
886
887/*
888 * lookup range in layout
889 */
Benny Halevye5e94012010-10-20 00:18:01 -0400890static struct pnfs_layout_segment *
Benny Halevyfb3296e2011-05-22 19:47:26 +0300891pnfs_find_lseg(struct pnfs_layout_hdr *lo,
892 struct pnfs_layout_range *range)
Benny Halevye5e94012010-10-20 00:18:01 -0400893{
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400894 struct pnfs_layout_segment *lseg, *ret = NULL;
895
896 dprintk("%s:Begin\n", __func__);
897
Fred Isamanb7edfaa2011-01-06 11:36:21 +0000898 assert_spin_locked(&lo->plh_inode->i_lock);
899 list_for_each_entry(lseg, &lo->plh_segs, pls_list) {
Fred Isaman4541d162011-01-06 11:36:23 +0000900 if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) &&
Benny Halevyfb3296e2011-05-22 19:47:26 +0300901 is_matching_lseg(&lseg->pls_range, range)) {
Fred Isamand684d2a2011-03-01 01:34:13 +0000902 ret = get_lseg(lseg);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400903 break;
904 }
Benny Halevyd771e3a2011-06-14 16:30:16 -0400905 if (lseg->pls_range.offset > range->offset)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400906 break;
907 }
908
909 dprintk("%s:Return lseg %p ref %d\n",
Fred Isaman4541d162011-01-06 11:36:23 +0000910 __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0);
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400911 return ret;
Benny Halevye5e94012010-10-20 00:18:01 -0400912}
913
914/*
915 * Layout segment is retreived from the server if not cached.
916 * The appropriate layout segment is referenced and returned to the caller.
917 */
Andy Adamson7c24d942011-06-13 18:22:38 -0400918struct pnfs_layout_segment *
Benny Halevye5e94012010-10-20 00:18:01 -0400919pnfs_update_layout(struct inode *ino,
920 struct nfs_open_context *ctx,
Benny Halevyfb3296e2011-05-22 19:47:26 +0300921 loff_t pos,
922 u64 count,
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400923 enum pnfs_iomode iomode,
924 gfp_t gfp_flags)
Benny Halevye5e94012010-10-20 00:18:01 -0400925{
Benny Halevyfb3296e2011-05-22 19:47:26 +0300926 struct pnfs_layout_range arg = {
927 .iomode = iomode,
928 .offset = pos,
929 .length = count,
930 };
Benny Halevy707ed5f2011-05-22 19:47:46 +0300931 unsigned pg_offset;
Benny Halevye5e94012010-10-20 00:18:01 -0400932 struct nfs_inode *nfsi = NFS_I(ino);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400933 struct nfs_server *server = NFS_SERVER(ino);
934 struct nfs_client *clp = server->nfs_client;
Benny Halevye5e94012010-10-20 00:18:01 -0400935 struct pnfs_layout_hdr *lo;
936 struct pnfs_layout_segment *lseg = NULL;
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000937 bool first = false;
Benny Halevye5e94012010-10-20 00:18:01 -0400938
939 if (!pnfs_enabled_sb(NFS_SERVER(ino)))
940 return NULL;
941 spin_lock(&ino->i_lock);
Trond Myklebusta75b9df2011-05-11 18:00:51 -0400942 lo = pnfs_find_alloc_layout(ino, gfp_flags);
Benny Halevye5e94012010-10-20 00:18:01 -0400943 if (lo == NULL) {
944 dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__);
945 goto out_unlock;
946 }
947
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000948 /* Do we even need to bother with this? */
949 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
950 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
951 dprintk("%s matches recall, use MDS\n", __func__);
Benny Halevye5e94012010-10-20 00:18:01 -0400952 goto out_unlock;
953 }
954
955 /* if LAYOUTGET already failed once we don't try again */
Fred Isaman566052c2011-01-06 11:36:20 +0000956 if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags))
Benny Halevye5e94012010-10-20 00:18:01 -0400957 goto out_unlock;
958
Andy Adamson568e8c42011-03-01 01:34:22 +0000959 /* Check to see if the layout for the given range already exists */
Benny Halevyfb3296e2011-05-22 19:47:26 +0300960 lseg = pnfs_find_lseg(lo, &arg);
Andy Adamson568e8c42011-03-01 01:34:22 +0000961 if (lseg)
962 goto out_unlock;
963
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000964 if (pnfs_layoutgets_blocked(lo, NULL, 0))
Fred Isamancf7d63f2011-01-06 11:36:25 +0000965 goto out_unlock;
966 atomic_inc(&lo->plh_outstanding);
967
Fred Isamancc6e5342011-01-06 11:36:28 +0000968 get_layout_hdr(lo);
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000969 if (list_empty(&lo->plh_segs))
970 first = true;
971 spin_unlock(&ino->i_lock);
972 if (first) {
Fred Isaman2130ff62011-01-06 11:36:26 +0000973 /* The lo must be on the clp list if there is any
974 * chance of a CB_LAYOUTRECALL(FILE) coming in.
975 */
976 spin_lock(&clp->cl_lock);
977 BUG_ON(!list_empty(&lo->plh_layouts));
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400978 list_add_tail(&lo->plh_layouts, &server->layouts);
Fred Isaman2130ff62011-01-06 11:36:26 +0000979 spin_unlock(&clp->cl_lock);
980 }
Benny Halevye5e94012010-10-20 00:18:01 -0400981
Benny Halevy707ed5f2011-05-22 19:47:46 +0300982 pg_offset = arg.offset & ~PAGE_CACHE_MASK;
983 if (pg_offset) {
984 arg.offset -= pg_offset;
985 arg.length += pg_offset;
986 }
Andy Adamson7c24d942011-06-13 18:22:38 -0400987 if (arg.length != NFS4_MAX_UINT64)
988 arg.length = PAGE_CACHE_ALIGN(arg.length);
Benny Halevy707ed5f2011-05-22 19:47:46 +0300989
Benny Halevyfb3296e2011-05-22 19:47:26 +0300990 lseg = send_layoutget(lo, ctx, &arg, gfp_flags);
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000991 if (!lseg && first) {
992 spin_lock(&clp->cl_lock);
993 list_del_init(&lo->plh_layouts);
994 spin_unlock(&clp->cl_lock);
Fred Isaman2130ff62011-01-06 11:36:26 +0000995 }
Fred Isamancf7d63f2011-01-06 11:36:25 +0000996 atomic_dec(&lo->plh_outstanding);
Fred Isamancc6e5342011-01-06 11:36:28 +0000997 put_layout_hdr(lo);
Benny Halevye5e94012010-10-20 00:18:01 -0400998out:
999 dprintk("%s end, state 0x%lx lseg %p\n", __func__,
Andy Adamsonbf9c1382011-03-01 01:34:07 +00001000 nfsi->layout ? nfsi->layout->plh_flags : -1, lseg);
Benny Halevye5e94012010-10-20 00:18:01 -04001001 return lseg;
1002out_unlock:
1003 spin_unlock(&ino->i_lock);
1004 goto out;
1005}
Andy Adamson7c24d942011-06-13 18:22:38 -04001006EXPORT_SYMBOL_GPL(pnfs_update_layout);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001007
1008int
1009pnfs_layout_process(struct nfs4_layoutget *lgp)
1010{
1011 struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout;
1012 struct nfs4_layoutget_res *res = &lgp->res;
1013 struct pnfs_layout_segment *lseg;
Fred Isamanb7edfaa2011-01-06 11:36:21 +00001014 struct inode *ino = lo->plh_inode;
Fred Isaman43f1b3d2011-01-06 11:36:30 +00001015 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001016 int status = 0;
1017
1018 /* Inject layout blob into I/O device driver */
Trond Myklebusta75b9df2011-05-11 18:00:51 -04001019 lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001020 if (!lseg || IS_ERR(lseg)) {
1021 if (!lseg)
1022 status = -ENOMEM;
1023 else
1024 status = PTR_ERR(lseg);
1025 dprintk("%s: Could not allocate layout: error %d\n",
1026 __func__, status);
1027 goto out;
1028 }
1029
1030 spin_lock(&ino->i_lock);
Fred Isaman43f1b3d2011-01-06 11:36:30 +00001031 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
1032 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1033 dprintk("%s forget reply due to recall\n", __func__);
1034 goto out_forget_reply;
1035 }
1036
1037 if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) {
1038 dprintk("%s forget reply due to state\n", __func__);
1039 goto out_forget_reply;
1040 }
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001041 init_lseg(lo, lseg);
Fred Isaman566052c2011-01-06 11:36:20 +00001042 lseg->pls_range = res->range;
Fred Isamand684d2a2011-03-01 01:34:13 +00001043 *lgp->lsegpp = get_lseg(lseg);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001044 pnfs_insert_layout(lo, lseg);
1045
Fred Isamanf7e89172011-01-06 11:36:32 +00001046 if (res->return_on_close) {
1047 set_bit(NFS_LSEG_ROC, &lseg->pls_flags);
1048 set_bit(NFS_LAYOUT_ROC, &lo->plh_flags);
1049 }
1050
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001051 /* Done processing layoutget. Set the layout stateid */
Fred Isaman43f1b3d2011-01-06 11:36:30 +00001052 pnfs_set_layout_stateid(lo, &res->stateid, false);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001053 spin_unlock(&ino->i_lock);
1054out:
1055 return status;
Fred Isaman43f1b3d2011-01-06 11:36:30 +00001056
1057out_forget_reply:
1058 spin_unlock(&ino->i_lock);
1059 lseg->pls_layout = lo;
1060 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
1061 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001062}
1063
Trond Myklebustd8007d42011-06-10 13:30:23 -04001064void
1065pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
1066{
1067 BUG_ON(pgio->pg_lseg != NULL);
1068
1069 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
1070 req->wb_context,
1071 req_offset(req),
1072 req->wb_bytes,
1073 IOMODE_READ,
1074 GFP_KERNEL);
Trond Myklebuste885de12011-06-10 13:30:23 -04001075 /* If no lseg, fall back to read through mds */
1076 if (pgio->pg_lseg == NULL)
1077 nfs_pageio_init_read_mds(pgio, pgio->pg_inode);
1078
Trond Myklebustd8007d42011-06-10 13:30:23 -04001079}
1080EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_read);
1081
1082void
1083pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
1084{
1085 BUG_ON(pgio->pg_lseg != NULL);
1086
1087 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
1088 req->wb_context,
1089 req_offset(req),
1090 req->wb_bytes,
1091 IOMODE_RW,
1092 GFP_NOFS);
Trond Myklebuste885de12011-06-10 13:30:23 -04001093 /* If no lseg, fall back to write through mds */
1094 if (pgio->pg_lseg == NULL)
1095 nfs_pageio_init_write_mds(pgio, pgio->pg_inode, pgio->pg_ioflags);
Trond Myklebustd8007d42011-06-10 13:30:23 -04001096}
1097EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write);
1098
Benny Halevy18ad0a92011-05-25 21:03:56 +03001099bool
Trond Myklebust1751c362011-06-10 13:30:23 -04001100pnfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, struct inode *inode)
1101{
1102 struct nfs_server *server = NFS_SERVER(inode);
1103 struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld;
1104
1105 if (ld == NULL)
1106 return false;
1107 nfs_pageio_init(pgio, inode, ld->pg_read_ops, server->rsize, 0);
1108 return true;
1109}
1110
1111bool
1112pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, struct inode *inode, int ioflags)
1113{
1114 struct nfs_server *server = NFS_SERVER(inode);
1115 struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld;
1116
1117 if (ld == NULL)
1118 return false;
1119 nfs_pageio_init(pgio, inode, ld->pg_write_ops, server->wsize, ioflags);
1120 return true;
1121}
1122
1123bool
Benny Halevydfed2062011-05-25 20:25:22 +03001124pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
1125 struct nfs_page *req)
Fred Isamanbae724e2011-03-01 01:34:15 +00001126{
Trond Myklebustd8007d42011-06-10 13:30:23 -04001127 if (pgio->pg_lseg == NULL)
1128 return nfs_generic_pg_test(pgio, prev, req);
Benny Halevy89a58e32011-05-25 20:54:40 +03001129
Trond Myklebust19982ba2011-06-10 13:30:23 -04001130 /*
1131 * Test if a nfs_page is fully contained in the pnfs_layout_range.
1132 * Note that this test makes several assumptions:
1133 * - that the previous nfs_page in the struct nfs_pageio_descriptor
1134 * is known to lie within the range.
1135 * - that the nfs_page being tested is known to be contiguous with the
1136 * previous nfs_page.
1137 * - Layout ranges are page aligned, so we only have to test the
1138 * start offset of the request.
1139 *
1140 * Please also note that 'end_offset' is actually the offset of the
1141 * first byte that lies outside the pnfs_layout_range. FIXME?
1142 *
1143 */
1144 return req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset,
1145 pgio->pg_lseg->pls_range.length);
Fred Isamanbae724e2011-03-01 01:34:15 +00001146}
Benny Halevy89a58e32011-05-25 20:54:40 +03001147EXPORT_SYMBOL_GPL(pnfs_generic_pg_test);
Fred Isamanbae724e2011-03-01 01:34:15 +00001148
Benny Halevyd20581a2011-05-22 19:52:03 +03001149/*
1150 * Called by non rpc-based layout drivers
1151 */
1152int
1153pnfs_ld_write_done(struct nfs_write_data *data)
Fred Isaman94ad1c82011-03-01 01:34:14 +00001154{
Benny Halevyd20581a2011-05-22 19:52:03 +03001155 int status;
Fred Isaman94ad1c82011-03-01 01:34:14 +00001156
Benny Halevyd20581a2011-05-22 19:52:03 +03001157 if (!data->pnfs_error) {
1158 pnfs_set_layoutcommit(data);
1159 data->mds_ops->rpc_call_done(&data->task, data);
1160 data->mds_ops->rpc_release(data);
1161 return 0;
Fred Isaman44b83792011-03-03 15:13:44 +00001162 }
Fred Isaman44b83792011-03-03 15:13:44 +00001163
Benny Halevyd20581a2011-05-22 19:52:03 +03001164 dprintk("%s: pnfs_error=%d, retry via MDS\n", __func__,
1165 data->pnfs_error);
1166 status = nfs_initiate_write(data, NFS_CLIENT(data->inode),
1167 data->mds_ops, NFS_FILE_SYNC);
1168 return status ? : -EAGAIN;
Fred Isaman44b83792011-03-03 15:13:44 +00001169}
Benny Halevyd20581a2011-05-22 19:52:03 +03001170EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
Fred Isaman44b83792011-03-03 15:13:44 +00001171
Andy Adamson0382b742011-03-03 15:13:45 +00001172enum pnfs_try_status
1173pnfs_try_to_write_data(struct nfs_write_data *wdata,
1174 const struct rpc_call_ops *call_ops, int how)
1175{
1176 struct inode *inode = wdata->inode;
1177 enum pnfs_try_status trypnfs;
1178 struct nfs_server *nfss = NFS_SERVER(inode);
1179
1180 wdata->mds_ops = call_ops;
1181
1182 dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__,
1183 inode->i_ino, wdata->args.count, wdata->args.offset, how);
1184
1185 trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how);
1186 if (trypnfs == PNFS_NOT_ATTEMPTED) {
1187 put_lseg(wdata->lseg);
1188 wdata->lseg = NULL;
1189 } else
1190 nfs_inc_stats(inode, NFSIOS_PNFS_WRITE);
1191
1192 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
1193 return trypnfs;
1194}
1195
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001196/*
Benny Halevyd20581a2011-05-22 19:52:03 +03001197 * Called by non rpc-based layout drivers
1198 */
1199int
1200pnfs_ld_read_done(struct nfs_read_data *data)
1201{
1202 int status;
1203
1204 if (!data->pnfs_error) {
1205 __nfs4_read_done_cb(data);
1206 data->mds_ops->rpc_call_done(&data->task, data);
1207 data->mds_ops->rpc_release(data);
1208 return 0;
1209 }
1210
1211 dprintk("%s: pnfs_error=%d, retry via MDS\n", __func__,
1212 data->pnfs_error);
1213 status = nfs_initiate_read(data, NFS_CLIENT(data->inode),
1214 data->mds_ops);
1215 return status ? : -EAGAIN;
1216}
1217EXPORT_SYMBOL_GPL(pnfs_ld_read_done);
1218
1219/*
Andy Adamson64419a92011-03-01 01:34:16 +00001220 * Call the appropriate parallel I/O subsystem read function.
1221 */
1222enum pnfs_try_status
1223pnfs_try_to_read_data(struct nfs_read_data *rdata,
1224 const struct rpc_call_ops *call_ops)
1225{
1226 struct inode *inode = rdata->inode;
1227 struct nfs_server *nfss = NFS_SERVER(inode);
1228 enum pnfs_try_status trypnfs;
1229
1230 rdata->mds_ops = call_ops;
1231
1232 dprintk("%s: Reading ino:%lu %u@%llu\n",
1233 __func__, inode->i_ino, rdata->args.count, rdata->args.offset);
1234
1235 trypnfs = nfss->pnfs_curr_ld->read_pagelist(rdata);
1236 if (trypnfs == PNFS_NOT_ATTEMPTED) {
1237 put_lseg(rdata->lseg);
1238 rdata->lseg = NULL;
1239 } else {
1240 nfs_inc_stats(inode, NFSIOS_PNFS_READ);
1241 }
1242 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
1243 return trypnfs;
1244}
Andy Adamson863a3c62011-03-23 13:27:54 +00001245
1246/*
1247 * Currently there is only one (whole file) write lseg.
1248 */
1249static struct pnfs_layout_segment *pnfs_list_write_lseg(struct inode *inode)
1250{
1251 struct pnfs_layout_segment *lseg, *rv = NULL;
1252
1253 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
1254 if (lseg->pls_range.iomode == IOMODE_RW)
1255 rv = lseg;
1256 return rv;
1257}
1258
1259void
1260pnfs_set_layoutcommit(struct nfs_write_data *wdata)
1261{
1262 struct nfs_inode *nfsi = NFS_I(wdata->inode);
Vitaliy Gusev4b8ee2b2011-05-20 01:34:46 +04001263 loff_t end_pos = wdata->mds_offset + wdata->res.count;
Weston Andros Adamson79a48a12011-04-13 10:53:51 -04001264 bool mark_as_dirty = false;
Andy Adamson863a3c62011-03-23 13:27:54 +00001265
1266 spin_lock(&nfsi->vfs_inode.i_lock);
1267 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
1268 /* references matched in nfs4_layoutcommit_release */
1269 get_lseg(wdata->lseg);
1270 wdata->lseg->pls_lc_cred =
1271 get_rpccred(wdata->args.context->state->owner->so_cred);
Weston Andros Adamson79a48a12011-04-13 10:53:51 -04001272 mark_as_dirty = true;
Andy Adamson863a3c62011-03-23 13:27:54 +00001273 dprintk("%s: Set layoutcommit for inode %lu ",
1274 __func__, wdata->inode->i_ino);
1275 }
1276 if (end_pos > wdata->lseg->pls_end_pos)
1277 wdata->lseg->pls_end_pos = end_pos;
1278 spin_unlock(&nfsi->vfs_inode.i_lock);
Weston Andros Adamson79a48a12011-04-13 10:53:51 -04001279
1280 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
1281 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
1282 if (mark_as_dirty)
1283 mark_inode_dirty_sync(wdata->inode);
Andy Adamson863a3c62011-03-23 13:27:54 +00001284}
1285EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
1286
Andy Adamsonde4b15c2011-03-12 02:58:09 -05001287/*
1288 * For the LAYOUT4_NFSV4_1_FILES layout type, NFS_DATA_SYNC WRITEs and
1289 * NFS_UNSTABLE WRITEs with a COMMIT to data servers must store enough
1290 * data to disk to allow the server to recover the data if it crashes.
1291 * LAYOUTCOMMIT is only needed when the NFL4_UFLG_COMMIT_THRU_MDS flag
1292 * is off, and a COMMIT is sent to a data server, or
1293 * if WRITEs to a data server return NFS_DATA_SYNC.
1294 */
Andy Adamson863a3c62011-03-23 13:27:54 +00001295int
Andy Adamsonef311532011-03-12 02:58:10 -05001296pnfs_layoutcommit_inode(struct inode *inode, bool sync)
Andy Adamson863a3c62011-03-23 13:27:54 +00001297{
1298 struct nfs4_layoutcommit_data *data;
1299 struct nfs_inode *nfsi = NFS_I(inode);
1300 struct pnfs_layout_segment *lseg;
1301 struct rpc_cred *cred;
1302 loff_t end_pos;
1303 int status = 0;
1304
1305 dprintk("--> %s inode %lu\n", __func__, inode->i_ino);
1306
Andy Adamsonde4b15c2011-03-12 02:58:09 -05001307 if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
1308 return 0;
1309
Andy Adamson863a3c62011-03-23 13:27:54 +00001310 /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */
1311 data = kzalloc(sizeof(*data), GFP_NOFS);
Andy Adamsonde4b15c2011-03-12 02:58:09 -05001312 if (!data) {
1313 mark_inode_dirty_sync(inode);
1314 status = -ENOMEM;
1315 goto out;
1316 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001317
Andy Adamsonde4b15c2011-03-12 02:58:09 -05001318 spin_lock(&inode->i_lock);
Andy Adamson863a3c62011-03-23 13:27:54 +00001319 if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
1320 spin_unlock(&inode->i_lock);
1321 kfree(data);
1322 goto out;
1323 }
1324 /*
1325 * Currently only one (whole file) write lseg which is referenced
1326 * in pnfs_set_layoutcommit and will be found.
1327 */
1328 lseg = pnfs_list_write_lseg(inode);
1329
1330 end_pos = lseg->pls_end_pos;
1331 cred = lseg->pls_lc_cred;
1332 lseg->pls_end_pos = 0;
1333 lseg->pls_lc_cred = NULL;
1334
Andy Adamsonde4b15c2011-03-12 02:58:09 -05001335 memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data,
1336 sizeof(nfsi->layout->plh_stateid.data));
Andy Adamson863a3c62011-03-23 13:27:54 +00001337 spin_unlock(&inode->i_lock);
1338
1339 data->args.inode = inode;
1340 data->lseg = lseg;
1341 data->cred = cred;
1342 nfs_fattr_init(&data->fattr);
1343 data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
1344 data->res.fattr = &data->fattr;
1345 data->args.lastbytewritten = end_pos - 1;
1346 data->res.server = NFS_SERVER(inode);
1347
1348 status = nfs4_proc_layoutcommit(data, sync);
1349out:
1350 dprintk("<-- %s status %d\n", __func__, status);
1351 return status;
1352}