1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/tests/flock.c
38 * Lustre Light user test program
48 #include <sys/types.h>
51 #include <sys/queue.h>
59 static char lustre_path[] = "/mnt/lustre";
65 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
68 memset(buf+len, '=', 100-len); \
79 sprintf(buf, "===== END TEST %s: successfully ", \
83 memset(buf+len, '=', 100-len); \
92 #define MAX_PATH_LENGTH 4096
95 int t_fcntl(int fd, int cmd, ...)
108 printf("fcntl GETFL failed: %s\n",
114 arg = va_arg(ap, long);
116 rc = fcntl(fd, cmd, arg);
118 printf("fcntl SETFL %ld failed: %s\n",
119 arg, strerror(errno));
126 lock = va_arg(ap, struct flock *);
128 rc = fcntl(fd, cmd, lock);
130 printf("fcntl cmd %d failed: %s\n",
131 cmd, strerror(errno));
136 arg = va_arg(ap, long);
138 rc = fcntl(fd, cmd, arg);
140 printf("fcntl F_DUPFD %d failed: %s\n",
141 (int)arg, strerror(errno));
147 printf("fcntl cmd %d not supported\n", cmd);
150 printf("fcntl %d = %d, ltype = %d\n", cmd, rc, lock->l_type);
154 int t_unlink(const char *path)
160 printf("unlink(%s) error: %s\n", path, strerror(errno));
168 char file[MAX_PATH_LENGTH] = "";
170 struct flock lock = {
172 .l_whence = SEEK_SET,
175 ENTRY("basic fcntl support");
176 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
178 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
180 printf("error open file: %m\n", file);
184 t_fcntl(fd, F_SETFL, O_APPEND);
185 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
186 printf("error get flag: ret %x\n", ret);
190 t_fcntl(fd, F_SETLK, &lock);
191 t_fcntl(fd, F_GETLK, &lock);
192 lock.l_type = F_WRLCK;
193 t_fcntl(fd, F_SETLKW, &lock);
194 t_fcntl(fd, F_GETLK, &lock);
195 lock.l_type = F_UNLCK;
196 t_fcntl(fd, F_SETLK, &lock);
204 int main(int argc, char * const argv[])
206 /* Set D_VFSTRACE to see messages from ll_file_flock.
207 The test passes either with -o flock or -o noflock
208 mount -o flock -t lustre uml1:/mds1/client /mnt/lustre */
211 printf("completed successfully\n");