11
11
#include <linux/nfs_mount.h>
12
12
#include <linux/nfs_page.h>
13
13
#include <linux/module.h>
14
+ #include <linux/file.h>
14
15
#include <linux/sched/mm.h>
15
16
16
17
#include <linux/sunrpc/metrics.h>
@@ -162,6 +163,21 @@ decode_name(struct xdr_stream *xdr, u32 *id)
162
163
return 0 ;
163
164
}
164
165
166
+ static struct nfsd_file *
167
+ ff_local_open_fh (struct nfs_client * clp , const struct cred * cred ,
168
+ struct nfs_fh * fh , fmode_t mode )
169
+ {
170
+ if (mode & FMODE_WRITE ) {
171
+ /*
172
+ * Always request read and write access since this corresponds
173
+ * to a rw layout.
174
+ */
175
+ mode |= FMODE_READ ;
176
+ }
177
+
178
+ return nfs_local_open_fh (clp , cred , fh , mode );
179
+ }
180
+
165
181
static bool ff_mirror_match_fh (const struct nfs4_ff_layout_mirror * m1 ,
166
182
const struct nfs4_ff_layout_mirror * m2 )
167
183
{
@@ -237,7 +253,7 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
237
253
238
254
static void ff_layout_free_mirror (struct nfs4_ff_layout_mirror * mirror )
239
255
{
240
- const struct cred * cred ;
256
+ const struct cred * cred ;
241
257
242
258
ff_layout_remove_mirror (mirror );
243
259
kfree (mirror -> fh_versions );
@@ -1756,6 +1772,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1756
1772
struct pnfs_layout_segment * lseg = hdr -> lseg ;
1757
1773
struct nfs4_pnfs_ds * ds ;
1758
1774
struct rpc_clnt * ds_clnt ;
1775
+ struct nfsd_file * localio ;
1759
1776
struct nfs4_ff_layout_mirror * mirror ;
1760
1777
const struct cred * ds_cred ;
1761
1778
loff_t offset = hdr -> args .offset ;
@@ -1802,11 +1819,18 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
1802
1819
hdr -> args .offset = offset ;
1803
1820
hdr -> mds_offset = offset ;
1804
1821
1822
+ /* Start IO accounting for local read */
1823
+ localio = ff_local_open_fh (ds -> ds_clp , ds_cred , fh , FMODE_READ );
1824
+ if (localio ) {
1825
+ hdr -> task .tk_start = ktime_get ();
1826
+ ff_layout_read_record_layoutstats_start (& hdr -> task , hdr );
1827
+ }
1828
+
1805
1829
/* Perform an asynchronous read to ds */
1806
1830
nfs_initiate_pgio (ds_clnt , hdr , ds_cred , ds -> ds_clp -> rpc_ops ,
1807
1831
vers == 3 ? & ff_layout_read_call_ops_v3 :
1808
1832
& ff_layout_read_call_ops_v4 ,
1809
- 0 , RPC_TASK_SOFTCONN , NULL );
1833
+ 0 , RPC_TASK_SOFTCONN , localio );
1810
1834
put_cred (ds_cred );
1811
1835
return PNFS_ATTEMPTED ;
1812
1836
@@ -1826,6 +1850,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1826
1850
struct pnfs_layout_segment * lseg = hdr -> lseg ;
1827
1851
struct nfs4_pnfs_ds * ds ;
1828
1852
struct rpc_clnt * ds_clnt ;
1853
+ struct nfsd_file * localio ;
1829
1854
struct nfs4_ff_layout_mirror * mirror ;
1830
1855
const struct cred * ds_cred ;
1831
1856
loff_t offset = hdr -> args .offset ;
@@ -1870,11 +1895,19 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
1870
1895
*/
1871
1896
hdr -> args .offset = offset ;
1872
1897
1898
+ /* Start IO accounting for local write */
1899
+ localio = ff_local_open_fh (ds -> ds_clp , ds_cred , fh ,
1900
+ FMODE_READ |FMODE_WRITE );
1901
+ if (localio ) {
1902
+ hdr -> task .tk_start = ktime_get ();
1903
+ ff_layout_write_record_layoutstats_start (& hdr -> task , hdr );
1904
+ }
1905
+
1873
1906
/* Perform an asynchronous write */
1874
1907
nfs_initiate_pgio (ds_clnt , hdr , ds_cred , ds -> ds_clp -> rpc_ops ,
1875
1908
vers == 3 ? & ff_layout_write_call_ops_v3 :
1876
1909
& ff_layout_write_call_ops_v4 ,
1877
- sync , RPC_TASK_SOFTCONN , NULL );
1910
+ sync , RPC_TASK_SOFTCONN , localio );
1878
1911
put_cred (ds_cred );
1879
1912
return PNFS_ATTEMPTED ;
1880
1913
@@ -1908,6 +1941,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1908
1941
struct pnfs_layout_segment * lseg = data -> lseg ;
1909
1942
struct nfs4_pnfs_ds * ds ;
1910
1943
struct rpc_clnt * ds_clnt ;
1944
+ struct nfsd_file * localio ;
1911
1945
struct nfs4_ff_layout_mirror * mirror ;
1912
1946
const struct cred * ds_cred ;
1913
1947
u32 idx ;
@@ -1946,10 +1980,18 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
1946
1980
if (fh )
1947
1981
data -> args .fh = fh ;
1948
1982
1983
+ /* Start IO accounting for local commit */
1984
+ localio = ff_local_open_fh (ds -> ds_clp , ds_cred , fh ,
1985
+ FMODE_READ |FMODE_WRITE );
1986
+ if (localio ) {
1987
+ data -> task .tk_start = ktime_get ();
1988
+ ff_layout_commit_record_layoutstats_start (& data -> task , data );
1989
+ }
1990
+
1949
1991
ret = nfs_initiate_commit (ds_clnt , data , ds -> ds_clp -> rpc_ops ,
1950
1992
vers == 3 ? & ff_layout_commit_call_ops_v3 :
1951
1993
& ff_layout_commit_call_ops_v4 ,
1952
- how , RPC_TASK_SOFTCONN , NULL );
1994
+ how , RPC_TASK_SOFTCONN , localio );
1953
1995
put_cred (ds_cred );
1954
1996
return ret ;
1955
1997
out_err :
0 commit comments