4
* Simple tool for NLM testing. You will have to adjust the values in
5
* host.h to your test system.
7
* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
22
static char myhostname[256];
23
static int hostnamelen;
25
static void makelock(struct nlm_lock *, u_int32_t, off_t, off_t);
26
static void makeowner(struct netobj *, u_int32_t);
27
static void makefileh(struct netobj *);
28
static char * nlm_stat_name(int status);
29
static char * holderstr(struct netobj *oh);
32
main(int argc, char **argv)
35
nlm_testargs testargs;
36
nlm_lockargs lockargs;
37
nlm_unlockargs unlockargs;
41
char *filename = NLMTEST_FILE;
42
char *svchost = NLMTEST_HOST;
43
unsigned long offset = 0, length = 0;
47
u_int32_t cookie = 4321;
48
u_int32_t mypid = 1234;
51
while ((c = getopt(argc, argv, "bf:h:l:o:p:ux")) != EOF) {
63
length = atoi(optarg);
66
offset = atoi(optarg);
78
fprintf(stderr, "nlmtest: bad option %c\n", c);
83
client = clnt_create(svchost, NLM_PROG, NLM_VERS, "udp");
85
clnt_pcreateerror("localhost");
89
/* Get local host name */
90
if (gethostname(myhostname, sizeof(myhostname)) < 0)
91
strcpy(myhostname, "unknown");
92
hostnamelen = strlen(myhostname);
94
makelock(&alock, mypid, offset, length);
96
testargs.cookie.n_bytes = (void*)&cookie;
97
testargs.cookie.n_len = 4;
98
testargs.exclusive = exclusive;
99
testargs.alock = alock;
101
if ((testres = nlm_test_1(&testargs, client)) == NULL) {
102
clnt_perror(client, "nlm_test call failed:");
105
printf ("nlm_test reply:\n"
108
*(int*)(testres->cookie.n_bytes),
109
nlm_stat_name(testres->stat.stat)
112
if (testres->stat.stat == nlm_denied) {
113
nlm_holder *holder = &(testres->stat.nlm_testrply_u.holder);
114
printf ("\tconflicting lock:\n"
119
"\t exclusive: %d\n",
120
holderstr(&holder->oh),
127
if (testres->stat.stat != nlm_granted && !unlock && !blocking)
131
unlockargs.cookie.n_bytes = (void*)&cookie;
132
unlockargs.cookie.n_len = sizeof(cookie);
133
unlockargs.alock = alock;
135
if ((lockres = nlm_unlock_1(&unlockargs, client)) == NULL) {
136
clnt_perror(client, "nlm_unlock call failed:");
139
printf ("nlm_unlock reply:\n"
142
*(int*)(lockres->cookie.n_bytes),
143
nlm_stat_name(lockres->stat.stat)
146
lockargs.cookie.n_bytes = (void*)&cookie;
147
lockargs.cookie.n_len = sizeof(cookie);
148
lockargs.exclusive = exclusive;
149
lockargs.alock = alock;
150
lockargs.reclaim = 0;
153
if ((lockres = nlm_lock_1(&lockargs, client)) == NULL) {
154
clnt_perror(client, "nlm_lock call failed:");
157
printf ("nlm_lock reply:\n"
160
*(int*)(lockres->cookie.n_bytes),
161
nlm_stat_name(lockres->stat.stat)
169
nlm_stat_name(int status)
175
return "nlm_granted";
178
case nlm_denied_nolocks:
179
return "nlm_denied_nolocks";
181
return "nlm_blocked";
182
case nlm_denied_grace_period:
183
return "nlm_denied_grace_period";
185
sprintf(buf, "%d", status);
190
holderstr(struct netobj *oh)
192
static char buffer[4096];
193
unsigned char c, *sp;
196
for (i = 0, sp = buffer; i < oh->n_len; i++) {
197
c = (unsigned char) oh->n_bytes[i];
198
if (c < 0x20 || c > 0x7f)
199
sp += sprintf(sp, "\\%03o", c);
209
makelock(struct nlm_lock *alock, u_int32_t mypid, off_t offset, off_t length)
211
makeowner(&alock->oh, mypid); /* Create owner handle */
212
makefileh(&alock->fh); /* Create file handle */
214
alock->caller_name = myhostname;
216
alock->l_offset = offset;
217
alock->l_len = length;
221
makeowner(struct netobj *oh, u_int32_t mypid)
223
static char ohdata[1024];
225
oh->n_bytes = ohdata;
226
oh->n_len = hostnamelen + 1 + 4;
228
strcpy(ohdata, myhostname);
229
memcpy(ohdata + hostnamelen + 1, &mypid, 4);
233
makefileh(struct netobj *fh)
235
static struct knfs_fh f;
237
#error this needs updating if it is still wanted
238
memset(&f, 0, sizeof(f));
240
if (stat(NLMTEST_DIR, &stb) < 0) {
241
perror("couldn't stat mount point " NLMTEST_DIR);
244
f.fh_xdev = stb.st_dev;
245
f.fh_xino = stb.st_ino;
247
if (stat(NLMTEST_DIR, &stb) < 0) {
248
perror("couldn't stat mount point " NLMTEST_DIR);
251
f.fh_dev = stb.st_dev;
252
f.fh_ino = stb.st_ino;
254
f.fh_version = NLMTEST_VERSION;
263
fh->n_bytes = (void *) &f;