From 0d646e7ee7be8c8c28a27120f9db4231e3e0cde7 Mon Sep 17 00:00:00 2001 From: adilger Date: Wed, 16 Oct 2002 17:27:18 +0000 Subject: [PATCH] - Extract the file size and blocks from osc_open() in ll_file_open(). Avoids a bug where the file size is incorrectly stored on the MDS (not sure why, but then we don't trust the file size on the MDS anyways. - Fix the unlock half of the boolean locking check I fixed last week. - Use the common ll_create_objects() helper to create objects, so the BA OST workaround is in use for all creates. --- lustre/include/linux/lustre_lite.h | 2 ++ lustre/llite/file.c | 30 ++++++++++-------- lustre/llite/namei.c | 63 ++++++++++++++++---------------------- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/lustre/include/linux/lustre_lite.h b/lustre/include/linux/lustre_lite.h index 4174dab..50f2c34 100644 --- a/lustre/include/linux/lustre_lite.h +++ b/lustre/include/linux/lustre_lite.h @@ -167,6 +167,8 @@ int ll_size_lock(struct inode *, struct lov_stripe_md *, obd_off start, int ll_size_unlock(struct inode *, struct lov_stripe_md *, int mode, struct lustre_handle *); int ll_file_size(struct inode *inode, struct lov_stripe_md *md); +int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid, + gid_t gid, struct lov_stripe_md **lsmp); /* rw.c */ struct page *ll_getpage(struct inode *inode, unsigned long offset, diff --git a/lustre/llite/file.c b/lustre/llite/file.c index a0c4c61..370baac 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -32,7 +32,8 @@ int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc); extern int ll_setattr(struct dentry *de, struct iattr *attr); -static int ll_create_objects(struct inode *inode, struct ll_inode_info *lli) +int ll_create_objects(struct super_block *sb, obd_id id, uid_t uid, gid_t gid, + struct lov_stripe_md **lsmp) { struct obdo *oa; int rc; @@ -43,15 +44,17 @@ static int ll_create_objects(struct inode *inode, struct ll_inode_info *lli) RETURN(-ENOMEM); oa->o_mode = S_IFREG | 0600; - oa->o_easize = ll_mds_easize(inode->i_sb); - oa->o_id = inode->i_ino; - oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | - OBD_MD_FLMODE | OBD_MD_FLEASIZE; - rc = obd_create(ll_i2obdconn(inode), oa, &lli->lli_smd); + oa->o_easize = ll_mds_easize(sb); + oa->o_id = id; + oa->o_uid = uid; + oa->o_gid = gid; + oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLEASIZE | OBD_MD_FLUID | OBD_MD_FLGID; + rc = obd_create(ll_s2obdconn(sb), oa, lsmp); obdo_free(oa); if (!rc) - LASSERT(lli->lli_smd->lsm_object_id); + LASSERT((*lsmp)->lsm_object_id); RETURN(rc); } @@ -83,7 +86,8 @@ static int ll_file_open(struct inode *inode, struct file *file) down(&lli->lli_open_sem); /* Check to see if we lost the race */ if (!lli->lli_smd) - rc = ll_create_objects(inode, lli); + rc = ll_create_objects(inode->i_sb, inode->i_ino, 0, 0, + &lli->lli_smd); up(&lli->lli_open_sem); if (rc) RETURN(rc); @@ -121,8 +125,10 @@ static int ll_file_open(struct inode *inode, struct file *file) oa->o_id = lsm->lsm_object_id; oa->o_mode = S_IFREG; - oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE; + oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE | + OBD_MD_FLBLOCKS; rc = obd_open(ll_i2obdconn(inode), oa, lsm); + obdo_to_inode(inode, oa, oa->o_valid & (OBD_MD_FLSIZE|OBD_MD_FLBLOCKS)); obd_oa2handle(&fd->fd_osthandle, oa); obdo_free(oa); @@ -509,8 +515,8 @@ ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos) obdo_free(oa); } - if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) || - sbi->ll_flags & LL_SBI_NOLCK) { + if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) && + !(sbi->ll_flags & LL_SBI_NOLCK)) { OBD_ALLOC(lockhs, lsm->lsm_stripe_count * sizeof(*lockhs)); if (!lockhs) GOTO(out_eof, retval = -ENOMEM); @@ -589,7 +595,7 @@ static int ll_lov_setstripe(struct inode *inode, struct file *file, lsm->lsm_mds_easize = size; file->f_flags &= ~O_LOV_DELAY_CREATE; - rc = ll_create_objects(inode, lli); + rc = ll_create_objects(inode->i_sb, inode->i_ino, 0, 0, &lsm); if (rc) OBD_FREE(lli->lli_smd, size); else diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index cd02e57..33dacf6 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -341,8 +341,7 @@ static struct inode *ll_create_node(struct inode *dir, const char *name, } body = lustre_msg_buf(request->rq_repmsg, 0); if (lsm != NULL) { - mds_md_size = ll_mds_easize(dir->i_sb); - OBD_ALLOC(lmm, mds_md_size); + OBD_ALLOC(lmm, lsm->lsm_mds_easize); lov_packmd(lmm, lsm); lic.lic_lmm = lmm; } else @@ -449,10 +448,9 @@ int ll_mdc_rename(struct inode *src, struct inode *tgt, * with d_instantiate(). */ -static int ll_create(struct inode * dir, struct dentry * dentry, int mode) +static int ll_create(struct inode *dir, struct dentry *dentry, int mode) { int err, rc = 0; - struct obdo *oa = NULL; struct inode *inode; struct lov_stripe_md *lsm = NULL; struct ll_inode_info *lli = NULL; @@ -461,31 +459,22 @@ static int ll_create(struct inode * dir, struct dentry * dentry, int mode) CHECK_MOUNT_EPOCH(dir); if (dentry->d_it->it_disposition == 0) { - int gid = current->fsgid; - - if (dir->i_mode & S_ISGID) - gid = dir->i_gid; - - oa = obdo_alloc(); - if (!oa) - RETURN(-ENOMEM); - - oa->o_mode = S_IFREG | 0600; /* FIXME: we set the UID/GID fields to 0 for now, because it * fixes a bug on the BA OSTs. We should really set * them properly, and this needs to be revisited when * we do proper credentials checking on the OST, and * set the attributes on the OST in ll_inode_setattr(). - oa->o_uid = current->fsuid; - oa->o_gid = gid; - */ - oa->o_uid = 0; - oa->o_gid = 0; - oa->o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLUID | - OBD_MD_FLGID; - rc = obd_create(ll_i2obdconn(dir), oa, &lsm); - CDEBUG(D_DENTRY, "name %s mode %o o_id "LPX64": rc = %d\n", - dentry->d_name.name, mode, oa->o_id, rc); + * See also ll_file_open() and ll_lov_setstripe(). + gid_t gid = current->fsgid; + + if (dir->i_mode & S_ISGID) + gid = dir->i_gid; + rc = ll_create_objects(ll_i2obdconn(dir), 0, current->fsuid, + gid, &lsm); + */ + rc = ll_create_objects(dir->i_sb, 0, 0, 0, &lsm); + CDEBUG(D_DENTRY, "name %*s mode %o: rc = %d\n", + dentry->d_name.len, dentry->d_name.name, mode, rc); if (rc) GOTO(out_free, rc); } @@ -495,8 +484,8 @@ static int ll_create(struct inode * dir, struct dentry * dentry, int mode) if (IS_ERR(inode)) { rc = PTR_ERR(inode); - CERROR("error creating MDS object for id "LPX64": rc = %d\n", - oa->o_id, rc); + CERROR("error creating MDS object for %*s: rc = %d\n", + dentry->d_name.len, dentry->d_name.name, rc); GOTO(out_destroy, rc); } @@ -512,22 +501,24 @@ static int ll_create(struct inode * dir, struct dentry * dentry, int mode) } out_free: - obdo_free(oa); RETURN(rc); out_destroy: if (lsm) { - if (!oa) - oa = obdo_alloc(); - if (!oa) - RETURN(-ENOMEM); - - oa->o_easize = ll_mds_easize(inode->i_sb); - oa->o_valid |= OBD_MD_FLEASIZE; - err = obd_destroy(ll_i2obdconn(dir), oa, lsm); + struct obdo *oa; + oa = obdo_alloc(); + if (oa) { + oa->o_easize = lsm->lsm_mds_easize; + oa->o_id = lsm->lsm_object_id; + oa->o_valid |= OBD_MD_FLID | OBD_MD_FLEASIZE; + err = obd_destroy(ll_i2obdconn(dir), oa, lsm); + obdo_free(oa); + } else + err = -ENOMEM; if (err) CERROR("error uncreating objid "LPX64": err %d\n", - oa->o_id, err); + lsm->lsm_object_id, err); + OBD_FREE(lsm, ll_ost_easize(dir->i_sb)); } goto out_free; -- 1.8.3.1