From 27129b7dd923d6dbd52b6427f2bcd474e67cf1b1 Mon Sep 17 00:00:00 2001 From: wangchao Date: Thu, 20 Nov 2003 06:06:55 +0000 Subject: [PATCH] bug: 1944 reviewer: Andreas Add "lfs osts" and "lfs check " to lfs. --- lustre/utils/lfs.c | 106 +++++++++++++++++++++++++++++++++++++++++++- lustre/utils/liblustreapi.c | 83 ++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index b22745a..7339242 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -28,21 +28,28 @@ #include #include #include +#include +#include +#include #include #include #include "parser.h" +#include "obdctl.h" extern int op_create_file(char *name, long stripe_size, int stripe_offset, int stripe_count); extern int op_find(char *path, struct obd_uuid *obduuid, int recursive, int verbose, int quiet); +extern int op_check(int type_num, char **obd_type_p, char *dir); /* all functions */ static int lfs_setstripe(int argc, char **argv); static int lfs_find(int argc, char **argv); static int lfs_getstripe(int argc, char **argv); +static int lfs_osts(int argc, char **argv); +static int lfs_check(int argc, char **argv); /* all avaialable commands */ command_t cmdlist[] = { @@ -58,6 +65,10 @@ command_t cmdlist[] = { {"getstripe", lfs_getstripe, 0, "blah...\n" "usage:getstripe "}, + {"check", lfs_check, 0, + "blah...\n" + "usage: check "}, + {"osts", lfs_osts, 0, "osts"}, {"help", Parser_help, 0, "help"}, {"exit", Parser_quit, 0, "quit"}, {"quit", Parser_quit, 0, "quit"}, @@ -187,12 +198,104 @@ static int lfs_getstripe(int argc, char **argv) return rc; } +static int lfs_osts(int argc, char **argv) +{ + FILE *fp; + struct mntent *mnt = NULL; + struct obd_uuid *obduuid = NULL; + int rc=0; + + if (argc != 1) + return CMD_HELP; + + fp = setmntent(MOUNTED, "r"); + + if (fp == NULL) { + fprintf(stderr, "setmntent(%s): %s:", MOUNTED, + strerror (errno)); + } else { + mnt = getmntent(fp); + while (feof(fp) == 0 && ferror(fp) ==0) { + if (strcmp(mnt->mnt_type, "lustre_lite") == 0) { + rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0); + if (rc) + fprintf(stderr, "error: lfs osts failed for %s\n", + mnt->mnt_dir); + } + mnt = getmntent(fp); + } + endmntent(fp); + } + + return rc; +} + +static int lfs_check(int argc, char **argv) +{ + int rc; + FILE *fp; + struct mntent *mnt = NULL; + int type_num = 1; + char *obd_type_p[2]; + char obd_type1[4]; + char obd_type2[4]; + + if (argc != 2) + return CMD_HELP; + + obd_type_p[1]=obd_type1; + obd_type_p[2]=obd_type2; + + if (strcmp(argv[1],"osts")==0) { + strcpy(obd_type_p[0],"osc"); + } else if (strcmp(argv[1],"mds")==0) { + strcpy(obd_type_p[0],"mdc"); + } else if (strcmp(argv[1],"servers")==0) { + type_num=2; + strcpy(obd_type_p[0],"osc"); + strcpy(obd_type_p[1],"mdc"); + } else { + fprintf(stderr, "error: %s: option '%s' unrecognized\n", + argv[0], argv[1]); + return CMD_HELP; + } + + fp = setmntent(MOUNTED, "r"); + if (fp == NULL) { + fprintf(stderr, "setmntent(%s): %s:", MOUNTED, + strerror (errno)); + } else { + mnt = getmntent(fp); + while (feof(fp) == 0 && ferror(fp) ==0) { + if (strcmp(mnt->mnt_type, "lustre_lite") == 0) + break; + mnt = getmntent(fp); + } + endmntent(fp); + } + + rc = op_check(type_num,obd_type_p,mnt->mnt_dir); + + if (rc) + fprintf(stderr, "error: %s: %s status failed\n", + argv[0],argv[1]); + + return rc; + +} + int main(int argc, char **argv) { int rc; setlinebuf(stdout); - + + ptl_initialize(argc, argv); + if (obd_initialize(argc, argv) < 0) + exit(2); + if (dbg_initialize(argc, argv) < 0) + exit(3); + Parser_init("lfs > ", cmdlist); if (argc > 1) { @@ -201,5 +304,6 @@ int main(int argc, char **argv) rc = Parser_commands(); } + obd_cleanup(argc, argv); return rc; } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 2ae9eb8..7ea801c 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -29,6 +29,8 @@ #include #include +#include +#include #include #include #include @@ -46,6 +48,8 @@ #include #include +#include + static void err_msg(char *fmt, ...) { va_list args; @@ -448,3 +452,82 @@ out: return ret; } +#define MAX_STRING_SIZE 128 + +int op_check(int type_num, char **obd_type, char *dir) +{ + int rc=0; + int i=0,j=0,k; + char buf[OBD_MAX_IOCTL_BUFFER]; + char *buf2; + struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf; + + memset(buf, 0, sizeof(buf)); + data->ioc_version = OBD_IOCTL_VERSION; + data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data)); + data->ioc_len = obd_ioctl_packlen(data); + + rc = l_ioctl(OBD_DEV_ID, OBD_IOC_LIST, data); + + buf2 = data->ioc_bulk; + + if (!data->ioc_inlbuf1) { + err_msg("No buffer passed!\n"); + rc = errno; + } + + do { + char status[3]; + char obd_type_name[sizeof(struct obd_type)]; + char obd_name[MAX_STRING_SIZE]; + char obd_uuid[sizeof(struct obd_uuid)]; + int obd_type_refcnt; + + char rawbuf[OBD_MAX_IOCTL_BUFFER]; + char *bufl = rawbuf; + int max = sizeof(rawbuf); + struct obd_ioctl_data datal; + struct obd_statfs osfs_buffer; + + memset (&osfs_buffer, 0, sizeof (osfs_buffer)); + + memset(bufl, 0, sizeof(rawbuf)); + datal.ioc_pbuf1 = (char *)&osfs_buffer; + datal.ioc_plen1 = sizeof (osfs_buffer); + + j = sscanf(buf2,"%d %s %s %s %s %d",&j, + status,obd_type_name, + obd_name, obd_uuid, + &obd_type_refcnt); + + if (j != 6) break; + + for (k=0;k