From 2b152f21b052e305b0d146a8a004e34ac09004ad Mon Sep 17 00:00:00 2001 From: wangdi Date: Tue, 8 Aug 2006 12:05:54 +0000 Subject: [PATCH] Branch: b_new_cmd 1)we should set size to ost object after creating ost object, if the object size is not zero because of truncate. 2)enable ATTR_SIZE in osd_inode_setattr, since we could set size in mds for reg file, but not truncate. --- lustre/mdd/mdd_handler.c | 5 --- lustre/mdd/mdd_internal.h | 5 +++ lustre/mdd/mdd_lov.c | 78 +++++++++++++++++++++++++++++++++++++++++++++-- lustre/osd/osd_handler.c | 2 +- 4 files changed, 82 insertions(+), 8 deletions(-) diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 8bc517e..cfb6685 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -61,11 +61,6 @@ static void __mdd_ref_del(const struct lu_context *ctxt, struct mdd_object *obj, static int mdd_lookup(const struct lu_context *ctxt, struct md_object *pobj, const char *name, struct lu_fid* fid); -static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj) -{ - return lu_object_fid(&obj->mod_obj.mo_lu); -} - static struct md_object_operations mdd_obj_ops; static struct md_dir_operations mdd_dir_ops; diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index b2cfc8f..7ce55c7 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -124,6 +124,11 @@ static inline struct obd_device *mdd2_obd(struct mdd_device *mdd) return mdd->mdd_md_dev.md_lu_dev.ld_obd; } +static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj) +{ + return lu_object_fid(&obj->mod_obj.mo_lu); +} + int mdd_lov_mdsize(const struct lu_context *ctxt, struct mdd_device *mdd, int *md_size); int mdd_lov_cookiesize(const struct lu_context *ctxt, struct mdd_device *mdd, diff --git a/lustre/mdd/mdd_lov.c b/lustre/mdd/mdd_lov.c index 16f1513..8bd37fb 100644 --- a/lustre/mdd/mdd_lov.c +++ b/lustre/mdd/mdd_lov.c @@ -338,6 +338,51 @@ static obd_id mdd_lov_create_id(const struct lu_fid *fid) return ((fid_seq(fid) - 1) * LUSTRE_SEQ_MAX_WIDTH + fid_oid(fid)); } +/*FIXME: it is just the helper function used by mdd lov obd to + * get attr from obdo, copied from obdo_from_inode*/ +static void obdo_from_la(struct obdo *dst, struct lu_attr *la, obd_flag valid) +{ + obd_flag newvalid = 0; + + if (valid & OBD_MD_FLATIME) { + dst->o_atime = la->la_atime; + newvalid |= OBD_MD_FLATIME; + } + if (valid & OBD_MD_FLMTIME) { + dst->o_mtime = la->la_mtime; + newvalid |= OBD_MD_FLMTIME; + } + if (valid & OBD_MD_FLCTIME) { + dst->o_ctime = la->la_ctime; + newvalid |= OBD_MD_FLCTIME; + } + if (valid & OBD_MD_FLSIZE) { + dst->o_size = la->la_size; + newvalid |= OBD_MD_FLSIZE; + } + if (valid & OBD_MD_FLBLOCKS) { /* allocation of space (x512 bytes) */ + dst->o_blocks = la->la_blocks; + newvalid |= OBD_MD_FLBLOCKS; + } + if (valid & OBD_MD_FLTYPE) { + dst->o_mode = (la->la_mode & S_IALLUGO)|(la->la_mode & S_IFMT); + newvalid |= OBD_MD_FLTYPE; + } + if (valid & OBD_MD_FLMODE) { + dst->o_mode = (la->la_mode & S_IFMT)|(la->la_mode & S_IALLUGO); + newvalid |= OBD_MD_FLMODE; + } + if (valid & OBD_MD_FLUID) { + dst->o_uid = la->la_uid; + newvalid |= OBD_MD_FLUID; + } + if (valid & OBD_MD_FLGID) { + dst->o_gid = la->la_gid; + newvalid |= OBD_MD_FLGID; + } + dst->o_valid |= newvalid; +} + int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, struct mdd_object *parent, struct mdd_object *child, struct lov_mds_md **lmm, int *lmm_size, const void *eadata, @@ -382,8 +427,8 @@ int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, rc = obd_create(lov_exp, oa, &lsm, NULL); if (rc) { if (rc > 0) { - CERROR("obd_create returned invalid " - "rc %d\n", rc); + CERROR("create errro for "DFID3": %d \n", + PFID3(mdo2fid(child)), rc); rc = -EIO; } GOTO(out_oa, rc); @@ -397,6 +442,35 @@ int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd, } lsm->lsm_object_id = oa->o_id; } + /*after creating the object, if the la_size is not zero. + *since truncate when no lsm, we should set the size to + *ost object*/ + if (la->la_size) { + oa->o_size = la->la_size; + obdo_from_la(oa, la, OBD_MD_FLTYPE | OBD_MD_FLATIME | + OBD_MD_FLMTIME | OBD_MD_FLCTIME | OBD_MD_FLSIZE); + + /* FIXME:pack lustre id to OST, in OST, it will be packed + * by filter_fid, but can not see what is the usages. So just + * pack o_seq o_ver here, maybe fix it after this cycle*/ + oa->o_fid = lu_object_fid(mdd2lu_obj(child))->f_seq; + oa->o_generation = lu_object_fid(mdd2lu_obj(child))->f_ver; + oa->o_valid |= OBD_MD_FLFID | OBD_MD_FLGENER; + + rc = obd_setattr(lov_exp, oa, lsm, NULL); + if (rc) { + CERROR("error setting attrs for "DFID3": rc %d\n", + PFID3(mdo2fid(child)), rc); + if (rc > 0) { + CERROR("obd_setattr for "DFID3" rc %d\n", + PFID3(mdo2fid(child)), rc); + rc = -EIO; + } + GOTO(out_oa, rc); + } + } + /*set blksize after create data object*/ + la->la_valid |= OBD_MD_FLBLKSZ | OBD_MD_FLEASIZE; rc = obd_packmd(lov_exp, lmm, lsm); if (rc < 0) { diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 9f3379c..f2f7e74d 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -634,7 +634,7 @@ static int osd_inode_setattr(const struct lu_context *ctx, LTIME_S(iattr.ia_ctime) = attr->la_ctime; /* TODO: handle ATTR_SIZE & truncate in the future */ - iattr.ia_valid &= ~ATTR_SIZE; + //iattr.ia_valid &= ~ATTR_SIZE; /* Don't allow setattr to change file type */ if (iattr.ia_valid & ATTR_MODE) -- 1.8.3.1