Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 1 | /* |
| 2 | * pNFS Objects layout implementation over open-osd initiator library |
| 3 | * |
| 4 | * Copyright (C) 2009 Panasas Inc. [year of first publication] |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Benny Halevy <bhalevy@panasas.com> |
| 8 | * Boaz Harrosh <bharrosh@panasas.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 |
| 12 | * See the file COPYING included with this distribution for more details. |
| 13 | * |
| 14 | * Redistribution and use in source and binary forms, with or without |
| 15 | * modification, are permitted provided that the following conditions |
| 16 | * are met: |
| 17 | * |
| 18 | * 1. Redistributions of source code must retain the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer. |
| 20 | * 2. Redistributions in binary form must reproduce the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer in the |
| 22 | * documentation and/or other materials provided with the distribution. |
| 23 | * 3. Neither the name of the Panasas company nor the names of its |
| 24 | * contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 30 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 34 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 35 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 36 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 37 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | */ |
| 39 | |
| 40 | #include <linux/module.h> |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 41 | #include <scsi/osd_ore.h> |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 42 | |
| 43 | #include "objlayout.h" |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 44 | #include "../internal.h" |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 45 | |
| 46 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 47 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 48 | struct objio_dev_ent { |
| 49 | struct nfs4_deviceid_node id_node; |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 50 | struct ore_dev od; |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static void |
| 54 | objio_free_deviceid_node(struct nfs4_deviceid_node *d) |
| 55 | { |
| 56 | struct objio_dev_ent *de = container_of(d, struct objio_dev_ent, id_node); |
| 57 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 58 | dprintk("%s: free od=%p\n", __func__, de->od.od); |
| 59 | osduld_put_device(de->od.od); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 60 | kfree(de); |
| 61 | } |
| 62 | |
| 63 | static struct objio_dev_ent *_dev_list_find(const struct nfs_server *nfss, |
| 64 | const struct nfs4_deviceid *d_id) |
| 65 | { |
| 66 | struct nfs4_deviceid_node *d; |
| 67 | struct objio_dev_ent *de; |
| 68 | |
| 69 | d = nfs4_find_get_deviceid(nfss->pnfs_curr_ld, nfss->nfs_client, d_id); |
| 70 | if (!d) |
| 71 | return NULL; |
| 72 | |
| 73 | de = container_of(d, struct objio_dev_ent, id_node); |
| 74 | return de; |
| 75 | } |
| 76 | |
| 77 | static struct objio_dev_ent * |
| 78 | _dev_list_add(const struct nfs_server *nfss, |
| 79 | const struct nfs4_deviceid *d_id, struct osd_dev *od, |
| 80 | gfp_t gfp_flags) |
| 81 | { |
| 82 | struct nfs4_deviceid_node *d; |
| 83 | struct objio_dev_ent *de = kzalloc(sizeof(*de), gfp_flags); |
| 84 | struct objio_dev_ent *n; |
| 85 | |
| 86 | if (!de) { |
| 87 | dprintk("%s: -ENOMEM od=%p\n", __func__, od); |
| 88 | return NULL; |
| 89 | } |
| 90 | |
| 91 | dprintk("%s: Adding od=%p\n", __func__, od); |
| 92 | nfs4_init_deviceid_node(&de->id_node, |
| 93 | nfss->pnfs_curr_ld, |
| 94 | nfss->nfs_client, |
| 95 | d_id); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 96 | de->od.od = od; |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 97 | |
| 98 | d = nfs4_insert_deviceid_node(&de->id_node); |
| 99 | n = container_of(d, struct objio_dev_ent, id_node); |
| 100 | if (n != de) { |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 101 | dprintk("%s: Race with other n->od=%p\n", __func__, n->od.od); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 102 | objio_free_deviceid_node(&de->id_node); |
| 103 | de = n; |
| 104 | } |
| 105 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 106 | return de; |
| 107 | } |
| 108 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 109 | struct objio_segment { |
| 110 | struct pnfs_layout_segment lseg; |
| 111 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 112 | struct ore_layout layout; |
| 113 | struct ore_components oc; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static inline struct objio_segment * |
| 117 | OBJIO_LSEG(struct pnfs_layout_segment *lseg) |
| 118 | { |
| 119 | return container_of(lseg, struct objio_segment, lseg); |
| 120 | } |
| 121 | |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 122 | struct objio_state { |
| 123 | /* Generic layer */ |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 124 | struct objlayout_io_res oir; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 125 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 126 | bool sync; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 127 | /*FIXME: Support for extra_bytes at ore_get_rw_state() */ |
| 128 | struct ore_io_state *ios; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 129 | }; |
| 130 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 131 | /* Send and wait for a get_device_info of devices in the layout, |
| 132 | then look them up with the osd_initiator library */ |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 133 | static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay, |
| 134 | struct objio_segment *objio_seg, unsigned c, struct nfs4_deviceid *d_id, |
| 135 | gfp_t gfp_flags) |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 136 | { |
| 137 | struct pnfs_osd_deviceaddr *deviceaddr; |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 138 | struct objio_dev_ent *ode; |
| 139 | struct osd_dev *od; |
| 140 | struct osd_dev_info odi; |
Sachin Bhamare | 18d98f6 | 2012-03-19 20:47:58 -0700 | [diff] [blame] | 141 | bool retry_flag = true; |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 142 | int err; |
| 143 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 144 | ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 145 | if (ode) { |
| 146 | objio_seg->oc.ods[c] = &ode->od; /* must use container_of */ |
| 147 | return 0; |
| 148 | } |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 149 | |
| 150 | err = objlayout_get_deviceinfo(pnfslay, d_id, &deviceaddr, gfp_flags); |
| 151 | if (unlikely(err)) { |
| 152 | dprintk("%s: objlayout_get_deviceinfo dev(%llx:%llx) =>%d\n", |
| 153 | __func__, _DEVID_LO(d_id), _DEVID_HI(d_id), err); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 154 | return err; |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | odi.systemid_len = deviceaddr->oda_systemid.len; |
| 158 | if (odi.systemid_len > sizeof(odi.systemid)) { |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 159 | dprintk("%s: odi.systemid_len > sizeof(systemid=%zd)\n", |
| 160 | __func__, sizeof(odi.systemid)); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 161 | err = -EINVAL; |
| 162 | goto out; |
| 163 | } else if (odi.systemid_len) |
| 164 | memcpy(odi.systemid, deviceaddr->oda_systemid.data, |
| 165 | odi.systemid_len); |
| 166 | odi.osdname_len = deviceaddr->oda_osdname.len; |
| 167 | odi.osdname = (u8 *)deviceaddr->oda_osdname.data; |
| 168 | |
| 169 | if (!odi.osdname_len && !odi.systemid_len) { |
| 170 | dprintk("%s: !odi.osdname_len && !odi.systemid_len\n", |
| 171 | __func__); |
| 172 | err = -ENODEV; |
| 173 | goto out; |
| 174 | } |
| 175 | |
Sachin Bhamare | 18d98f6 | 2012-03-19 20:47:58 -0700 | [diff] [blame] | 176 | retry_lookup: |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 177 | od = osduld_info_lookup(&odi); |
| 178 | if (unlikely(IS_ERR(od))) { |
| 179 | err = PTR_ERR(od); |
| 180 | dprintk("%s: osduld_info_lookup => %d\n", __func__, err); |
Sachin Bhamare | 18d98f6 | 2012-03-19 20:47:58 -0700 | [diff] [blame] | 181 | if (err == -ENODEV && retry_flag) { |
| 182 | err = objlayout_autologin(deviceaddr); |
| 183 | if (likely(!err)) { |
| 184 | retry_flag = false; |
| 185 | goto retry_lookup; |
| 186 | } |
| 187 | } |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 188 | goto out; |
| 189 | } |
| 190 | |
| 191 | ode = _dev_list_add(NFS_SERVER(pnfslay->plh_inode), d_id, od, |
| 192 | gfp_flags); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 193 | objio_seg->oc.ods[c] = &ode->od; /* must use container_of */ |
| 194 | dprintk("Adding new dev_id(%llx:%llx)\n", |
| 195 | _DEVID_LO(d_id), _DEVID_HI(d_id)); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 196 | out: |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 197 | objlayout_put_deviceinfo(deviceaddr); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 198 | return err; |
| 199 | } |
| 200 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 201 | static void copy_single_comp(struct ore_components *oc, unsigned c, |
| 202 | struct pnfs_osd_object_cred *src_comp) |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 203 | { |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 204 | struct ore_comp *ocomp = &oc->comps[c]; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 205 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 206 | WARN_ON(src_comp->oc_cap_key.cred_len > 0); /* libosd is NO_SEC only */ |
| 207 | WARN_ON(src_comp->oc_cap.cred_len > sizeof(ocomp->cred)); |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 208 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 209 | ocomp->obj.partition = src_comp->oc_object_id.oid_partition_id; |
| 210 | ocomp->obj.id = src_comp->oc_object_id.oid_object_id; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 211 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 212 | memcpy(ocomp->cred, src_comp->oc_cap.cred, sizeof(ocomp->cred)); |
| 213 | } |
| 214 | |
Trond Myklebust | 1385b81 | 2012-05-04 13:54:24 -0400 | [diff] [blame] | 215 | static int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags, |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 216 | struct objio_segment **pseg) |
| 217 | { |
Boaz Harrosh | 5318a29c | 2012-03-13 20:44:26 -0700 | [diff] [blame] | 218 | /* This is the in memory structure of the objio_segment |
| 219 | * |
| 220 | * struct __alloc_objio_segment { |
| 221 | * struct objio_segment olseg; |
| 222 | * struct ore_dev *ods[numdevs]; |
| 223 | * struct ore_comp comps[numdevs]; |
| 224 | * } *aolseg; |
| 225 | * NOTE: The code as above compiles and runs perfectly. It is elegant, |
| 226 | * type safe and compact. At some Past time Linus has decided he does not |
| 227 | * like variable length arrays, For the sake of this principal we uglify |
| 228 | * the code as below. |
| 229 | */ |
| 230 | struct objio_segment *lseg; |
| 231 | size_t lseg_size = sizeof(*lseg) + |
| 232 | numdevs * sizeof(lseg->oc.ods[0]) + |
| 233 | numdevs * sizeof(*lseg->oc.comps); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 234 | |
Boaz Harrosh | 5318a29c | 2012-03-13 20:44:26 -0700 | [diff] [blame] | 235 | lseg = kzalloc(lseg_size, gfp_flags); |
| 236 | if (unlikely(!lseg)) { |
Masanari Iida | a895d57 | 2013-04-09 02:06:50 +0900 | [diff] [blame] | 237 | dprintk("%s: Failed allocation numdevs=%d size=%zd\n", __func__, |
Boaz Harrosh | 5318a29c | 2012-03-13 20:44:26 -0700 | [diff] [blame] | 238 | numdevs, lseg_size); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 239 | return -ENOMEM; |
| 240 | } |
| 241 | |
Boaz Harrosh | 5318a29c | 2012-03-13 20:44:26 -0700 | [diff] [blame] | 242 | lseg->oc.numdevs = numdevs; |
| 243 | lseg->oc.single_comp = EC_MULTPLE_COMPS; |
| 244 | lseg->oc.ods = (void *)(lseg + 1); |
| 245 | lseg->oc.comps = (void *)(lseg->oc.ods + numdevs); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 246 | |
Boaz Harrosh | 5318a29c | 2012-03-13 20:44:26 -0700 | [diff] [blame] | 247 | *pseg = lseg; |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 248 | return 0; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | int objio_alloc_lseg(struct pnfs_layout_segment **outp, |
| 252 | struct pnfs_layout_hdr *pnfslay, |
| 253 | struct pnfs_layout_range *range, |
| 254 | struct xdr_stream *xdr, |
| 255 | gfp_t gfp_flags) |
| 256 | { |
| 257 | struct objio_segment *objio_seg; |
| 258 | struct pnfs_osd_xdr_decode_layout_iter iter; |
| 259 | struct pnfs_osd_layout layout; |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 260 | struct pnfs_osd_object_cred src_comp; |
| 261 | unsigned cur_comp; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 262 | int err; |
| 263 | |
| 264 | err = pnfs_osd_xdr_decode_layout_map(&layout, &iter, xdr); |
| 265 | if (unlikely(err)) |
| 266 | return err; |
| 267 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 268 | err = __alloc_objio_seg(layout.olo_num_comps, gfp_flags, &objio_seg); |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 269 | if (unlikely(err)) |
| 270 | return err; |
| 271 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 272 | objio_seg->layout.stripe_unit = layout.olo_map.odm_stripe_unit; |
| 273 | objio_seg->layout.group_width = layout.olo_map.odm_group_width; |
| 274 | objio_seg->layout.group_depth = layout.olo_map.odm_group_depth; |
| 275 | objio_seg->layout.mirrors_p1 = layout.olo_map.odm_mirror_cnt + 1; |
| 276 | objio_seg->layout.raid_algorithm = layout.olo_map.odm_raid_algorithm; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 277 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 278 | err = ore_verify_layout(layout.olo_map.odm_num_comps, |
| 279 | &objio_seg->layout); |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 280 | if (unlikely(err)) |
| 281 | goto err; |
| 282 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 283 | objio_seg->oc.first_dev = layout.olo_comps_index; |
| 284 | cur_comp = 0; |
| 285 | while (pnfs_osd_xdr_decode_layout_comp(&src_comp, &iter, xdr, &err)) { |
| 286 | copy_single_comp(&objio_seg->oc, cur_comp, &src_comp); |
| 287 | err = objio_devices_lookup(pnfslay, objio_seg, cur_comp, |
| 288 | &src_comp.oc_object_id.oid_device_id, |
| 289 | gfp_flags); |
| 290 | if (err) |
| 291 | goto err; |
| 292 | ++cur_comp; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 293 | } |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 294 | /* pnfs_osd_xdr_decode_layout_comp returns false on error */ |
| 295 | if (unlikely(err)) |
| 296 | goto err; |
Boaz Harrosh | 9342077 | 2011-05-25 21:25:29 +0300 | [diff] [blame] | 297 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 298 | *outp = &objio_seg->lseg; |
| 299 | return 0; |
| 300 | |
| 301 | err: |
| 302 | kfree(objio_seg); |
| 303 | dprintk("%s: Error: return %d\n", __func__, err); |
| 304 | *outp = NULL; |
| 305 | return err; |
| 306 | } |
| 307 | |
| 308 | void objio_free_lseg(struct pnfs_layout_segment *lseg) |
| 309 | { |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 310 | int i; |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 311 | struct objio_segment *objio_seg = OBJIO_LSEG(lseg); |
| 312 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 313 | for (i = 0; i < objio_seg->oc.numdevs; i++) { |
| 314 | struct ore_dev *od = objio_seg->oc.ods[i]; |
| 315 | struct objio_dev_ent *ode; |
| 316 | |
| 317 | if (!od) |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 318 | break; |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 319 | ode = container_of(od, typeof(*ode), od); |
| 320 | nfs4_put_deviceid_node(&ode->id_node); |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 321 | } |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 322 | kfree(objio_seg); |
| 323 | } |
| 324 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 325 | static int |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 326 | objio_alloc_io_state(struct pnfs_layout_hdr *pnfs_layout_type, bool is_reading, |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 327 | struct pnfs_layout_segment *lseg, struct page **pages, unsigned pgbase, |
| 328 | loff_t offset, size_t count, void *rpcdata, gfp_t gfp_flags, |
| 329 | struct objio_state **outp) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 330 | { |
| 331 | struct objio_segment *objio_seg = OBJIO_LSEG(lseg); |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 332 | struct ore_io_state *ios; |
| 333 | int ret; |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 334 | struct __alloc_objio_state { |
| 335 | struct objio_state objios; |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 336 | struct pnfs_osd_ioerr ioerrs[objio_seg->oc.numdevs]; |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 337 | } *aos; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 338 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 339 | aos = kzalloc(sizeof(*aos), gfp_flags); |
| 340 | if (unlikely(!aos)) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 341 | return -ENOMEM; |
| 342 | |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 343 | objlayout_init_ioerrs(&aos->objios.oir, objio_seg->oc.numdevs, |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 344 | aos->ioerrs, rpcdata, pnfs_layout_type); |
| 345 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 346 | ret = ore_get_rw_state(&objio_seg->layout, &objio_seg->oc, is_reading, |
| 347 | offset, count, &ios); |
| 348 | if (unlikely(ret)) { |
| 349 | kfree(aos); |
| 350 | return ret; |
| 351 | } |
| 352 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 353 | ios->pages = pages; |
| 354 | ios->pgbase = pgbase; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 355 | ios->private = aos; |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 356 | BUG_ON(ios->nr_pages > (pgbase + count + PAGE_SIZE - 1) >> PAGE_SHIFT); |
| 357 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 358 | aos->objios.sync = 0; |
| 359 | aos->objios.ios = ios; |
| 360 | *outp = &aos->objios; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 361 | return 0; |
| 362 | } |
| 363 | |
Boaz Harrosh | e2e0435 | 2011-10-31 15:03:35 -0700 | [diff] [blame] | 364 | void objio_free_result(struct objlayout_io_res *oir) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 365 | { |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 366 | struct objio_state *objios = container_of(oir, struct objio_state, oir); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 367 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 368 | ore_put_io_state(objios->ios); |
| 369 | kfree(objios); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 370 | } |
| 371 | |
Trond Myklebust | 2e928e4 | 2012-10-16 12:34:56 -0400 | [diff] [blame] | 372 | static enum pnfs_osd_errno osd_pri_2_pnfs_err(enum osd_err_priority oep) |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 373 | { |
| 374 | switch (oep) { |
| 375 | case OSD_ERR_PRI_NO_ERROR: |
| 376 | return (enum pnfs_osd_errno)0; |
| 377 | |
| 378 | case OSD_ERR_PRI_CLEAR_PAGES: |
| 379 | BUG_ON(1); |
| 380 | return 0; |
| 381 | |
| 382 | case OSD_ERR_PRI_RESOURCE: |
| 383 | return PNFS_OSD_ERR_RESOURCE; |
| 384 | case OSD_ERR_PRI_BAD_CRED: |
| 385 | return PNFS_OSD_ERR_BAD_CRED; |
| 386 | case OSD_ERR_PRI_NO_ACCESS: |
| 387 | return PNFS_OSD_ERR_NO_ACCESS; |
| 388 | case OSD_ERR_PRI_UNREACHABLE: |
| 389 | return PNFS_OSD_ERR_UNREACHABLE; |
| 390 | case OSD_ERR_PRI_NOT_FOUND: |
| 391 | return PNFS_OSD_ERR_NOT_FOUND; |
| 392 | case OSD_ERR_PRI_NO_SPACE: |
| 393 | return PNFS_OSD_ERR_NO_SPACE; |
| 394 | default: |
| 395 | WARN_ON(1); |
| 396 | /* fallthrough */ |
| 397 | case OSD_ERR_PRI_EIO: |
| 398 | return PNFS_OSD_ERR_EIO; |
| 399 | } |
| 400 | } |
| 401 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 402 | static void __on_dev_error(struct ore_io_state *ios, |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 403 | struct ore_dev *od, unsigned dev_index, enum osd_err_priority oep, |
| 404 | u64 dev_offset, u64 dev_len) |
| 405 | { |
| 406 | struct objio_state *objios = ios->private; |
| 407 | struct pnfs_osd_objid pooid; |
| 408 | struct objio_dev_ent *ode = container_of(od, typeof(*ode), od); |
| 409 | /* FIXME: what to do with more-then-one-group layouts. We need to |
| 410 | * translate from ore_io_state index to oc->comps index |
| 411 | */ |
| 412 | unsigned comp = dev_index; |
| 413 | |
| 414 | pooid.oid_device_id = ode->id_node.deviceid; |
| 415 | pooid.oid_partition_id = ios->oc->comps[comp].obj.partition; |
| 416 | pooid.oid_object_id = ios->oc->comps[comp].obj.id; |
| 417 | |
| 418 | objlayout_io_set_result(&objios->oir, comp, |
| 419 | &pooid, osd_pri_2_pnfs_err(oep), |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 420 | dev_offset, dev_len, !ios->reading); |
Boaz Harrosh | af4f5b5 | 2011-10-31 15:04:19 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 423 | /* |
| 424 | * read |
| 425 | */ |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 426 | static void _read_done(struct ore_io_state *ios, void *private) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 427 | { |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 428 | struct objio_state *objios = private; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 429 | ssize_t status; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 430 | int ret = ore_check_io(ios, &__on_dev_error); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 431 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 432 | /* FIXME: _io_free(ios) can we dealocate the libosd resources; */ |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 433 | |
| 434 | if (likely(!ret)) |
| 435 | status = ios->length; |
| 436 | else |
| 437 | status = ret; |
| 438 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 439 | objlayout_read_done(&objios->oir, status, objios->sync); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 440 | } |
| 441 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 442 | int objio_read_pagelist(struct nfs_read_data *rdata) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 443 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 444 | struct nfs_pgio_header *hdr = rdata->header; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 445 | struct objio_state *objios; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 446 | int ret; |
| 447 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 448 | ret = objio_alloc_io_state(NFS_I(hdr->inode)->layout, true, |
| 449 | hdr->lseg, rdata->args.pages, rdata->args.pgbase, |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 450 | rdata->args.offset, rdata->args.count, rdata, |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 451 | GFP_KERNEL, &objios); |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 452 | if (unlikely(ret)) |
| 453 | return ret; |
| 454 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 455 | objios->ios->done = _read_done; |
| 456 | dprintk("%s: offset=0x%llx length=0x%x\n", __func__, |
| 457 | rdata->args.offset, rdata->args.count); |
Boaz Harrosh | 9909d45 | 2012-06-08 05:29:40 +0300 | [diff] [blame] | 458 | ret = ore_read(objios->ios); |
| 459 | if (unlikely(ret)) |
| 460 | objio_free_result(&objios->oir); |
| 461 | return ret; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* |
| 465 | * write |
| 466 | */ |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 467 | static void _write_done(struct ore_io_state *ios, void *private) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 468 | { |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 469 | struct objio_state *objios = private; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 470 | ssize_t status; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 471 | int ret = ore_check_io(ios, &__on_dev_error); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 472 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 473 | /* FIXME: _io_free(ios) can we dealocate the libosd resources; */ |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 474 | |
| 475 | if (likely(!ret)) { |
| 476 | /* FIXME: should be based on the OSD's persistence model |
| 477 | * See OSD2r05 Section 4.13 Data persistence model */ |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 478 | objios->oir.committed = NFS_FILE_SYNC; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 479 | status = ios->length; |
| 480 | } else { |
| 481 | status = ret; |
| 482 | } |
| 483 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 484 | objlayout_write_done(&objios->oir, status, objios->sync); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 485 | } |
| 486 | |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 487 | static struct page *__r4w_get_page(void *priv, u64 offset, bool *uptodate) |
| 488 | { |
| 489 | struct objio_state *objios = priv; |
| 490 | struct nfs_write_data *wdata = objios->oir.rpcdata; |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 491 | struct address_space *mapping = wdata->header->inode->i_mapping; |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 492 | pgoff_t index = offset / PAGE_SIZE; |
Boaz Harrosh | c999ff6 | 2012-06-08 02:02:30 +0300 | [diff] [blame] | 493 | struct page *page; |
| 494 | loff_t i_size = i_size_read(wdata->header->inode); |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 495 | |
Boaz Harrosh | c999ff6 | 2012-06-08 02:02:30 +0300 | [diff] [blame] | 496 | if (offset >= i_size) { |
| 497 | *uptodate = true; |
| 498 | dprintk("%s: g_zero_page index=0x%lx\n", __func__, index); |
| 499 | return ZERO_PAGE(0); |
| 500 | } |
| 501 | |
| 502 | page = find_get_page(mapping, index); |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 503 | if (!page) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 504 | page = find_or_create_page(mapping, index, GFP_NOFS); |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 505 | if (unlikely(!page)) { |
| 506 | dprintk("%s: grab_cache_page Failed index=0x%lx\n", |
| 507 | __func__, index); |
| 508 | return NULL; |
| 509 | } |
| 510 | unlock_page(page); |
| 511 | } |
| 512 | if (PageDirty(page) || PageWriteback(page)) |
| 513 | *uptodate = true; |
| 514 | else |
| 515 | *uptodate = PageUptodate(page); |
| 516 | dprintk("%s: index=0x%lx uptodate=%d\n", __func__, index, *uptodate); |
| 517 | return page; |
| 518 | } |
| 519 | |
| 520 | static void __r4w_put_page(void *priv, struct page *page) |
| 521 | { |
Boaz Harrosh | c999ff6 | 2012-06-08 02:02:30 +0300 | [diff] [blame] | 522 | dprintk("%s: index=0x%lx\n", __func__, |
| 523 | (page == ZERO_PAGE(0)) ? -1UL : page->index); |
| 524 | if (ZERO_PAGE(0) != page) |
| 525 | page_cache_release(page); |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 526 | return; |
| 527 | } |
| 528 | |
| 529 | static const struct _ore_r4w_op _r4w_op = { |
| 530 | .get_page = &__r4w_get_page, |
| 531 | .put_page = &__r4w_put_page, |
| 532 | }; |
| 533 | |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 534 | int objio_write_pagelist(struct nfs_write_data *wdata, int how) |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 535 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 536 | struct nfs_pgio_header *hdr = wdata->header; |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 537 | struct objio_state *objios; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 538 | int ret; |
| 539 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 540 | ret = objio_alloc_io_state(NFS_I(hdr->inode)->layout, false, |
| 541 | hdr->lseg, wdata->args.pages, wdata->args.pgbase, |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 542 | wdata->args.offset, wdata->args.count, wdata, GFP_NOFS, |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 543 | &objios); |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 544 | if (unlikely(ret)) |
| 545 | return ret; |
| 546 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 547 | objios->sync = 0 != (how & FLUSH_SYNC); |
Boaz Harrosh | 278c023 | 2011-10-31 15:16:54 -0700 | [diff] [blame] | 548 | objios->ios->r4w = &_r4w_op; |
Boaz Harrosh | 9621855 | 2011-10-31 14:47:32 -0700 | [diff] [blame] | 549 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 550 | if (!objios->sync) |
| 551 | objios->ios->done = _write_done; |
| 552 | |
| 553 | dprintk("%s: offset=0x%llx length=0x%x\n", __func__, |
| 554 | wdata->args.offset, wdata->args.count); |
| 555 | ret = ore_write(objios->ios); |
Boaz Harrosh | 9909d45 | 2012-06-08 05:29:40 +0300 | [diff] [blame] | 556 | if (unlikely(ret)) { |
| 557 | objio_free_result(&objios->oir); |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 558 | return ret; |
Boaz Harrosh | 9909d45 | 2012-06-08 05:29:40 +0300 | [diff] [blame] | 559 | } |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 560 | |
Boaz Harrosh | eecfc63 | 2011-10-31 15:15:38 -0700 | [diff] [blame] | 561 | if (objios->sync) |
| 562 | _write_done(objios->ios, objios); |
| 563 | |
| 564 | return 0; |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 565 | } |
| 566 | |
Boaz Harrosh | 9342077 | 2011-05-25 21:25:29 +0300 | [diff] [blame] | 567 | static bool objio_pg_test(struct nfs_pageio_descriptor *pgio, |
| 568 | struct nfs_page *prev, struct nfs_page *req) |
| 569 | { |
| 570 | if (!pnfs_generic_pg_test(pgio, prev, req)) |
| 571 | return false; |
| 572 | |
| 573 | return pgio->pg_count + req->wb_bytes <= |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 574 | (unsigned long)pgio->pg_layout_private; |
| 575 | } |
| 576 | |
Trond Myklebust | 2e928e4 | 2012-10-16 12:34:56 -0400 | [diff] [blame] | 577 | static void objio_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 578 | { |
| 579 | pnfs_generic_pg_init_read(pgio, req); |
| 580 | if (unlikely(pgio->pg_lseg == NULL)) |
| 581 | return; /* Not pNFS */ |
| 582 | |
| 583 | pgio->pg_layout_private = (void *) |
| 584 | OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length; |
| 585 | } |
| 586 | |
| 587 | static bool aligned_on_raid_stripe(u64 offset, struct ore_layout *layout, |
| 588 | unsigned long *stripe_end) |
| 589 | { |
| 590 | u32 stripe_off; |
| 591 | unsigned stripe_size; |
| 592 | |
| 593 | if (layout->raid_algorithm == PNFS_OSD_RAID_0) |
| 594 | return true; |
| 595 | |
| 596 | stripe_size = layout->stripe_unit * |
| 597 | (layout->group_width - layout->parity); |
| 598 | |
| 599 | div_u64_rem(offset, stripe_size, &stripe_off); |
| 600 | if (!stripe_off) |
| 601 | return true; |
| 602 | |
| 603 | *stripe_end = stripe_size - stripe_off; |
| 604 | return false; |
| 605 | } |
| 606 | |
Trond Myklebust | 2e928e4 | 2012-10-16 12:34:56 -0400 | [diff] [blame] | 607 | static void objio_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 608 | { |
| 609 | unsigned long stripe_end = 0; |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 610 | u64 wb_size; |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 611 | |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 612 | if (pgio->pg_dreq == NULL) |
| 613 | wb_size = i_size_read(pgio->pg_inode) - req_offset(req); |
| 614 | else |
| 615 | wb_size = nfs_dreq_bytes_left(pgio->pg_dreq); |
| 616 | |
| 617 | pnfs_generic_pg_init_write(pgio, req, wb_size); |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 618 | if (unlikely(pgio->pg_lseg == NULL)) |
| 619 | return; /* Not pNFS */ |
| 620 | |
| 621 | if (req->wb_offset || |
| 622 | !aligned_on_raid_stripe(req->wb_index * PAGE_SIZE, |
| 623 | &OBJIO_LSEG(pgio->pg_lseg)->layout, |
| 624 | &stripe_end)) { |
| 625 | pgio->pg_layout_private = (void *)stripe_end; |
| 626 | } else { |
| 627 | pgio->pg_layout_private = (void *) |
| 628 | OBJIO_LSEG(pgio->pg_lseg)->layout.max_io_length; |
| 629 | } |
Boaz Harrosh | 9342077 | 2011-05-25 21:25:29 +0300 | [diff] [blame] | 630 | } |
| 631 | |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 632 | static const struct nfs_pageio_ops objio_pg_read_ops = { |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 633 | .pg_init = objio_init_read, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 634 | .pg_test = objio_pg_test, |
Trond Myklebust | 493292d | 2011-07-13 15:58:28 -0400 | [diff] [blame] | 635 | .pg_doio = pnfs_generic_pg_readpages, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | static const struct nfs_pageio_ops objio_pg_write_ops = { |
Boaz Harrosh | 7de6e28 | 2012-08-02 15:38:23 +0300 | [diff] [blame] | 639 | .pg_init = objio_init_write, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 640 | .pg_test = objio_pg_test, |
Trond Myklebust | dce8129 | 2011-07-13 15:59:19 -0400 | [diff] [blame] | 641 | .pg_doio = pnfs_generic_pg_writepages, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 642 | }; |
| 643 | |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 644 | static struct pnfs_layoutdriver_type objlayout_type = { |
| 645 | .id = LAYOUT_OSD2_OBJECTS, |
| 646 | .name = "LAYOUT_OSD2_OBJECTS", |
Boaz Harrosh | fe0fe83 | 2012-01-06 09:31:20 +0200 | [diff] [blame] | 647 | .flags = PNFS_LAYOUTRET_ON_SETATTR | |
| 648 | PNFS_LAYOUTRET_ON_ERROR, |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 649 | |
fanchaoting | 5a12cca | 2013-02-04 21:15:02 +0800 | [diff] [blame] | 650 | .owner = THIS_MODULE, |
Benny Halevy | e51b841 | 2011-05-22 19:51:48 +0300 | [diff] [blame] | 651 | .alloc_layout_hdr = objlayout_alloc_layout_hdr, |
| 652 | .free_layout_hdr = objlayout_free_layout_hdr, |
| 653 | |
Boaz Harrosh | 09f5bf4 | 2011-05-22 19:50:20 +0300 | [diff] [blame] | 654 | .alloc_lseg = objlayout_alloc_lseg, |
| 655 | .free_lseg = objlayout_free_lseg, |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 656 | |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 657 | .read_pagelist = objlayout_read_pagelist, |
| 658 | .write_pagelist = objlayout_write_pagelist, |
Trond Myklebust | 1751c36 | 2011-06-10 13:30:23 -0400 | [diff] [blame] | 659 | .pg_read_ops = &objio_pg_read_ops, |
| 660 | .pg_write_ops = &objio_pg_write_ops, |
Boaz Harrosh | 04f8345 | 2011-05-22 19:52:19 +0300 | [diff] [blame] | 661 | |
Boaz Harrosh | b6c05f1 | 2011-05-26 21:45:34 +0300 | [diff] [blame] | 662 | .free_deviceid_node = objio_free_deviceid_node, |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 663 | |
Boaz Harrosh | a0fe8bf | 2011-05-22 19:54:13 +0300 | [diff] [blame] | 664 | .encode_layoutcommit = objlayout_encode_layoutcommit, |
Boaz Harrosh | adb5853 | 2011-05-26 21:49:46 +0300 | [diff] [blame] | 665 | .encode_layoutreturn = objlayout_encode_layoutreturn, |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | MODULE_DESCRIPTION("pNFS Layout Driver for OSD2 objects"); |
| 669 | MODULE_AUTHOR("Benny Halevy <bhalevy@panasas.com>"); |
| 670 | MODULE_LICENSE("GPL"); |
| 671 | |
| 672 | static int __init |
| 673 | objlayout_init(void) |
| 674 | { |
| 675 | int ret = pnfs_register_layoutdriver(&objlayout_type); |
| 676 | |
| 677 | if (ret) |
| 678 | printk(KERN_INFO |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 679 | "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n", |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 680 | __func__, ret); |
| 681 | else |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 682 | printk(KERN_INFO "NFS: %s: Registered OSD pNFS Layout Driver\n", |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 683 | __func__); |
| 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | static void __exit |
| 688 | objlayout_exit(void) |
| 689 | { |
| 690 | pnfs_unregister_layoutdriver(&objlayout_type); |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 691 | printk(KERN_INFO "NFS: %s: Unregistered OSD pNFS Layout Driver\n", |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 692 | __func__); |
| 693 | } |
| 694 | |
J. Bruce Fields | f85ef69 | 2011-07-15 19:18:42 -0400 | [diff] [blame] | 695 | MODULE_ALIAS("nfs-layouttype4-2"); |
| 696 | |
Benny Halevy | c93407d | 2011-05-22 19:49:06 +0300 | [diff] [blame] | 697 | module_init(objlayout_init); |
| 698 | module_exit(objlayout_exit); |