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_proc_layoutget(struct inode
*inode
, const struct svc_fh
*fhp
,
18 struct nfsd4_layoutget
*args
)
20 struct nfsd4_layout_seg
*seg
= &args
->lg_seg
;
21 struct super_block
*sb
= inode
->i_sb
;
22 u32 block_size
= (1 << inode
->i_blkbits
);
23 struct pnfs_block_extent
*bex
;
25 u32 device_generation
= 0;
28 if (seg
->offset
& (block_size
- 1)) {
29 dprintk("pnfsd: I/O misaligned\n");
30 goto out_layoutunavailable
;
34 * Some clients barf on non-zero block numbers for NONE or INVALID
35 * layouts, so make sure to zero the whole structure.
38 bex
= kzalloc(sizeof(*bex
), GFP_KERNEL
);
41 args
->lg_content
= bex
;
43 error
= sb
->s_export_op
->map_blocks(inode
, seg
->offset
, seg
->length
,
44 &iomap
, seg
->iomode
!= IOMODE_READ
,
48 goto out_layoutunavailable
;
52 if (iomap
.length
< args
->lg_minlength
) {
53 dprintk("pnfsd: extent smaller than minlength\n");
54 goto out_layoutunavailable
;
59 if (seg
->iomode
== IOMODE_READ
)
60 bex
->es
= PNFS_BLOCK_READ_DATA
;
62 bex
->es
= PNFS_BLOCK_READWRITE_DATA
;
63 bex
->soff
= (iomap
.blkno
<< 9);
66 if (seg
->iomode
& IOMODE_RW
) {
68 * Crack monkey special case from section 2.3.1.
70 if (args
->lg_minlength
== 0) {
71 dprintk("pnfsd: no soup for you!\n");
72 goto out_layoutunavailable
;
75 bex
->es
= PNFS_BLOCK_INVALID_DATA
;
76 bex
->soff
= (iomap
.blkno
<< 9);
81 if (seg
->iomode
== IOMODE_READ
) {
82 bex
->es
= PNFS_BLOCK_NONE_DATA
;
88 WARN(1, "pnfsd: filesystem returned %d extent\n", iomap
.type
);
89 goto out_layoutunavailable
;
92 error
= nfsd4_set_deviceid(&bex
->vol_id
, fhp
, device_generation
);
95 bex
->foff
= iomap
.offset
;
96 bex
->len
= iomap
.length
;
98 seg
->offset
= iomap
.offset
;
99 seg
->length
= iomap
.length
;
101 dprintk("GET: 0x%llx:0x%llx %d\n", bex
->foff
, bex
->len
, bex
->es
);
106 return nfserrno(error
);
107 out_layoutunavailable
:
109 return nfserr_layoutunavailable
;
113 nfsd4_block_commit_blocks(struct inode
*inode
, struct nfsd4_layoutcommit
*lcp
,
114 struct iomap
*iomaps
, int nr_iomaps
)
116 loff_t new_size
= lcp
->lc_last_wr
+ 1;
117 struct iattr iattr
= { .ia_valid
= 0 };
120 if (lcp
->lc_mtime
.tv_nsec
== UTIME_NOW
||
121 timespec_compare(&lcp
->lc_mtime
, &inode
->i_mtime
) < 0)
122 lcp
->lc_mtime
= current_fs_time(inode
->i_sb
);
123 iattr
.ia_valid
|= ATTR_ATIME
| ATTR_CTIME
| ATTR_MTIME
;
124 iattr
.ia_atime
= iattr
.ia_ctime
= iattr
.ia_mtime
= lcp
->lc_mtime
;
126 if (new_size
> i_size_read(inode
)) {
127 iattr
.ia_valid
|= ATTR_SIZE
;
128 iattr
.ia_size
= new_size
;
131 error
= inode
->i_sb
->s_export_op
->commit_blocks(inode
, iomaps
,
134 return nfserrno(error
);
137 #ifdef CONFIG_NFSD_BLOCKLAYOUT
139 nfsd4_block_get_device_info_simple(struct super_block
*sb
,
140 struct nfsd4_getdeviceinfo
*gdp
)
142 struct pnfs_block_deviceaddr
*dev
;
143 struct pnfs_block_volume
*b
;
145 dev
= kzalloc(sizeof(struct pnfs_block_deviceaddr
) +
146 sizeof(struct pnfs_block_volume
), GFP_KERNEL
);
149 gdp
->gd_device
= dev
;
152 b
= &dev
->volumes
[0];
154 b
->type
= PNFS_BLOCK_VOLUME_SIMPLE
;
155 b
->simple
.sig_len
= PNFS_BLOCK_UUID_LEN
;
156 return sb
->s_export_op
->get_uuid(sb
, b
->simple
.sig
, &b
->simple
.sig_len
,
161 nfsd4_block_proc_getdeviceinfo(struct super_block
*sb
,
162 struct nfsd4_getdeviceinfo
*gdp
)
164 if (sb
->s_bdev
!= sb
->s_bdev
->bd_contains
)
166 return nfserrno(nfsd4_block_get_device_info_simple(sb
, gdp
));
170 nfsd4_block_proc_layoutcommit(struct inode
*inode
,
171 struct nfsd4_layoutcommit
*lcp
)
173 struct iomap
*iomaps
;
176 nr_iomaps
= nfsd4_block_decode_layoutupdate(lcp
->lc_up_layout
,
177 lcp
->lc_up_len
, &iomaps
, 1 << inode
->i_blkbits
);
179 return nfserrno(nr_iomaps
);
181 return nfsd4_block_commit_blocks(inode
, lcp
, iomaps
, nr_iomaps
);
184 const struct nfsd4_layout_ops bl_layout_ops
= {
186 * Pretend that we send notification to the client. This is a blatant
187 * lie to force recent Linux clients to cache our device IDs.
188 * We rarely ever change the device ID, so the harm of leaking deviceids
189 * for a while isn't too bad. Unfortunately RFC5661 is a complete mess
190 * in this regard, but I filed errata 4119 for this a while ago, and
191 * hopefully the Linux client will eventually start caching deviceids
192 * without this again.
195 NOTIFY_DEVICEID4_DELETE
| NOTIFY_DEVICEID4_CHANGE
,
196 .proc_getdeviceinfo
= nfsd4_block_proc_getdeviceinfo
,
197 .encode_getdeviceinfo
= nfsd4_block_encode_getdeviceinfo
,
198 .proc_layoutget
= nfsd4_block_proc_layoutget
,
199 .encode_layoutget
= nfsd4_block_encode_layoutget
,
200 .proc_layoutcommit
= nfsd4_block_proc_layoutcommit
,
202 #endif /* CONFIG_NFSD_BLOCKLAYOUT */