Commit | Line | Data |
---|---|---|
155e7524 FI |
1 | /* |
2 | * linux/fs/nfs/blocklayout/blocklayout.c | |
3 | * | |
4 | * Module for the NFSv4.1 pNFS block layout driver. | |
5 | * | |
6 | * Copyright (c) 2006 The Regents of the University of Michigan. | |
7 | * All rights reserved. | |
8 | * | |
9 | * Andy Adamson <andros@citi.umich.edu> | |
10 | * Fred Isaman <iisaman@umich.edu> | |
11 | * | |
12 | * permission is granted to use, copy, create derivative works and | |
13 | * redistribute this software and such derivative works for any purpose, | |
14 | * so long as the name of the university of michigan is not used in | |
15 | * any advertising or publicity pertaining to the use or distribution | |
16 | * of this software without specific, written prior authorization. if | |
17 | * the above copyright notice or any other identification of the | |
18 | * university of michigan is included in any copy of any portion of | |
19 | * this software, then the disclaimer below must also be included. | |
20 | * | |
21 | * this software is provided as is, without representation from the | |
22 | * university of michigan as to its fitness for any purpose, and without | |
23 | * warranty by the university of michigan of any kind, either express | |
24 | * or implied, including without limitation the implied warranties of | |
25 | * merchantability and fitness for a particular purpose. the regents | |
26 | * of the university of michigan shall not be liable for any damages, | |
27 | * including special, indirect, incidental, or consequential damages, | |
28 | * with respect to any claim arising out or in connection with the use | |
29 | * of the software, even if it has been or is hereafter advised of the | |
30 | * possibility of such damages. | |
31 | */ | |
32 | #include <linux/module.h> | |
33 | #include <linux/init.h> | |
fe0a9b74 JR |
34 | #include <linux/mount.h> |
35 | #include <linux/namei.h> | |
155e7524 FI |
36 | |
37 | #include "blocklayout.h" | |
38 | ||
39 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD | |
40 | ||
41 | MODULE_LICENSE("GPL"); | |
42 | MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>"); | |
43 | MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver"); | |
44 | ||
fe0a9b74 JR |
45 | struct dentry *bl_device_pipe; |
46 | wait_queue_head_t bl_wq; | |
47 | ||
155e7524 FI |
48 | static enum pnfs_try_status |
49 | bl_read_pagelist(struct nfs_read_data *rdata) | |
50 | { | |
51 | return PNFS_NOT_ATTEMPTED; | |
52 | } | |
53 | ||
54 | static enum pnfs_try_status | |
55 | bl_write_pagelist(struct nfs_write_data *wdata, | |
56 | int sync) | |
57 | { | |
58 | return PNFS_NOT_ATTEMPTED; | |
59 | } | |
60 | ||
9e692969 | 61 | /* FIXME - range ignored */ |
155e7524 | 62 | static void |
9e692969 | 63 | release_extents(struct pnfs_block_layout *bl, struct pnfs_layout_range *range) |
155e7524 | 64 | { |
9e692969 FI |
65 | int i; |
66 | struct pnfs_block_extent *be; | |
67 | ||
68 | spin_lock(&bl->bl_ext_lock); | |
69 | for (i = 0; i < EXTENT_LISTS; i++) { | |
70 | while (!list_empty(&bl->bl_extents[i])) { | |
71 | be = list_first_entry(&bl->bl_extents[i], | |
72 | struct pnfs_block_extent, | |
73 | be_node); | |
74 | list_del(&be->be_node); | |
75 | bl_put_extent(be); | |
76 | } | |
77 | } | |
78 | spin_unlock(&bl->bl_ext_lock); | |
155e7524 FI |
79 | } |
80 | ||
81 | /* STUB */ | |
82 | static void | |
83 | release_inval_marks(struct pnfs_inval_markings *marks) | |
84 | { | |
85 | return; | |
86 | } | |
87 | ||
88 | static void bl_free_layout_hdr(struct pnfs_layout_hdr *lo) | |
89 | { | |
90 | struct pnfs_block_layout *bl = BLK_LO2EXT(lo); | |
91 | ||
92 | dprintk("%s enter\n", __func__); | |
93 | release_extents(bl, NULL); | |
94 | release_inval_marks(&bl->bl_inval); | |
95 | kfree(bl); | |
96 | } | |
97 | ||
98 | static struct pnfs_layout_hdr *bl_alloc_layout_hdr(struct inode *inode, | |
99 | gfp_t gfp_flags) | |
100 | { | |
101 | struct pnfs_block_layout *bl; | |
102 | ||
103 | dprintk("%s enter\n", __func__); | |
104 | bl = kzalloc(sizeof(*bl), gfp_flags); | |
105 | if (!bl) | |
106 | return NULL; | |
107 | spin_lock_init(&bl->bl_ext_lock); | |
108 | INIT_LIST_HEAD(&bl->bl_extents[0]); | |
109 | INIT_LIST_HEAD(&bl->bl_extents[1]); | |
110 | INIT_LIST_HEAD(&bl->bl_commit); | |
111 | INIT_LIST_HEAD(&bl->bl_committing); | |
112 | bl->bl_count = 0; | |
113 | bl->bl_blocksize = NFS_SERVER(inode)->pnfs_blksize >> SECTOR_SHIFT; | |
114 | BL_INIT_INVAL_MARKS(&bl->bl_inval, bl->bl_blocksize); | |
115 | return &bl->bl_layout; | |
116 | } | |
117 | ||
a60d2ebd | 118 | static void bl_free_lseg(struct pnfs_layout_segment *lseg) |
155e7524 | 119 | { |
a60d2ebd FI |
120 | dprintk("%s enter\n", __func__); |
121 | kfree(lseg); | |
155e7524 FI |
122 | } |
123 | ||
a60d2ebd FI |
124 | /* We pretty much ignore lseg, and store all data layout wide, so we |
125 | * can correctly merge. | |
126 | */ | |
127 | static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, | |
128 | struct nfs4_layoutget_res *lgr, | |
129 | gfp_t gfp_flags) | |
155e7524 | 130 | { |
a60d2ebd FI |
131 | struct pnfs_layout_segment *lseg; |
132 | int status; | |
133 | ||
134 | dprintk("%s enter\n", __func__); | |
135 | lseg = kzalloc(sizeof(*lseg), gfp_flags); | |
136 | if (!lseg) | |
137 | return ERR_PTR(-ENOMEM); | |
138 | status = nfs4_blk_process_layoutget(lo, lgr, gfp_flags); | |
139 | if (status) { | |
140 | /* We don't want to call the full-blown bl_free_lseg, | |
141 | * since on error extents were not touched. | |
142 | */ | |
143 | kfree(lseg); | |
144 | return ERR_PTR(status); | |
145 | } | |
146 | return lseg; | |
155e7524 FI |
147 | } |
148 | ||
149 | static void | |
150 | bl_encode_layoutcommit(struct pnfs_layout_hdr *lo, struct xdr_stream *xdr, | |
151 | const struct nfs4_layoutcommit_args *arg) | |
152 | { | |
153 | } | |
154 | ||
155 | static void | |
156 | bl_cleanup_layoutcommit(struct nfs4_layoutcommit_data *lcdata) | |
157 | { | |
158 | } | |
159 | ||
160 | static int | |
161 | bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh) | |
162 | { | |
163 | dprintk("%s enter\n", __func__); | |
164 | return 0; | |
165 | } | |
166 | ||
167 | static int | |
168 | bl_clear_layoutdriver(struct nfs_server *server) | |
169 | { | |
170 | dprintk("%s enter\n", __func__); | |
171 | return 0; | |
172 | } | |
173 | ||
e9643fe8 BH |
174 | static const struct nfs_pageio_ops bl_pg_read_ops = { |
175 | .pg_init = pnfs_generic_pg_init_read, | |
176 | .pg_test = pnfs_generic_pg_test, | |
177 | .pg_doio = pnfs_generic_pg_readpages, | |
178 | }; | |
179 | ||
180 | static const struct nfs_pageio_ops bl_pg_write_ops = { | |
181 | .pg_init = pnfs_generic_pg_init_write, | |
182 | .pg_test = pnfs_generic_pg_test, | |
183 | .pg_doio = pnfs_generic_pg_writepages, | |
184 | }; | |
185 | ||
155e7524 FI |
186 | static struct pnfs_layoutdriver_type blocklayout_type = { |
187 | .id = LAYOUT_BLOCK_VOLUME, | |
188 | .name = "LAYOUT_BLOCK_VOLUME", | |
189 | .read_pagelist = bl_read_pagelist, | |
190 | .write_pagelist = bl_write_pagelist, | |
191 | .alloc_layout_hdr = bl_alloc_layout_hdr, | |
192 | .free_layout_hdr = bl_free_layout_hdr, | |
193 | .alloc_lseg = bl_alloc_lseg, | |
194 | .free_lseg = bl_free_lseg, | |
195 | .encode_layoutcommit = bl_encode_layoutcommit, | |
196 | .cleanup_layoutcommit = bl_cleanup_layoutcommit, | |
197 | .set_layoutdriver = bl_set_layoutdriver, | |
198 | .clear_layoutdriver = bl_clear_layoutdriver, | |
e9643fe8 BH |
199 | .pg_read_ops = &bl_pg_read_ops, |
200 | .pg_write_ops = &bl_pg_write_ops, | |
155e7524 FI |
201 | }; |
202 | ||
fe0a9b74 JR |
203 | static const struct rpc_pipe_ops bl_upcall_ops = { |
204 | .upcall = bl_pipe_upcall, | |
205 | .downcall = bl_pipe_downcall, | |
206 | .destroy_msg = bl_pipe_destroy_msg, | |
207 | }; | |
208 | ||
155e7524 FI |
209 | static int __init nfs4blocklayout_init(void) |
210 | { | |
fe0a9b74 JR |
211 | struct vfsmount *mnt; |
212 | struct path path; | |
155e7524 FI |
213 | int ret; |
214 | ||
215 | dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__); | |
216 | ||
217 | ret = pnfs_register_layoutdriver(&blocklayout_type); | |
fe0a9b74 JR |
218 | if (ret) |
219 | goto out; | |
220 | ||
221 | init_waitqueue_head(&bl_wq); | |
222 | ||
223 | mnt = rpc_get_mount(); | |
224 | if (IS_ERR(mnt)) { | |
225 | ret = PTR_ERR(mnt); | |
226 | goto out_remove; | |
227 | } | |
228 | ||
229 | ret = vfs_path_lookup(mnt->mnt_root, | |
230 | mnt, | |
231 | NFS_PIPE_DIRNAME, 0, &path); | |
232 | if (ret) | |
233 | goto out_remove; | |
234 | ||
235 | bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL, | |
236 | &bl_upcall_ops, 0); | |
237 | if (IS_ERR(bl_device_pipe)) { | |
238 | ret = PTR_ERR(bl_device_pipe); | |
239 | goto out_remove; | |
240 | } | |
241 | out: | |
242 | return ret; | |
243 | ||
244 | out_remove: | |
245 | pnfs_unregister_layoutdriver(&blocklayout_type); | |
155e7524 FI |
246 | return ret; |
247 | } | |
248 | ||
249 | static void __exit nfs4blocklayout_exit(void) | |
250 | { | |
251 | dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n", | |
252 | __func__); | |
253 | ||
254 | pnfs_unregister_layoutdriver(&blocklayout_type); | |
fe0a9b74 | 255 | rpc_unlink(bl_device_pipe); |
155e7524 FI |
256 | } |
257 | ||
258 | MODULE_ALIAS("nfs-layouttype4-3"); | |
259 | ||
260 | module_init(nfs4blocklayout_init); | |
261 | module_exit(nfs4blocklayout_exit); |