1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light user test program
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <sys/types.h>
34 #include <sys/queue.h>
42 static char lustre_path[] = "/mnt/lustre";
48 sprintf(buf, "===== START %s: %s ", __FUNCTION__, (str)); \
51 memset(buf+len, '=', 100-len); \
62 sprintf(buf, "===== END TEST %s: successfully ", \
66 memset(buf+len, '=', 100-len); \
75 #define MAX_PATH_LENGTH 4096
78 int t_fcntl(int fd, int cmd, ...)
91 printf("fcntl GETFL failed: %s\n",
97 arg = va_arg(ap, long);
99 rc = fcntl(fd, cmd, arg);
101 printf("fcntl SETFL %ld failed: %s\n",
102 arg, strerror(errno));
109 lock = va_arg(ap, struct flock *);
111 rc = fcntl(fd, cmd, lock);
113 printf("fcntl cmd %d failed: %s\n",
114 cmd, strerror(errno));
119 arg = va_arg(ap, long);
121 rc = fcntl(fd, cmd, arg);
123 printf("fcntl F_DUPFD %d failed: %s\n",
124 (int)arg, strerror(errno));
130 printf("fcntl cmd %d not supported\n", cmd);
133 printf("fcntl %d = %d, ltype = %d\n", cmd, rc, lock->l_type);
137 int t_unlink(const char *path)
143 printf("unlink(%s) error: %s\n", path, strerror(errno));
151 char file[MAX_PATH_LENGTH] = "";
153 struct flock lock = {
155 .l_whence = SEEK_SET,
158 ENTRY("basic fcntl support");
159 snprintf(file, MAX_PATH_LENGTH, "%s/test_t21_file", lustre_path);
161 fd = open(file, O_RDWR|O_CREAT, (mode_t)0666);
163 printf("error open file: %m\n", file);
167 t_fcntl(fd, F_SETFL, O_APPEND);
168 if (!(ret = t_fcntl(fd, F_GETFL)) & O_APPEND) {
169 printf("error get flag: ret %x\n", ret);
173 t_fcntl(fd, F_SETLK, &lock);
174 t_fcntl(fd, F_GETLK, &lock);
175 lock.l_type = F_WRLCK;
176 t_fcntl(fd, F_SETLKW, &lock);
177 t_fcntl(fd, F_GETLK, &lock);
178 lock.l_type = F_UNLCK;
179 t_fcntl(fd, F_SETLK, &lock);
187 int main(int argc, char * const argv[])
189 /* Set D_VFSTRACE to see messages from ll_file_flock.
190 The test passes either with -o flock or -o noflock
191 mount -o flock -t lustre uml1:/mds1/client /mnt/lustre */
194 printf("completed successfully\n");