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_page
*first
= nfs_list_entry(data
->pages
.next
);
35 data
->task
.tk_status
= 0;
36 memcpy(&data
->verf
.verifier
, &first
->wb_verf
,
37 sizeof(data
->verf
.verifier
));
38 data
->verf
.verifier
.data
[0]++; /* ensure verifier mismatch */
40 EXPORT_SYMBOL_GPL(pnfs_generic_prepare_to_resend_writes
);
42 void pnfs_generic_write_commit_done(struct rpc_task
*task
, void *data
)
44 struct nfs_commit_data
*wdata
= data
;
46 /* Note this may cause RPC to be resent */
47 wdata
->mds_ops
->rpc_call_done(task
, data
);
49 EXPORT_SYMBOL_GPL(pnfs_generic_write_commit_done
);
51 void pnfs_generic_commit_release(void *calldata
)
53 struct nfs_commit_data
*data
= calldata
;
55 data
->completion_ops
->completion(data
);
56 pnfs_put_lseg(data
->lseg
);
57 nfs_put_client(data
->ds_clp
);
58 nfs_commitdata_release(data
);
60 EXPORT_SYMBOL_GPL(pnfs_generic_commit_release
);
62 /* The generic layer is about to remove the req from the commit list.
63 * If this will make the bucket empty, it will need to put the lseg reference.
64 * Note this must be called holding i_lock
67 pnfs_generic_clear_request_commit(struct nfs_page
*req
,
68 struct nfs_commit_info
*cinfo
)
70 struct pnfs_layout_segment
*freeme
= NULL
;
72 if (!test_and_clear_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
))
74 cinfo
->ds
->nwritten
--;
75 if (list_is_singular(&req
->wb_list
)) {
76 struct pnfs_commit_bucket
*bucket
;
78 bucket
= list_first_entry(&req
->wb_list
,
79 struct pnfs_commit_bucket
,
81 freeme
= bucket
->wlseg
;
85 nfs_request_remove_commit_list(req
, cinfo
);
86 pnfs_put_lseg(freeme
);
88 EXPORT_SYMBOL_GPL(pnfs_generic_clear_request_commit
);
91 pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket
*bucket
,
92 struct nfs_commit_info
*cinfo
,
95 struct list_head
*src
= &bucket
->written
;
96 struct list_head
*dst
= &bucket
->committing
;
99 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
100 ret
= nfs_scan_commit_list(src
, dst
, cinfo
, max
);
102 cinfo
->ds
->nwritten
-= ret
;
103 cinfo
->ds
->ncommitting
+= ret
;
104 if (bucket
->clseg
== NULL
)
105 bucket
->clseg
= pnfs_get_lseg(bucket
->wlseg
);
106 if (list_empty(src
)) {
107 pnfs_put_lseg(bucket
->wlseg
);
108 bucket
->wlseg
= NULL
;
114 /* Move reqs from written to committing lists, returning count
117 int pnfs_generic_scan_commit_lists(struct nfs_commit_info
*cinfo
,
122 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
123 for (i
= 0; i
< cinfo
->ds
->nbuckets
&& max
!= 0; i
++) {
124 cnt
= pnfs_generic_scan_ds_commit_list(&cinfo
->ds
->buckets
[i
],
131 EXPORT_SYMBOL_GPL(pnfs_generic_scan_commit_lists
);
133 /* Pull everything off the committing lists and dump into @dst. */
134 void pnfs_generic_recover_commit_reqs(struct list_head
*dst
,
135 struct nfs_commit_info
*cinfo
)
137 struct pnfs_commit_bucket
*b
;
138 struct pnfs_layout_segment
*freeme
;
142 lockdep_assert_held(&NFS_I(cinfo
->inode
)->commit_mutex
);
144 for (i
= 0, b
= cinfo
->ds
->buckets
; i
< cinfo
->ds
->nbuckets
; i
++, b
++) {
145 nwritten
= nfs_scan_commit_list(&b
->written
, dst
, cinfo
, 0);
148 cinfo
->ds
->nwritten
-= nwritten
;
149 if (list_empty(&b
->written
)) {
152 spin_unlock(&cinfo
->inode
->i_lock
);
153 pnfs_put_lseg(freeme
);
154 spin_lock(&cinfo
->inode
->i_lock
);
159 EXPORT_SYMBOL_GPL(pnfs_generic_recover_commit_reqs
);
161 static void pnfs_generic_retry_commit(struct nfs_commit_info
*cinfo
, int idx
)
163 struct pnfs_ds_commit_info
*fl_cinfo
= cinfo
->ds
;
164 struct pnfs_commit_bucket
*bucket
;
165 struct pnfs_layout_segment
*freeme
;
166 struct list_head
*pos
;
170 spin_lock(&cinfo
->inode
->i_lock
);
171 for (i
= idx
; i
< fl_cinfo
->nbuckets
; i
++) {
172 bucket
= &fl_cinfo
->buckets
[i
];
173 if (list_empty(&bucket
->committing
))
175 freeme
= bucket
->clseg
;
176 bucket
->clseg
= NULL
;
177 list_for_each(pos
, &bucket
->committing
)
178 cinfo
->ds
->ncommitting
--;
179 list_splice_init(&bucket
->committing
, &pages
);
180 spin_unlock(&cinfo
->inode
->i_lock
);
181 nfs_retry_commit(&pages
, freeme
, cinfo
, i
);
182 pnfs_put_lseg(freeme
);
183 spin_lock(&cinfo
->inode
->i_lock
);
185 spin_unlock(&cinfo
->inode
->i_lock
);
189 pnfs_generic_alloc_ds_commits(struct nfs_commit_info
*cinfo
,
190 struct list_head
*list
)
192 struct pnfs_ds_commit_info
*fl_cinfo
;
193 struct pnfs_commit_bucket
*bucket
;
194 struct nfs_commit_data
*data
;
196 unsigned int nreq
= 0;
198 fl_cinfo
= cinfo
->ds
;
199 bucket
= fl_cinfo
->buckets
;
200 for (i
= 0; i
< fl_cinfo
->nbuckets
; i
++, bucket
++) {
201 if (list_empty(&bucket
->committing
))
203 data
= nfs_commitdata_alloc(false);
206 data
->ds_commit_index
= i
;
207 list_add(&data
->pages
, list
);
211 /* Clean up on error */
212 pnfs_generic_retry_commit(cinfo
, i
);
217 void pnfs_fetch_commit_bucket_list(struct list_head
*pages
,
218 struct nfs_commit_data
*data
,
219 struct nfs_commit_info
*cinfo
)
221 struct pnfs_commit_bucket
*bucket
;
222 struct list_head
*pos
;
224 bucket
= &cinfo
->ds
->buckets
[data
->ds_commit_index
];
225 spin_lock(&cinfo
->inode
->i_lock
);
226 list_for_each(pos
, &bucket
->committing
)
227 cinfo
->ds
->ncommitting
--;
228 list_splice_init(&bucket
->committing
, pages
);
229 data
->lseg
= bucket
->clseg
;
230 bucket
->clseg
= NULL
;
231 spin_unlock(&cinfo
->inode
->i_lock
);
235 /* Helper function for pnfs_generic_commit_pagelist to catch an empty
236 * page list. This can happen when two commits race.
238 * This must be called instead of nfs_init_commit - call one or the other, but
242 pnfs_generic_commit_cancel_empty_pagelist(struct list_head
*pages
,
243 struct nfs_commit_data
*data
,
244 struct nfs_commit_info
*cinfo
)
246 if (list_empty(pages
)) {
247 if (atomic_dec_and_test(&cinfo
->mds
->rpcs_out
))
248 wake_up_var(&cinfo
->mds
->rpcs_out
);
249 /* don't call nfs_commitdata_release - it tries to put
250 * the open_context which is not acquired until nfs_init_commit
251 * which has not been called on @data */
252 WARN_ON_ONCE(data
->context
);
253 nfs_commit_free(data
);
260 /* This follows nfs_commit_list pretty closely */
262 pnfs_generic_commit_pagelist(struct inode
*inode
, struct list_head
*mds_pages
,
263 int how
, struct nfs_commit_info
*cinfo
,
264 int (*initiate_commit
)(struct nfs_commit_data
*data
,
267 struct nfs_commit_data
*data
, *tmp
;
269 unsigned int nreq
= 0;
271 if (!list_empty(mds_pages
)) {
272 data
= nfs_commitdata_alloc(true);
273 data
->ds_commit_index
= -1;
274 list_add(&data
->pages
, &list
);
278 nreq
+= pnfs_generic_alloc_ds_commits(cinfo
, &list
);
283 atomic_add(nreq
, &cinfo
->mds
->rpcs_out
);
285 list_for_each_entry_safe(data
, tmp
, &list
, pages
) {
286 list_del_init(&data
->pages
);
287 if (data
->ds_commit_index
< 0) {
288 /* another commit raced with us */
289 if (pnfs_generic_commit_cancel_empty_pagelist(mds_pages
,
293 nfs_init_commit(data
, mds_pages
, NULL
, cinfo
);
294 nfs_initiate_commit(NFS_CLIENT(inode
), data
,
295 NFS_PROTO(data
->inode
),
296 data
->mds_ops
, how
, 0);
300 pnfs_fetch_commit_bucket_list(&pages
, data
, cinfo
);
302 /* another commit raced with us */
303 if (pnfs_generic_commit_cancel_empty_pagelist(&pages
,
307 nfs_init_commit(data
, &pages
, data
->lseg
, cinfo
);
308 initiate_commit(data
, how
);
312 return PNFS_ATTEMPTED
;
314 EXPORT_SYMBOL_GPL(pnfs_generic_commit_pagelist
);
319 * Data servers can be mapped to different device ids.
320 * nfs4_pnfs_ds reference counting
321 * - set to 1 on allocation
322 * - incremented when a device id maps a data server already in the cache.
323 * - decremented when deviceid is removed from the cache.
325 static DEFINE_SPINLOCK(nfs4_ds_cache_lock
);
326 static LIST_HEAD(nfs4_data_server_cache
);
330 print_ds(struct nfs4_pnfs_ds
*ds
)
333 printk(KERN_WARNING
"%s NULL device\n", __func__
);
336 printk(KERN_WARNING
" ds %s\n"
339 " cl_exchange_flags %x\n",
341 refcount_read(&ds
->ds_count
), ds
->ds_clp
,
342 ds
->ds_clp
? ds
->ds_clp
->cl_exchange_flags
: 0);
346 same_sockaddr(struct sockaddr
*addr1
, struct sockaddr
*addr2
)
348 struct sockaddr_in
*a
, *b
;
349 struct sockaddr_in6
*a6
, *b6
;
351 if (addr1
->sa_family
!= addr2
->sa_family
)
354 switch (addr1
->sa_family
) {
356 a
= (struct sockaddr_in
*)addr1
;
357 b
= (struct sockaddr_in
*)addr2
;
359 if (a
->sin_addr
.s_addr
== b
->sin_addr
.s_addr
&&
360 a
->sin_port
== b
->sin_port
)
365 a6
= (struct sockaddr_in6
*)addr1
;
366 b6
= (struct sockaddr_in6
*)addr2
;
368 /* LINKLOCAL addresses must have matching scope_id */
369 if (ipv6_addr_src_scope(&a6
->sin6_addr
) ==
370 IPV6_ADDR_SCOPE_LINKLOCAL
&&
371 a6
->sin6_scope_id
!= b6
->sin6_scope_id
)
374 if (ipv6_addr_equal(&a6
->sin6_addr
, &b6
->sin6_addr
) &&
375 a6
->sin6_port
== b6
->sin6_port
)
380 dprintk("%s: unhandled address family: %u\n",
381 __func__
, addr1
->sa_family
);
389 * Checks if 'dsaddrs1' contains a subset of 'dsaddrs2'. If it does,
393 _same_data_server_addrs_locked(const struct list_head
*dsaddrs1
,
394 const struct list_head
*dsaddrs2
)
396 struct nfs4_pnfs_ds_addr
*da1
, *da2
;
397 struct sockaddr
*sa1
, *sa2
;
400 list_for_each_entry(da1
, dsaddrs1
, da_node
) {
401 sa1
= (struct sockaddr
*)&da1
->da_addr
;
403 list_for_each_entry(da2
, dsaddrs2
, da_node
) {
404 sa2
= (struct sockaddr
*)&da2
->da_addr
;
405 match
= same_sockaddr(sa1
, sa2
);
416 * Lookup DS by addresses. nfs4_ds_cache_lock is held
418 static struct nfs4_pnfs_ds
*
419 _data_server_lookup_locked(const struct list_head
*dsaddrs
)
421 struct nfs4_pnfs_ds
*ds
;
423 list_for_each_entry(ds
, &nfs4_data_server_cache
, ds_node
)
424 if (_same_data_server_addrs_locked(&ds
->ds_addrs
, dsaddrs
))
429 static void destroy_ds(struct nfs4_pnfs_ds
*ds
)
431 struct nfs4_pnfs_ds_addr
*da
;
433 dprintk("--> %s\n", __func__
);
437 nfs_put_client(ds
->ds_clp
);
439 while (!list_empty(&ds
->ds_addrs
)) {
440 da
= list_first_entry(&ds
->ds_addrs
,
441 struct nfs4_pnfs_ds_addr
,
443 list_del_init(&da
->da_node
);
444 kfree(da
->da_remotestr
);
448 kfree(ds
->ds_remotestr
);
452 void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds
*ds
)
454 if (refcount_dec_and_lock(&ds
->ds_count
,
455 &nfs4_ds_cache_lock
)) {
456 list_del_init(&ds
->ds_node
);
457 spin_unlock(&nfs4_ds_cache_lock
);
461 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put
);
464 * Create a string with a human readable address and port to avoid
465 * complicated setup around many dprinks.
468 nfs4_pnfs_remotestr(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
470 struct nfs4_pnfs_ds_addr
*da
;
475 len
= 3; /* '{', '}' and eol */
476 list_for_each_entry(da
, dsaddrs
, da_node
) {
477 len
+= strlen(da
->da_remotestr
) + 1; /* string plus comma */
480 remotestr
= kzalloc(len
, gfp_flags
);
487 list_for_each_entry(da
, dsaddrs
, da_node
) {
488 size_t ll
= strlen(da
->da_remotestr
);
493 memcpy(p
, da
->da_remotestr
, ll
);
513 * Given a list of multipath struct nfs4_pnfs_ds_addr, add it to ds cache if
514 * uncached and return cached struct nfs4_pnfs_ds.
516 struct nfs4_pnfs_ds
*
517 nfs4_pnfs_ds_add(struct list_head
*dsaddrs
, gfp_t gfp_flags
)
519 struct nfs4_pnfs_ds
*tmp_ds
, *ds
= NULL
;
522 if (list_empty(dsaddrs
)) {
523 dprintk("%s: no addresses defined\n", __func__
);
527 ds
= kzalloc(sizeof(*ds
), gfp_flags
);
531 /* this is only used for debugging, so it's ok if its NULL */
532 remotestr
= nfs4_pnfs_remotestr(dsaddrs
, gfp_flags
);
534 spin_lock(&nfs4_ds_cache_lock
);
535 tmp_ds
= _data_server_lookup_locked(dsaddrs
);
536 if (tmp_ds
== NULL
) {
537 INIT_LIST_HEAD(&ds
->ds_addrs
);
538 list_splice_init(dsaddrs
, &ds
->ds_addrs
);
539 ds
->ds_remotestr
= remotestr
;
540 refcount_set(&ds
->ds_count
, 1);
541 INIT_LIST_HEAD(&ds
->ds_node
);
543 list_add(&ds
->ds_node
, &nfs4_data_server_cache
);
544 dprintk("%s add new data server %s\n", __func__
,
549 refcount_inc(&tmp_ds
->ds_count
);
550 dprintk("%s data server %s found, inc'ed ds_count to %d\n",
551 __func__
, tmp_ds
->ds_remotestr
,
552 refcount_read(&tmp_ds
->ds_count
));
555 spin_unlock(&nfs4_ds_cache_lock
);
559 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_add
);
561 static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds
*ds
)
564 wait_on_bit(&ds
->ds_state
, NFS4DS_CONNECTING
,
568 static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds
*ds
)
570 smp_mb__before_atomic();
571 clear_bit(NFS4DS_CONNECTING
, &ds
->ds_state
);
572 smp_mb__after_atomic();
573 wake_up_bit(&ds
->ds_state
, NFS4DS_CONNECTING
);
576 static struct nfs_client
*(*get_v3_ds_connect
)(
577 struct nfs_server
*mds_srv
,
578 const struct sockaddr
*ds_addr
,
581 unsigned int ds_timeo
,
582 unsigned int ds_retrans
);
584 static bool load_v3_ds_connect(void)
586 if (!get_v3_ds_connect
) {
587 get_v3_ds_connect
= symbol_request(nfs3_set_ds_client
);
588 WARN_ON_ONCE(!get_v3_ds_connect
);
591 return(get_v3_ds_connect
!= NULL
);
594 void nfs4_pnfs_v3_ds_connect_unload(void)
596 if (get_v3_ds_connect
) {
597 symbol_put(nfs3_set_ds_client
);
598 get_v3_ds_connect
= NULL
;
602 static int _nfs4_pnfs_v3_ds_connect(struct nfs_server
*mds_srv
,
603 struct nfs4_pnfs_ds
*ds
,
605 unsigned int retrans
)
607 struct nfs_client
*clp
= ERR_PTR(-EIO
);
608 struct nfs4_pnfs_ds_addr
*da
;
611 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
613 if (!load_v3_ds_connect())
616 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
617 dprintk("%s: DS %s: trying address %s\n",
618 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
621 struct xprt_create xprt_args
= {
622 .ident
= XPRT_TRANSPORT_TCP
,
624 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
625 .addrlen
= da
->da_addrlen
,
626 .servername
= clp
->cl_hostname
,
628 /* Add this address as an alias */
629 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
630 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
,
639 status
= PTR_ERR(clp
);
645 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
650 static int _nfs4_pnfs_v4_ds_connect(struct nfs_server
*mds_srv
,
651 struct nfs4_pnfs_ds
*ds
,
653 unsigned int retrans
,
656 struct nfs_client
*clp
= ERR_PTR(-EIO
);
657 struct nfs4_pnfs_ds_addr
*da
;
660 dprintk("--> %s DS %s\n", __func__
, ds
->ds_remotestr
);
662 list_for_each_entry(da
, &ds
->ds_addrs
, da_node
) {
663 dprintk("%s: DS %s: trying address %s\n",
664 __func__
, ds
->ds_remotestr
, da
->da_remotestr
);
666 if (!IS_ERR(clp
) && clp
->cl_mvops
->session_trunk
) {
667 struct xprt_create xprt_args
= {
668 .ident
= XPRT_TRANSPORT_TCP
,
670 .dstaddr
= (struct sockaddr
*)&da
->da_addr
,
671 .addrlen
= da
->da_addrlen
,
672 .servername
= clp
->cl_hostname
,
674 struct nfs4_add_xprt_data xprtdata
= {
676 .cred
= nfs4_get_clid_cred(clp
),
678 struct rpc_add_xprt_test rpcdata
= {
679 .add_xprt_test
= clp
->cl_mvops
->session_trunk
,
684 * Test this address for session trunking and
687 rpc_clnt_add_xprt(clp
->cl_rpcclient
, &xprt_args
,
688 rpc_clnt_setup_test_and_add_xprt
,
691 put_rpccred(xprtdata
.cred
);
693 clp
= nfs4_set_ds_client(mds_srv
,
694 (struct sockaddr
*)&da
->da_addr
,
695 da
->da_addrlen
, IPPROTO_TCP
,
696 timeo
, retrans
, minor_version
);
700 status
= nfs4_init_ds_session(clp
,
701 mds_srv
->nfs_client
->cl_lease_time
);
712 status
= PTR_ERR(clp
);
718 dprintk("%s [new] addr: %s\n", __func__
, ds
->ds_remotestr
);
724 * Create an rpc connection to the nfs4_pnfs_ds data server.
725 * Currently only supports IPv4 and IPv6 addresses.
726 * If connection fails, make devid unavailable and return a -errno.
728 int nfs4_pnfs_ds_connect(struct nfs_server
*mds_srv
, struct nfs4_pnfs_ds
*ds
,
729 struct nfs4_deviceid_node
*devid
, unsigned int timeo
,
730 unsigned int retrans
, u32 version
, u32 minor_version
)
736 if (test_and_set_bit(NFS4DS_CONNECTING
, &ds
->ds_state
) == 0) {
738 err
= _nfs4_pnfs_v3_ds_connect(mds_srv
, ds
, timeo
,
740 } else if (version
== 4) {
741 err
= _nfs4_pnfs_v4_ds_connect(mds_srv
, ds
, timeo
,
742 retrans
, minor_version
);
744 dprintk("%s: unsupported DS version %d\n", __func__
,
746 err
= -EPROTONOSUPPORT
;
749 nfs4_clear_ds_conn_bit(ds
);
751 nfs4_wait_ds_connect(ds
);
753 /* what was waited on didn't connect AND didn't mark unavail */
754 if (!ds
->ds_clp
&& !nfs4_test_deviceid_unavailable(devid
))
759 * At this point the ds->ds_clp should be ready, but it might have
763 if (!ds
->ds_clp
|| !nfs_client_init_is_complete(ds
->ds_clp
)) {
764 WARN_ON_ONCE(ds
->ds_clp
||
765 !nfs4_test_deviceid_unavailable(devid
));
768 err
= nfs_client_init_status(ds
->ds_clp
);
773 EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_connect
);
776 * Currently only supports ipv4, ipv6 and one multi-path address.
778 struct nfs4_pnfs_ds_addr
*
779 nfs4_decode_mp_ds_addr(struct net
*net
, struct xdr_stream
*xdr
, gfp_t gfp_flags
)
781 struct nfs4_pnfs_ds_addr
*da
= NULL
;
787 char *netid
, *match_netid
;
788 size_t len
, match_netid_len
;
794 p
= xdr_inline_decode(xdr
, 4);
797 nlen
= be32_to_cpup(p
++);
799 p
= xdr_inline_decode(xdr
, nlen
);
803 netid
= kmalloc(nlen
+1, gfp_flags
);
804 if (unlikely(!netid
))
808 memcpy(netid
, p
, nlen
);
810 /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
811 p
= xdr_inline_decode(xdr
, 4);
814 rlen
= be32_to_cpup(p
);
816 p
= xdr_inline_decode(xdr
, rlen
);
820 /* port is ".ABC.DEF", 8 chars max */
821 if (rlen
> INET6_ADDRSTRLEN
+ IPV6_SCOPE_ID_LEN
+ 8) {
822 dprintk("%s: Invalid address, length %d\n", __func__
,
826 buf
= kmalloc(rlen
+ 1, gfp_flags
);
828 dprintk("%s: Not enough memory\n", __func__
);
832 memcpy(buf
, p
, rlen
);
834 /* replace port '.' with '-' */
835 portstr
= strrchr(buf
, '.');
837 dprintk("%s: Failed finding expected dot in port\n",
843 /* find '.' between address and port */
844 portstr
= strrchr(buf
, '.');
846 dprintk("%s: Failed finding expected dot between address and "
852 da
= kzalloc(sizeof(*da
), gfp_flags
);
856 INIT_LIST_HEAD(&da
->da_node
);
858 if (!rpc_pton(net
, buf
, portstr
-buf
, (struct sockaddr
*)&da
->da_addr
,
859 sizeof(da
->da_addr
))) {
860 dprintk("%s: error parsing address %s\n", __func__
, buf
);
865 sscanf(portstr
, "%d-%d", &tmp
[0], &tmp
[1]);
866 port
= htons((tmp
[0] << 8) | (tmp
[1]));
868 switch (da
->da_addr
.ss_family
) {
870 ((struct sockaddr_in
*)&da
->da_addr
)->sin_port
= port
;
871 da
->da_addrlen
= sizeof(struct sockaddr_in
);
877 ((struct sockaddr_in6
*)&da
->da_addr
)->sin6_port
= port
;
878 da
->da_addrlen
= sizeof(struct sockaddr_in6
);
879 match_netid
= "tcp6";
886 dprintk("%s: unsupported address family: %u\n",
887 __func__
, da
->da_addr
.ss_family
);
891 if (nlen
!= match_netid_len
|| strncmp(netid
, match_netid
, nlen
)) {
892 dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n",
893 __func__
, netid
, match_netid
);
897 /* save human readable address */
898 len
= strlen(startsep
) + strlen(buf
) + strlen(endsep
) + 7;
899 da
->da_remotestr
= kzalloc(len
, gfp_flags
);
901 /* NULL is ok, only used for dprintk */
902 if (da
->da_remotestr
)
903 snprintf(da
->da_remotestr
, len
, "%s%s%s:%u", startsep
,
904 buf
, endsep
, ntohs(port
));
906 dprintk("%s: Parsed DS addr %s\n", __func__
, da
->da_remotestr
);
914 dprintk("%s: Error parsing DS addr: %s\n", __func__
, buf
);
921 EXPORT_SYMBOL_GPL(nfs4_decode_mp_ds_addr
);
924 pnfs_layout_mark_request_commit(struct nfs_page
*req
,
925 struct pnfs_layout_segment
*lseg
,
926 struct nfs_commit_info
*cinfo
,
929 struct list_head
*list
;
930 struct pnfs_commit_bucket
*buckets
;
932 mutex_lock(&NFS_I(cinfo
->inode
)->commit_mutex
);
933 buckets
= cinfo
->ds
->buckets
;
934 list
= &buckets
[ds_commit_idx
].written
;
935 if (list_empty(list
)) {
936 if (!pnfs_is_valid_lseg(lseg
)) {
937 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
938 cinfo
->completion_ops
->resched_write(cinfo
, req
);
941 /* Non-empty buckets hold a reference on the lseg. That ref
942 * is normally transferred to the COMMIT call and released
943 * there. It could also be released if the last req is pulled
944 * off due to a rewrite, in which case it will be done in
945 * pnfs_common_clear_request_commit
947 WARN_ON_ONCE(buckets
[ds_commit_idx
].wlseg
!= NULL
);
948 buckets
[ds_commit_idx
].wlseg
= pnfs_get_lseg(lseg
);
950 set_bit(PG_COMMIT_TO_DS
, &req
->wb_flags
);
951 cinfo
->ds
->nwritten
++;
953 nfs_request_add_commit_list_locked(req
, list
, cinfo
);
954 mutex_unlock(&NFS_I(cinfo
->inode
)->commit_mutex
);
955 nfs_mark_page_unstable(req
->wb_page
, cinfo
);
957 EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit
);
960 pnfs_nfs_generic_sync(struct inode
*inode
, bool datasync
)
964 if (!pnfs_layoutcommit_outstanding(inode
))
966 ret
= nfs_commit_inode(inode
, FLUSH_SYNC
);
971 return pnfs_layoutcommit_inode(inode
, true);
973 EXPORT_SYMBOL_GPL(pnfs_nfs_generic_sync
);