From 46c67ec622e27ff7ade170dba9005f08e1573bcf Mon Sep 17 00:00:00 2001 From: nikita Date: Tue, 25 Jul 2006 20:42:43 +0000 Subject: [PATCH] osd: implement (trivial) ->dt_body_operaions --- lustre/include/dt_object.h | 14 +++---- lustre/mdd/mdd_lov.c | 15 ++++---- lustre/mdt/mdt_fs.c | 7 ++-- lustre/osd/osd_handler.c | 94 ++++++++++++++++++++++++++++++++++++---------- lustre/osd/osd_internal.h | 4 ++ 5 files changed, 95 insertions(+), 39 deletions(-) diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index a4a12ff..2ae1320 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -242,18 +242,14 @@ struct dt_body_operations { /* * precondition: lu_object_exists(ctxt, &dt->do_lu); */ - int (*dbo_read)(const struct lu_context *ctxt, - struct dt_object *dt, ...); + ssize_t (*dbo_read)(const struct lu_context *ctxt, struct dt_object *dt, + char *buf, size_t count, loff_t *pos); /* * precondition: lu_object_exists(ctxt, &dt->do_lu); */ - int (*dbo_write)(const struct lu_context *ctxt, - struct dt_object *dt, ...); - /* - * precondition: lu_object_exists(ctxt, &dt->do_lu); - */ - int (*dbo_truncate)(const struct lu_context *ctxt, - struct dt_object *dt, ...); + ssize_t (*dbo_write)(const struct lu_context *ctxt, + struct dt_object *dt, const char *buf, + size_t count, loff_t *pos, struct thandle *handle); }; /* diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index 800a862..f4d2801 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -57,6 +57,7 @@ static int mdd_lov_read_objids(struct obd_device *obd, struct md_lov_info *mli, struct lu_attr *lu_attr = NULL; obd_id *ids; int i, rc; + loff_t off = 0; ENTRY; LASSERT(!mli->md_lov_objids_size); @@ -83,14 +84,13 @@ static int mdd_lov_read_objids(struct obd_device *obd, struct md_lov_info *mli, mli->md_lov_objids = ids; mli->md_lov_objids_size = lu_attr->la_size; -#if 0 - rc = obj_ids->do_body_ops->dbo_read(ctxt, obj_ids, ids, + rc = obj_ids->do_body_ops->dbo_read(ctxt, obj_ids, (char *)ids, lu_attr->la_size, &off); if (rc < 0) { CERROR("Error reading objids %d\n", rc); RETURN(rc); } -#endif + mli->md_lov_objids_in_file = lu_attr->la_size / sizeof(*ids); for (i = 0; i < mli->md_lov_objids_in_file; i++) { @@ -121,9 +121,10 @@ int mdd_lov_write_objids(struct obd_device *obd, struct md_lov_info *mli, CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n", mli->md_lov_objids[i], i); #if 0 - rc = ids_obj->do_body_ops->dbo_write(ctxt, ids_obj, - mli->mdd_lov_objids, - tgts * sizeof(obd_id), &off); + rc = ids_obj->do_body_ops->dbo_write(ctxt, obj_ids, + (char *)mli->mdd_lov_objids, + tgts * sizeof(obd_id), &off, + NULL /* XXX transaction handle */); if (rc >= 0) { mli->mdd_lov_objids_dirty = 0; rc = 0; @@ -145,7 +146,7 @@ static int mdd_lov_read_catlist(struct obd_device *obd, void *idarray, int size, RETURN(rc); } -struct md_lov_ops mdd_lov_ops = { +static struct md_lov_ops mdd_lov_ops = { .ml_read_objids = mdd_lov_read_objids, .ml_write_objids = mdd_lov_write_objids, .ml_read_catlist = mdd_lov_read_catlist, diff --git a/lustre/mdt/mdt_fs.c b/lustre/mdt/mdt_fs.c index 32db503..1bd5a50 100644 --- a/lustre/mdt/mdt_fs.c +++ b/lustre/mdt/mdt_fs.c @@ -89,12 +89,11 @@ int mdt_client_add(const struct lu_context *ctxt, if (new_client) { loff_t off = med->med_lr_off; int rc = 0; - /* rc = mdt->mdt_last->do_body_ops->dbo_write(ctxt, mdt->mdt_last, mcd, sizeof(*mcd), - &off); + &off, NULL); */ if (rc) return rc; @@ -121,7 +120,7 @@ int mdt_update_server_data(const struct lu_context *ctxt, rc = mdt->mdt_last->do_body_ops->dbo_write(ctxt, mdt->mdt_last, msd, - sizeof(*msd), &off); + sizeof(*msd), &off, NULL); */ RETURN(rc); @@ -165,7 +164,7 @@ int mdt_client_free(const struct lu_context *ctxt, rc = mdt->mdt_last->do_body_ops->dbo_write(ctxt, mdt->mdt_last, mcd, - sizeof(*mcd), &off); + sizeof(*mcd), &off, NULL); */ CDEBUG_EX(rc == 0 ? D_INFO : D_ERROR, "zeroing out client idx %u in %s rc %d\n", diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 77765db..8fac73b 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -370,7 +370,7 @@ static int osd_object_print(const struct lu_context *ctx, void *cookie, static int osd_statfs(const struct lu_context *ctx, struct dt_device *d, struct kstatfs *sfs) { - struct osd_device *osd = osd_dt_dev(d); + struct osd_device *osd = osd_dt_dev(d); struct super_block *sb = osd_sb(osd); int result; @@ -923,14 +923,14 @@ int osd_readpage(const struct lu_context *ctxt, it = iops->init(ctxt, dt); if (it == NULL) return -ENOMEM; - + rc = iops->get(ctxt, it, (const void *)""); if (rc > 0) { for (i = 0, tmpcount = rdpg->rp_count; i < rdpg->rp_npages; i++, tmpcount -= tmpsize) { struct lu_dir_entry *entry, *last; int page_space = PAGE_SIZE; - + tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount; entry = kmap(rdpg->rp_pages[i]); last = entry; @@ -949,16 +949,16 @@ int osd_readpage(const struct lu_context *ctxt, entry->de_fid = *fid; fid_cpu_to_le(&entry->de_fid); - + entry->de_name_len = cpu_to_le16(len + 1); entry->de_rec_len = cpu_to_le16(LU_DIR_REC_LEN(len + 1)); - + strncpy(entry->de_name, name, len); entry->de_name[len] = '\0'; page_space -= LU_DIR_REC_LEN(len + 1); last = entry; - + entry = (struct lu_dir_entry *)((char *)entry + LU_DIR_REC_LEN(len + 1)); } @@ -969,13 +969,13 @@ int osd_readpage(const struct lu_context *ctxt, kunmap(rdpg->rp_pages[i]); } iops->put(ctxt, it); - + rc = 0; } else if (rc == 0) { rc = -EIO; } iops->fini(ctxt, it); - + return rc; } @@ -994,7 +994,63 @@ static struct dt_object_operations osd_obj_ops = { .do_readpage = osd_readpage }; +/* + * Body operations. + */ + +static struct file *osd_rw_init(const struct lu_context *ctxt, + struct inode *inode, mm_segment_t *seg) +{ + struct osd_thread_info *info = lu_context_key_get(ctxt, &osd_key); + struct dentry *dentry = &info->oti_dentry; + struct file *file = &info->oti_file; + + file->f_dentry = dentry; + file->f_mapping = inode->i_mapping; + dentry->d_inode = inode; + + *seg = get_fs(); + set_fs(KERNEL_DS); + return file; +} + +static void osd_rw_fini(mm_segment_t *seg) +{ + set_fs(*seg); +} + +static ssize_t osd_read(const struct lu_context *ctxt, struct dt_object *dt, + char *buf, size_t count, loff_t *pos) +{ + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct file *file; + mm_segment_t seg; + ssize_t result; + + file = osd_rw_init(ctxt, inode, &seg); + result = inode->i_fop->read(file, buf, count, pos); + osd_rw_fini(&seg); + return result; +} + +static int osd_write(const struct lu_context *ctxt, struct dt_object *dt, + const char *buf, size_t count, loff_t *pos, + struct thandle *handle) +{ + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct file *file; + mm_segment_t seg; + ssize_t result; + + file = osd_rw_init(ctxt, inode, &seg); + result = inode->i_fop->write(file, buf, count, pos); + osd_rw_fini(&seg); + return result; +} + static struct dt_body_operations osd_body_ops = { + .dbo_read = osd_read, + .dbo_write = osd_write }; /* @@ -1542,7 +1598,7 @@ static struct lu_device *osd_device_fini(const struct lu_context *ctx, server_put_mount(o->od_mount->lmi_name, o->od_mount->lmi_mnt); o->od_mount = NULL; - RETURN(NULL); + RETURN(NULL); } static struct lu_device *osd_device_alloc(const struct lu_context *ctx, @@ -1667,18 +1723,18 @@ static struct inode *osd_iget(struct osd_thread_info *info, { struct inode *inode; - inode = iget(osd_sb(dev), id->oii_ino); - if (inode == NULL) { + inode = iget(osd_sb(dev), id->oii_ino); + if (inode == NULL) { CERROR("no inode\n"); - inode = ERR_PTR(-EACCES); - } else if (is_bad_inode(inode)) { + inode = ERR_PTR(-EACCES); + } else if (is_bad_inode(inode)) { CERROR("bad inode\n"); - iput(inode); - inode = ERR_PTR(-ENOENT); - } else if (inode->i_generation != id->oii_gen) { + iput(inode); + inode = ERR_PTR(-ENOENT); + } else if (inode->i_generation != id->oii_gen) { CERROR("stale inode\n"); - iput(inode); - inode = ERR_PTR(-ESTALE); + iput(inode); + inode = ERR_PTR(-ESTALE); } return inode; @@ -1799,7 +1855,7 @@ static struct super_block *osd_sb(const struct osd_device *dev) static journal_t *osd_journal(const struct osd_device *dev) { - return LDISKFS_SB(osd_sb(dev))->s_journal; + return LDISKFS_SB(osd_sb(dev))->s_journal; } static int osd_has_index(const struct osd_object *obj) diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index 8f05102..ffe8095 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -69,6 +69,10 @@ struct osd_thread_info { * XXX temporary: fake dentry used by xattr calls. */ struct dentry oti_dentry; + /* + * XXX temporary: fake file for body operations. + */ + struct file oti_file; }; #endif /* __KERNEL__ */ -- 1.8.3.1