From 2d2bd9be5d0510d35da9c67a0c84db114fe4aa01 Mon Sep 17 00:00:00 2001 From: nikita Date: Sun, 16 Apr 2006 17:46:36 +0000 Subject: [PATCH] osd: add better object index stub: generate fids from ino/generation and other way around --- lustre/osd/osd_handler.c | 106 ++++++++++++++++++++++++++++++---------------- lustre/osd/osd_internal.h | 6 ++- lustre/osd/osd_oi.c | 95 ++++------------------------------------- lustre/osd/osd_oi.h | 4 ++ 4 files changed, 86 insertions(+), 125 deletions(-) diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 84496e3..ebeee1a 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -75,17 +75,19 @@ static void osd_key_fini (struct lu_context *ctx, void *data); static int osd_fid_lookup (struct lu_context *ctx, struct osd_object *obj, const struct lu_fid *fid); -static struct osd_object *osd_obj (const struct lu_object *o); -static struct osd_device *osd_dev (const struct lu_device *d); -static struct osd_device *osd_dt_dev (const struct dt_device *d); -static struct lu_device *osd_device_alloc(struct lu_device_type *t, - struct lustre_cfg *cfg); -static struct lu_object *osd_object_alloc(struct lu_context *ctx, - struct lu_device *d); -static struct inode *osd_iget (struct osd_thread_info *info, - struct osd_device *dev, - const struct osd_inode_id *id); -static struct super_block *osd_sb (const struct osd_device *dev); +static struct osd_object *osd_obj (const struct lu_object *o); +static struct osd_device *osd_dev (const struct lu_device *d); +static struct osd_device *osd_dt_dev (const struct dt_device *d); +static struct lu_device *osd_device_alloc (struct lu_device_type *t, + struct lustre_cfg *cfg); +static struct lu_object *osd_object_alloc (struct lu_context *ctx, + struct lu_device *d); +static struct inode *osd_iget (struct osd_thread_info *info, + struct osd_device *dev, + const struct osd_inode_id *id); +static struct super_block *osd_sb (const struct osd_device *dev); +static struct lu_fid *osd_inode_get_fid(const struct inode *inode, + struct lu_fid *fid); static struct lu_device_type_operations osd_device_type_ops; static struct lu_device_type osd_device_type; @@ -95,30 +97,13 @@ static struct lprocfs_vars lprocfs_osd_obd_vars[]; static struct lu_device_operations osd_lu_ops; static struct lu_context_key osd_key; -static struct lu_fid *lu_inode_get_fid(const struct inode *inode) -{ - static struct lu_fid stub = { - .f_seq = 42, - .f_oid = 42, - .f_ver = 0 - }; - return &stub; -} - /* * DT methods. */ static int osd_root_get(struct lu_context *ctx, struct dt_device *dev, struct lu_fid *f) { - struct osd_device *od = osd_dt_dev(dev); - extern const struct lu_fid root_fid; - - /* - * XXX hack. Should return fid associated with - * osd_sb(od)->s_root->d_inode. - */ - *f = root_fid; + osd_inode_get_fid(osd_dt_dev(dev)->od_root_dir->d_inode, f); return 0; } @@ -240,10 +225,10 @@ static int osd_attr_get(struct lu_context *ctxt, struct dt_object *dt, void *buf, int size, const char *name, struct md_params *arg) { - struct osd_object *o = dt2osd_obj(dt); - struct osd_device *dev = osd_obj2dev(o); + //struct osd_object *o = dt2osd_obj(dt); + //struct osd_device *dev = osd_obj2dev(o); //struct super_block *sb = osd_sb(dev); - struct inode *inode = o->oo_inode; + //struct inode *inode = o->oo_inode; int result = -EOPNOTSUPP; ENTRY; @@ -320,6 +305,14 @@ static int osd_device_init(struct lu_device *d, const char *top) o->od_mount = lmi; result = osd_oi_init(&o->od_oi, osd_sb(o)->s_root, o->od_dt_dev.dd_lu_dev.ld_site); + if (result == 0) { + o->od_root_dir = osd_open(osd_sb(o)->s_root, + "ROOT", S_IFDIR); + if (IS_ERR(o->od_root_dir)) { + result = PTR_ERR(o->od_root_dir); + o->od_root_dir = NULL; + } + } } else { CERROR("Cannot get mount info for %s!\n", top); result = -EFAULT; @@ -333,11 +326,15 @@ static void osd_device_fini(struct lu_device *d) { struct osd_device *o = osd_dev(d); + if (o->od_root_dir != NULL) { + dput(o->od_root_dir); + o->od_root_dir = NULL; + } + osd_oi_fini(&o->od_oi); if (o->od_mount != NULL) { server_put_mount(o->od_mount->lmi_name, o->od_mount->lmi_mnt); o->od_mount = NULL; } - osd_oi_fini(&o->od_oi); } static struct lu_device *osd_device_alloc(struct lu_device_type *t, @@ -366,16 +363,50 @@ static void osd_device_free(struct lu_device *d) } /* - * + * fid<->inode<->object functions. */ -struct dentry *osd_lookup(struct dentry *parent, const char *name, int len) +static struct lu_fid *osd_inode_get_fid(const struct inode *inode, + struct lu_fid *fid) +{ + /* + * XXX: Should return fid stored together with inode in memory. + */ + fid->f_seq = inode->i_ino; + fid->f_oid = inode->i_generation; + return fid; +} + +struct dentry *osd_open(struct dentry *parent, const char *name, mode_t mode) +{ + struct dentry *dentry; + struct dentry *result; + + result = dentry = osd_lookup(parent, name); + if (IS_ERR(dentry)) { + CERROR("Error opening %s: %ld\n", name, PTR_ERR(dentry)); + dentry = NULL; /* dput(NULL) below is OK */ + } else if (dentry->d_inode == NULL) { + CERROR("Not found: %s\n", name); + result = ERR_PTR(-ENOENT); + } else if ((dentry->d_inode->i_mode & S_IFMT) != mode) { + CERROR("Wrong mode: %s: %o != %o\n", name, + dentry->d_inode->i_mode, mode); + result = ERR_PTR(mode == S_IFDIR ? -ENOTDIR : -EISDIR); + } + + if (IS_ERR(result)) + dput(dentry); + return result; +} + +struct dentry *osd_lookup(struct dentry *parent, const char *name) { struct dentry *dentry; CDEBUG(D_INODE, "looking up object %s\n", name); down(&parent->d_inode->i_sem); - dentry = lookup_one_len(name, parent, len); + dentry = lookup_one_len(name, parent, strlen(name)); up(&parent->d_inode->i_sem); if (IS_ERR(dentry)) { @@ -403,7 +434,8 @@ static struct inode *osd_iget(struct osd_thread_info *info, CERROR("bad inode\n"); iput(inode); inode = ERR_PTR(-ENOENT); - } else if (inode->i_generation != id->oii_gen) { + } else if (inode->i_generation != id->oii_gen && + id->oii_gen != OSD_GEN_IGNORE) { CERROR("stale inode\n"); iput(inode); inode = ERR_PTR(-ESTALE); diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index ddcb848..4ca9db8 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -39,6 +39,7 @@ #include "osd_oi.h" struct inode; +struct dentry; struct osd_object { struct dt_object oo_dt; @@ -54,6 +55,7 @@ struct osd_device { struct dt_device od_dt_dev; struct lustre_mount_info *od_mount; struct osd_oi od_oi; + struct dentry *od_root_dir; }; static inline struct osd_object * dt2osd_obj(struct dt_object *o) @@ -81,7 +83,9 @@ static inline struct lu_device * osd2lu_dev(struct osd_device * osd) return &osd->od_dt_dev.dd_lu_dev; } -struct dentry *osd_lookup(struct dentry *parent, const char *name, int len); +struct dentry *osd_lookup(struct dentry *parent, const char *name); +struct dentry *osd_open(struct dentry *parent, const char *name, mode_t mode); + struct osd_thread_info { char oti_name[64]; diff --git a/lustre/osd/osd_oi.c b/lustre/osd/osd_oi.c index 8040bc3..ad61600 100644 --- a/lustre/osd/osd_oi.c +++ b/lustre/osd/osd_oi.c @@ -50,7 +50,6 @@ static struct lu_fid *oi_fid_key(struct osd_thread_info *info, const struct lu_fid *fid); -static void osd_oi_init0(struct osd_oi *oi); static const char osd_oi_dirname[] = "oi"; @@ -58,8 +57,7 @@ int osd_oi_init(struct osd_oi *oi, struct dentry *root, struct lu_site *site) { int result; - oi->oi_dir = osd_lookup(root, - osd_oi_dirname, (sizeof osd_oi_dirname) - 1); + oi->oi_dir = osd_open(root, osd_oi_dirname, S_IFDIR); if (IS_ERR(oi->oi_dir)) { result = PTR_ERR(oi->oi_dir); oi->oi_dir = NULL; @@ -68,10 +66,6 @@ int osd_oi_init(struct osd_oi *oi, struct dentry *root, struct lu_site *site) init_rwsem(&oi->oi_lock); oi->oi_site = site; } - /* - * XXX prototype stuff: add root fid. - */ - osd_oi_init0(oi); return result; } @@ -114,42 +108,15 @@ static struct lu_fid *oi_fid_key(struct osd_thread_info *info, * XXX prototype. ****************************************************************************/ -struct oi_entry { - struct lu_fid oe_key; - struct osd_inode_id oe_rec; - struct list_head oe_linkage; -}; - -static CFS_LIST_HEAD(oi_head); - -static struct oi_entry *oi_lookup(const struct lu_fid *fid) -{ - struct oi_entry *entry; - - list_for_each_entry(entry, &oi_head, oe_linkage) { - if (lu_fid_eq(fid, &entry->oe_key)) - return entry; - } - return NULL; -} - /* * Locking: requires at least read lock on oi. */ int osd_oi_lookup(struct osd_thread_info *info, struct osd_oi *oi, const struct lu_fid *fid, struct osd_inode_id *id) { - struct oi_entry *entry; - int result; - - LASSERT(fid_is_local(oi->oi_site, fid)); - entry = oi_lookup(fid); - if (entry != NULL) { - *id = entry->oe_rec; - result = 0; - } else - result = -ENOENT; - return result; + id->oii_ino = fid_seq(fid); + id->oii_gen = fid_oid(fid); + return 0; } /* @@ -158,23 +125,9 @@ int osd_oi_lookup(struct osd_thread_info *info, struct osd_oi *oi, int osd_oi_insert(struct osd_thread_info *info, struct osd_oi *oi, const struct lu_fid *fid, const struct osd_inode_id *id) { - struct oi_entry *entry; - int result; - - LASSERT(fid_is_local(oi->oi_site, fid)); - entry = oi_lookup(fid); - if (entry == NULL) { - OBD_ALLOC_PTR(entry); - if (entry != NULL) { - entry->oe_key = *fid; - entry->oe_rec = *id; - list_add(&entry->oe_linkage, &oi_head); - result = 0; - } else - result = -ENOMEM; - } else - result = -EEXIST; - return result; + LASSERT(id->oii_ino == fid_seq(fid)); + LASSERT(id->oii_gen == fid_oid(fid)); + return 0; } /* @@ -183,37 +136,5 @@ int osd_oi_insert(struct osd_thread_info *info, struct osd_oi *oi, int osd_oi_delete(struct osd_thread_info *info, struct osd_oi *oi, const struct lu_fid *fid) { - struct oi_entry *entry; - int result; - - LASSERT(fid_is_local(oi->oi_site, fid)); - entry = oi_lookup(fid); - if (entry != NULL) { - list_del(&entry->oe_linkage); - OBD_FREE_PTR(entry); - result = 0; - } else - result = -ENOENT; - return result; -} - -#define LDISKFS_ROOT_INO 2 /* Root inode */ - -/* XXX used by osd_root_get() */ -const struct lu_fid root_fid = { - .f_seq = LUSTRE_ROOT_FID_SEQ, - .f_oid = LUSTRE_ROOT_FID_OID, - .f_ver = 0 -}; - -static const struct osd_inode_id root_id = { - .oii_ino = LDISKFS_ROOT_INO, - .oii_gen = 0 -}; - -static void osd_oi_init0(struct osd_oi *oi) -{ - int result; - result = osd_oi_insert(NULL, oi, &root_fid, &root_id); - LASSERT(result == 0); + return 0; } diff --git a/lustre/osd/osd_oi.h b/lustre/osd/osd_oi.h index c432678..d08728a 100644 --- a/lustre/osd/osd_oi.h +++ b/lustre/osd/osd_oi.h @@ -52,6 +52,10 @@ struct osd_inode_id { __u32 oii_gen; }; +enum { + OSD_GEN_IGNORE = (__u32)~0 +}; + int osd_oi_init(struct osd_oi *oi, struct dentry *root, struct lu_site *s); void osd_oi_fini(struct osd_oi *oi); -- 1.8.3.1