From 3fdb188c286eeb7b0a120bd3c86a5cdec8111401 Mon Sep 17 00:00:00 2001 From: adilger Date: Thu, 1 Apr 2004 00:52:40 +0000 Subject: [PATCH] Don't allow setstripe on a file/directory without write permission for same. Regression tests for setstripe permission check. b=1414 --- lustre/include/linux/lustre_compat25.h | 2 +- lustre/llite/dir.c | 12 +++--- lustre/llite/llite_lib.c | 5 --- lustre/llite/special.c | 4 -- lustre/mds/mds_reint.c | 8 +++- lustre/tests/sanity.sh | 77 ++++++++++++++++++++++------------ 6 files changed, 62 insertions(+), 46 deletions(-) diff --git a/lustre/include/linux/lustre_compat25.h b/lustre/include/linux/lustre_compat25.h index 4a4e3a0..fb97fa6 100644 --- a/lustre/include/linux/lustre_compat25.h +++ b/lustre/include/linux/lustre_compat25.h @@ -52,7 +52,7 @@ #define LTIME_S(time) (time.tv_sec) #define ll_path_lookup path_lookup -#define ll_permission permission +#define ll_permission(a,b,c) permission(a,b,c) #define ll_pgcache_lock(mapping) spin_lock(&mapping->page_lock) #define ll_pgcache_unlock(mapping) spin_unlock(&mapping->page_lock) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 97fbf99..7b463ca 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -385,7 +385,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, switch(cmd) { case EXT3_IOC_GETFLAGS: case EXT3_IOC_SETFLAGS: - RETURN( ll_iocontrol(inode, file, cmd, arg) ); + RETURN(ll_iocontrol(inode, file, cmd, arg)); case IOC_MDC_LOOKUP: { struct ptlrpc_request *request = NULL; struct ll_fid fid; @@ -426,17 +426,15 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, case LL_IOC_LOV_SETSTRIPE: { struct ptlrpc_request *request = NULL; struct mdc_op_data op_data; - struct iattr attr; + struct iattr attr = { 0 }; struct lov_user_md lum, *lump = (struct lov_user_md *)arg; int rc = 0; ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0); - memset(&attr, 0x0, sizeof(attr)); - LASSERT(sizeof(lum) == sizeof(*lump)); - LASSERT(sizeof(lum.lmm_objects[0]) - == sizeof(lump->lmm_objects[0])); + LASSERT(sizeof(lum.lmm_objects[0]) == + sizeof(lump->lmm_objects[0])); rc = copy_from_user(&lum, lump, sizeof(lum)); if (rc) return(-EFAULT); @@ -455,7 +453,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, ptlrpc_req_finished(request); return rc; - } + } case LL_IOC_LOV_GETSTRIPE: { struct ptlrpc_request *request = NULL; struct lov_user_md *lump = (struct lov_user_md *)arg; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 89dcec9..5812e16 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -1171,11 +1171,6 @@ void ll_read_inode2(struct inode *inode, void *opaque) inode->i_fop = &ll_special_fifo_inode_fops; else if (S_ISSOCK(inode->i_mode)) inode->i_fop = &ll_special_sock_inode_fops; - CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop, - inode->i_fop); - if (lli->ll_save_ifop->owner) - CWARN("%p has owner %p\n", lli->ll_save_ifop, - lli->ll_save_ifop->owner); #endif EXIT; } diff --git a/lustre/llite/special.c b/lustre/llite/special.c index 7243811..ffd868f 100644 --- a/lustre/llite/special.c +++ b/lustre/llite/special.c @@ -75,10 +75,6 @@ static void save_fops(struct file *filp, struct inode *inode, filp->f_op = &ll_special_chr_file_fops; else if (S_ISFIFO(inode->i_mode)) filp->f_op = &ll_special_fifo_file_fops; - - CWARN("saved %p, replaced with %p\n", *pfop, filp->f_op); - if ((*pfop)->owner) - CWARN("%p has owner %p\n", *pfop,(*pfop)->owner); } } diff --git a/lustre/mds/mds_reint.c b/lustre/mds/mds_reint.c index 889d2cd..b2dd794 100644 --- a/lustre/mds/mds_reint.c +++ b/lustre/mds/mds_reint.c @@ -432,16 +432,20 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset, rec->ur_eadata != NULL) { struct lov_stripe_md *lsm = NULL; + rc = ll_permission(inode, MAY_WRITE, NULL); + if (rc < 0) + GOTO(cleanup, rc); + rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, mds->mds_osc_exp, 0, &lsm, rec->ur_eadata); if (rc) GOTO(cleanup, rc); - + obd_free_memmd(mds->mds_osc_exp, &lsm); rc = fsfilt_set_md(obd, inode, handle, rec->ur_eadata, rec->ur_eadatalen); - if (rc) + if (rc) GOTO(cleanup, rc); } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 2cffeee..4b003ef 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -20,8 +20,10 @@ TMP=${TMP:-/tmp} CHECKSTAT=${CHECKSTAT:-"checkstat -v"} CREATETEST=${CREATETEST:-createtest} -LFIND=${LFIND:-lfind} -LSTRIPE=${LSTRIPE:-lstripe} +LFS=${LFS:-lfs} +LSTRIPE=${LSTRIPE:-"$LFS setstripe"} +LFIND=${LFIND:-"$LFS find"} +LVERIFY=${LVERIFY:-ll_dirstripe_verify} LCTL=${LCTL:-lctl} MCREATE=${MCREATE:-mcreate} OPENFILE=${OPENFILE:-openfile} @@ -783,6 +785,13 @@ test_27k() { # bug 2844 } run_test 27k "limit i_blksize for broken user apps =============" +test_27l() { + mcreate $DIR/f27l || error "creating file" + $RUNAS $LSTRIPE $DIR/f27l 65536 -1 1 && \ + error "lstripe should have failed" || true +} +run_test 27l "check setstripe permissions (should return error)" + test_28() { mkdir $DIR/d28 $CREATETEST $DIR/d28/ct || error @@ -1823,49 +1832,63 @@ test_64a () { df $DIR grep "[0-9]" /proc/fs/lustre/osc/OSC*MNT*/cur* } -run_test 64a "verify filter grant calculations (in kernel) ======" +run_test 64a "verify filter grant calculations (in kernel) =====" test_64b () { sh oos.sh $MOUNT } -run_test 64b "check out-of-space detection on client ============" +run_test 64b "check out-of-space detection on client ===========" # bug 1414 - set/get directories' stripe info -test_65() { - LFS=${LFS:-lfs} - LVERIFY=${LVERIFY:-ll_dirstripe_verify} - - echo "dir has no stripe info" - mkdir $DIR/d65 +test_65a() { + mkdir -p $DIR/d65 touch $DIR/d65/f1 - $LVERIFY $DIR/d65 $DIR/d65/f1 || error + $LVERIFY $DIR/d65 $DIR/d65/f1 || error "lverify failed" +} +run_test 65a "directory with no stripe info ====================" - echo "setstripe $(($STRIPESIZE * 2)) 0 1" - $LFS setstripe $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error +test_65b() { + mkdir -p $DIR/d65 + $LSTRIPE $DIR/d65 $(($STRIPESIZE * 2)) 0 1 || error "setstripe" touch $DIR/d65/f2 - $LVERIFY $DIR/d65 $DIR/d65/f2 || error + $LVERIFY $DIR/d65 $DIR/d65/f2 || error "lverify failed" +} +run_test 65b "directory setstripe $(($STRIPESIZE * 2)) 0 1 ===============" - if [ $ostcount -gt 1 ]; then - echo "setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))" - $LFS setstripe $DIR/d65 $(($STRIPESIZE * 4)) 1 \ - $(($OSTCOUNT - 1)) || error +test_65c() { + if [ $OSTCOUNT -gt 1 ]; then + mkdir -p $DIR/d65 + $LSTRIPE DIR/d65 $(($STRIPESIZE * 4)) 1 \ + $(($OSTCOUNT - 1)) || error "setstripe" touch $DIR/d65/f3 - $LVERIFY $DIR/d65 $DIR/d65/f3 || error + $LVERIFY $DIR/d65 $DIR/d65/f3 || error "lverify failed" fi +} +run_test 65c "directory setstripe $(($STRIPESIZE * 4)) 1 $(($OSTCOUNT - 1))" - [ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1)) +[ $STRIPECOUNT -eq 0 ] && sc=1 || sc=$(($STRIPECOUNT - 1)) - echo "setstripe $STRIPESIZE -1 $sc" - $LFS setstripe $DIR/d65 $STRIPESIZE -1 $sc || error +test_65d() { + mkdir -p $DIR/d65 + $LSTRIPE $DIR/d65 $STRIPESIZE -1 $sc || error "setstripe" touch $DIR/d65/f4 $DIR/d65/f5 - $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error + $LVERIFY $DIR/d65 $DIR/d65/f4 $DIR/d65/f5 || error "lverify failed" +} +run_test 65d "directory setstripe $STRIPESIZE -1 $sc ======================" - echo "setstripe 0 -1 0 (default)" - $LFS setstripe $DIR/d65 0 -1 0 || error +test_65e() { + mkdir -p $DIR/d65 + $LSTRIPE $DIR/d65 0 -1 0 || error "setstripe" touch $DIR/d65/f6 - $LVERIFY $DIR/d65 $DIR/d65/f6 || error + $LVERIFY $DIR/d65 $DIR/d65/f6 || error "lverify failed" +} +run_test 65e "directory setstripe 0 -1 0 (default) =============" + +test_65f() { + mkdir -p $DIR/d65f + $RUNAS $LSTRIPE $DIR/d65f 0 -1 0 && error "setstripe succeeded" || true } -run_test 65 "Verify that the files are created using parent dir's stripe info" +run_test 65f "dir setstripe permission (should return error) ===" # bug 2543 - update blocks count on client test_66() { -- 1.8.3.1