Skip to content

Commit 37711e5

Browse files
committed
Merge tag 'nfs-for-5.9-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
Pull NFS client updates from Trond Myklebust: "Stable fixes: - pNFS: Don't return layout segments that are being used for I/O - pNFS: Don't move layout segments off the active list when being used for I/O Features: - NFS: Add support for user xattrs through the NFSv4.2 protocol - NFS: Allow applications to speed up readdir+statx() using AT_STATX_DONT_SYNC - NFSv4.0 allow nconnect for v4.0 Bugfixes and cleanups: - nfs: ensure correct writeback errors are returned on close() - nfs: nfs_file_write() should check for writeback errors - nfs: Fix getxattr kernel panic and memory overflow - NFS: Fix the pNFS/flexfiles mirrored read failover code - SUNRPC: dont update timeout value on connection reset - freezer: Add unsafe versions of freezable_schedule_timeout_interruptible for NFS - sunrpc: destroy rpc_inode_cachep after unregister_filesystem" * tag 'nfs-for-5.9-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: (32 commits) NFS: Fix flexfiles read failover fs: nfs: delete repeated words in comments rpc_pipefs: convert comma to semicolon nfs: Fix getxattr kernel panic and memory overflow NFS: Don't return layout segments that are in use NFS: Don't move layouts to plh_return_segs list while in use NFS: Add layout segment info to pnfs read/write/commit tracepoints NFS: Add tracepoints for layouterror and layoutstats. NFS: Report the stateid + status in trace_nfs4_layoutreturn_on_close() SUNRPC dont update timeout value on connection reset nfs: nfs_file_write() should check for writeback errors nfs: ensure correct writeback errors are returned on close() NFSv4.2: xattr cache: get rid of cache discard work queue NFS: remove redundant initialization of variable result NFSv4.0 allow nconnect for v4.0 freezer: Add unsafe versions of freezable_schedule_timeout_interruptible for NFS sunrpc: destroy rpc_inode_cachep after unregister_filesystem NFSv4.2: add client side xattr caching. NFSv4.2: hook in the user extended attribute handlers NFSv4.2: add the extended attribute proc functions. ...
2 parents 6ffdcde + 563c53e commit 37711e5

31 files changed

+2368
-123
lines changed

fs/nfs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o
3030
nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o
3131
nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o
3232
nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o pnfs_nfs.o
33-
nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o
33+
nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o nfs42xattr.o
3434

3535
obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/
3636
obj-$(CONFIG_PNFS_BLOCK) += blocklayout/

fs/nfs/blocklayout/rpc_pipefs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
7979
goto out_free_data;
8080

8181
bl_msg = msg->data;
82-
bl_msg->type = BL_DEVICE_MOUNT,
82+
bl_msg->type = BL_DEVICE_MOUNT;
8383
bl_msg->totallen = b->simple.len;
8484
nfs4_encode_simple(msg->data + sizeof(*bl_msg), b);
8585

fs/nfs/client.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "nfs.h"
5151
#include "netns.h"
5252
#include "sysfs.h"
53+
#include "nfs42.h"
5354

5455
#define NFSDBG_FACILITY NFSDBG_CLIENT
5556

@@ -749,7 +750,7 @@ static int nfs_init_server(struct nfs_server *server,
749750
static void nfs_server_set_fsinfo(struct nfs_server *server,
750751
struct nfs_fsinfo *fsinfo)
751752
{
752-
unsigned long max_rpc_payload;
753+
unsigned long max_rpc_payload, raw_max_rpc_payload;
753754

754755
/* Work out a lot of parameters */
755756
if (server->rsize == 0)
@@ -762,7 +763,9 @@ static void nfs_server_set_fsinfo(struct nfs_server *server,
762763
if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax)
763764
server->wsize = nfs_block_size(fsinfo->wtmax, NULL);
764765

765-
max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
766+
raw_max_rpc_payload = rpc_max_payload(server->client);
767+
max_rpc_payload = nfs_block_size(raw_max_rpc_payload, NULL);
768+
766769
if (server->rsize > max_rpc_payload)
767770
server->rsize = max_rpc_payload;
768771
if (server->rsize > NFS_MAX_FILE_IO_SIZE)
@@ -795,6 +798,21 @@ static void nfs_server_set_fsinfo(struct nfs_server *server,
795798
server->clone_blksize = fsinfo->clone_blksize;
796799
/* We're airborne Set socket buffersize */
797800
rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
801+
802+
#ifdef CONFIG_NFS_V4_2
803+
/*
804+
* Defaults until limited by the session parameters.
805+
*/
806+
server->gxasize = min_t(unsigned int, raw_max_rpc_payload,
807+
XATTR_SIZE_MAX);
808+
server->sxasize = min_t(unsigned int, raw_max_rpc_payload,
809+
XATTR_SIZE_MAX);
810+
server->lxasize = min_t(unsigned int, raw_max_rpc_payload,
811+
nfs42_listxattr_xdrsize(XATTR_LIST_MAX));
812+
813+
if (fsinfo->xattr_support)
814+
server->caps |= NFS_CAP_XATTR;
815+
#endif
798816
}
799817

800818
/*

fs/nfs/dir.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, co
24602460
return NULL;
24612461
}
24622462

2463-
static int nfs_access_get_cached(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res, bool may_block)
2463+
static int nfs_access_get_cached_locked(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res, bool may_block)
24642464
{
24652465
struct nfs_inode *nfsi = NFS_I(inode);
24662466
struct nfs_access_entry *cache;
@@ -2533,6 +2533,20 @@ static int nfs_access_get_cached_rcu(struct inode *inode, const struct cred *cre
25332533
return err;
25342534
}
25352535

2536+
int nfs_access_get_cached(struct inode *inode, const struct cred *cred, struct
2537+
nfs_access_entry *res, bool may_block)
2538+
{
2539+
int status;
2540+
2541+
status = nfs_access_get_cached_rcu(inode, cred, res);
2542+
if (status != 0)
2543+
status = nfs_access_get_cached_locked(inode, cred, res,
2544+
may_block);
2545+
2546+
return status;
2547+
}
2548+
EXPORT_SYMBOL_GPL(nfs_access_get_cached);
2549+
25362550
static void nfs_access_add_rbtree(struct inode *inode, struct nfs_access_entry *set)
25372551
{
25382552
struct nfs_inode *nfsi = NFS_I(inode);
@@ -2647,9 +2661,7 @@ static int nfs_do_access(struct inode *inode, const struct cred *cred, int mask)
26472661

26482662
trace_nfs_access_enter(inode);
26492663

2650-
status = nfs_access_get_cached_rcu(inode, cred, &cache);
2651-
if (status != 0)
2652-
status = nfs_access_get_cached(inode, cred, &cache, may_block);
2664+
status = nfs_access_get_cached(inode, cred, &cache, may_block);
26532665
if (status == 0)
26542666
goto out_cached;
26552667

@@ -2661,6 +2673,10 @@ static int nfs_do_access(struct inode *inode, const struct cred *cred, int mask)
26612673
* Determine which access bits we want to ask for...
26622674
*/
26632675
cache.mask = NFS_ACCESS_READ | NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND;
2676+
if (nfs_server_capable(inode, NFS_CAP_XATTR)) {
2677+
cache.mask |= NFS_ACCESS_XAREAD | NFS_ACCESS_XAWRITE |
2678+
NFS_ACCESS_XALIST;
2679+
}
26642680
if (S_ISDIR(inode->i_mode))
26652681
cache.mask |= NFS_ACCESS_DELETE | NFS_ACCESS_LOOKUP;
26662682
else

fs/nfs/direct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
896896
*/
897897
ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
898898
{
899-
ssize_t result = -EINVAL, requested;
899+
ssize_t result, requested;
900900
size_t count;
901901
struct file *file = iocb->ki_filp;
902902
struct address_space *mapping = file->f_mapping;

fs/nfs/file.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static int
140140
nfs_file_flush(struct file *file, fl_owner_t id)
141141
{
142142
struct inode *inode = file_inode(file);
143+
errseq_t since;
143144

144145
dprintk("NFS: flush(%pD2)\n", file);
145146

@@ -148,7 +149,9 @@ nfs_file_flush(struct file *file, fl_owner_t id)
148149
return 0;
149150

150151
/* Flush writes to the server and return any errors */
151-
return nfs_wb_all(inode);
152+
since = filemap_sample_wb_err(file->f_mapping);
153+
nfs_wb_all(inode);
154+
return filemap_check_wb_err(file->f_mapping, since);
152155
}
153156

154157
ssize_t
@@ -587,12 +590,14 @@ static const struct vm_operations_struct nfs_file_vm_ops = {
587590
.page_mkwrite = nfs_vm_page_mkwrite,
588591
};
589592

590-
static int nfs_need_check_write(struct file *filp, struct inode *inode)
593+
static int nfs_need_check_write(struct file *filp, struct inode *inode,
594+
int error)
591595
{
592596
struct nfs_open_context *ctx;
593597

594598
ctx = nfs_file_open_context(filp);
595-
if (nfs_ctx_key_to_expire(ctx, inode))
599+
if (nfs_error_is_fatal_on_server(error) ||
600+
nfs_ctx_key_to_expire(ctx, inode))
596601
return 1;
597602
return 0;
598603
}
@@ -603,6 +608,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
603608
struct inode *inode = file_inode(file);
604609
unsigned long written = 0;
605610
ssize_t result;
611+
errseq_t since;
612+
int error;
606613

607614
result = nfs_key_timeout_notify(file, inode);
608615
if (result)
@@ -627,6 +634,7 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
627634
if (iocb->ki_pos > i_size_read(inode))
628635
nfs_revalidate_mapping(inode, file->f_mapping);
629636

637+
since = filemap_sample_wb_err(file->f_mapping);
630638
nfs_start_io_write(inode);
631639
result = generic_write_checks(iocb, from);
632640
if (result > 0) {
@@ -645,7 +653,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
645653
goto out;
646654

647655
/* Return error values */
648-
if (nfs_need_check_write(file, inode)) {
656+
error = filemap_check_wb_err(file->f_mapping, since);
657+
if (nfs_need_check_write(file, inode, error)) {
649658
int err = nfs_wb_all(inode);
650659
if (err < 0)
651660
result = err;

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,19 @@ ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
790790
return ff_layout_choose_any_ds_for_read(lseg, start_idx, best_idx);
791791
}
792792

793+
static struct nfs4_pnfs_ds *
794+
ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio, int *best_idx)
795+
{
796+
struct pnfs_layout_segment *lseg = pgio->pg_lseg;
797+
struct nfs4_pnfs_ds *ds;
798+
799+
ds = ff_layout_choose_best_ds_for_read(lseg, pgio->pg_mirror_idx,
800+
best_idx);
801+
if (ds || !pgio->pg_mirror_idx)
802+
return ds;
803+
return ff_layout_choose_best_ds_for_read(lseg, 0, best_idx);
804+
}
805+
793806
static void
794807
ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio,
795808
struct nfs_page *req,
@@ -840,12 +853,11 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
840853
goto out_nolseg;
841854
}
842855

843-
ds = ff_layout_choose_best_ds_for_read(pgio->pg_lseg, 0, &ds_idx);
856+
ds = ff_layout_get_ds_for_read(pgio, &ds_idx);
844857
if (!ds) {
845858
if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
846859
goto out_mds;
847-
pnfs_put_lseg(pgio->pg_lseg);
848-
pgio->pg_lseg = NULL;
860+
pnfs_generic_pg_cleanup(pgio);
849861
/* Sleep for 1 second before retrying */
850862
ssleep(1);
851863
goto retry;
@@ -871,8 +883,6 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
871883
0, NFS4_MAX_UINT64, IOMODE_READ,
872884
NFS_I(pgio->pg_inode)->layout,
873885
pgio->pg_lseg);
874-
pnfs_put_lseg(pgio->pg_lseg);
875-
pgio->pg_lseg = NULL;
876886
pgio->pg_maxretrans = 0;
877887
nfs_pageio_reset_read_mds(pgio);
878888
}
@@ -916,8 +926,7 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
916926
if (!ds) {
917927
if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
918928
goto out_mds;
919-
pnfs_put_lseg(pgio->pg_lseg);
920-
pgio->pg_lseg = NULL;
929+
pnfs_generic_pg_cleanup(pgio);
921930
/* Sleep for 1 second before retrying */
922931
ssleep(1);
923932
goto retry;
@@ -939,8 +948,6 @@ ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
939948
0, NFS4_MAX_UINT64, IOMODE_RW,
940949
NFS_I(pgio->pg_inode)->layout,
941950
pgio->pg_lseg);
942-
pnfs_put_lseg(pgio->pg_lseg);
943-
pgio->pg_lseg = NULL;
944951
pgio->pg_maxretrans = 0;
945952
nfs_pageio_reset_write_mds(pgio);
946953
pgio->pg_error = -EAGAIN;
@@ -953,8 +960,8 @@ ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
953960
if (!pgio->pg_lseg) {
954961
pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
955962
nfs_req_openctx(req),
956-
0,
957-
NFS4_MAX_UINT64,
963+
req_offset(req),
964+
req->wb_bytes,
958965
IOMODE_RW,
959966
false,
960967
GFP_NOFS);
@@ -1028,11 +1035,24 @@ static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs)
10281035
}
10291036
}
10301037

1038+
static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)
1039+
{
1040+
u32 idx = hdr->pgio_mirror_idx + 1;
1041+
int new_idx = 0;
1042+
1043+
if (ff_layout_choose_any_ds_for_read(hdr->lseg, idx + 1, &new_idx))
1044+
ff_layout_send_layouterror(hdr->lseg);
1045+
else
1046+
pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
1047+
pnfs_read_resend_pnfs(hdr, new_idx);
1048+
}
1049+
10311050
static void ff_layout_reset_read(struct nfs_pgio_header *hdr)
10321051
{
10331052
struct rpc_task *task = &hdr->task;
10341053

10351054
pnfs_layoutcommit_inode(hdr->inode, false);
1055+
pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
10361056

10371057
if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
10381058
dprintk("%s Reset task %5u for i/o through MDS "
@@ -1234,6 +1254,12 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
12341254
break;
12351255
case NFS4ERR_NXIO:
12361256
ff_layout_mark_ds_unreachable(lseg, idx);
1257+
/*
1258+
* Don't return the layout if this is a read and we still
1259+
* have layouts to try
1260+
*/
1261+
if (opnum == OP_READ)
1262+
break;
12371263
/* Fallthrough */
12381264
default:
12391265
pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode,
@@ -1247,7 +1273,6 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
12471273
static int ff_layout_read_done_cb(struct rpc_task *task,
12481274
struct nfs_pgio_header *hdr)
12491275
{
1250-
int new_idx = hdr->pgio_mirror_idx;
12511276
int err;
12521277

12531278
if (task->tk_status < 0) {
@@ -1267,10 +1292,6 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
12671292
clear_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags);
12681293
switch (err) {
12691294
case -NFS4ERR_RESET_TO_PNFS:
1270-
if (ff_layout_choose_best_ds_for_read(hdr->lseg,
1271-
hdr->pgio_mirror_idx + 1,
1272-
&new_idx))
1273-
goto out_layouterror;
12741295
set_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
12751296
return task->tk_status;
12761297
case -NFS4ERR_RESET_TO_MDS:
@@ -1281,10 +1302,6 @@ static int ff_layout_read_done_cb(struct rpc_task *task,
12811302
}
12821303

12831304
return 0;
1284-
out_layouterror:
1285-
ff_layout_read_record_layoutstats_done(task, hdr);
1286-
ff_layout_send_layouterror(hdr->lseg);
1287-
hdr->pgio_mirror_idx = new_idx;
12881305
out_eagain:
12891306
rpc_restart_call_prepare(task);
12901307
return -EAGAIN;
@@ -1411,10 +1428,9 @@ static void ff_layout_read_release(void *data)
14111428
struct nfs_pgio_header *hdr = data;
14121429

14131430
ff_layout_read_record_layoutstats_done(&hdr->task, hdr);
1414-
if (test_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags)) {
1415-
ff_layout_send_layouterror(hdr->lseg);
1416-
pnfs_read_resend_pnfs(hdr);
1417-
} else if (test_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags))
1431+
if (test_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags))
1432+
ff_layout_resend_pnfs_read(hdr);
1433+
else if (test_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags))
14181434
ff_layout_reset_read(hdr);
14191435
pnfs_generic_rw_release(data);
14201436
}

fs/nfs/fs_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ static int nfs23_parse_monolithic(struct fs_context *fc,
982982
/*
983983
* The legacy version 6 binary mount data from userspace has a
984984
* field used only to transport selinux information into the
985-
* the kernel. To continue to support that functionality we
985+
* kernel. To continue to support that functionality we
986986
* have a touch of selinux knowledge here in the NFS code. The
987987
* userspace code converted context=blah to just blah so we are
988988
* converting back to the full string selinux understands.

0 commit comments

Comments
 (0)