From 4f025745ebb53786e190e76daaf353fd1bc96a6e Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 22 Apr 2009 17:12:27 +0000 Subject: [PATCH] b=18676 i=johann i=manoj replace obd ioctl with dir ioctl for changelogs --- lustre/include/lustre/lustre_user.h | 10 ++- lustre/llite/dir.c | 17 ++++ lustre/lmv/lmv_obd.c | 11 +++ lustre/mdc/mdc_request.c | 3 +- lustre/mdd/mdd_device.c | 8 +- lustre/mdt/mdt_handler.c | 8 +- lustre/utils/liblustreapi.c | 156 +++++++++++++++++++++--------------- 7 files changed, 138 insertions(+), 75 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index daa4b4e..cc1852d 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -70,7 +70,7 @@ struct obd_statfs; -/* +/* * The ioctl naming rules: * LL_* - works on the currently opened filehandle instead of parent dir * *_OBD_* - gets data for both OSC or MDC (LOV, LMV indirectly) @@ -213,7 +213,7 @@ static inline void obd_str2uuid(struct obd_uuid *uuid, const char *tmp) } /* For printf's only, make sure uuid is terminated */ -static inline char *obd_uuid2str(struct obd_uuid *uuid) +static inline char *obd_uuid2str(struct obd_uuid *uuid) { if (uuid->uuid[sizeof(*uuid) - 1] != '\0') { /* Obviously not safe, but for printfs, no real harm done... @@ -352,6 +352,12 @@ struct if_quotactl { struct obd_uuid obd_uuid; }; +struct ioc_changelog_clear { + __u32 icc_mdtindex; + __u32 icc_id; + __u64 icc_recno; +}; + #ifndef offsetof # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb))) #endif diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index a31cc3e..13a51f1 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1220,6 +1220,23 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, sizeof(struct lu_fid))) RETURN(-EFAULT); RETURN(0); + case OBD_IOC_CHANGELOG_CLEAR: { + struct ioc_changelog_clear *icc; + int rc; + + OBD_ALLOC_PTR(icc); + if (icc == NULL) + RETURN(-ENOMEM); + if (copy_from_user(icc, (void *)arg, sizeof(*icc))) + GOTO(icc_free, rc = -EFAULT); + + rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(*icc), icc,NULL); + +icc_free: + OBD_FREE_PTR(icc); + RETURN(rc); + } + default: RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg)); } diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index f98f511..49025ce 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -809,6 +809,17 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, OBD_FREE_PTR(oqctl); break; } + case OBD_IOC_CHANGELOG_CLEAR: { + struct ioc_changelog_clear *icc = karg; + + if (icc->icc_mdtindex >= count) + RETURN(-ENODEV); + + rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex].ltd_exp, + sizeof(*icc), icc, NULL); + break; + } + default : { for (i = 0; i < count; i++) { int err; diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 5d0c34d..2b03257 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -1010,8 +1010,9 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, } switch (cmd) { case OBD_IOC_CHANGELOG_CLEAR: { + struct ioc_changelog_clear *icc = karg; struct changelog_setinfo cs = - {data->ioc_u64_1, data->ioc_u32_1}; + {icc->icc_recno, icc->icc_id}; rc = obd_set_info_async(exp, strlen(KEY_CHANGELOG_CLEAR), KEY_CHANGELOG_CLEAR, sizeof(cs), &cs, NULL); diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index a4e73ea..d41e652 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -1285,8 +1285,8 @@ static int mdd_changelog_user_purge(struct mdd_device *mdd, int id, /** mdd_iocontrol * May be called remotely from mdt_iocontrol_handle or locally from - * mdt_iocontrol. Data may be freeform - remote handling doesn't enforce or - * swab an obd_ioctl_data format (but local ioctl handler does). + * mdt_iocontrol. Data may be freeform - remote handling doesn't enforce + * an obd_ioctl_data format (but local ioctl handler does). * \param cmd - ioc * \param len - data len * \param karg - ioctl data, in kernel space @@ -1304,10 +1304,6 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, /* Doesn't use obd_ioctl_data */ if (cmd == OBD_IOC_CHANGELOG_CLEAR) { struct changelog_setinfo *cs = karg; - if (len != sizeof(*cs)) { - CERROR("Bad changelog_clear ioctl size %d\n", len); - RETURN(-EINVAL); - } rc = mdd_changelog_user_purge(mdd, cs->cs_id, cs->cs_recno); RETURN(rc); } diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 59c0753..d7aaaf9 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -1113,9 +1113,13 @@ static int mdt_set_info(struct mdt_thread_info *info) spin_unlock(&req->rq_export->exp_lock); } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) { + struct changelog_setinfo *cs = + (struct changelog_setinfo *)val; + if (vallen != sizeof(*cs)) { + CERROR("Bad changelog_clear setinfo size %d\n", vallen); + RETURN(-EINVAL); + } if (lustre_msg_swabbed(req->rq_reqmsg)) { - struct changelog_setinfo *cs = - (struct changelog_setinfo *)val; __swab64s(&cs->cs_recno); __swab32s(&cs->cs_id); } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 26f3a5e..506f581 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -432,6 +432,48 @@ static int search_fsname(char *pathname, char *fsname) return -ENOENT; } +/* + * Return an open fd to the named Lustre fs root + */ +static int get_root_fd(char *fsname) +{ + char *ptr; + FILE *fp; + struct mntent *mnt = NULL; + int fd; + + /* get the mount point */ + fp = setmntent(MOUNTED, "r"); + if (fp == NULL) { + llapi_err(LLAPI_MSG_ERROR, + "setmntent(%s) failed: %s:", MOUNTED, + strerror (errno)); + return -EIO; + } + mnt = getmntent(fp); + while ((feof(fp) == 0) && ferror(fp) == 0) { + if (llapi_is_lustre_mnt(mnt)) { + ptr = strrchr(mnt->mnt_fsname, '/'); + if (!ptr) + return -EINVAL; + ptr++; + + if (strcmp(ptr, fsname) == 0) { + fd = open(mnt->mnt_dir, O_RDONLY | O_DIRECTORY); + if (fd < 0) { + perror("open"); + return -errno; + } + endmntent(fp); + return fd; + } + } + mnt = getmntent(fp); + } + endmntent(fp); + return -ENOENT; +} + /* return the first file matching this pattern */ static int first_match(char *pattern, char *buffer) { @@ -2391,7 +2433,9 @@ int llapi_ls(int argc, char *argv[]) exit(execvp(argv[0], argv)); } -/* format must have %s%s, buf must be > 16 */ +/* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed. + * format must have %s%s, buf must be > 16 + */ static int get_mdtname(const char *name, char *format, char *buf) { char suffix[]="-MDT0000"; @@ -2438,6 +2482,53 @@ int llapi_changelog_open(const char *mdtname, long long startrec) return fd; } +int llapi_changelog_clear(const char *mdtname, const char *idstr, + long long endrec) +{ + struct ioc_changelog_clear data; + char *ptr; + int id, fd, index, rc; + + if (endrec < 0) { + llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, + "can't purge negative records\n"); + return -EINVAL; + } + + id = strtol(idstr + strlen(CHANGELOG_USER_PREFIX), NULL, 10); + if ((id == 0) || (strncmp(idstr, CHANGELOG_USER_PREFIX, + strlen(CHANGELOG_USER_PREFIX)) != 0)) { + llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, + "expecting id of the form '"CHANGELOG_USER_PREFIX + "'; got '%s'\n", idstr); + return -EINVAL; + } + + ptr = strstr(mdtname, "-MDT"); + if (!ptr) + return -EINVAL; + index = strtol(ptr + 1, NULL, 10); + *ptr = '\0'; + + fd = get_root_fd((char *)mdtname); + if (fd < 0) { + llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, + "can't open fs root for '%s': %d\n", mdtname, fd); + return fd; + } + + data.icc_mdtindex = index; + data.icc_id = id; + data.icc_recno = endrec; + rc = ioctl(fd, OBD_IOC_CHANGELOG_CLEAR, &data); + if (rc) + llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, + "ioctl err %d", rc); + + close(fd); + return rc; +} + static int dev_ioctl(struct obd_ioctl_data *data, int dev, int cmd) { static char rawbuf[8192]; @@ -2485,69 +2576,6 @@ static int dev_name2dev(char *name) return data.ioc_dev; } -/* We need the full mdc name, and we shouldn't just grep from proc... */ -static void do_get_mdcname(char *obd_type_name, char *obd_name, - char *obd_uuid, void *name) -{ - if (strncmp(obd_name, (char *)name, strlen((char *)name)) == 0) - strcpy((char *)name, obd_name); -} - -static int get_mdcdev(const char *mdtname) -{ - char name[MAX_OBD_NAME]; - char *type[] = { "mdc" }; - int rc; - - strcpy(name, mdtname); - rc = llapi_target_iterate(1, type, (void *)name, do_get_mdcname); - rc = rc < 0 ? : -rc; - if (rc < 0) { - llapi_err(LLAPI_MSG_ERROR, "Device %s not found %d\n", name,rc); - return rc; - } - return dev_name2dev(name); -} - -int llapi_changelog_clear(const char *mdtname, const char *idstr, - long long endrec) -{ - struct obd_ioctl_data data; - int dev, id, rc; - - if (endrec < 0) { - llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, - "can't purge negative records\n"); - return -EINVAL; - } - - id = strtol(idstr + strlen(CHANGELOG_USER_PREFIX), NULL, 10); - if ((id == 0) || (strncmp(idstr, CHANGELOG_USER_PREFIX, - strlen(CHANGELOG_USER_PREFIX)) != 0)) { - llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, - "expecting id of the form '"CHANGELOG_USER_PREFIX - "'; got '%s'\n", idstr); - return -EINVAL; - } - - dev = get_mdcdev(mdtname); - if (dev < 0) { - llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, - "can't find mdc for '%s'\n", mdtname); - return dev; - } - - memset(&data, 0, sizeof(data)); - data.ioc_u32_1 = id; - data.ioc_u64_1 = endrec; - rc = dev_ioctl(&data, dev, OBD_IOC_CHANGELOG_CLEAR); - if (rc) - llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, - "ioctl err %d", rc); - return rc; -} - - int llapi_fid2path(char *device, char *fidstr, char *buf, int buflen, long long *recno, int *linkno) { -- 1.8.3.1