From b8a0753a3bd2953ef6c24ddd18d15786808c2066 Mon Sep 17 00:00:00 2001 From: Vladimir Saveliev Date: Fri, 16 Jul 2010 17:51:18 +0400 Subject: [PATCH] b=13698 llapi_get_version this uses OBD_GET_VERSION ioctl to obtain lustre version i=andreas.dilger --- lustre/include/lustre/liblustreapi.h | 1 + lustre/utils/liblustreapi.c | 28 ++++++++++++++++++++++++++++ lustre/utils/obd.c | 21 +++++++-------------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index a48887d..2c035b2 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -204,6 +204,7 @@ extern int llapi_ls(int argc, char *argv[]); extern int llapi_fid2path(const char *device, const char *fidstr, char *path, int pathlen, long long *recno, int *linkno); extern int llapi_path2fid(const char *path, lustre_fid *fid); +extern int llapi_get_version(char *buffer, int buffer_size, char **version); /* Changelog interface. priv is private state, managed internally by these functions */ diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 7631b51..0855805 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3270,3 +3270,31 @@ int llapi_get_connect_flags(const char *mnt, __u64 *flags) "ioctl on %s for getting connect flags failed", mnt); return rc; } + +int llapi_get_version(char *buffer, int buffer_size, + char **version) +{ + int rc; + int fd; + struct obd_ioctl_data *data = (struct obd_ioctl_data *)buffer; + + fd = open(OBD_DEV_PATH, O_RDONLY); + if (fd == -1) + return -errno; + + memset(buffer, 0, buffer_size); + data->ioc_version = OBD_IOCTL_VERSION; + data->ioc_inllen1 = buffer_size - cfs_size_round(sizeof(*data)); + data->ioc_inlbuf1 = buffer + cfs_size_round(sizeof(*data)); + data->ioc_len = obd_ioctl_packlen(data); + + rc = ioctl(fd, OBD_GET_VERSION, buffer); + if (rc == -1) { + rc = errno; + close(fd); + return -rc; + } + close(fd); + *version = data->ioc_bulk; + return 0; +} diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 619c96b..b0e0eb8 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -900,25 +900,18 @@ int jt_obd_abort_recovery(int argc, char **argv) int jt_get_version(int argc, char **argv) { int rc; - char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; - struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf; + char rawbuf[MAX_IOC_BUFLEN]; + char *version; if (argc != 1) return CMD_HELP; - memset(buf, 0, sizeof(rawbuf)); - data->ioc_version = OBD_IOCTL_VERSION; - data->ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data)); - data->ioc_len = obd_ioctl_packlen(data); - - rc = l2_ioctl(OBD_DEV_ID, OBD_GET_VERSION, buf); - if (rc < 0) + rc = llapi_get_version(rawbuf, MAX_IOC_BUFLEN, &version); + if (rc) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), - strerror(rc = errno)); - else { - printf("Lustre version: %s\n", data->ioc_bulk); - } + strerror(-rc)); + else + printf("Lustre version: %s\n", version); printf("lctl version: %s\n", BUILD_VERSION); return rc; -- 1.8.3.1