From 2a209cc7a6002711bf7ba57afe21a6aa489ed2b6 Mon Sep 17 00:00:00 2001 From: yury Date: Wed, 2 Nov 2005 13:14:18 +0000 Subject: [PATCH] - fixes, comments and cleanups: - fixed test 34c from sanity.sh. It has two sub-bugs: (1) when reg file is created by mknod and did not open as reg file, it has no lsm and has no OST object. I nthis case truncate path should set i_size into inode on MDS. This ws done correctly, but i_size was not returned corectly to client after that as mds_reint_setattr() had bug with setting body->valid |= SIZE for that case (comment added). (2) later, in the same test, when file was opened and lsm created, MDS sent setattr RPC to OST to pass its inode attrs. As there was o_flags set to CROW, filter_setattr_internal() was confused and called fsfilt_iocontrol() instead of fsfilt_setattr(). Thus inode size was not set correctly and 0 was returned to client whereas MDS inode size should have been returned instead. - in filter_preprw_read() more fixes about handling unexisting object. No -ENOENT should be returned and everythign should be done like object exists, but its size is 0 (thanks to Niu for catching this out). --- lustre/llite/rw.c | 8 +++----- lustre/mds/mds_reint.c | 14 +++++++++----- lustre/obdclass/obdo.c | 10 ++++++++-- lustre/obdfilter/filter.c | 12 ++++++------ lustre/obdfilter/filter_io.c | 10 +++++----- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index fb56205..6d5ea5f 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -148,7 +148,7 @@ void ll_truncate(struct inode *inode) /* If the truncate leaves behind a partial page, update its * checksum. */ struct page *page = find_get_page(inode->i_mapping, - inode->i_size >> PAGE_CACHE_SHIFT); + inode->i_size >> PAGE_CACHE_SHIFT); if (page != NULL) { struct ll_async_page *llap = llap_cast_private(page); if (llap != NULL) { @@ -177,15 +177,13 @@ void ll_truncate(struct inode *inode) if (rc) CERROR("obd_truncate fails (%d) ino %lu\n", rc, inode->i_ino); else - obdo_to_inode(inode, &oa, OBD_MD_FLSIZE|OBD_MD_FLBLOCKS| - OBD_MD_FLATIME | OBD_MD_FLMTIME | - OBD_MD_FLCTIME); + obdo_to_inode(inode, &oa, OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | + OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME); EXIT; return; out_unlock: ll_inode_size_unlock(inode, 0); - EXIT; } /* ll_truncate */ int ll_prepare_write(struct file *file, struct page *page, unsigned from, diff --git a/lustre/mds/mds_reint.c b/lustre/mds/mds_reint.c index 3d8833a..ecc66bf 100644 --- a/lustre/mds/mds_reint.c +++ b/lustre/mds/mds_reint.c @@ -441,6 +441,7 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, { struct mds_obd *mds = mds_req2mds(req); struct obd_device *obd = req->rq_export->exp_obd; + unsigned int ia_valid = rec->ur_iattr.ia_valid; struct mds_body *body; struct dentry *de; struct inode *inode = NULL; @@ -588,12 +589,15 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, mds_pack_inode2fid(&body->fid1, inode); mds_pack_inode2body(body, inode); - /* Don't return OST-specific attributes if we didn't just set them */ - if (rec->ur_iattr.ia_valid & ATTR_SIZE) + /* don't return OST-specific attributes if we didn't just set them. Use + * saved ->ia_valid here, as rec->ur_iattr.ia_valid gets rewritten by + * fsfilt_setattr() what breaks case of truncating file with no object + * on OST and no lsm (test_34c from sanity.sh). --umka */ + if (ia_valid & ATTR_SIZE) body->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS; - if (rec->ur_iattr.ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) + if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) body->valid |= OBD_MD_FLMTIME; - if (rec->ur_iattr.ia_valid & (ATTR_ATIME | ATTR_ATIME_SET)) + if (ia_valid & (ATTR_ATIME | ATTR_ATIME_SET)) body->valid |= OBD_MD_FLATIME; if (rc == 0 && rec->ur_cookielen && !IS_ERR(mds->mds_osc_obd)) { @@ -653,7 +657,7 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, req->rq_status = rc; /* trigger dqrel/dqacq for original owner and new owner */ - if (rec->ur_iattr.ia_valid & (ATTR_UID | ATTR_GID)) { + if (ia_valid & (ATTR_UID | ATTR_GID)) { mds_adjust_qunit(obd, rec->ur_iattr.ia_uid, rec->ur_iattr.ia_gid, 0, 0, rc); mds_adjust_qunit(obd, child_uid, child_gid, 0, 0, rc); diff --git a/lustre/obdclass/obdo.c b/lustre/obdclass/obdo.c index 211923d..7523302 100644 --- a/lustre/obdclass/obdo.c +++ b/lustre/obdclass/obdo.c @@ -124,9 +124,15 @@ void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid) attr->ia_gid = oa->o_gid; attr->ia_valid |= ATTR_GID; } + + /* do not set CROW into flags, as it realy does not belong to attributes + * and only confuses filter_setattr_internal(). */ if (valid & OBD_MD_FLFLAGS) { - attr->ia_attr_flags = oa->o_flags; - attr->ia_valid |= ATTR_ATTR_FLAG; + obd_flag o_flags = (oa->o_flags & ~OBD_FL_CREATE_CROW); + if (o_flags) { + attr->ia_attr_flags = o_flags; + attr->ia_valid |= ATTR_ATTR_FLAG; + } } } EXPORT_SYMBOL(iattr_from_obdo); diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 5a8bf46..080b6a4 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -2666,11 +2666,10 @@ static int filter_create(struct obd_export *exp, struct obdo *oa, /* NB start and end are used for punch, but not truncate */ static int filter_truncate(struct obd_export *exp, struct obdo *oa, - struct lov_stripe_md *lsm, - obd_off start, obd_off end, - struct obd_trans_info *oti) + struct lov_stripe_md *lsm, obd_off start, + obd_off end, struct obd_trans_info *oti) { - int error; + int rc; ENTRY; if (end != OBD_OBJECT_EOF) @@ -2679,9 +2678,10 @@ static int filter_truncate(struct obd_export *exp, struct obdo *oa, CDEBUG(D_INODE, "calling truncate for object "LPU64", valid = "LPX64 ", o_size = "LPD64"\n", oa->o_id, oa->o_valid, start); + oa->o_size = start; - error = filter_setattr(exp, oa, NULL, oti); - RETURN(error); + rc = filter_setattr(exp, oa, NULL, oti); + RETURN(rc); } static int filter_sync(struct obd_export *exp, struct obdo *oa, diff --git a/lustre/obdfilter/filter_io.c b/lustre/obdfilter/filter_io.c index 4448c45..b9ca816 100644 --- a/lustre/obdfilter/filter_io.c +++ b/lustre/obdfilter/filter_io.c @@ -296,12 +296,12 @@ static int filter_preprw_read(int cmd, struct obd_export *exp, struct obdo *oa, dentry = filter_oa2dentry(obd, oa); if (IS_ERR(dentry)) { - rc = PTR_ERR(dentry); - if (rc == -ENOENT) { + if (PTR_ERR(dentry) == -ENOENT) { + dentry = NULL; inode = NULL; } else { dentry = NULL; - GOTO(cleanup, rc); + GOTO(cleanup, rc = PTR_ERR(dentry)); } } else { inode = dentry->d_inode; @@ -347,8 +347,8 @@ static int filter_preprw_read(int cmd, struct obd_export *exp, struct obdo *oa, fsfilt_check_slow(now, obd_timeout, "start_page_read"); if (inode != NULL) { - rc = filter_direct_io(OBD_BRW_READ, dentry, iobuf, exp, - NULL, NULL, NULL); + rc = filter_direct_io(OBD_BRW_READ, dentry, iobuf, + exp, NULL, NULL, NULL); if (rc) GOTO(cleanup, rc); } -- 1.8.3.1