2 * Copyright (c) 2014 Christoph Hellwig.
4 #include <linux/exportfs.h>
5 #include <linux/genhd.h>
6 #include <linux/slab.h>
8 #include <linux/nfsd/debug.h>
10 #include "blocklayoutxdr.h"
13 #define NFSDDBG_FACILITY NFSDDBG_PNFS
17 nfsd4_block_get_device_info_simple(struct super_block
*sb
,
18 struct nfsd4_getdeviceinfo
*gdp
)
20 struct pnfs_block_deviceaddr
*dev
;
21 struct pnfs_block_volume
*b
;
23 dev
= kzalloc(sizeof(struct pnfs_block_deviceaddr
) +
24 sizeof(struct pnfs_block_volume
), GFP_KERNEL
);
32 b
->type
= PNFS_BLOCK_VOLUME_SIMPLE
;
33 b
->simple
.sig_len
= PNFS_BLOCK_UUID_LEN
;
34 return sb
->s_export_op
->get_uuid(sb
, b
->simple
.sig
, &b
->simple
.sig_len
,
39 nfsd4_block_proc_getdeviceinfo(struct super_block
*sb
,
40 struct nfsd4_getdeviceinfo
*gdp
)
42 if (sb
->s_bdev
!= sb
->s_bdev
->bd_contains
)
44 return nfserrno(nfsd4_block_get_device_info_simple(sb
, gdp
));
48 nfsd4_block_proc_layoutget(struct inode
*inode
, const struct svc_fh
*fhp
,
49 struct nfsd4_layoutget
*args
)
51 struct nfsd4_layout_seg
*seg
= &args
->lg_seg
;
52 struct super_block
*sb
= inode
->i_sb
;
53 u32 block_size
= i_blocksize(inode
);
54 struct pnfs_block_extent
*bex
;
56 u32 device_generation
= 0;
59 if (seg
->offset
& (block_size
- 1)) {
60 dprintk("pnfsd: I/O misaligned\n");
61 goto out_layoutunavailable
;
65 * Some clients barf on non-zero block numbers for NONE or INVALID
66 * layouts, so make sure to zero the whole structure.
69 bex
= kzalloc(sizeof(*bex
), GFP_KERNEL
);
72 args
->lg_content
= bex
;
74 error
= sb
->s_export_op
->map_blocks(inode
, seg
->offset
, seg
->length
,
75 &iomap
, seg
->iomode
!= IOMODE_READ
,
79 goto out_layoutunavailable
;
83 if (iomap
.length
< args
->lg_minlength
) {
84 dprintk("pnfsd: extent smaller than minlength\n");
85 goto out_layoutunavailable
;
90 if (seg
->iomode
== IOMODE_READ
)
91 bex
->es
= PNFS_BLOCK_READ_DATA
;
93 bex
->es
= PNFS_BLOCK_READWRITE_DATA
;
94 bex
->soff
= (iomap
.blkno
<< 9);
97 if (seg
->iomode
& IOMODE_RW
) {
99 * Crack monkey special case from section 2.3.1.
101 if (args
->lg_minlength
== 0) {
102 dprintk("pnfsd: no soup for you!\n");
103 goto out_layoutunavailable
;
106 bex
->es
= PNFS_BLOCK_INVALID_DATA
;
107 bex
->soff
= (iomap
.blkno
<< 9);
112 if (seg
->iomode
== IOMODE_READ
) {
113 bex
->es
= PNFS_BLOCK_NONE_DATA
;
119 WARN(1, "pnfsd: filesystem returned %d extent\n", iomap
.type
);
120 goto out_layoutunavailable
;
123 error
= nfsd4_set_deviceid(&bex
->vol_id
, fhp
, device_generation
);
126 bex
->foff
= iomap
.offset
;
127 bex
->len
= iomap
.length
;
129 seg
->offset
= iomap
.offset
;
130 seg
->length
= iomap
.length
;
132 dprintk("GET: 0x%llx:0x%llx %d\n", bex
->foff
, bex
->len
, bex
->es
);
137 return nfserrno(error
);
138 out_layoutunavailable
:
140 return nfserr_layoutunavailable
;
144 nfsd4_block_proc_layoutcommit(struct inode
*inode
,
145 struct nfsd4_layoutcommit
*lcp
)
147 loff_t new_size
= lcp
->lc_last_wr
+ 1;
148 struct iattr iattr
= { .ia_valid
= 0 };
149 struct iomap
*iomaps
;
153 nr_iomaps
= nfsd4_block_decode_layoutupdate(lcp
->lc_up_layout
,
154 lcp
->lc_up_len
, &iomaps
, i_blocksize(inode
));
156 return nfserrno(nr_iomaps
);
158 if (lcp
->lc_mtime
.tv_nsec
== UTIME_NOW
||
159 timespec_compare(&lcp
->lc_mtime
, &inode
->i_mtime
) < 0)
160 lcp
->lc_mtime
= current_fs_time(inode
->i_sb
);
161 iattr
.ia_valid
|= ATTR_ATIME
| ATTR_CTIME
| ATTR_MTIME
;
162 iattr
.ia_atime
= iattr
.ia_ctime
= iattr
.ia_mtime
= lcp
->lc_mtime
;
164 if (new_size
> i_size_read(inode
)) {
165 iattr
.ia_valid
|= ATTR_SIZE
;
166 iattr
.ia_size
= new_size
;
169 error
= inode
->i_sb
->s_export_op
->commit_blocks(inode
, iomaps
,
172 return nfserrno(error
);
175 const struct nfsd4_layout_ops bl_layout_ops
= {
177 * Pretend that we send notification to the client. This is a blatant
178 * lie to force recent Linux clients to cache our device IDs.
179 * We rarely ever change the device ID, so the harm of leaking deviceids
180 * for a while isn't too bad. Unfortunately RFC5661 is a complete mess
181 * in this regard, but I filed errata 4119 for this a while ago, and
182 * hopefully the Linux client will eventually start caching deviceids
183 * without this again.
186 NOTIFY_DEVICEID4_DELETE
| NOTIFY_DEVICEID4_CHANGE
,
187 .proc_getdeviceinfo
= nfsd4_block_proc_getdeviceinfo
,
188 .encode_getdeviceinfo
= nfsd4_block_encode_getdeviceinfo
,
189 .proc_layoutget
= nfsd4_block_proc_layoutget
,
190 .encode_layoutget
= nfsd4_block_encode_layoutget
,
191 .proc_layoutcommit
= nfsd4_block_proc_layoutcommit
,