Skip to content

Commit a75b9df

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFSv4.1: Ensure that layoutget uses the correct gfp modes
Currently, writebacks may end up recursing back into the filesystem due to GFP_KERNEL direct reclaims in the pnfs subsystem. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 2887fe4 commit a75b9df

8 files changed

Lines changed: 59 additions & 50 deletions

File tree

‎fs/nfs/nfs4filelayout.c‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ static int
418418
filelayout_check_layout(struct pnfs_layout_hdr *lo,
419419
struct nfs4_filelayout_segment *fl,
420420
struct nfs4_layoutget_res *lgr,
421-
struct nfs4_deviceid *id)
421+
struct nfs4_deviceid *id,
422+
gfp_t gfp_flags)
422423
{
423424
struct nfs4_file_layout_dsaddr *dsaddr;
424425
int status = -EINVAL;
@@ -441,7 +442,7 @@ filelayout_check_layout(struct pnfs_layout_hdr *lo,
441442
/* find and reference the deviceid */
442443
dsaddr = nfs4_fl_find_get_deviceid(id);
443444
if (dsaddr == NULL) {
444-
dsaddr = get_device_info(lo->plh_inode, id);
445+
dsaddr = get_device_info(lo->plh_inode, id, gfp_flags);
445446
if (dsaddr == NULL)
446447
goto out;
447448
}
@@ -502,7 +503,8 @@ static int
502503
filelayout_decode_layout(struct pnfs_layout_hdr *flo,
503504
struct nfs4_filelayout_segment *fl,
504505
struct nfs4_layoutget_res *lgr,
505-
struct nfs4_deviceid *id)
506+
struct nfs4_deviceid *id,
507+
gfp_t gfp_flags)
506508
{
507509
struct xdr_stream stream;
508510
struct xdr_buf buf = {
@@ -518,7 +520,7 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,
518520

519521
dprintk("%s: set_layout_map Begin\n", __func__);
520522

521-
scratch = alloc_page(GFP_KERNEL);
523+
scratch = alloc_page(gfp_flags);
522524
if (!scratch)
523525
return -ENOMEM;
524526

@@ -556,13 +558,13 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,
556558
goto out_err;
557559

558560
fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
559-
GFP_KERNEL);
561+
gfp_flags);
560562
if (!fl->fh_array)
561563
goto out_err;
562564

563565
for (i = 0; i < fl->num_fh; i++) {
564566
/* Do we want to use a mempool here? */
565-
fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), GFP_KERNEL);
567+
fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
566568
if (!fl->fh_array[i])
567569
goto out_err_free;
568570

@@ -607,19 +609,20 @@ filelayout_free_lseg(struct pnfs_layout_segment *lseg)
607609

608610
static struct pnfs_layout_segment *
609611
filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
610-
struct nfs4_layoutget_res *lgr)
612+
struct nfs4_layoutget_res *lgr,
613+
gfp_t gfp_flags)
611614
{
612615
struct nfs4_filelayout_segment *fl;
613616
int rc;
614617
struct nfs4_deviceid id;
615618

616619
dprintk("--> %s\n", __func__);
617-
fl = kzalloc(sizeof(*fl), GFP_KERNEL);
620+
fl = kzalloc(sizeof(*fl), gfp_flags);
618621
if (!fl)
619622
return NULL;
620623

621-
rc = filelayout_decode_layout(layoutid, fl, lgr, &id);
622-
if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id)) {
624+
rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags);
625+
if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) {
623626
_filelayout_free_lseg(fl);
624627
return NULL;
625628
}
@@ -635,7 +638,7 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
635638
int size = (fl->stripe_type == STRIPE_SPARSE) ?
636639
fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
637640

638-
fl->commit_buckets = kcalloc(size, sizeof(struct list_head), GFP_KERNEL);
641+
fl->commit_buckets = kcalloc(size, sizeof(struct list_head), gfp_flags);
639642
if (!fl->commit_buckets) {
640643
filelayout_free_lseg(&fl->generic_hdr);
641644
return NULL;

‎fs/nfs/nfs4filelayout.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ extern struct nfs4_file_layout_dsaddr *
104104
nfs4_fl_find_get_deviceid(struct nfs4_deviceid *dev_id);
105105
extern void nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
106106
struct nfs4_file_layout_dsaddr *
107-
get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id);
107+
get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags);
108108

109109
#endif /* FS_NFS_NFS4FILELAYOUT_H */

‎fs/nfs/nfs4filelayoutdev.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
225225
}
226226

227227
static struct nfs4_pnfs_ds *
228-
nfs4_pnfs_ds_add(struct inode *inode, u32 ip_addr, u32 port)
228+
nfs4_pnfs_ds_add(struct inode *inode, u32 ip_addr, u32 port, gfp_t gfp_flags)
229229
{
230230
struct nfs4_pnfs_ds *tmp_ds, *ds;
231231

232-
ds = kzalloc(sizeof(*tmp_ds), GFP_KERNEL);
232+
ds = kzalloc(sizeof(*tmp_ds), gfp_flags);
233233
if (!ds)
234234
goto out;
235235

@@ -261,7 +261,7 @@ nfs4_pnfs_ds_add(struct inode *inode, u32 ip_addr, u32 port)
261261
* Currently only support ipv4, and one multi-path address.
262262
*/
263263
static struct nfs4_pnfs_ds *
264-
decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode)
264+
decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode, gfp_t gfp_flags)
265265
{
266266
struct nfs4_pnfs_ds *ds = NULL;
267267
char *buf;
@@ -303,7 +303,7 @@ decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode)
303303
rlen);
304304
goto out_err;
305305
}
306-
buf = kmalloc(rlen + 1, GFP_KERNEL);
306+
buf = kmalloc(rlen + 1, gfp_flags);
307307
if (!buf) {
308308
dprintk("%s: Not enough memory\n", __func__);
309309
goto out_err;
@@ -333,7 +333,7 @@ decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode)
333333
sscanf(pstr, "-%d-%d", &tmp[0], &tmp[1]);
334334
port = htons((tmp[0] << 8) | (tmp[1]));
335335

336-
ds = nfs4_pnfs_ds_add(inode, ip_addr, port);
336+
ds = nfs4_pnfs_ds_add(inode, ip_addr, port, gfp_flags);
337337
dprintk("%s: Decoded address and port %s\n", __func__, buf);
338338
out_free:
339339
kfree(buf);
@@ -343,7 +343,7 @@ decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode)
343343

344344
/* Decode opaque device data and return the result */
345345
static struct nfs4_file_layout_dsaddr*
346-
decode_device(struct inode *ino, struct pnfs_device *pdev)
346+
decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
347347
{
348348
int i;
349349
u32 cnt, num;
@@ -362,7 +362,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev)
362362
struct page *scratch;
363363

364364
/* set up xdr stream */
365-
scratch = alloc_page(GFP_KERNEL);
365+
scratch = alloc_page(gfp_flags);
366366
if (!scratch)
367367
goto out_err;
368368

@@ -384,7 +384,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev)
384384
}
385385

386386
/* read stripe indices */
387-
stripe_indices = kcalloc(cnt, sizeof(u8), GFP_KERNEL);
387+
stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags);
388388
if (!stripe_indices)
389389
goto out_err_free_scratch;
390390

@@ -423,7 +423,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev)
423423

424424
dsaddr = kzalloc(sizeof(*dsaddr) +
425425
(sizeof(struct nfs4_pnfs_ds *) * (num - 1)),
426-
GFP_KERNEL);
426+
gfp_flags);
427427
if (!dsaddr)
428428
goto out_err_free_stripe_indices;
429429

@@ -452,7 +452,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev)
452452
for (j = 0; j < mp_count; j++) {
453453
if (j == 0) {
454454
dsaddr->ds_list[i] = decode_and_add_ds(&stream,
455-
ino);
455+
ino, gfp_flags);
456456
if (dsaddr->ds_list[i] == NULL)
457457
goto out_err_free_deviceid;
458458
} else {
@@ -503,12 +503,12 @@ decode_device(struct inode *ino, struct pnfs_device *pdev)
503503
* available devices.
504504
*/
505505
static struct nfs4_file_layout_dsaddr *
506-
decode_and_add_device(struct inode *inode, struct pnfs_device *dev)
506+
decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags)
507507
{
508508
struct nfs4_file_layout_dsaddr *d, *new;
509509
long hash;
510510

511-
new = decode_device(inode, dev);
511+
new = decode_device(inode, dev, gfp_flags);
512512
if (!new) {
513513
printk(KERN_WARNING "%s: Could not decode or add device\n",
514514
__func__);
@@ -537,7 +537,7 @@ decode_and_add_device(struct inode *inode, struct pnfs_device *dev)
537537
* of available devices, and return it.
538538
*/
539539
struct nfs4_file_layout_dsaddr *
540-
get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id)
540+
get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags)
541541
{
542542
struct pnfs_device *pdev = NULL;
543543
u32 max_resp_sz;
@@ -556,17 +556,17 @@ get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id)
556556
dprintk("%s inode %p max_resp_sz %u max_pages %d\n",
557557
__func__, inode, max_resp_sz, max_pages);
558558

559-
pdev = kzalloc(sizeof(struct pnfs_device), GFP_KERNEL);
559+
pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags);
560560
if (pdev == NULL)
561561
return NULL;
562562

563-
pages = kzalloc(max_pages * sizeof(struct page *), GFP_KERNEL);
563+
pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
564564
if (pages == NULL) {
565565
kfree(pdev);
566566
return NULL;
567567
}
568568
for (i = 0; i < max_pages; i++) {
569-
pages[i] = alloc_page(GFP_KERNEL);
569+
pages[i] = alloc_page(gfp_flags);
570570
if (!pages[i])
571571
goto out_free;
572572
}
@@ -587,7 +587,7 @@ get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id)
587587
* Found new device, need to decode it and then add it to the
588588
* list of known devices for this mountpoint.
589589
*/
590-
dsaddr = decode_and_add_device(inode, pdev);
590+
dsaddr = decode_and_add_device(inode, pdev, gfp_flags);
591591
out_free:
592592
for (i = 0; i < max_pages; i++)
593593
__free_page(pages[i]);

‎fs/nfs/pnfs.c‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
467467
static struct pnfs_layout_segment *
468468
send_layoutget(struct pnfs_layout_hdr *lo,
469469
struct nfs_open_context *ctx,
470-
u32 iomode)
470+
u32 iomode,
471+
gfp_t gfp_flags)
471472
{
472473
struct inode *ino = lo->plh_inode;
473474
struct nfs_server *server = NFS_SERVER(ino);
@@ -480,20 +481,20 @@ send_layoutget(struct pnfs_layout_hdr *lo,
480481
dprintk("--> %s\n", __func__);
481482

482483
BUG_ON(ctx == NULL);
483-
lgp = kzalloc(sizeof(*lgp), GFP_KERNEL);
484+
lgp = kzalloc(sizeof(*lgp), gfp_flags);
484485
if (lgp == NULL)
485486
return NULL;
486487

487488
/* allocate pages for xdr post processing */
488489
max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
489490
max_pages = max_resp_sz >> PAGE_SHIFT;
490491

491-
pages = kzalloc(max_pages * sizeof(struct page *), GFP_KERNEL);
492+
pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags);
492493
if (!pages)
493494
goto out_err_free;
494495

495496
for (i = 0; i < max_pages; i++) {
496-
pages[i] = alloc_page(GFP_KERNEL);
497+
pages[i] = alloc_page(gfp_flags);
497498
if (!pages[i])
498499
goto out_err_free;
499500
}
@@ -509,6 +510,7 @@ send_layoutget(struct pnfs_layout_hdr *lo,
509510
lgp->args.layout.pages = pages;
510511
lgp->args.layout.pglen = max_pages * PAGE_SIZE;
511512
lgp->lsegpp = &lseg;
513+
lgp->gfp_flags = gfp_flags;
512514

513515
/* Synchronously retrieve layout information from server and
514516
* store in lseg.
@@ -666,11 +668,11 @@ pnfs_insert_layout(struct pnfs_layout_hdr *lo,
666668
}
667669

668670
static struct pnfs_layout_hdr *
669-
alloc_init_layout_hdr(struct inode *ino)
671+
alloc_init_layout_hdr(struct inode *ino, gfp_t gfp_flags)
670672
{
671673
struct pnfs_layout_hdr *lo;
672674

673-
lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL);
675+
lo = kzalloc(sizeof(struct pnfs_layout_hdr), gfp_flags);
674676
if (!lo)
675677
return NULL;
676678
atomic_set(&lo->plh_refcount, 1);
@@ -682,7 +684,7 @@ alloc_init_layout_hdr(struct inode *ino)
682684
}
683685

684686
static struct pnfs_layout_hdr *
685-
pnfs_find_alloc_layout(struct inode *ino)
687+
pnfs_find_alloc_layout(struct inode *ino, gfp_t gfp_flags)
686688
{
687689
struct nfs_inode *nfsi = NFS_I(ino);
688690
struct pnfs_layout_hdr *new = NULL;
@@ -697,7 +699,7 @@ pnfs_find_alloc_layout(struct inode *ino)
697699
return nfsi->layout;
698700
}
699701
spin_unlock(&ino->i_lock);
700-
new = alloc_init_layout_hdr(ino);
702+
new = alloc_init_layout_hdr(ino, gfp_flags);
701703
spin_lock(&ino->i_lock);
702704

703705
if (likely(nfsi->layout == NULL)) /* Won the race? */
@@ -757,7 +759,8 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo, u32 iomode)
757759
struct pnfs_layout_segment *
758760
pnfs_update_layout(struct inode *ino,
759761
struct nfs_open_context *ctx,
760-
enum pnfs_iomode iomode)
762+
enum pnfs_iomode iomode,
763+
gfp_t gfp_flags)
761764
{
762765
struct nfs_inode *nfsi = NFS_I(ino);
763766
struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
@@ -768,7 +771,7 @@ pnfs_update_layout(struct inode *ino,
768771
if (!pnfs_enabled_sb(NFS_SERVER(ino)))
769772
return NULL;
770773
spin_lock(&ino->i_lock);
771-
lo = pnfs_find_alloc_layout(ino);
774+
lo = pnfs_find_alloc_layout(ino, gfp_flags);
772775
if (lo == NULL) {
773776
dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__);
774777
goto out_unlock;
@@ -808,7 +811,7 @@ pnfs_update_layout(struct inode *ino,
808811
spin_unlock(&clp->cl_lock);
809812
}
810813

811-
lseg = send_layoutget(lo, ctx, iomode);
814+
lseg = send_layoutget(lo, ctx, iomode, gfp_flags);
812815
if (!lseg && first) {
813816
spin_lock(&clp->cl_lock);
814817
list_del_init(&lo->plh_layouts);
@@ -847,7 +850,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
847850
goto out;
848851
}
849852
/* Inject layout blob into I/O device driver */
850-
lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res);
853+
lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags);
851854
if (!lseg || IS_ERR(lseg)) {
852855
if (!lseg)
853856
status = -ENOMEM;
@@ -900,7 +903,8 @@ static int pnfs_read_pg_test(struct nfs_pageio_descriptor *pgio,
900903
/* This is first coelesce call for a series of nfs_pages */
901904
pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
902905
prev->wb_context,
903-
IOMODE_READ);
906+
IOMODE_READ,
907+
GFP_KERNEL);
904908
}
905909
return NFS_SERVER(pgio->pg_inode)->pnfs_curr_ld->pg_test(pgio, prev, req);
906910
}
@@ -922,7 +926,8 @@ static int pnfs_write_pg_test(struct nfs_pageio_descriptor *pgio,
922926
/* This is first coelesce call for a series of nfs_pages */
923927
pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
924928
prev->wb_context,
925-
IOMODE_RW);
929+
IOMODE_RW,
930+
GFP_NOFS);
926931
}
927932
return NFS_SERVER(pgio->pg_inode)->pnfs_curr_ld->pg_test(pgio, prev, req);
928933
}

‎fs/nfs/pnfs.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct pnfs_layoutdriver_type {
7070
const u32 id;
7171
const char *name;
7272
struct module *owner;
73-
struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr);
73+
struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
7474
void (*free_lseg) (struct pnfs_layout_segment *lseg);
7575

7676
/* test for nfs page cache coalescing */
@@ -126,7 +126,7 @@ void get_layout_hdr(struct pnfs_layout_hdr *lo);
126126
void put_lseg(struct pnfs_layout_segment *lseg);
127127
struct pnfs_layout_segment *
128128
pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
129-
enum pnfs_iomode access_type);
129+
enum pnfs_iomode access_type, gfp_t gfp_flags);
130130
void set_pnfs_layoutdriver(struct nfs_server *, u32 id);
131131
void unset_pnfs_layoutdriver(struct nfs_server *);
132132
enum pnfs_try_status pnfs_try_to_write_data(struct nfs_write_data *,
@@ -245,7 +245,7 @@ static inline void put_lseg(struct pnfs_layout_segment *lseg)
245245

246246
static inline struct pnfs_layout_segment *
247247
pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
248-
enum pnfs_iomode access_type)
248+
enum pnfs_iomode access_type, gfp_t gfp_flags)
249249
{
250250
return NULL;
251251
}

0 commit comments

Comments
 (0)