1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Nikita Danilov <nikita@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
36 #include <sys/types.h>
42 #include <libcfs/libcfs.h>
46 * Maximal format name length.
51 struct iam_uapi_info {
56 char iui_fmt_name[DX_FMT_NAME_LEN];
65 IAM_IOC_INIT = _IOW('i', 1, struct iam_uapi_info),
66 IAM_IOC_GETINFO = _IOR('i', 2, struct iam_uapi_info),
67 IAM_IOC_INSERT = _IOR('i', 3, struct iam_uapi_op),
68 IAM_IOC_LOOKUP = _IOWR('i', 4, struct iam_uapi_op),
69 IAM_IOC_DELETE = _IOR('i', 5, struct iam_uapi_op)
72 static void usage(void)
74 printf("usage: iam_ut [-v] [-h] file\n");
77 static int doop(int fd, const void *key, const void *rec,
78 int cmd, const char *name)
82 struct iam_uapi_op op = {
86 result = ioctl(fd, cmd, &op);
88 fprintf(stderr, "ioctl(%s): %i/%i (%m)\n", name, result, errno);
92 static int insert(int fd, const void *key, const void *rec)
94 return doop(fd, key, rec, IAM_IOC_INSERT, "IAM_IOC_INSERT");
97 static int lookup(int fd, const void *key, void *rec)
99 return doop(fd, key, rec, IAM_IOC_LOOKUP, "IAM_IOC_LOOKUP");
102 static int delete(int fd, const void *key, void *rec)
104 return doop(fd, key, rec, IAM_IOC_DELETE, "IAM_IOC_DELETE");
107 static void print_rec(const unsigned char *rec, int nr)
111 for (i = 0; i < nr; ++i)
112 printf("%c", rec[i]);
114 for (i = 0; i < nr; ++i)
115 printf("%x", rec[i]);
126 int main(int argc, char **argv)
143 struct iam_uapi_info ua;
145 setbuf(stdout, NULL);
146 setbuf(stderr, NULL);
154 opt = getopt(argc, argv, "vilk:r:d");
177 fprintf(stderr, "Unable to parse options.");
184 rc = ioctl(0, IAM_IOC_INIT, &ua);
186 fprintf(stderr, "ioctl(IAM_IOC_INIT): %i (%m)\n", rc);
189 rc = ioctl(0, IAM_IOC_GETINFO, &ua);
191 fprintf(stderr, "ioctl(IAM_IOC_GETATTR): %i (%m)\n", rc);
195 keysize = ua.iui_keysize;
196 recsize = ua.iui_recsize;
198 printf("keysize: %i, recsize: %i, ptrsize: %i, "
199 "height: %i, name: %s\n",
200 keysize, recsize, ua.iui_ptrsize,
201 ua.iui_height, ua.iui_fmt_name);
203 key = calloc(keysize + 1, sizeof key[0]);
204 rec = calloc(recsize + 1, sizeof rec[0]);
206 if (key == NULL || rec == NULL) {
207 fprintf(stderr, "cannot allocte memory\n");
211 strncpy(key, key_opt ? : "RIVERRUN", keysize + 1);
212 strncpy(rec, rec_opt ? : "PALEFIRE", recsize + 1);
215 return insert(0, key, rec);
216 else if (op == OP_DELETE)
217 return delete(0, key, rec);
218 else if (op == OP_LOOKUP) {
219 rc = lookup(0, key, rec);
221 print_rec(rec, recsize);
225 rc = insert(0, key, rec);
229 rc = insert(0, "DAEDALUS", "FINNEGAN");
233 rc = insert(0, "DAEDALUS", "FINNEGAN");
234 if (errno != EEXIST) {
236 fprintf(stderr, "Duplicate key not detected!\n");
240 rc = lookup(0, "RIVERRUN", rec);
244 print_rec(rec, recsize);
246 for (i = 0; i < 0x10000; ++i) {
247 memset(key, 0, keysize + 1);
248 memset(rec, 0, recsize + 1);
249 snprintf(key, keysize, "y-%x-x", i);
250 snprintf(rec, recsize, "p-%x-q", 1000 - i);
251 rc = insert(0, key, rec);
255 printf("key %#x inserted\n", i);