From 4a7feafcb8f8ddf51ef1e2d6726ce371ff808637 Mon Sep 17 00:00:00 2001 From: Vladimir Saveliev Date: Thu, 30 Sep 2010 01:21:37 +0400 Subject: [PATCH] b=22766 cascading_rw: take lmm_stripe_count returned by ioctl(LL_IOC_LOV_SETSTRIPE) +cleanup in ll_dir_ioctl(): do not save return code of copy_to_user and copy_from_user i=adilger --- lustre/llite/dir.c | 32 +++++++++++++++----------------- lustre/tests/mpi/cascading_rw.c | 8 -------- lustre/utils/liblustreapi.c | 2 ++ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 7a40543..d101b30 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1202,13 +1202,11 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, sizeof(lumv3p->lmm_objects[0])); /* first try with v1 which is smaller than v3 */ - rc = copy_from_user(lumv1, lumv1p, sizeof(*lumv1)); - if (rc) - return(-EFAULT); + if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1))) + RETURN(-EFAULT); if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) { - rc = copy_from_user(&lumv3, lumv3p, sizeof(lumv3)); - if (rc) + if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3))) RETURN(-EFAULT); } @@ -1271,9 +1269,11 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, lmdp = (struct lov_user_mds_data *)arg; lump = &lmdp->lmd_lmm; } - rc = copy_to_user(lump, lmm, lmmsize); - if (rc) - GOTO(out_lmm, rc = -EFAULT); + if (copy_to_user(lump, lmm, lmmsize) != 0) { + if (copy_to_user(lump, lmm, sizeof(*lump)) != 0) + GOTO(out_lmm, rc = -EFAULT); + rc = -EOVERFLOW; + } skip_lmm: if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) { struct lov_user_mds_data *lmdp; @@ -1294,8 +1294,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, st.st_ino = body->ino; lmdp = (struct lov_user_mds_data *)arg; - rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st)); - if (rc) + if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st))) GOTO(out_lmm, rc = -EFAULT); } @@ -1326,8 +1325,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, RETURN(rc); OBD_ALLOC(lmm, lmmsize); - rc = copy_from_user(lmm, lum, lmmsize); - if (rc) + if (copy_from_user(lmm, lum, lmmsize)) GOTO(free_lmm, rc = -EFAULT); if (LOV_USER_MAGIC != cpu_to_le32(LOV_USER_MAGIC)) { @@ -1356,8 +1354,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, if (rc) GOTO(free_lsm, rc); - rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st)); - if (rc) + if (copy_to_user(&lumd->lmd_st, &st, sizeof(st))) GOTO(free_lsm, rc = -EFAULT); EXIT; @@ -1408,7 +1405,8 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF, data->ioc_plen1); if (!rc) - rc = copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1); + if (copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1)) + rc = -EFAULT; ptlrpc_req_finished(req); out_catinfo: obd_ioctl_freedata(buf, len); @@ -1454,7 +1452,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, if (rc) { CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc); if (copy_to_user((void *)arg, check, sizeof(*check))) - rc = -EFAULT; + CDEBUG(D_QUOTA, "copy_to_user failed\n"); GOTO(out_poll, rc); } @@ -1463,7 +1461,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, if (rc) { CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc); if (copy_to_user((void *)arg, check, sizeof(*check))) - rc = -EFAULT; + CDEBUG(D_QUOTA, "copy_to_user failed\n"); GOTO(out_poll, rc); } out_poll: diff --git a/lustre/tests/mpi/cascading_rw.c b/lustre/tests/mpi/cascading_rw.c index e9f00aa..694f6a4 100644 --- a/lustre/tests/mpi/cascading_rw.c +++ b/lustre/tests/mpi/cascading_rw.c @@ -65,7 +65,6 @@ char *testdir = NULL; void rw_file(char *name, long stride, unsigned int seed) { char filename[MAX_FILENAME_LEN]; - char path[MAX_FILENAME_LEN]; char errmsg[MAX_FILENAME_LEN+20]; char *buf, *o_buf; struct lov_user_md lum = {0}; @@ -100,13 +99,6 @@ void rw_file(char *name, long stride, unsigned int seed) sprintf(errmsg, "close of file %s", filename); FAIL(errmsg); } - - strncpy(path, filename, MAX_FILENAME_LEN); - rc = llapi_file_get_stripe(path, &lum); - if (rc == -1) { - sprintf(errmsg, "get stripe of file %s", filename); - FAIL(errmsg); - } } MPI_Barrier(MPI_COMM_WORLD); diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 9a0aeb4..18f6184 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1566,6 +1566,8 @@ int llapi_file_get_stripe(const char *path, struct lov_user_md *lum) int fd, rc = 0; fname = strrchr(path, '/'); + if (strlen(fname) + 1 < sizeof(struct lov_user_md)) + return ENAMETOOLONG; /* It should be a file (or other non-directory) */ if (fname == NULL) { -- 1.8.3.1