2 * Common NFS I/O operations for the pnfs file based
5 * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
7 * Tom Haynes <loghyr@primarydata.com>
10 #include <linux/nfs_fs.h>
11 #include <linux/nfs_page.h>
12 #include <linux/sunrpc/addr.h>
13 #include <linux/module.h>
15 #include "nfs4session.h"
19 #define NFSDBG_FACILITY NFSDBG_PNFS
21 void pnfs_generic_rw_release(void *data
)
23 struct nfs_pgio_header
*hdr
= data
;
25 nfs_put_client(hdr
->ds_clp
);
26 hdr
->mds_ops
->rpc_release(data
);
28 EXPORT_SYMBOL_GPL(pnfs_generic_rw_release
);
30 /* Fake up some data that will cause nfs_commit_release to retry the writes. */
31 void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data
*data
)
33 struct nfs_writeverf
*verf
= data
->res
.verf
;
35 data
->task
.tk_status
= 0;
36 memset(&verf
->verifier
, 0, sizeof(verf
->verifier
));
37 verf
->committed
= NFS_UNSTABLE
;
39 EXPORT_SYMBOL_GPL(pnfs_generic_prepare_to_resend_writes
);
41 void pnfs_generic_write_commit_done(struct rpc_task
*task
, void *data
)
43 struct nfs_commit_data
*wdata
= data
;
45 /* Note this may cause RPC to be resent */
46 wdata
->mds_ops
->rpc_call_done(task
, data
);
48 EXPORT_SYMBOL_GPL(pnfs_generic_write_commit_done
);
50 void pnfs_generic_commit_release(void *calldata
)
52 struct nfs_commit_data
*data
= calldata
;
54 data
->completion_ops
->completion(data
);
55 pnfs_put_lseg(data
->lseg
);
56 nfs_put_client(data
->ds_clp
);
57 nfs_commitdata_release(data
);
59 EXPORT_SYMBOL_GPL(pnfs_generic_commit_release
);
61 /* The generic layer is about to remove the req from the commit list.
62 * If this will make the bucket empty, it will need to put the lseg reference.
63 * Note this must be called holding nfsi->commit_mutex
66 pnfs_generic_clear_request_commit(struct nfs_page
*req
,
67 struct nfs_commit_info
*cinfo
)
69 struct pnfs_layout_segment
*freeme
= NULL
;
71 if (!test_and_clear_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
))
73 cinfo
->ds
->nwritten
--;
74 if (list_is_singular(&req
->wb_list
)) {
75 struct pnfs_commit_bucket
*bucket
;
77 bucket
= list_first_entry(&req
->wb_list
,
78 struct pnfs_commit_bucket
,
80 freeme
= bucket
->wlseg
;
84 nfs_request_remove_commit_list(req
, cinfo
);
85 pnfs_put_lseg(freeme
);
87 EXPORT_SYMBOL_GPL(pnfs_generic_clear_request_commit
);
90 pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket
*bucket
,
91 struct nfs_commit_info
*cinfo
,
94 struct list_head
*src
= &bucket
->written
;
95 struct list_head
*dst
= &bucket
->committing
;
98 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
99 ret
= nfs_scan_commit_list(src
, dst
, cinfo
, max
);
101 cinfo
->ds
->nwritten
-= ret
;
102 cinfo
->ds
->ncommitting
+= ret
;
103 if (bucket
->clseg
== NULL
)
104 bucket
->clseg
= pnfs_get_lseg(bucket
->wlseg
);
105 if (list_empty(src
)) {
106 pnfs_put_lseg(bucket
->wlseg
);
107 bucket
->wlseg
= NULL
;
113 /* Move reqs from written to committing lists, returning count
116 int pnfs_generic_scan_commit_lists(struct nfs_commit_info
*cinfo
,
121 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
122 for (i
= 0; i
< cinfo
->ds
->nbuckets
&& max
!= 0; i
++) {
123 cnt
= pnfs_generic_scan_ds_commit_list(&cinfo
->ds
->buckets
[i
],
130 EXPORT_SYMBOL_GPL(pnfs_generic_scan_commit_lists
);
132 /* Pull everything off the committing lists and dump into @dst. */
133 void pnfs_generic_recover_commit_reqs(struct list_head
*dst
,
134 struct nfs_commit_info
*cinfo
)
136 struct pnfs_commit_bucket
*b
;
137 struct pnfs_layout_segment
*freeme
;
141 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
143 for (i
= 0, b
= cinfo
->ds
->buckets
; i
< cinfo
->ds
->nbuckets
; i
++, b
++) {
144 nwritten
= nfs_scan_commit_list(&b
->written
, dst
, cinfo
, 0);
147 cinfo
->ds
->nwritten
-= nwritten
;
148 if (list_empty(&b
->written
)) {
151 pnfs_put_lseg(freeme
);
156 EXPORT_SYMBOL_GPL(pnfs_generic_recover_commit_reqs
);
158 static void pnfs_generic_retry_commit(struct nfs_commit_info
*cinfo
, int idx
)
160 struct pnfs_ds_commit_info
*fl_cinfo
= cinfo
->ds
;
161 struct pnfs_commit_bucket
*bucket
;
162 struct pnfs_layout_segment
*freeme
;
163 struct list_head
*pos
;
167 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
168 for (i
= idx
; i
< fl_cinfo
->nbuckets
; i
++) {
169 bucket
= &fl_cinfo
->buckets
[i
];
170 if (list_empty(&bucket
->committing
))
172 freeme
= bucket
->clseg
;
173 bucket
->clseg
= NULL
;
174 list_for_each(pos
, &bucket
->committing
)
175 cinfo
->ds
->ncommitting
--;
176 list_splice_init(&bucket
->committing
, &pages
);
177 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
178 nfs_retry_commit(&pages
, freeme
, cinfo
, i
);
179 pnfs_put_lseg(freeme
);
180 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
182 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
186 pnfs_generic_alloc_ds_commits(struct nfs_commit_info
*cinfo
,
187 struct list_head
*list
)
189 struct pnfs_ds_commit_info
*fl_cinfo
;
190 struct pnfs_commit_bucket
*bucket
;
191 struct nfs_commit_data
*data
;
193 unsigned int nreq
= 0;
195 fl_cinfo
= cinfo
->ds
;
196 bucket
= fl_cinfo
->buckets
;
197 for (i
= 0; i
< fl_cinfo
->nbuckets
; i
++, bucket
++) {
198 if (list_empty(&bucket
->committing
))
200 data
= nfs_commitdata_alloc(false);
203 data
->ds_commit_index
= i
;
204 list_add(&data
->pages
, list
);
208 /* Clean up on error */
209 pnfs_generic_retry_commit(cinfo
, i
);
214 void pnfs_fetch_commit_bucket_list(struct list_head
*pages
,
215 struct nfs_commit_data
*data
,
216 struct nfs_commit_info
*cinfo
)
218 struct pnfs_commit_bucket
*bucket
;
219 struct list_head
*pos
;
221 bucket
= &cinfo
->ds
->buckets
[data
->ds_commit_index
];
222 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
223 list_for_each(pos
, &bucket
->committing
)
224 cinfo
->ds
->ncommitting
--;
225 list_splice_init(&bucket
->committing
, pages
);
226 data
->lseg
= bucket
->clseg
;
227 bucket
->clseg
= NULL
;
228 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
232 /* Helper function for pnfs_generic_commit_pagelist to catch an empty
233 * page list. This can happen when two commits race.
235 * This must be called instead of nfs_init_commit - call one or the other, but
239 pnfs_generic_commit_cancel_empty_pagelist(struct list_head
*pages
,
240 struct nfs_commit_data
*data
,
241 struct nfs_commit_info
*cinfo
)
243 if (list_empty(pages
)) {
244 if (atomic_dec_and_test(&cinfo
->mds
->rpcs_out
))
245 wake_up_var(&cinfo
->mds
->rpcs_out
);
246 /* don't call nfs_commitdata_release - it tries to put
247 * the open_context which is not acquired until nfs_init_commit
248 * which has not been called on @data */
249 WARN_ON_ONCE(data
->context
);
250 nfs_commit_free(data
);
257 /* This follows nfs_commit_list pretty closely */
259 pnfs_generic_commit_pagelist(struct inode
*inode
, struct list_head
*mds_pages
,
260 int how
, struct nfs_commit_info
*cinfo
,
261 int (*initiate_commit
)(struct nfs_commit_data
*data
,
264 struct nfs_commit_data
*data
, *tmp
;
266 unsigned int nreq
= 0;
268 if (!list_empty(mds_pages
)) {
269 data
= nfs_commitdata_alloc(true);
270 data
->ds_commit_index
= -1;
271 list_add(&data
->pages
, &list
);
275 nreq
+= pnfs_generic_alloc_ds_commits(cinfo
, &list
);
280 atomic_add(nreq
, &cinfo
->mds
->rpcs_out
);
282 list_for_each_entry_safe(data
, tmp
, &list
, pages
) {
283 list_del_init(&data
->pages
);
284 if (data
->ds_commit_index
< 0) {
285 /* another commit raced with us */
286 if (pnfs_generic_commit_cancel_empty_pagelist(mds_pages
,
290 nfs_init_commit(data
, mds_pages
, NULL
, cinfo
);
291 nfs_initiate_commit(NFS_CLIENT(inode
), data
,
292 NFS_PROTO(data
->inode
),
293 data
->mds_ops
, how
, 0);
297 pnfs_fetch_commit_bucket_list(&pages
, data
, cinfo
);
299 /* another commit raced with us */
300 if (pnfs_generic_commit_cancel_empty_pagelist(&pages
,
304 nfs_init_commit(data
, &pages
, data
->lseg
, cinfo
);
305 initiate_commit(data
, how
);
309 return PNFS_ATTEMPTED
;
311 EXPORT_SYMBOL_GPL(pnfs_generic_commit_pagelist
);
316 * Data servers can be mapped to different device ids.
317 * nfs4_pnfs_ds reference counting
318 * - set to 1 on allocation
319 * - incremented when a device id maps a data server already in the cache.
320 * - decremented when deviceid is removed from the cache.
322 static DEFINE_SPINLOCK(nfs4_ds_cache_lock
);
323 static LIST_HEAD(nfs4_data_server_cache
);
327 print_ds(struct nfs4_pnfs_ds
*ds
)
330 printk(KERN_WARNING
"%s NULL device\n", __func__
);
333 printk(KERN_WARNING
" ds %s\n"
336 " cl_exchange_flags %x\n",
338 refcount_read(&ds
->ds_count
), ds
->ds_clp
,
339 ds
->ds_clp
? ds
->ds_clp
->cl_exchange_flags
: 0);
343 same_sockaddr(struct sockaddr
*addr1
, struct sockaddr
*addr2
)
345 struct sockaddr_in
*a
, *b
;
346 struct sockaddr_in6
*a6
, *b6
;
348 if (addr1
->sa_family
!= addr2
->sa_family
)
351 switch (addr1
->sa_family
) {
353 a
= (struct sockaddr_in
*)addr1
;
354 b
= (struct sockaddr_in
*)addr2
;
356 if (a
->sin_addr
.s_addr
== b
->sin_addr
.s_addr
&&
357 a
->sin_port
== b
->sin_port
)
362 a6
= (struct sockaddr_in6
*)addr1
;
363 b6
= (struct sockaddr_in6
*)addr2
;
365 /* LINKLOCAL addresses must have matching scope_id */
366 if (ipv6_addr_src_scope(&a6
->sin6_addr
) ==
367 IPV6_ADDR_SCOPE_LINKLOCAL
&&
368 a6
->sin6_scope_id
!= b6
->sin6_scope_id
)
371 if (ipv6_addr_equal(&a6
->sin6_addr
, &b6
->sin6_addr
) &&
372 a6
->sin6_port
== b6
->sin6_port
)
377 dprintk("%s: unhandled address family: %u\n",
378 __func__
, addr1
->sa_family
);
386 * Checks if 'dsaddrs1' contains a subset of 'dsaddrs2'. If it does,
390 _same_data_server_addrs_locked(const struct list_head
*dsaddrs1
,
391 const struct list_head
*dsaddrs2
)
393 struct nfs4_pnfs_ds_addr
*da1
, *da2
;
394 struct sockaddr
*sa1
, *sa2
;
397 list_for_each_entry(da1
, dsaddrs1
, da_node
) {
398 sa1
= (struct sockaddr
*)&da1
->da_addr
;
400 list_for_each_entry(da2
, dsaddrs2
, da_node
) {
401 sa2
= (struct sockaddr
*)&da2
->da_addr
;
402 match
= same_sockaddr(sa1
, sa2
);
413 * Lookup DS by addresses. nfs4_ds_cache_lock is held
415 static struct nfs4_pnfs_ds
*
416 _data_server_lookup_locked(const struct list_head
*dsaddrs
)
418 struct nfs4_pnfs_ds
*ds
;
420 list_for_each_entry(ds
, &nfs4_data_server_cache
, ds_node
)
421 if (_same_data_server_addrs_locked(&ds
->ds_addrs
, dsaddrs
))
426 static void destroy_ds(struct nfs4_pnfs_ds
*ds
)
428 struct nfs4_pnfs_ds_addr
*da
;
430 dprintk("--> %s\n", __func__
);
434 nfs_put_client(ds
->ds_clp
);
436 while (!list_empty(&ds
->ds_addrs
)) {
437 da
= list_first_entry(&ds
->ds_addrs
,
438 struct nfs4_pnfs_ds_addr
,
440 list_del_init(&da
->da_node
);
441 kfree(da
->da_remotestr
);
445 kfree(ds
->ds_remotestr
);
449 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds
*ds
)
451 if (refcount_dec_and_lock(&ds
->ds_count
,
452 &nfs4_ds_cache_lock
)) {
453 list_del_init(&ds
->ds_node
);
454 spin_unlock(&nfs4_ds_cache_lock
);
458 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put
);
461 * Create a string with a human readable address and port to avoid
462 * complicated setup around many dprinks.
465 nfs4_pnfs_remotestr(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
467 struct nfs4_pnfs_ds_addr
*da
;
472 len
= 3; /* '{', '}' and eol */
473 list_for_each_entry(da
, dsaddrs
, da_node
) {
474 len
+= strlen(da
->da_remotestr
) + 1; /* string plus comma */
477 remotestr
= kzalloc(len
, gfp_flags
);
484 list_for_each_entry(da
, dsaddrs
, da_node
) {
485 size_t ll
= strlen(da
->da_remotestr
);
490 memcpy(p
, da
->da_remotestr
, ll
);
510 * Given a list of multipath struct nfs4_pnfs_ds_addr, add it to ds cache if
511 * uncached and return cached struct nfs4_pnfs_ds.
513 struct nfs4_pnfs_ds
*
514 nfs4_pnfs_ds_add(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
516 struct nfs4_pnfs_ds
*tmp_ds
, *ds
= NULL
;
519 if (list_empty(dsaddrs
)) {
520 dprintk("%s: no addresses defined\n", __func__
);
524 ds
= kzalloc(sizeof(*ds
), gfp_flags
);
528 /* this is only used for debugging, so it's ok if its NULL */
529 remotestr
= nfs4_pnfs_remotestr(dsaddrs
, gfp_flags
);
531 spin_lock(&nfs4_ds_cache_lock
);
532 tmp_ds
= _data_server_lookup_locked(dsaddrs
);
533 if (tmp_ds
== NULL
) {
534 INIT_LIST_HEAD(&ds
->ds_addrs
);
535 list_splice_init(dsaddrs
, &ds
->ds_addrs
);
536 ds
->ds_remotestr
= remotestr
;
537 refcount_set(&ds
->ds_count
, 1);
538 INIT_LIST_HEAD(&ds
->ds_node
);
540 list_add(&ds
->ds_node
, &nfs4_data_server_cache
);
541 dprintk("%s add new data server %s\n", __func__
,
546 refcount_inc(&tmp_ds
->ds_count
);
547 dprintk("%s data server %s found, inc'ed ds_count to %d\n",
548 __func__
, tmp_ds
->ds_remotestr
,
549 refcount_read(&tmp_ds
->ds_count
));
552 spin_unlock(&nfs4_ds_cache_lock
);
556 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_add
);
558 static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds
*ds
)
561 wait_on_bit(&ds
->ds_state
, NFS4DS_CONNECTING
,
565 static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds
*ds
)
567 smp_mb__before_atomic();
568 clear_bit(NFS4DS_CONNECTING
, &ds
->ds_state
);
569 smp_mb__after_atomic();
570 wake_up_bit(&ds
->ds_state
, NFS4DS_CONNECTING
);
573 static struct nfs_client
*(*get_v3_ds_connect
)(
574 struct nfs_server
*mds_srv
,
575 const struct sockaddr
*ds_addr
,
578 unsigned int ds_timeo
,
579 unsigned int ds_retrans
);
581 static bool load_v3_ds_connect(void)
583 if (!get_v3_ds_connect
) {
584 get_v3_ds_connect
= symbol_request(nfs3_set_ds_client
);
585 WARN_ON_ONCE(!get_v3_ds_connect
);
588 return(get_v3_ds_connect
!= NULL
);
591 void nfs4_pnfs_v3_ds_connect_unload(void)
593 if (get_v3_ds_connect
) {
594 symbol_put(nfs3_set_ds_client
);
595 get_v3_ds_connect
= NULL
;
599 static int _nfs4_pnfs_v3_ds_connect(struct nfs_server
*mds_srv
,
600 struct nfs4_pnfs_ds
*ds
,
602 unsigned int retrans
)
604 struct nfs_client
*clp
= ERR_PTR(-EIO
);
605 struct nfs4_pnfs_ds_addr
*da
;
608 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
610 if (!load_v3_ds_connect())
613 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
614 dprintk("%s: DS %s: trying address %s\n",
615 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
618 struct xprt_create xprt_args
= {
619 .ident
= XPRT_TRANSPORT_TCP
,
621 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
622 .addrlen
= da
->da_addrlen
,
623 .servername
= clp
->cl_hostname
,
625 /* Add this address as an alias */
626 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
627 rpc_clnt_test_and_add_xprt
, NULL
);
629 clp
= get_v3_ds_connect(mds_srv
,
630 (struct sockaddr
*)&da
->da_addr
,
631 da
->da_addrlen
, IPPROTO_TCP
,
636 status
= PTR_ERR(clp
);
642 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
647 static int _nfs4_pnfs_v4_ds_connect(struct nfs_server
*mds_srv
,
648 struct nfs4_pnfs_ds
*ds
,
650 unsigned int retrans
,
653 struct nfs_client
*clp
= ERR_PTR(-EIO
);
654 struct nfs4_pnfs_ds_addr
*da
;
657 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
659 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
660 dprintk("%s: DS %s: trying address %s\n",
661 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
663 if (!IS_ERR(clp
) && clp
->cl_mvops
->session_trunk
) {
664 struct xprt_create xprt_args
= {
665 .ident
= XPRT_TRANSPORT_TCP
,
667 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
668 .addrlen
= da
->da_addrlen
,
669 .servername
= clp
->cl_hostname
,
671 struct nfs4_add_xprt_data xprtdata
= {
673 .cred
= nfs4_get_clid_cred(clp
),
675 struct rpc_add_xprt_test rpcdata
= {
676 .add_xprt_test
= clp
->cl_mvops
->session_trunk
,
681 * Test this address for session trunking and
684 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
685 rpc_clnt_setup_test_and_add_xprt
,
688 put_rpccred(xprtdata
.cred
);
690 clp
= nfs4_set_ds_client(mds_srv
,
691 (struct sockaddr
*)&da
->da_addr
,
692 da
->da_addrlen
, IPPROTO_TCP
,
693 timeo
, retrans
, minor_version
);
697 status
= nfs4_init_ds_session(clp
,
698 mds_srv
->nfs_client
->cl_lease_time
);
709 status
= PTR_ERR(clp
);
715 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
721 * Create an rpc connection to the nfs4_pnfs_ds data server.
722 * Currently only supports IPv4 and IPv6 addresses.
723 * If connection fails, make devid unavailable and return a -errno.
725 int nfs4_pnfs_ds_connect(struct nfs_server
*mds_srv
, struct nfs4_pnfs_ds
*ds
,
726 struct nfs4_deviceid_node
*devid
, unsigned int timeo
,
727 unsigned int retrans
, u32 version
, u32 minor_version
)
733 if (test_and_set_bit(NFS4DS_CONNECTING
, &ds
->ds_state
) == 0) {
735 err
= _nfs4_pnfs_v3_ds_connect(mds_srv
, ds
, timeo
,
737 } else if (version
== 4) {
738 err
= _nfs4_pnfs_v4_ds_connect(mds_srv
, ds
, timeo
,
739 retrans
, minor_version
);
741 dprintk("%s: unsupported DS version %d\n", __func__
,
743 err
= -EPROTONOSUPPORT
;
746 nfs4_clear_ds_conn_bit(ds
);
748 nfs4_wait_ds_connect(ds
);
750 /* what was waited on didn't connect AND didn't mark unavail */
751 if (!ds
->ds_clp
&& !nfs4_test_deviceid_unavailable(devid
))
756 * At this point the ds->ds_clp should be ready, but it might have
760 if (!ds
->ds_clp
|| !nfs_client_init_is_complete(ds
->ds_clp
)) {
761 WARN_ON_ONCE(ds
->ds_clp
||
762 !nfs4_test_deviceid_unavailable(devid
));
765 err
= nfs_client_init_status(ds
->ds_clp
);
770 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_connect
);
773 * Currently only supports ipv4, ipv6 and one multi-path address.
775 struct nfs4_pnfs_ds_addr
*
776 nfs4_decode_mp_ds_addr(struct net
*net
, struct xdr_stream
*xdr
, gfp_t gfp_flags
)
778 struct nfs4_pnfs_ds_addr
*da
= NULL
;
784 char *netid
, *match_netid
;
785 size_t len
, match_netid_len
;
791 p
= xdr_inline_decode(xdr
, 4);
794 nlen
= be32_to_cpup(p
++);
796 p
= xdr_inline_decode(xdr
, nlen
);
800 netid
= kmalloc(nlen
+1, gfp_flags
);
801 if (unlikely(!netid
))
805 memcpy(netid
, p
, nlen
);
807 /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
808 p
= xdr_inline_decode(xdr
, 4);
811 rlen
= be32_to_cpup(p
);
813 p
= xdr_inline_decode(xdr
, rlen
);
817 /* port is ".ABC.DEF", 8 chars max */
818 if (rlen
> INET6_ADDRSTRLEN
+ IPV6_SCOPE_ID_LEN
+ 8) {
819 dprintk("%s: Invalid address, length %d\n", __func__
,
823 buf
= kmalloc(rlen
+ 1, gfp_flags
);
825 dprintk("%s: Not enough memory\n", __func__
);
829 memcpy(buf
, p
, rlen
);
831 /* replace port '.' with '-' */
832 portstr
= strrchr(buf
, '.');
834 dprintk("%s: Failed finding expected dot in port\n",
840 /* find '.' between address and port */
841 portstr
= strrchr(buf
, '.');
843 dprintk("%s: Failed finding expected dot between address and "
849 da
= kzalloc(sizeof(*da
), gfp_flags
);
853 INIT_LIST_HEAD(&da
->da_node
);
855 if (!rpc_pton(net
, buf
, portstr
-buf
, (struct sockaddr
*)&da
->da_addr
,
856 sizeof(da
->da_addr
))) {
857 dprintk("%s: error parsing address %s\n", __func__
, buf
);
862 sscanf(portstr
, "%d-%d", &tmp
[0], &tmp
[1]);
863 port
= htons((tmp
[0] << 8) | (tmp
[1]));
865 switch (da
->da_addr
.ss_family
) {
867 ((struct sockaddr_in
*)&da
->da_addr
)->sin_port
= port
;
868 da
->da_addrlen
= sizeof(struct sockaddr_in
);
874 ((struct sockaddr_in6
*)&da
->da_addr
)->sin6_port
= port
;
875 da
->da_addrlen
= sizeof(struct sockaddr_in6
);
876 match_netid
= "tcp6";
883 dprintk("%s: unsupported address family: %u\n",
884 __func__
, da
->da_addr
.ss_family
);
888 if (nlen
!= match_netid_len
|| strncmp(netid
, match_netid
, nlen
)) {
889 dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n",
890 __func__
, netid
, match_netid
);
894 /* save human readable address */
895 len
= strlen(startsep
) + strlen(buf
) + strlen(endsep
) + 7;
896 da
->da_remotestr
= kzalloc(len
, gfp_flags
);
898 /* NULL is ok, only used for dprintk */
899 if (da
->da_remotestr
)
900 snprintf(da
->da_remotestr
, len
, "%s%s%s:%u", startsep
,
901 buf
, endsep
, ntohs(port
));
903 dprintk("%s: Parsed DS addr %s\n", __func__
, da
->da_remotestr
);
911 dprintk("%s: Error parsing DS addr: %s\n", __func__
, buf
);
918 EXPORT_SYMBOL_GPL(nfs4_decode_mp_ds_addr
);
921 pnfs_layout_mark_request_commit(struct nfs_page
*req
,
922 struct pnfs_layout_segment
*lseg
,
923 struct nfs_commit_info
*cinfo
,
926 struct list_head
*list
;
927 struct pnfs_commit_bucket
*buckets
;
929 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
930 buckets
= cinfo
->ds
->buckets
;
931 list
= &buckets
[ds_commit_idx
].written
;
932 if (list_empty(list
)) {
933 if (!pnfs_is_valid_lseg(lseg
)) {
934 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
935 cinfo
->completion_ops
->resched_write(cinfo
, req
);
938 /* Non-empty buckets hold a reference on the lseg. That ref
939 * is normally transferred to the COMMIT call and released
940 * there. It could also be released if the last req is pulled
941 * off due to a rewrite, in which case it will be done in
942 * pnfs_common_clear_request_commit
944 WARN_ON_ONCE(buckets
[ds_commit_idx
].wlseg
!= NULL
);
945 buckets
[ds_commit_idx
].wlseg
= pnfs_get_lseg(lseg
);
947 set_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
);
948 cinfo
->ds
->nwritten
++;
950 nfs_request_add_commit_list_locked(req
, list
, cinfo
);
951 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
952 nfs_mark_page_unstable(req
->wb_page
, cinfo
);
954 EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit
);
957 pnfs_nfs_generic_sync(struct inode
*inode
, bool datasync
)
961 if (!pnfs_layoutcommit_outstanding(inode
))
963 ret
= nfs_commit_inode(inode
, FLUSH_SYNC
);
968 return pnfs_layoutcommit_inode(inode
, true);
970 EXPORT_SYMBOL_GPL(pnfs_nfs_generic_sync
);