X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Ftestreq.c;h=774398de936bf231613ac6735cd367ec9f5d3048;hb=040033cef24c5aca2967daf2da7a862abcd074cf;hp=98886f48c1f8e2ee81c62fafc8ab759e010769f2;hpb=dfe6b1adaedec5d6c7ae7220c2dfaf8236631eca;p=fs%2Flustre-release.git diff --git a/lustre/tests/testreq.c b/lustre/tests/testreq.c index 98886f4..774398d 100644 --- a/lustre/tests/testreq.c +++ b/lustre/tests/testreq.c @@ -1,31 +1,141 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2002 Cluster File Systems, Inc. + * + * This file is part of Lustre, http://www.sf.net/projects/lustre/ + * + * Lustre is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * Lustre is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Lustre; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include #include -#include #include #include #include -#define IOC_REQUEST_GETATTR _IOWR('f', 30, long) -#define IOC_REQUEST_READPAGE _IOWR('f', 31, long) +#include +#include +#include + +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE + +#include +#include + +static void usage(char *argv0, int status) +{ + printf( +"Usage: %s [OPTION...]\n\ +\n\ +--getattr \n\ +--setattr \n\ +--readpage \n\ +--open \n\ +--close \n\ +--create \n", argv0); + + exit(status); +} int main(int argc, char **argv) { - int fd, rc; - int cmd = IOC_REQUEST_GETATTR; - - printf("ioctl type %d, nr %d size %d\n", - _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)); - - fd = open("/dev/request", O_RDONLY); - if (fd == -1) { - printf("error opening /dev/request: %s\n", strerror(errno)); - return 1; - } - - printf("getattr test... "); - rc = ioctl(fd, IOC_REQUEST_GETATTR, NULL); - printf("result: %d\n", rc); - - printf("readpage test... "); - rc = ioctl(fd, IOC_REQUEST_READPAGE, NULL); - printf("result: %d\n", rc); - return 0; + int fd = 0; + int rc = 0; + int c = 0; + long cmd = 0; + unsigned long arg; + char *short_opts = "h", *name = argv[0]; + static struct option long_opts[] = { +#define OPT_GETATTR -2 + {"getattr", no_argument, NULL, OPT_GETATTR}, +#define OPT_READPAGE -3 + {"readpage", no_argument, NULL, OPT_READPAGE}, +#define OPT_SETATTR -4 + {"setattr", no_argument, NULL, OPT_SETATTR}, +#define OPT_CREATE -5 + {"create", no_argument, NULL, OPT_CREATE}, +#define OPT_OPEN -6 + {"open", no_argument, NULL, OPT_OPEN}, +#define OPT_CLOSE -7 + {"close", required_argument, NULL, OPT_CLOSE}, +#define OPT_HELP 'h' + {"help", no_argument, NULL, OPT_HELP}, + {0} + }; + + do { + c = getopt_long(argc, argv, short_opts, long_opts, NULL); + + switch (c) { + case OPT_HELP: + usage(argv[0], 0); + break; + case OPT_GETATTR: + cmd = IOC_REQUEST_GETATTR; + name = "getattr"; + arg = 2; + break; + case OPT_SETATTR: + cmd = IOC_REQUEST_SETATTR; + name = "setattr"; + arg = 2; + break; + case OPT_READPAGE: + cmd = IOC_REQUEST_READPAGE; + name = "readpage"; + arg = 2; + break; + case OPT_CREATE: + cmd = IOC_REQUEST_CREATE; + name ="create"; + arg = 2; + break; + case OPT_OPEN: + cmd = IOC_REQUEST_OPEN; + name = "open"; + arg = 2; + break; + case OPT_CLOSE: + cmd = IOC_REQUEST_CLOSE; + name = "close"; + arg = strtoul(optarg, NULL, 0); + break; + case '?': + usage(argv[0], 1); + } + } while (c != -1); + + if (cmd == 0) + usage(argv[0], 1); + + fd = open("/dev/request", O_RDONLY); + if (fd == -1) { + fprintf(stderr, "error opening /dev/request: %s\n", + strerror(errno)); + exit(1); + } + + fprintf(stderr, "Executing %s test (arg=%lu)...\n", name, arg); + if (cmd == IOC_REQUEST_OPEN) { + rc = ioctl(fd, cmd, &arg); + printf("%lu\n", arg); + } else + rc = ioctl(fd, cmd, arg); + fprintf(stderr, "result code: %d\n", rc); + + return 0; }