From 39beec2289c74015f79fac872b09b1a6e3aadbad Mon Sep 17 00:00:00 2001 From: nikita Date: Tue, 25 Jul 2006 13:09:32 +0000 Subject: [PATCH] xattr support in md/dt stack --- lustre/cmm/cmm_object.c | 24 +++++++-- lustre/include/dt_object.h | 13 ++++- lustre/include/lu_object.h | 5 ++ lustre/include/lustre/lustre_idl.h | 2 +- lustre/include/lustre_mds.h | 4 +- lustre/include/md_object.h | 12 +++-- .../kernel_patches/patches/ext3-iam-separate.patch | 4 +- lustre/kernel_patches/patches/ext3-iam-uapi.patch | 22 ++++---- lustre/llite/namei.c | 19 +++---- lustre/mdd/mdd_handler.c | 41 ++++++++++++-- lustre/mdd/mdd_internal.h | 2 +- lustre/mdd/mdd_lov.c | 44 +++++++++------ lustre/mdt/mdt_handler.c | 45 ++++++++-------- lustre/mdt/mdt_lib.c | 28 +++++----- lustre/mdt/mdt_open.c | 30 +++++------ lustre/mdt/mdt_reint.c | 8 +-- lustre/mdt/mdt_xattr.c | 52 +++++++++++------- lustre/osd/osd_handler.c | 63 +++++++++++++++++++--- lustre/osd/osd_internal.h | 7 ++- 19 files changed, 285 insertions(+), 140 deletions(-) diff --git a/lustre/cmm/cmm_object.c b/lustre/cmm/cmm_object.c index 1ffeb0a..ef5fd16 100644 --- a/lustre/cmm/cmm_object.c +++ b/lustre/cmm/cmm_object.c @@ -257,11 +257,20 @@ static int cml_xattr_list(const struct lu_context *ctx, struct md_object *mo, } static int cml_xattr_set(const struct lu_context *ctx, struct md_object *mo, - const void *buf, int buflen, const char *name) + const void *buf, int buflen, const char *name, int fl) { int rc; ENTRY; - rc = mo_xattr_set(ctx, md_object_next(mo), buf, buflen, name); + rc = mo_xattr_set(ctx, md_object_next(mo), buf, buflen, name, fl); + RETURN(rc); +} + +static int cml_xattr_del(const struct lu_context *ctx, struct md_object *mo, + const char *name) +{ + int rc; + ENTRY; + rc = mo_xattr_del(ctx, md_object_next(mo), name); RETURN(rc); } @@ -313,6 +322,7 @@ static struct md_object_operations cml_mo_ops = { .moo_xattr_get = cml_xattr_get, .moo_xattr_list = cml_xattr_list, .moo_xattr_set = cml_xattr_set, + .moo_xattr_del = cml_xattr_del, .moo_object_create = cml_object_create, .moo_ref_add = cml_ref_add, .moo_ref_del = cml_ref_del, @@ -543,7 +553,13 @@ static int cmr_xattr_list(const struct lu_context *ctx, struct md_object *mo, } static int cmr_xattr_set(const struct lu_context *ctx, struct md_object *mo, - const void *buf, int buflen, const char *name) + const void *buf, int buflen, const char *name, int fl) +{ + RETURN(-EFAULT); +} + +static int cmr_xattr_del(const struct lu_context *ctx, struct md_object *mo, + const char *name) { RETURN(-EFAULT); } @@ -574,6 +590,8 @@ static struct md_object_operations cmr_mo_ops = { .moo_attr_set = cmr_attr_set, .moo_xattr_get = cmr_xattr_get, .moo_xattr_set = cmr_xattr_set, + .moo_xattr_list = cmr_xattr_list, + .moo_xattr_del = cmr_xattr_del, .moo_object_create = cmr_object_create, .moo_ref_add = cmr_ref_add, .moo_ref_del = cmr_ref_del, diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index 90a5d8f..a4a12ff 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -175,11 +175,21 @@ struct dt_object_operations { /* * Set value of an extended attribute. * + * @fl - flags from enum lu_xattr_flags + * * precondition: lu_object_exists(ctxt, &dt->do_lu); */ int (*do_xattr_set)(const struct lu_context *ctxt, struct dt_object *dt, const void *buf, int buf_len, + const char *name, int fl, struct thandle *handle); + /* + * Delete existing extended attribute. + * + * precondition: lu_object_exists(ctxt, &dt->do_lu); + */ + int (*do_xattr_del)(const struct lu_context *ctxt, + struct dt_object *dt, const char *name, struct thandle *handle); /* * Place list of existing extended attributes into @buf (which has @@ -188,8 +198,7 @@ struct dt_object_operations { * precondition: lu_object_exists(ctxt, &dt->do_lu); */ int (*do_xattr_list)(const struct lu_context *ctxt, - struct dt_object *dt, - void *buf, int buf_len); + struct dt_object *dt, void *buf, int buf_len); /* * Create new object on this device. * diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index a75faa5..ddb2947c5 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -782,6 +782,11 @@ struct lu_rdpg { __u64 rp_size; /* file size in total */ }; +enum lu_xattr_flags { + LU_XATTR_REPLACE = (1 << 0), + LU_XATTR_CREATE = (1 << 1) +}; + /* * lu_context. Execution context for lu_object methods. Currently associated * with thread. diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 1354a74..ea00dfe 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -591,7 +591,7 @@ struct lov_mds_md_v1 { /* LOV EA mds/wire data (little-endian) */ #define MAX_MD_SIZE (sizeof(struct lov_mds_md) + 4 * sizeof(struct lov_ost_data)) #define XATTR_NAME_ACL_ACCESS "system.posix_acl_access" -#define XATTR_NAME_LOV "lov" +#define XATTR_NAME_LOV "trusted.lov" #define OBD_MD_FLID (0x00000001ULL) /* object ID */ diff --git a/lustre/include/lustre_mds.h b/lustre/include/lustre_mds.h index 7bfb988..7708847 100644 --- a/lustre/include/lustre_mds.h +++ b/lustre/include/lustre_mds.h @@ -82,7 +82,7 @@ int mds_reint_rec(struct mds_update_record *r, int offset, struct ptlrpc_request *req, struct lustre_handle *); int md_lov_connect(struct obd_device *obd, struct md_lov_info *mli, - char *lov_name, struct obd_uuid *uuid, + char *lov_name, struct obd_uuid *uuid, struct md_lov_ops *mlo, const void *ctxt); int md_lov_notity_pre(struct obd_device *obd, struct md_lov_info *mli, struct obd_device *watched, enum obd_notify_event ev, @@ -102,7 +102,7 @@ int md_lov_start_synchronize(struct obd_device *obd, struct md_lov_info *mli, #define IOC_REQUEST_CLOSE _IOWR('f', 35, long) #define IOC_REQUEST_MAX_NR 35 -#define MDS_LOV_MD_NAME "lov" +#define MDS_LOV_MD_NAME "trusted.lov" #define MDD_OBD_NAME "mdd_obd" #define MDD_OBD_UUID "mdd_obd_uuid" #define MDD_OBD_TYPE "mds" diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index 1fbed82..e78ac87 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -78,7 +78,10 @@ struct md_object_operations { int (*moo_xattr_set)(const struct lu_context *ctxt, struct md_object *obj, const void *buf, - int buf_len, const char *name); + int buf_len, const char *name, int fl); + int (*moo_xattr_del)(const struct lu_context *ctxt, + struct md_object *obj, const char *name); + /* part of cross-ref operation */ int (*moo_object_create)(const struct lu_context *, struct md_object *, struct md_attr *); @@ -214,16 +217,15 @@ static inline int mo_xattr_del(const struct lu_context *cx, const char *name) { LASSERT(m->mo_ops->moo_xattr_set); - /*NULL buffer & zero length for set? or we need a new interface*/ - return m->mo_ops->moo_xattr_set(cx, m, NULL, 0, name); + return m->mo_ops->moo_xattr_del(cx, m, name); } static inline int mo_xattr_set(const struct lu_context *cx, struct md_object *m, const void *buf, - int buf_len, const char *name) + int buf_len, const char *name, int flags) { LASSERT(m->mo_ops->moo_xattr_set); - return m->mo_ops->moo_xattr_set(cx, m, buf, buf_len, name); + return m->mo_ops->moo_xattr_set(cx, m, buf, buf_len, name, flags); } static inline int mo_xattr_list(const struct lu_context *cx, diff --git a/lustre/kernel_patches/patches/ext3-iam-separate.patch b/lustre/kernel_patches/patches/ext3-iam-separate.patch index 8362924a..f2a76dc 100644 --- a/lustre/kernel_patches/patches/ext3-iam-separate.patch +++ b/lustre/kernel_patches/patches/ext3-iam-separate.patch @@ -1,7 +1,7 @@ Index: iam/fs/ext3/Makefile =================================================================== --- iam.orig/fs/ext3/Makefile 2006-05-31 20:24:32.000000000 +0400 -+++ iam/fs/ext3/Makefile 2006-07-21 23:12:10.000000000 +0400 ++++ iam/fs/ext3/Makefile 2006-07-25 16:59:51.000000000 +0400 @@ -6,7 +6,7 @@ obj-$(CONFIG_EXT3_FS) += ext3.o ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \ @@ -5461,7 +5461,7 @@ Index: iam/fs/ext3/namei.c Index: iam/include/linux/lustre_iam.h =================================================================== --- iam.orig/include/linux/lustre_iam.h 2006-05-31 20:24:32.000000000 +0400 -+++ iam/include/linux/lustre_iam.h 2006-07-21 23:12:10.000000000 +0400 ++++ iam/include/linux/lustre_iam.h 2006-07-25 16:59:51.000000000 +0400 @@ -1,9 +1,68 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: diff --git a/lustre/kernel_patches/patches/ext3-iam-uapi.patch b/lustre/kernel_patches/patches/ext3-iam-uapi.patch index 20cc4a7..a3db133 100644 --- a/lustre/kernel_patches/patches/ext3-iam-uapi.patch +++ b/lustre/kernel_patches/patches/ext3-iam-uapi.patch @@ -1,7 +1,7 @@ Index: iam/fs/ext3/Makefile =================================================================== ---- iam.orig/fs/ext3/Makefile 2006-07-21 23:12:10.000000000 +0400 -+++ iam/fs/ext3/Makefile 2006-07-21 23:12:10.000000000 +0400 +--- iam.orig/fs/ext3/Makefile 2006-07-25 16:59:51.000000000 +0400 ++++ iam/fs/ext3/Makefile 2006-07-25 16:59:51.000000000 +0400 @@ -6,7 +6,7 @@ obj-$(CONFIG_EXT3_FS) += ext3.o ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \ @@ -13,8 +13,8 @@ Index: iam/fs/ext3/Makefile ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o Index: iam/fs/ext3/dir.c =================================================================== ---- iam.orig/fs/ext3/dir.c 2006-07-21 23:12:10.000000000 +0400 -+++ iam/fs/ext3/dir.c 2006-07-21 23:12:10.000000000 +0400 +--- iam.orig/fs/ext3/dir.c 2006-07-25 16:59:51.000000000 +0400 ++++ iam/fs/ext3/dir.c 2006-07-25 16:59:51.000000000 +0400 @@ -28,6 +28,7 @@ #include #include @@ -112,8 +112,8 @@ Index: iam/fs/ext3/dir.c (filp->f_version != inode->i_version)) { Index: iam/fs/ext3/file.c =================================================================== ---- iam.orig/fs/ext3/file.c 2006-07-21 23:12:10.000000000 +0400 -+++ iam/fs/ext3/file.c 2006-07-21 23:12:10.000000000 +0400 +--- iam.orig/fs/ext3/file.c 2006-07-25 16:59:51.000000000 +0400 ++++ iam/fs/ext3/file.c 2006-07-25 16:59:51.000000000 +0400 @@ -23,6 +23,7 @@ #include #include @@ -149,7 +149,7 @@ Index: iam/fs/ext3/file.c Index: iam/fs/ext3/iam-uapi.c =================================================================== --- iam.orig/fs/ext3/iam-uapi.c 2004-04-06 17:27:52.000000000 +0400 -+++ iam/fs/ext3/iam-uapi.c 2006-07-21 23:12:10.000000000 +0400 ++++ iam/fs/ext3/iam-uapi.c 2006-07-25 16:59:51.000000000 +0400 @@ -0,0 +1,361 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: @@ -514,8 +514,8 @@ Index: iam/fs/ext3/iam-uapi.c +} Index: iam/fs/ext3/ioctl.c =================================================================== ---- iam.orig/fs/ext3/ioctl.c 2006-07-21 23:12:10.000000000 +0400 -+++ iam/fs/ext3/ioctl.c 2006-07-21 23:12:10.000000000 +0400 +--- iam.orig/fs/ext3/ioctl.c 2006-07-25 16:59:51.000000000 +0400 ++++ iam/fs/ext3/ioctl.c 2006-07-25 16:59:51.000000000 +0400 @@ -250,6 +250,6 @@ flags_err: @@ -526,8 +526,8 @@ Index: iam/fs/ext3/ioctl.c } Index: iam/include/linux/lustre_iam.h =================================================================== ---- iam.orig/include/linux/lustre_iam.h 2006-07-21 23:12:10.000000000 +0400 -+++ iam/include/linux/lustre_iam.h 2006-07-21 23:12:10.000000000 +0400 +--- iam.orig/include/linux/lustre_iam.h 2006-07-25 16:59:51.000000000 +0400 ++++ iam/include/linux/lustre_iam.h 2006-07-25 16:59:51.000000000 +0400 @@ -30,9 +30,6 @@ #ifndef __LINUX_LUSTRE_IAM_H__ #define __LINUX_LUSTRE_IAM_H__ diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 922ffba..962575b 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -386,12 +386,12 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, icbd.icbd_parent = parent; /* allocate new fid for child */ - if (it->it_op & IT_CREAT || + if (it->it_op & IT_CREAT || (it->it_op & IT_OPEN && it->it_create_mode & O_CREAT)) { struct lu_placement_hint hint = { .ph_pname = NULL, .ph_cname = &dentry->d_name, .ph_opc = LUSTRE_OPC_CREATE }; - + rc = ll_fid_md_alloc(ll_i2sbi(parent), &op_data.fid2, &hint); if (rc) { CERROR("can't allocate new fid, rc %d\n", rc); @@ -618,7 +618,7 @@ static int ll_symlink_generic(struct inode *dir, struct qstr *name, struct lu_placement_hint hint = { .ph_pname = NULL, .ph_cname = name, .ph_opc = LUSTRE_OPC_SYMLINK }; - + struct ptlrpc_request *request = NULL; struct ll_sb_info *sbi = ll_i2sbi(dir); struct md_op_data op_data = { { 0 } }; @@ -706,11 +706,8 @@ static int ll_mkdir_generic(struct inode *dir, struct qstr *name, int mode, err = md_create(sbi->ll_md_exp, &op_data, NULL, 0, mode, current->fsuid, current->fsgid, current->cap_effective, 0, &request); - if (err == 0) - ll_update_times(request, 0, dir); - ll_update_times(request, 0, dir); - if (dchild) { + if (!err && dchild) { err = ll_prep_inode(&inode, request, 0, dchild->d_sb); if (err) @@ -745,7 +742,7 @@ static int ll_rmdir_generic(struct inode *dir, struct dentry *dparent, RETURN(-EBUSY); } } - + ll_prepare_md_op_data(&op_data, dir, NULL, name->name, name->len, S_IFDIR); rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, &op_data, &request); @@ -936,7 +933,7 @@ static int ll_symlink(struct inode *dir, struct dentry *dentry, { return ll_symlink_generic(dir, &dentry->d_name, oldname); } -static int ll_link(struct dentry *old_dentry, struct inode *dir, +static int ll_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) { return ll_link_generic(old_dentry->d_inode, dir, &new_dentry->d_name); @@ -944,7 +941,7 @@ static int ll_link(struct dentry *old_dentry, struct inode *dir, static int ll_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { - return ll_rename_generic(old_dir, &old_dentry->d_name, new_dir, + return ll_rename_generic(old_dir, &old_dentry->d_name, new_dir, &new_dentry->d_name); } #endif @@ -990,7 +987,7 @@ struct inode_operations ll_special_inode_operations = { .setattr = ll_setattr, #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) .getattr_it = ll_getattr_it, -#else +#else .revalidate_it = ll_inode_revalidate_it, #endif .permission = ll_inode_permission, diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 5f01e84..951fc39 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -467,18 +467,19 @@ static int mdd_attr_set(const struct lu_context *ctxt, static int __mdd_xattr_set(const struct lu_context *ctxt,struct mdd_device *mdd, struct mdd_object *obj, const void *buf, - int buf_len, const char *name,struct thandle *handle) + int buf_len, const char *name, int fl, + struct thandle *handle) { struct dt_object *next; LASSERT(lu_object_exists(ctxt, mdd2lu_obj(obj))); next = mdd_object_child(obj); - return next->do_ops->do_xattr_set(ctxt, next, buf, buf_len, name, + return next->do_ops->do_xattr_set(ctxt, next, buf, buf_len, name, fl, handle); } int mdd_xattr_set(const struct lu_context *ctxt, struct md_object *obj, - const void *buf, int buf_len, const char *name) + const void *buf, int buf_len, const char *name, int fl) { struct mdd_device *mdd = mdo2mdd(obj); struct thandle *handle; @@ -491,7 +492,38 @@ int mdd_xattr_set(const struct lu_context *ctxt, struct md_object *obj, RETURN(PTR_ERR(handle)); rc = __mdd_xattr_set(ctxt, mdd, md2mdd_obj(obj), buf, buf_len, name, - handle); + fl, handle); + + mdd_trans_stop(ctxt, mdd, handle); + + RETURN(rc); +} + +static int __mdd_xattr_del(const struct lu_context *ctxt,struct mdd_device *mdd, + struct mdd_object *obj, + const char *name, struct thandle *handle) +{ + struct dt_object *next; + + LASSERT(lu_object_exists(ctxt, mdd2lu_obj(obj))); + next = mdd_object_child(obj); + return next->do_ops->do_xattr_del(ctxt, next, name, handle); +} + +int mdd_xattr_del(const struct lu_context *ctxt, struct md_object *obj, + const char *name) +{ + struct mdd_device *mdd = mdo2mdd(obj); + struct thandle *handle; + int rc; + ENTRY; + + mdd_txn_param_build(ctxt, &MDD_TXN_XATTR_SET); + handle = mdd_trans_start(ctxt, mdd); + if (IS_ERR(handle)) + RETURN(PTR_ERR(handle)); + + rc = __mdd_xattr_del(ctxt, mdd, md2mdd_obj(obj), name, handle); mdd_trans_stop(ctxt, mdd, handle); @@ -1210,6 +1242,7 @@ static struct md_object_operations mdd_obj_ops = { .moo_xattr_get = mdd_xattr_get, .moo_xattr_set = mdd_xattr_set, .moo_xattr_list = mdd_xattr_list, + .moo_xattr_del = mdd_xattr_del, .moo_object_create = mdd_object_create, .moo_ref_add = mdd_ref_add, .moo_ref_del = mdd_ref_del, diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 96a44c5..a168cb5 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -55,7 +55,7 @@ struct mdd_thread_info { int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd); int mdd_xattr_set(const struct lu_context *ctxt, struct md_object *obj, - const void *buf, int buf_len, const char *name); + const void *buf, int buf_len, const char *name, int fl); int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj, struct md_object *child, struct lov_mds_md *lmm, int lmm_size); diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index bc2c5fd..800a862 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -131,7 +131,7 @@ int mdd_lov_write_objids(struct obd_device *obd, struct md_lov_info *mli, #endif RETURN(rc); } -static int mdd_lov_write_catlist(struct obd_device *obd, void *idarray, int size, +static int mdd_lov_write_catlist(struct obd_device *obd, void *idarray, int size, const void *ctxt) { int rc = 0; @@ -162,7 +162,7 @@ int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd) struct md_lov_info *mli; int rc; ENTRY; - + lustre_cfg_bufs_reset(&bufs, MDD_OBD_NAME); lustre_cfg_bufs_set_string(&bufs, 1, MDD_OBD_TYPE); lustre_cfg_bufs_set_string(&bufs, 2, MDD_OBD_UUID); @@ -171,21 +171,21 @@ int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd) lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); if (!lcfg) RETURN(-ENOMEM); - + rc = class_attach(lcfg); if (rc) GOTO(lcfg_cleanup, rc); - + obd = class_name2obd(MDD_OBD_NAME); if (!obd) { CERROR("can not find obd %s \n", MDD_OBD_NAME); LBUG(); } - + /*init mli, which will be used in following mds setup*/ mli = &obd->u.mds.mds_lov_info; mli->md_lov_ops = &mdd_lov_ops; - + obj_id = dt_store_open(ctxt, mdd->mdd_child, mdd_lov_objid_name, &mli->md_lov_objid_fid); if (IS_ERR(obj_id)){ @@ -212,16 +212,16 @@ int mdd_cleanup_obd(struct mdd_device *mdd) struct lustre_cfg_bufs bufs; struct md_lov_info *mli; struct lustre_cfg *lcfg; - struct obd_device *obd; + struct obd_device *obd; int rc; ENTRY; - + obd = mdd->mdd_md_dev.md_lu_dev.ld_obd; LASSERT(obd); - + mli = &obd->u.mds.mds_lov_info; dt_object_fini(mli->md_lov_objid_obj); - + lustre_cfg_bufs_reset(&bufs, MDD_OBD_NAME); lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); if (!lcfg) @@ -230,7 +230,7 @@ int mdd_cleanup_obd(struct mdd_device *mdd) rc = class_cleanup(obd, lcfg); if (rc) GOTO(lcfg_cleanup, rc); - + rc = class_detach(obd, lcfg); if (rc) GOTO(lcfg_cleanup, rc); @@ -250,15 +250,20 @@ static int mdd_get_md(const struct lu_context *ctxt, struct md_object *obj, next = mdd_object_child(md2mdd_obj(obj)); rc = next->do_ops->do_xattr_get(ctxt, next, md, *md_size, MDS_LOV_MD_NAME); - if (rc < 0) { + /* + * XXX: handling of -ENODATA, the right way is to have ->do_md_get() + * exported by dt layer. + */ + if (rc == 0 || rc == -ENODATA) { + *md_size = 0; + rc = 0; + } else if (rc < 0) { CERROR("Error %d reading eadata \n", rc); } else if (rc > 0) { lmm_size = rc; /*FIXME convert lov EA necessary for this version?*/ *md_size = lmm_size; rc = lmm_size; - } else { - *md_size = 0; } RETURN (rc); @@ -278,7 +283,12 @@ int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj, rc = mdd_get_md(ctxt, pobj, &lmm, &size, 1); if (rc > 0) { rc = mdd_xattr_set(ctxt, child, lmm, size, - MDS_LOV_MD_NAME); + /* + * Flags are 0: we don't care + * whether attribute exists + * already. + */ + MDS_LOV_MD_NAME, 0); if (rc) CERROR("error on copy stripe info: rc = %d\n", rc); @@ -286,7 +296,7 @@ int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj, } else if (lmmp) { LASSERT(lmm_size > 0); rc = mdd_xattr_set(ctxt, child, lmmp, lmm_size, - MDS_LOV_MD_NAME); + MDS_LOV_MD_NAME, 0); if (rc) CERROR("error on copy stripe info: rc = %d\n", rc); @@ -299,7 +309,7 @@ int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, int *lmm_size) { struct obd_device *obd = mdd->mdd_md_dev.md_lu_dev.ld_obd; - struct obd_export *lov_exp = obd->u.mds.mds_osc_exp; + struct obd_export *lov_exp = obd->u.mds.mds_osc_exp; struct obdo *oa; struct lov_stripe_md *lsm = NULL; int rc = 0; diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index f79300c..d5cc81e 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -231,13 +231,12 @@ static int mdt_getattr_internal(struct mdt_thread_info *info, * also in mdt_md_create() and mdt_object_open() */ if (need_pack_reply) { - rc = req_capsule_pack(&info->mti_pill); + rc = req_capsule_pack(pill); if (rc) RETURN(rc); } - repbody = req_capsule_server_get(&info->mti_pill, - &RMF_MDT_BODY); + repbody = req_capsule_server_get(pill, &RMF_MDT_BODY); repbody->fid1 = *mdt_object_fid(o); repbody->valid |= OBD_MD_FLID; RETURN(0); @@ -304,7 +303,7 @@ skip_packing: /* now, to getattr*/ if (mdt_body_has_lov(la, reqbody)) { if (length > 0) { - rc = mo_xattr_get(info->mti_ctxt, next, + rc = mo_xattr_get(ctxt, next, buffer, length, XATTR_NAME_LOV); if (rc > 0) { if (S_ISDIR(la->la_mode)) @@ -318,8 +317,7 @@ skip_packing: } else if (S_ISLNK(la->la_mode) && (reqbody->valid & OBD_MD_LINKNAME) != 0) { /* FIXME How to readlink?? - rc = mo_xattr_get(info->mti_ctxt, next, - buffer, length, "readlink"); + rc = mo_xattr_get(ctxt, next, buffer, length, "readlink"); */ rc = 10; if (rc <= 0) { CERROR("readlink failed: %d\n", rc); @@ -344,13 +342,10 @@ skip_packing: #ifdef CONFIG_FS_POSIX_ACL if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) && (reqbody->valid & OBD_MD_FLACL)) { - buffer = req_capsule_server_get(&info->mti_pill, - &RMF_EADATA); - length = req_capsule_get_size(&info->mti_pill, - &RMF_EADATA, - RCL_SERVER); + buffer = req_capsule_server_get(pill, &RMF_EADATA); + length = req_capsule_get_size(pill, &RMF_EADATA, RCL_SERVER); if (length > 0) { - rc = mo_xattr_get(info->mti_ctxt, next, buffer, + rc = mo_xattr_get(ctxt, next, buffer, length, XATTR_NAME_ACL_ACCESS); if (rc < 0) { CERROR("got acl size: %d\n", rc); @@ -611,7 +606,7 @@ static int mdt_readpage(struct mdt_thread_info *info) OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]); if (rdpg->rp_pages == NULL) GOTO(out, rc = -ENOMEM); - + for (i = 0; i < rdpg->rp_npages; ++i) { rdpg->rp_pages[i] = alloc_pages(GFP_KERNEL, 0); if (rdpg->rp_pages[i] == NULL) @@ -622,13 +617,13 @@ static int mdt_readpage(struct mdt_thread_info *info) rc = mo_readpage(info->mti_ctxt, mdt_object_child(object), rdpg); if (rc) GOTO(free_rdpg, rc); - + repbody->size = rdpg->rp_size; repbody->valid = OBD_MD_FLSIZE; /* send pages to client */ rc = mdt_sendpage(info, rdpg); - + EXIT; free_rdpg: for (i = 0; i < rdpg->rp_npages; i++) @@ -1104,8 +1099,9 @@ struct lu_context_key mdt_txn_key; int mdt_update_last_transno(struct mdt_thread_info *info, int rc) { - struct mdt_device *mdt = info->mti_mdt; - struct ptlrpc_request * req = mdt_info_req(info); + struct mdt_device *mdt = info->mti_mdt; + struct ptlrpc_request *req = mdt_info_req(info); + struct obd_export *exp = req->rq_export; __u64 last_transno; __u64 last_committed; @@ -1135,13 +1131,20 @@ int mdt_update_last_transno(struct mdt_thread_info *info, int rc) /*last_committed = (mdt->mdt_last_committed);*/ last_committed = last_transno; #endif - last_transno = info->mti_transno; - CDEBUG(D_INFO, "last_transno = %llu, last_committed = %llu\n", - last_transno, last_committed); + if (rc == 0) { + last_transno = info->mti_transno; + CDEBUG(D_INFO, "last_transno = %llu, last_committed = %llu\n", + last_transno, last_committed); + } else { + last_transno = 0; + CERROR("replay %s transno "LPU64" failed: rc %d\n", + libcfs_nid2str(exp->exp_connection->c_peer.nid), + last_transno, rc); + } req->rq_repmsg->transno = req->rq_transno = last_transno; req->rq_repmsg->last_xid = req->rq_xid; req->rq_repmsg->last_committed = last_committed; - req->rq_export->exp_obd->obd_last_committed = last_committed; + exp->exp_obd->obd_last_committed = last_committed; return 0; } diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index 430f44e..456d356 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -49,29 +49,29 @@ int mdt_handle_last_unlink(struct mdt_thread_info *info, struct lu_attr *la = &info->mti_attr.ma_attr; int rc = 0; ENTRY; - + body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY); mdt_pack_attr2body(body, la, mdt_object_fid(mo)); - + /* if last unlinked object reference so client should destroy ost * objects*/ if (S_ISREG(la->la_mode) && la->la_nlink == 0 && mo->mot_header.loh_ref == 1) { struct lov_mds_md *lmm; - + /* reply should contains more data, * * so we need to extend it */ req_capsule_extend(&info->mti_pill, fmt); - + lmm = req_capsule_server_get(&info->mti_pill, &RMF_MDT_MD); - - + + /*TODO: lmm data & llog cookie * rc = mo_xattr_get(info->mti_ctxt, mdt_object_child(o), - * lmm, info->mti_mdt->mdt_max_mdsize, - * XATTR_NAME_LOV); + * lmm, info->mti_mdt->mdt_max_mdsize, + * MDS_LOV_MD_NAME); * if (rc >= 0) { * if (S_ISDIR(info->mti_attr.la_mode)) * body->valid |= OBD_MD_FLDIREA; @@ -113,14 +113,14 @@ static int mdt_setattr_unpack(struct mdt_thread_info *info) if (req_capsule_field_present(pill, &RMF_EADATA)) { rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA); - rr->rr_eadatalen = req_capsule_get_size(pill, + rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT); } if (req_capsule_field_present(pill, &RMF_LOGCOOKIES)) { - rr->rr_logcookies = req_capsule_client_get(pill, + rr->rr_logcookies = req_capsule_client_get(pill, &RMF_LOGCOOKIES); - rr->rr_logcookielen = req_capsule_get_size(pill, + rr->rr_logcookielen = req_capsule_get_size(pill, &RMF_LOGCOOKIES, RCL_CLIENT); } @@ -151,7 +151,7 @@ static int mdt_create_unpack(struct mdt_thread_info *info) rr->rr_name = req_capsule_client_get(pill, &RMF_NAME); if (rr->rr_name) { if (req_capsule_field_present(pill, &RMF_SYMTGT)) { - rr->rr_tgt = req_capsule_client_get(pill, + rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT); if (rr->rr_tgt == NULL) result = -EFAULT; @@ -210,9 +210,9 @@ static int mdt_unlink_unpack(struct mdt_thread_info *info) rr->rr_name = req_capsule_client_get(pill, &RMF_NAME); if (rr->rr_name == NULL) - result = -EFAULT; + result = -EFAULT; } else - result = -EFAULT; + result = -EFAULT; RETURN(result); } diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index d47981f..879f5d4 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -38,8 +38,8 @@ static void mdt_mfd_get(void *mfdp) { } -/* Create a new mdt_file_data struct, initialize it, - * and insert it to global hash table */ +/* Create a new mdt_file_data struct, initialize it, + * and insert it to global hash table */ static struct mdt_file_data *mdt_mfd_new(void) { struct mdt_file_data *mfd; @@ -71,7 +71,7 @@ static void mdt_mfd_free(struct mdt_file_data *mfd) } static int mdt_mfd_open(struct mdt_thread_info *info, - struct mdt_object *o, + struct mdt_object *o, int flags, int created) { struct mdt_export_data *med; @@ -92,9 +92,9 @@ static int mdt_mfd_open(struct mdt_thread_info *info, if (rc == 0) { ma->ma_valid |= MA_INODE; if (S_ISREG(la->la_mode)) { - rc = mo_xattr_get(info->mti_ctxt, + rc = mo_xattr_get(info->mti_ctxt, mdt_object_child(o), - ma->ma_lmm, + ma->ma_lmm, ma->ma_lmm_size, XATTR_NAME_LOV); if (rc >= 0) { @@ -117,11 +117,11 @@ static int mdt_mfd_open(struct mdt_thread_info *info, /* FIXME:maybe this can be done earlier? */ if (S_ISDIR(la->la_mode)) { if (flags & (MDS_OPEN_CREAT | FMODE_WRITE)) { - /* we are trying to create or + /* we are trying to create or * write an existing dir. */ rc = -EISDIR; } - } else if (flags & MDS_OPEN_DIRECTORY) + } else if (flags & MDS_OPEN_DIRECTORY) rc = -ENOTDIR; } if (rc != 0) @@ -157,7 +157,7 @@ static int mdt_mfd_open(struct mdt_thread_info *info, spin_unlock(&med->med_open_lock); repbody->handle.cookie = mfd->mfd_handle.h_cookie; - } else + } else rc = -ENOMEM; RETURN(rc); @@ -177,12 +177,12 @@ int mdt_open_by_fid(struct mdt_thread_info* info, const struct lu_fid *fid, if (la->la_flags & MDS_OPEN_EXCL && la->la_flags & MDS_OPEN_CREAT) rc = -EEXIST; - else + else rc = mdt_mfd_open(info, o, flags, 0); } else { rc = -ENOENT; if (la->la_flags & MDS_OPEN_CREAT) { - rc = mo_object_create(info->mti_ctxt, + rc = mo_object_create(info->mti_ctxt, mdt_object_child(o), &info->mti_attr); if (rc == 0) @@ -201,7 +201,7 @@ int mdt_pin(struct mdt_thread_info* info) struct mdt_body *body; int rc; ENTRY; - + rc = req_capsule_pack(&info->mti_pill); if (rc == 0) { body = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY); @@ -224,7 +224,7 @@ int mdt_reint_open(struct mdt_thread_info *info) int created = 0; struct mdt_reint_record *rr = &info->mti_rr; ENTRY; - + ma->ma_lmm = req_capsule_server_get(&info->mti_pill, &RMF_MDT_MD); ma->ma_lmm_size = req_capsule_get_size(&info->mti_pill, @@ -248,7 +248,7 @@ int mdt_reint_open(struct mdt_thread_info *info) lh->mlh_mode = LCK_PR; else lh->mlh_mode = LCK_PW; - parent = mdt_object_find_lock(info, rr->rr_fid1, lh, + parent = mdt_object_find_lock(info, rr->rr_fid1, lh, MDS_INODELOCK_UPDATE); if (IS_ERR(parent)) GOTO(out, result = PTR_ERR(parent)); @@ -301,7 +301,7 @@ finish_open: &info->mti_attr); if (rc2 != 0) CERROR("error in cleanup of open"); - } + } out_child: mdt_object_put(info->mti_ctxt, child); out_parent: @@ -351,7 +351,7 @@ int mdt_close(struct mdt_thread_info *info) class_handle_unhash(&mfd->mfd_handle); list_del_init(&mfd->mfd_list); spin_unlock(&med->med_open_lock); - + rc = mdt_handle_last_unlink(info, mfd->mfd_object, &RQF_MDS_CLOSE_LAST); diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index b65cc61..aebfc88 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -177,7 +177,7 @@ static int mdt_reint_setattr(struct mdt_thread_info *info) if (rr->rr_eadatalen > 0) rc = mo_xattr_set(info->mti_ctxt, next, rr->rr_eadata, rr->rr_eadatalen, - XATTR_NAME_LOV); + XATTR_NAME_LOV, 0); /* FIXME & TODO Please deal with logcookies here*/ GOTO(out_unlock, rc); @@ -247,7 +247,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info) if (strlen(rr->rr_name) == 0) { /* remote partial operation */ - rc = mo_ref_del(info->mti_ctxt, mdt_object_child(mp), + rc = mo_ref_del(info->mti_ctxt, mdt_object_child(mp), &info->mti_attr); GOTO(out_unlock_parent, rc); } @@ -273,10 +273,10 @@ static int mdt_reint_unlink(struct mdt_thread_info *info) /* cmm will take care if child is local or remote */ rc = mdo_unlink(info->mti_ctxt, mdt_object_child(mp), mdt_object_child(mc), rr->rr_name, &info->mti_attr); - + if (rc) GOTO(out_unlock_child, rc); - + rc = mdt_handle_last_unlink(info, mc, &RQF_MDS_REINT_UNLINK_LAST); GOTO(out_unlock_child, rc); diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index 572076c..9b1fe8e 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -34,6 +34,13 @@ #endif #define DEBUG_SUBSYSTEM S_MDS +/* prerequisite for linux/xattr.h */ +#include +/* prerequisite for linux/xattr.h */ +#include +/* XATTR_{REPLACE,CREATE} */ +#include + #include "mdt_internal.h" @@ -157,27 +164,30 @@ int mdt_setxattr(struct mdt_thread_info *info) const char user_string[] = "user."; const char trust_string[] = "trusted."; struct mdt_lock_handle *lh; - __u64 valid = info->mti_body->valid; + struct req_capsule *pill = &info->mti_pill; + struct mdt_object *obj = info->mti_object; + const struct mdt_body *body = info->mti_body; + const struct lu_context *ctx = info->mti_ctxt; + struct md_object *child = mdt_object_child(obj); + __u64 valid = body->valid; char *xattr_name; int xattr_len; __u64 lockpart; int rc; ENTRY; - CDEBUG(D_INODE, "setxattr "DFID3"\n", - PFID3(&info->mti_body->fid1)); + CDEBUG(D_INODE, "setxattr "DFID3"\n", PFID3(&body->fid1)); if (MDT_FAIL_CHECK(OBD_FAIL_MDS_SETXATTR)) RETURN(-ENOMEM); /* various sanity check for xattr name */ - xattr_name = req_capsule_client_get(&info->mti_pill, &RMF_NAME); + xattr_name = req_capsule_client_get(pill, &RMF_NAME); if (!xattr_name) GOTO(out, rc = -EFAULT); CDEBUG(D_INODE, "%s xattr %s\n", - info->mti_body->valid & OBD_MD_FLXATTR ? "set" : "remove", - xattr_name); + body->valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name); if (strncmp(xattr_name, trust_string, sizeof(trust_string) - 1) == 0) { if (strcmp(xattr_name + 8, XATTR_NAME_LOV) == 0) @@ -195,38 +205,40 @@ int mdt_setxattr(struct mdt_thread_info *info) lh = &info->mti_lh[MDT_LH_PARENT]; lh->mlh_mode = LCK_EX; - rc = mdt_object_lock(info, info->mti_object, lh, lockpart); + rc = mdt_object_lock(info, obj, lh, lockpart); if (rc != 0) GOTO(out, rc); if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) { char * xattr; - if (!req_capsule_field_present(&info->mti_pill, &RMF_EADATA)) { + if (!req_capsule_field_present(pill, &RMF_EADATA)) { CERROR("no xattr data supplied\n"); GOTO(out_unlock, rc = -EFAULT); } - xattr_len = req_capsule_get_size(&info->mti_pill, - &RMF_EADATA, RCL_CLIENT); + xattr_len = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT); if (xattr_len) { - xattr = req_capsule_client_get(&info->mti_pill, - &RMF_EADATA); + int flags = 0; + xattr = req_capsule_client_get(pill, &RMF_EADATA); + + if (body->flags & XATTR_REPLACE) + flags |= LU_XATTR_REPLACE; - rc = mo_xattr_set(info->mti_ctxt, - mdt_object_child(info->mti_object), - xattr, xattr_len, xattr_name); + if (body->flags & XATTR_CREATE) + flags |= LU_XATTR_CREATE; + + rc = mo_xattr_set(ctx, child, xattr, + xattr_len, xattr_name, flags); } } else if ((valid & OBD_MD_FLXATTRRM) == OBD_MD_FLXATTRRM) { - rc = mo_xattr_del(info->mti_ctxt, - mdt_object_child(info->mti_object), - xattr_name); + rc = mo_xattr_del(ctx, child, xattr_name); } else { - CERROR("valid bits: "LPX64"\n", info->mti_body->valid); + CERROR("valid bits: "LPX64"\n", body->valid); rc = -EINVAL; } EXIT; out_unlock: - mdt_object_unlock(info, info->mti_object, lh, rc); + mdt_object_unlock(info, obj, lh, rc); out: return rc; } diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index e8df2a3..4cb1023 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -36,6 +36,12 @@ /* LUSTRE_VERSION_CODE */ #include +/* prerequisite for linux/xattr.h */ +#include +/* prerequisite for linux/xattr.h */ +#include +/* XATTR_{REPLACE,CREATE} */ +#include /* * XXX temporary stuff: direct access to ldiskfs/jdb. Interface between osd * and file system is not yet specified. @@ -818,24 +824,69 @@ static void osd_object_ref_del(const struct lu_context *ctxt, } int osd_xattr_get(const struct lu_context *ctxt, struct dt_object *dt, - void *buf, int buf_len, const char *name) + void *buf, int size, const char *name) { - return 0; + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct osd_thread_info *info = lu_context_key_get(ctxt, &osd_key); + struct dentry *dentry = &info->oti_dentry; + + LASSERT(lu_object_exists(ctxt, &dt->do_lu)); + LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL); + dentry->d_inode = inode; + return inode->i_op->getxattr(dentry, name, buf, size); } int osd_xattr_set(const struct lu_context *ctxt, struct dt_object *dt, - const void *buf, int buf_len, const char *name, + const void *buf, int size, const char *name, int fl, struct thandle *handle) { - return 0; + int fs_flags; + + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct osd_thread_info *info = lu_context_key_get(ctxt, &osd_key); + struct dentry *dentry = &info->oti_dentry; + + LASSERT(lu_object_exists(ctxt, &dt->do_lu)); + LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL); + dentry->d_inode = inode; + + fs_flags = 0; + if (fl & LU_XATTR_REPLACE) + fs_flags |= XATTR_REPLACE; + + if (fl & LU_XATTR_CREATE) + fs_flags |= XATTR_CREATE; + + return inode->i_op->setxattr(dentry, name, buf, size, fs_flags); } int osd_xattr_list(const struct lu_context *ctxt, struct dt_object *dt, - void *buf, int buf_len) + void *buf, int size) { - return 0; + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct osd_thread_info *info = lu_context_key_get(ctxt, &osd_key); + struct dentry *dentry = &info->oti_dentry; + + LASSERT(lu_object_exists(ctxt, &dt->do_lu)); + LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL); + dentry->d_inode = inode; + return inode->i_op->listxattr(dentry, buf, size); +} + +int osd_xattr_del(const struct lu_context *ctxt, struct dt_object *dt, + const char *name, struct thandle *handle) +{ + struct inode *inode = osd_dt_obj(dt)->oo_inode; + struct osd_thread_info *info = lu_context_key_get(ctxt, &osd_key); + struct dentry *dentry = &info->oti_dentry; + + LASSERT(lu_object_exists(ctxt, &dt->do_lu)); + LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL); + dentry->d_inode = inode; + return inode->i_op->removexattr(dentry, name); } + int osd_readpage(const struct lu_context *ctxt, struct dt_object *dt, struct lu_rdpg *rdpg) { diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index db24abe..8f05102 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -37,13 +37,14 @@ #include /* struct dx_hash_info */ #include +/* struct dentry */ +#include #include #include #include "osd_oi.h" struct inode; -struct dentry; struct dentry *osd_lookup(struct dentry *parent, const char *name); struct dentry *osd_open(struct dentry *parent, const char *name, mode_t mode); @@ -64,6 +65,10 @@ struct osd_thread_info { */ struct qstr oti_str; struct txn_param oti_txn; + /* + * XXX temporary: fake dentry used by xattr calls. + */ + struct dentry oti_dentry; }; #endif /* __KERNEL__ */ -- 1.8.3.1