1 // SPDX-License-Identifier: GPL-2.0-only
3 * Common NFS I/O operations for the pnfs file based
6 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
8 * Tom Haynes <loghyr@primarydata.com>
11 #include <linux/nfs_fs.h>
12 #include <linux/nfs_page.h>
13 #include <linux/sunrpc/addr.h>
14 #include <linux/module.h>
16 #include "nfs4session.h"
20 #define NFSDBG_FACILITY NFSDBG_PNFS
22 void pnfs_generic_rw_release(void *data
)
24 struct nfs_pgio_header
*hdr
= data
;
26 nfs_put_client(hdr
->ds_clp
);
27 hdr
->mds_ops
->rpc_release(data
);
29 EXPORT_SYMBOL_GPL(pnfs_generic_rw_release
);
31 /* Fake up some data that will cause nfs_commit_release to retry the writes. */
32 void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data
*data
)
34 struct nfs_page
*first
= nfs_list_entry(data
->pages
.next
);
36 data
->task
.tk_status
= 0;
37 memcpy(&data
->verf
.verifier
, &first
->wb_verf
,
38 sizeof(data
->verf
.verifier
));
39 data
->verf
.verifier
.data
[0]++; /* ensure verifier mismatch */
41 EXPORT_SYMBOL_GPL(pnfs_generic_prepare_to_resend_writes
);
43 void pnfs_generic_write_commit_done(struct rpc_task
*task
, void *data
)
45 struct nfs_commit_data
*wdata
= data
;
47 /* Note this may cause RPC to be resent */
48 wdata
->mds_ops
->rpc_call_done(task
, data
);
50 EXPORT_SYMBOL_GPL(pnfs_generic_write_commit_done
);
52 void pnfs_generic_commit_release(void *calldata
)
54 struct nfs_commit_data
*data
= calldata
;
56 data
->completion_ops
->completion(data
);
57 pnfs_put_lseg(data
->lseg
);
58 nfs_put_client(data
->ds_clp
);
59 nfs_commitdata_release(data
);
61 EXPORT_SYMBOL_GPL(pnfs_generic_commit_release
);
63 /* The generic layer is about to remove the req from the commit list.
64 * If this will make the bucket empty, it will need to put the lseg reference.
65 * Note this must be called holding nfsi->commit_mutex
68 pnfs_generic_clear_request_commit(struct nfs_page
*req
,
69 struct nfs_commit_info
*cinfo
)
71 struct pnfs_layout_segment
*freeme
= NULL
;
73 if (!test_and_clear_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
))
75 cinfo
->ds
->nwritten
--;
76 if (list_is_singular(&req
->wb_list
)) {
77 struct pnfs_commit_bucket
*bucket
;
79 bucket
= list_first_entry(&req
->wb_list
,
80 struct pnfs_commit_bucket
,
82 freeme
= bucket
->wlseg
;
86 nfs_request_remove_commit_list(req
, cinfo
);
87 pnfs_put_lseg(freeme
);
89 EXPORT_SYMBOL_GPL(pnfs_generic_clear_request_commit
);
92 pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket
*bucket
,
93 struct nfs_commit_info
*cinfo
,
96 struct list_head
*src
= &bucket
->written
;
97 struct list_head
*dst
= &bucket
->committing
;
100 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
101 ret
= nfs_scan_commit_list(src
, dst
, cinfo
, max
);
103 cinfo
->ds
->nwritten
-= ret
;
104 cinfo
->ds
->ncommitting
+= ret
;
105 if (bucket
->clseg
== NULL
)
106 bucket
->clseg
= pnfs_get_lseg(bucket
->wlseg
);
107 if (list_empty(src
)) {
108 pnfs_put_lseg(bucket
->wlseg
);
109 bucket
->wlseg
= NULL
;
115 /* Move reqs from written to committing lists, returning count
118 int pnfs_generic_scan_commit_lists(struct nfs_commit_info
*cinfo
,
123 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
124 for (i
= 0; i
< cinfo
->ds
->nbuckets
&& max
!= 0; i
++) {
125 cnt
= pnfs_generic_scan_ds_commit_list(&cinfo
->ds
->buckets
[i
],
132 EXPORT_SYMBOL_GPL(pnfs_generic_scan_commit_lists
);
134 /* Pull everything off the committing lists and dump into @dst. */
135 void pnfs_generic_recover_commit_reqs(struct list_head
*dst
,
136 struct nfs_commit_info
*cinfo
)
138 struct pnfs_commit_bucket
*b
;
139 struct pnfs_layout_segment
*freeme
;
143 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
145 for (i
= 0, b
= cinfo
->ds
->buckets
; i
< cinfo
->ds
->nbuckets
; i
++, b
++) {
146 nwritten
= nfs_scan_commit_list(&b
->written
, dst
, cinfo
, 0);
149 cinfo
->ds
->nwritten
-= nwritten
;
150 if (list_empty(&b
->written
)) {
153 pnfs_put_lseg(freeme
);
158 EXPORT_SYMBOL_GPL(pnfs_generic_recover_commit_reqs
);
160 static void pnfs_generic_retry_commit(struct nfs_commit_info
*cinfo
, int idx
)
162 struct pnfs_ds_commit_info
*fl_cinfo
= cinfo
->ds
;
163 struct pnfs_commit_bucket
*bucket
;
164 struct pnfs_layout_segment
*freeme
;
165 struct list_head
*pos
;
169 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
170 for (i
= idx
; i
< fl_cinfo
->nbuckets
; i
++) {
171 bucket
= &fl_cinfo
->buckets
[i
];
172 if (list_empty(&bucket
->committing
))
174 freeme
= bucket
->clseg
;
175 bucket
->clseg
= NULL
;
176 list_for_each(pos
, &bucket
->committing
)
177 cinfo
->ds
->ncommitting
--;
178 list_splice_init(&bucket
->committing
, &pages
);
179 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
180 nfs_retry_commit(&pages
, freeme
, cinfo
, i
);
181 pnfs_put_lseg(freeme
);
182 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
184 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
188 pnfs_generic_alloc_ds_commits(struct nfs_commit_info
*cinfo
,
189 struct list_head
*list
)
191 struct pnfs_ds_commit_info
*fl_cinfo
;
192 struct pnfs_commit_bucket
*bucket
;
193 struct nfs_commit_data
*data
;
195 unsigned int nreq
= 0;
197 fl_cinfo
= cinfo
->ds
;
198 bucket
= fl_cinfo
->buckets
;
199 for (i
= 0; i
< fl_cinfo
->nbuckets
; i
++, bucket
++) {
200 if (list_empty(&bucket
->committing
))
202 data
= nfs_commitdata_alloc(false);
205 data
->ds_commit_index
= i
;
206 list_add(&data
->pages
, list
);
210 /* Clean up on error */
211 pnfs_generic_retry_commit(cinfo
, i
);
216 void pnfs_fetch_commit_bucket_list(struct list_head
*pages
,
217 struct nfs_commit_data
*data
,
218 struct nfs_commit_info
*cinfo
)
220 struct pnfs_commit_bucket
*bucket
;
221 struct list_head
*pos
;
223 bucket
= &cinfo
->ds
->buckets
[data
->ds_commit_index
];
224 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
225 list_for_each(pos
, &bucket
->committing
)
226 cinfo
->ds
->ncommitting
--;
227 list_splice_init(&bucket
->committing
, pages
);
228 data
->lseg
= bucket
->clseg
;
229 bucket
->clseg
= NULL
;
230 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
234 /* Helper function for pnfs_generic_commit_pagelist to catch an empty
235 * page list. This can happen when two commits race.
237 * This must be called instead of nfs_init_commit - call one or the other, but
241 pnfs_generic_commit_cancel_empty_pagelist(struct list_head
*pages
,
242 struct nfs_commit_data
*data
,
243 struct nfs_commit_info
*cinfo
)
245 if (list_empty(pages
)) {
246 if (atomic_dec_and_test(&cinfo
->mds
->rpcs_out
))
247 wake_up_var(&cinfo
->mds
->rpcs_out
);
248 /* don't call nfs_commitdata_release - it tries to put
249 * the open_context which is not acquired until nfs_init_commit
250 * which has not been called on @data */
251 WARN_ON_ONCE(data
->context
);
252 nfs_commit_free(data
);
259 /* This follows nfs_commit_list pretty closely */
261 pnfs_generic_commit_pagelist(struct inode
*inode
, struct list_head
*mds_pages
,
262 int how
, struct nfs_commit_info
*cinfo
,
263 int (*initiate_commit
)(struct nfs_commit_data
*data
,
266 struct nfs_commit_data
*data
, *tmp
;
268 unsigned int nreq
= 0;
270 if (!list_empty(mds_pages
)) {
271 data
= nfs_commitdata_alloc(true);
272 data
->ds_commit_index
= -1;
273 list_add(&data
->pages
, &list
);
277 nreq
+= pnfs_generic_alloc_ds_commits(cinfo
, &list
);
282 atomic_add(nreq
, &cinfo
->mds
->rpcs_out
);
284 list_for_each_entry_safe(data
, tmp
, &list
, pages
) {
285 list_del_init(&data
->pages
);
286 if (data
->ds_commit_index
< 0) {
287 /* another commit raced with us */
288 if (pnfs_generic_commit_cancel_empty_pagelist(mds_pages
,
292 nfs_init_commit(data
, mds_pages
, NULL
, cinfo
);
293 nfs_initiate_commit(NFS_CLIENT(inode
), data
,
294 NFS_PROTO(data
->inode
),
295 data
->mds_ops
, how
, 0);
299 pnfs_fetch_commit_bucket_list(&pages
, data
, cinfo
);
301 /* another commit raced with us */
302 if (pnfs_generic_commit_cancel_empty_pagelist(&pages
,
306 nfs_init_commit(data
, &pages
, data
->lseg
, cinfo
);
307 initiate_commit(data
, how
);
311 return PNFS_ATTEMPTED
;
313 EXPORT_SYMBOL_GPL(pnfs_generic_commit_pagelist
);
318 * Data servers can be mapped to different device ids.
319 * nfs4_pnfs_ds reference counting
320 * - set to 1 on allocation
321 * - incremented when a device id maps a data server already in the cache.
322 * - decremented when deviceid is removed from the cache.
324 static DEFINE_SPINLOCK(nfs4_ds_cache_lock
);
325 static LIST_HEAD(nfs4_data_server_cache
);
329 print_ds(struct nfs4_pnfs_ds
*ds
)
332 printk(KERN_WARNING
"%s NULL device\n", __func__
);
335 printk(KERN_WARNING
" ds %s\n"
338 " cl_exchange_flags %x\n",
340 refcount_read(&ds
->ds_count
), ds
->ds_clp
,
341 ds
->ds_clp
? ds
->ds_clp
->cl_exchange_flags
: 0);
345 same_sockaddr(struct sockaddr
*addr1
, struct sockaddr
*addr2
)
347 struct sockaddr_in
*a
, *b
;
348 struct sockaddr_in6
*a6
, *b6
;
350 if (addr1
->sa_family
!= addr2
->sa_family
)
353 switch (addr1
->sa_family
) {
355 a
= (struct sockaddr_in
*)addr1
;
356 b
= (struct sockaddr_in
*)addr2
;
358 if (a
->sin_addr
.s_addr
== b
->sin_addr
.s_addr
&&
359 a
->sin_port
== b
->sin_port
)
364 a6
= (struct sockaddr_in6
*)addr1
;
365 b6
= (struct sockaddr_in6
*)addr2
;
367 /* LINKLOCAL addresses must have matching scope_id */
368 if (ipv6_addr_src_scope(&a6
->sin6_addr
) ==
369 IPV6_ADDR_SCOPE_LINKLOCAL
&&
370 a6
->sin6_scope_id
!= b6
->sin6_scope_id
)
373 if (ipv6_addr_equal(&a6
->sin6_addr
, &b6
->sin6_addr
) &&
374 a6
->sin6_port
== b6
->sin6_port
)
379 dprintk("%s: unhandled address family: %u\n",
380 __func__
, addr1
->sa_family
);
388 * Checks if 'dsaddrs1' contains a subset of 'dsaddrs2'. If it does,
392 _same_data_server_addrs_locked(const struct list_head
*dsaddrs1
,
393 const struct list_head
*dsaddrs2
)
395 struct nfs4_pnfs_ds_addr
*da1
, *da2
;
396 struct sockaddr
*sa1
, *sa2
;
399 list_for_each_entry(da1
, dsaddrs1
, da_node
) {
400 sa1
= (struct sockaddr
*)&da1
->da_addr
;
402 list_for_each_entry(da2
, dsaddrs2
, da_node
) {
403 sa2
= (struct sockaddr
*)&da2
->da_addr
;
404 match
= same_sockaddr(sa1
, sa2
);
415 * Lookup DS by addresses. nfs4_ds_cache_lock is held
417 static struct nfs4_pnfs_ds
*
418 _data_server_lookup_locked(const struct list_head
*dsaddrs
)
420 struct nfs4_pnfs_ds
*ds
;
422 list_for_each_entry(ds
, &nfs4_data_server_cache
, ds_node
)
423 if (_same_data_server_addrs_locked(&ds
->ds_addrs
, dsaddrs
))
428 static void destroy_ds(struct nfs4_pnfs_ds
*ds
)
430 struct nfs4_pnfs_ds_addr
*da
;
432 dprintk("--> %s\n", __func__
);
436 nfs_put_client(ds
->ds_clp
);
438 while (!list_empty(&ds
->ds_addrs
)) {
439 da
= list_first_entry(&ds
->ds_addrs
,
440 struct nfs4_pnfs_ds_addr
,
442 list_del_init(&da
->da_node
);
443 kfree(da
->da_remotestr
);
447 kfree(ds
->ds_remotestr
);
451 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds
*ds
)
453 if (refcount_dec_and_lock(&ds
->ds_count
,
454 &nfs4_ds_cache_lock
)) {
455 list_del_init(&ds
->ds_node
);
456 spin_unlock(&nfs4_ds_cache_lock
);
460 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put
);
463 * Create a string with a human readable address and port to avoid
464 * complicated setup around many dprinks.
467 nfs4_pnfs_remotestr(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
469 struct nfs4_pnfs_ds_addr
*da
;
474 len
= 3; /* '{', '}' and eol */
475 list_for_each_entry(da
, dsaddrs
, da_node
) {
476 len
+= strlen(da
->da_remotestr
) + 1; /* string plus comma */
479 remotestr
= kzalloc(len
, gfp_flags
);
486 list_for_each_entry(da
, dsaddrs
, da_node
) {
487 size_t ll
= strlen(da
->da_remotestr
);
492 memcpy(p
, da
->da_remotestr
, ll
);
512 * Given a list of multipath struct nfs4_pnfs_ds_addr, add it to ds cache if
513 * uncached and return cached struct nfs4_pnfs_ds.
515 struct nfs4_pnfs_ds
*
516 nfs4_pnfs_ds_add(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
518 struct nfs4_pnfs_ds
*tmp_ds
, *ds
= NULL
;
521 if (list_empty(dsaddrs
)) {
522 dprintk("%s: no addresses defined\n", __func__
);
526 ds
= kzalloc(sizeof(*ds
), gfp_flags
);
530 /* this is only used for debugging, so it's ok if its NULL */
531 remotestr
= nfs4_pnfs_remotestr(dsaddrs
, gfp_flags
);
533 spin_lock(&nfs4_ds_cache_lock
);
534 tmp_ds
= _data_server_lookup_locked(dsaddrs
);
535 if (tmp_ds
== NULL
) {
536 INIT_LIST_HEAD(&ds
->ds_addrs
);
537 list_splice_init(dsaddrs
, &ds
->ds_addrs
);
538 ds
->ds_remotestr
= remotestr
;
539 refcount_set(&ds
->ds_count
, 1);
540 INIT_LIST_HEAD(&ds
->ds_node
);
542 list_add(&ds
->ds_node
, &nfs4_data_server_cache
);
543 dprintk("%s add new data server %s\n", __func__
,
548 refcount_inc(&tmp_ds
->ds_count
);
549 dprintk("%s data server %s found, inc'ed ds_count to %d\n",
550 __func__
, tmp_ds
->ds_remotestr
,
551 refcount_read(&tmp_ds
->ds_count
));
554 spin_unlock(&nfs4_ds_cache_lock
);
558 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_add
);
560 static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds
*ds
)
563 wait_on_bit(&ds
->ds_state
, NFS4DS_CONNECTING
,
567 static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds
*ds
)
569 smp_mb__before_atomic();
570 clear_bit(NFS4DS_CONNECTING
, &ds
->ds_state
);
571 smp_mb__after_atomic();
572 wake_up_bit(&ds
->ds_state
, NFS4DS_CONNECTING
);
575 static struct nfs_client
*(*get_v3_ds_connect
)(
576 struct nfs_server
*mds_srv
,
577 const struct sockaddr
*ds_addr
,
580 unsigned int ds_timeo
,
581 unsigned int ds_retrans
);
583 static bool load_v3_ds_connect(void)
585 if (!get_v3_ds_connect
) {
586 get_v3_ds_connect
= symbol_request(nfs3_set_ds_client
);
587 WARN_ON_ONCE(!get_v3_ds_connect
);
590 return(get_v3_ds_connect
!= NULL
);
593 void nfs4_pnfs_v3_ds_connect_unload(void)
595 if (get_v3_ds_connect
) {
596 symbol_put(nfs3_set_ds_client
);
597 get_v3_ds_connect
= NULL
;
601 static int _nfs4_pnfs_v3_ds_connect(struct nfs_server
*mds_srv
,
602 struct nfs4_pnfs_ds
*ds
,
604 unsigned int retrans
)
606 struct nfs_client
*clp
= ERR_PTR(-EIO
);
607 struct nfs4_pnfs_ds_addr
*da
;
610 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
612 if (!load_v3_ds_connect())
615 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
616 dprintk("%s: DS %s: trying address %s\n",
617 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
620 struct xprt_create xprt_args
= {
621 .ident
= XPRT_TRANSPORT_TCP
,
623 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
624 .addrlen
= da
->da_addrlen
,
625 .servername
= clp
->cl_hostname
,
627 /* Add this address as an alias */
628 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
629 rpc_clnt_test_and_add_xprt
, NULL
);
632 clp
= get_v3_ds_connect(mds_srv
,
633 (struct sockaddr
*)&da
->da_addr
,
634 da
->da_addrlen
, IPPROTO_TCP
,
638 clp
->cl_rpcclient
->cl_softerr
= 0;
639 clp
->cl_rpcclient
->cl_softrtry
= 0;
643 status
= PTR_ERR(clp
);
649 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
654 static int _nfs4_pnfs_v4_ds_connect(struct nfs_server
*mds_srv
,
655 struct nfs4_pnfs_ds
*ds
,
657 unsigned int retrans
,
660 struct nfs_client
*clp
= ERR_PTR(-EIO
);
661 struct nfs4_pnfs_ds_addr
*da
;
664 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
666 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
667 dprintk("%s: DS %s: trying address %s\n",
668 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
670 if (!IS_ERR(clp
) && clp
->cl_mvops
->session_trunk
) {
671 struct xprt_create xprt_args
= {
672 .ident
= XPRT_TRANSPORT_TCP
,
674 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
675 .addrlen
= da
->da_addrlen
,
676 .servername
= clp
->cl_hostname
,
678 struct nfs4_add_xprt_data xprtdata
= {
680 .cred
= nfs4_get_clid_cred(clp
),
682 struct rpc_add_xprt_test rpcdata
= {
683 .add_xprt_test
= clp
->cl_mvops
->session_trunk
,
688 * Test this address for session trunking and
691 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
692 rpc_clnt_setup_test_and_add_xprt
,
695 put_cred(xprtdata
.cred
);
697 clp
= nfs4_set_ds_client(mds_srv
,
698 (struct sockaddr
*)&da
->da_addr
,
699 da
->da_addrlen
, IPPROTO_TCP
,
700 timeo
, retrans
, minor_version
);
704 status
= nfs4_init_ds_session(clp
,
705 mds_srv
->nfs_client
->cl_lease_time
);
716 status
= PTR_ERR(clp
);
722 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
728 * Create an rpc connection to the nfs4_pnfs_ds data server.
729 * Currently only supports IPv4 and IPv6 addresses.
730 * If connection fails, make devid unavailable and return a -errno.
732 int nfs4_pnfs_ds_connect(struct nfs_server
*mds_srv
, struct nfs4_pnfs_ds
*ds
,
733 struct nfs4_deviceid_node
*devid
, unsigned int timeo
,
734 unsigned int retrans
, u32 version
, u32 minor_version
)
740 if (test_and_set_bit(NFS4DS_CONNECTING
, &ds
->ds_state
) == 0) {
742 err
= _nfs4_pnfs_v3_ds_connect(mds_srv
, ds
, timeo
,
744 } else if (version
== 4) {
745 err
= _nfs4_pnfs_v4_ds_connect(mds_srv
, ds
, timeo
,
746 retrans
, minor_version
);
748 dprintk("%s: unsupported DS version %d\n", __func__
,
750 err
= -EPROTONOSUPPORT
;
753 nfs4_clear_ds_conn_bit(ds
);
755 nfs4_wait_ds_connect(ds
);
757 /* what was waited on didn't connect AND didn't mark unavail */
758 if (!ds
->ds_clp
&& !nfs4_test_deviceid_unavailable(devid
))
763 * At this point the ds->ds_clp should be ready, but it might have
767 if (!ds
->ds_clp
|| !nfs_client_init_is_complete(ds
->ds_clp
)) {
768 WARN_ON_ONCE(ds
->ds_clp
||
769 !nfs4_test_deviceid_unavailable(devid
));
772 err
= nfs_client_init_status(ds
->ds_clp
);
777 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_connect
);
780 * Currently only supports ipv4, ipv6 and one multi-path address.
782 struct nfs4_pnfs_ds_addr
*
783 nfs4_decode_mp_ds_addr(struct net
*net
, struct xdr_stream
*xdr
, gfp_t gfp_flags
)
785 struct nfs4_pnfs_ds_addr
*da
= NULL
;
791 char *netid
, *match_netid
;
792 size_t len
, match_netid_len
;
798 p
= xdr_inline_decode(xdr
, 4);
801 nlen
= be32_to_cpup(p
++);
803 p
= xdr_inline_decode(xdr
, nlen
);
807 netid
= kmalloc(nlen
+1, gfp_flags
);
808 if (unlikely(!netid
))
812 memcpy(netid
, p
, nlen
);
814 /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
815 p
= xdr_inline_decode(xdr
, 4);
818 rlen
= be32_to_cpup(p
);
820 p
= xdr_inline_decode(xdr
, rlen
);
824 /* port is ".ABC.DEF", 8 chars max */
825 if (rlen
> INET6_ADDRSTRLEN
+ IPV6_SCOPE_ID_LEN
+ 8) {
826 dprintk("%s: Invalid address, length %d\n", __func__
,
830 buf
= kmalloc(rlen
+ 1, gfp_flags
);
832 dprintk("%s: Not enough memory\n", __func__
);
836 memcpy(buf
, p
, rlen
);
838 /* replace port '.' with '-' */
839 portstr
= strrchr(buf
, '.');
841 dprintk("%s: Failed finding expected dot in port\n",
847 /* find '.' between address and port */
848 portstr
= strrchr(buf
, '.');
850 dprintk("%s: Failed finding expected dot between address and "
856 da
= kzalloc(sizeof(*da
), gfp_flags
);
860 INIT_LIST_HEAD(&da
->da_node
);
862 if (!rpc_pton(net
, buf
, portstr
-buf
, (struct sockaddr
*)&da
->da_addr
,
863 sizeof(da
->da_addr
))) {
864 dprintk("%s: error parsing address %s\n", __func__
, buf
);
869 sscanf(portstr
, "%d-%d", &tmp
[0], &tmp
[1]);
870 port
= htons((tmp
[0] << 8) | (tmp
[1]));
872 switch (da
->da_addr
.ss_family
) {
874 ((struct sockaddr_in
*)&da
->da_addr
)->sin_port
= port
;
875 da
->da_addrlen
= sizeof(struct sockaddr_in
);
881 ((struct sockaddr_in6
*)&da
->da_addr
)->sin6_port
= port
;
882 da
->da_addrlen
= sizeof(struct sockaddr_in6
);
883 match_netid
= "tcp6";
890 dprintk("%s: unsupported address family: %u\n",
891 __func__
, da
->da_addr
.ss_family
);
895 if (nlen
!= match_netid_len
|| strncmp(netid
, match_netid
, nlen
)) {
896 dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n",
897 __func__
, netid
, match_netid
);
901 /* save human readable address */
902 len
= strlen(startsep
) + strlen(buf
) + strlen(endsep
) + 7;
903 da
->da_remotestr
= kzalloc(len
, gfp_flags
);
905 /* NULL is ok, only used for dprintk */
906 if (da
->da_remotestr
)
907 snprintf(da
->da_remotestr
, len
, "%s%s%s:%u", startsep
,
908 buf
, endsep
, ntohs(port
));
910 dprintk("%s: Parsed DS addr %s\n", __func__
, da
->da_remotestr
);
918 dprintk("%s: Error parsing DS addr: %s\n", __func__
, buf
);
925 EXPORT_SYMBOL_GPL(nfs4_decode_mp_ds_addr
);
928 pnfs_layout_mark_request_commit(struct nfs_page
*req
,
929 struct pnfs_layout_segment
*lseg
,
930 struct nfs_commit_info
*cinfo
,
933 struct list_head
*list
;
934 struct pnfs_commit_bucket
*buckets
;
936 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
937 buckets
= cinfo
->ds
->buckets
;
938 list
= &buckets
[ds_commit_idx
].written
;
939 if (list_empty(list
)) {
940 if (!pnfs_is_valid_lseg(lseg
)) {
941 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
942 cinfo
->completion_ops
->resched_write(cinfo
, req
);
945 /* Non-empty buckets hold a reference on the lseg. That ref
946 * is normally transferred to the COMMIT call and released
947 * there. It could also be released if the last req is pulled
948 * off due to a rewrite, in which case it will be done in
949 * pnfs_common_clear_request_commit
951 WARN_ON_ONCE(buckets
[ds_commit_idx
].wlseg
!= NULL
);
952 buckets
[ds_commit_idx
].wlseg
= pnfs_get_lseg(lseg
);
954 set_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
);
955 cinfo
->ds
->nwritten
++;
957 nfs_request_add_commit_list_locked(req
, list
, cinfo
);
958 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
959 nfs_mark_page_unstable(req
->wb_page
, cinfo
);
961 EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit
);
964 pnfs_nfs_generic_sync(struct inode
*inode
, bool datasync
)
968 if (!pnfs_layoutcommit_outstanding(inode
))
970 ret
= nfs_commit_inode(inode
, FLUSH_SYNC
);
975 return pnfs_layoutcommit_inode(inode
, true);
977 EXPORT_SYMBOL_GPL(pnfs_nfs_generic_sync
);