40 #include <linux/module.h>
44 #include "../internal.h"
46 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
54 objio_free_deviceid_node(
struct nfs4_deviceid_node *
d)
58 dprintk(
"%s: free od=%p\n", __func__, de->
od.od);
66 struct nfs4_deviceid_node *
d;
82 struct nfs4_deviceid_node *
d;
87 dprintk(
"%s: -ENOMEM od=%p\n", __func__, od);
91 dprintk(
"%s: Adding od=%p\n", __func__, od);
101 dprintk(
"%s: Race with other n->od=%p\n", __func__, n->
od.od);
102 objio_free_deviceid_node(&de->
id_node);
133 static int objio_devices_lookup(
struct pnfs_layout_hdr *pnfslay,
141 bool retry_flag =
true;
144 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
146 objio_seg->
oc.ods[
c] = &ode->
od;
152 dprintk(
"%s: objlayout_get_deviceinfo dev(%llx:%llx) =>%d\n",
159 dprintk(
"%s: odi.systemid_len > sizeof(systemid=%zd)\n",
170 dprintk(
"%s: !odi.osdname_len && !odi.systemid_len\n",
180 dprintk(
"%s: osduld_info_lookup => %d\n", __func__, err);
181 if (err == -
ENODEV && retry_flag) {
191 ode = _dev_list_add(NFS_SERVER(pnfslay->plh_inode), d_id, od,
193 objio_seg->
oc.ods[
c] = &ode->
od;
194 dprintk(
"Adding new dev_id(%llx:%llx)\n",
201 static void copy_single_comp(
struct ore_components *oc,
unsigned c,
215 static int __alloc_objio_seg(
unsigned numdevs,
gfp_t gfp_flags,
231 size_t lseg_size =
sizeof(*lseg) +
232 numdevs *
sizeof(lseg->
oc.ods[0]) +
233 numdevs *
sizeof(*lseg->
oc.comps);
235 lseg = kzalloc(lseg_size, gfp_flags);
237 dprintk(
"%s: Faild allocation numdevs=%d size=%zd\n", __func__,
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);
252 struct pnfs_layout_hdr *pnfslay,
254 struct xdr_stream *xdr,
268 err = __alloc_objio_seg(layout.
olo_num_comps, gfp_flags, &objio_seg);
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;
286 copy_single_comp(&objio_seg->
oc, cur_comp, &src_comp);
287 err = objio_devices_lookup(pnfslay, objio_seg, cur_comp,
298 *outp = &objio_seg->
lseg;
303 dprintk(
"%s: Error: return %d\n", __func__, err);
313 for (i = 0; i < objio_seg->
oc.numdevs; i++) {
326 objio_alloc_io_state(
struct pnfs_layout_hdr *pnfs_layout_type,
bool is_reading,
334 struct __alloc_objio_state {
339 aos = kzalloc(
sizeof(*aos), gfp_flags);
343 objlayout_init_ioerrs(&aos->objios.oir, objio_seg->
oc.numdevs,
344 aos->ioerrs, rpcdata, pnfs_layout_type);
347 offset, count, &ios);
358 aos->objios.sync = 0;
359 aos->objios.ios = ios;
360 *outp = &aos->objios;
404 u64 dev_offset,
u64 dev_len)
412 unsigned comp = dev_index;
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;
419 &pooid, osd_pri_2_pnfs_err(oep),
420 dev_offset, dev_len, !ios->
reading);
426 static void _read_done(
struct ore_io_state *ios,
void *
private)
448 ret = objio_alloc_io_state(NFS_I(hdr->
inode)->layout,
true,
450 rdata->
args.offset, rdata->
args.count, rdata,
455 objios->
ios->done = _read_done;
456 dprintk(
"%s: offset=0x%llx length=0x%x\n", __func__,
457 rdata->
args.offset, rdata->
args.count);
467 static void _write_done(
struct ore_io_state *ios,
void *
private)
487 static struct page *__r4w_get_page(
void *
priv,
u64 offset,
bool *uptodate)
494 loff_t i_size = i_size_read(wdata->
header->inode);
496 if (offset >= i_size) {
498 dprintk(
"%s: g_zero_page index=0x%lx\n", __func__, index);
506 dprintk(
"%s: grab_cache_page Failed index=0x%lx\n",
512 if (PageDirty(page) || PageWriteback(page))
515 *uptodate = PageUptodate(page);
516 dprintk(
"%s: index=0x%lx uptodate=%d\n", __func__, index, *uptodate);
520 static void __r4w_put_page(
void *priv,
struct page *page)
522 dprintk(
"%s: index=0x%lx\n", __func__,
530 .get_page = &__r4w_get_page,
531 .put_page = &__r4w_put_page,
540 ret = objio_alloc_io_state(NFS_I(hdr->
inode)->layout,
false,
548 objios->
ios->r4w = &_r4w_op;
551 objios->
ios->done = _write_done;
553 dprintk(
"%s: offset=0x%llx length=0x%x\n", __func__,
554 wdata->
args.offset, wdata->
args.count);
562 _write_done(objios->
ios, objios);
584 OBJIO_LSEG(pgio->
pg_lseg)->layout.max_io_length;
588 unsigned long *stripe_end)
599 div_u64_rem(offset, stripe_size, &stripe_off);
603 *stripe_end = stripe_size - stripe_off;
609 unsigned long stripe_end = 0;
613 wb_size = i_size_read(pgio->
pg_inode) - req_offset(req);
623 &OBJIO_LSEG(pgio->
pg_lseg)->layout,
628 OBJIO_LSEG(pgio->
pg_lseg)->layout.max_io_length;
633 .pg_init = objio_init_read,
634 .pg_test = objio_pg_test,
639 .pg_init = objio_init_write,
640 .pg_test = objio_pg_test,
644 static struct pnfs_layoutdriver_type objlayout_type = {
646 .name =
"LAYOUT_OSD2_OBJECTS",
647 .flags = PNFS_LAYOUTRET_ON_SETATTR |
648 PNFS_LAYOUTRET_ON_ERROR,
658 .pg_read_ops = &objio_pg_read_ops,
659 .pg_write_ops = &objio_pg_write_ops,
661 .free_deviceid_node = objio_free_deviceid_node,
678 "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n",