*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
*
* GPL HEADER END
*/
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* pull in O_DIRECTORY in bits/fcntl.h */
#endif
-#include <stdio.h>
+#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/vfs.h>
#include <sys/ioctl.h>
+#include <sys/xattr.h>
+#include <sys/file.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <time.h>
+#include <err.h>
-#include <lustre/lustre_idl.h>
#include <lustre/lustreapi.h>
#define T1 "write data before unlink\n"
int bufsize = 0;
sem_t sem;
#define ALIGN_LEN 65535
+#define XATTR "user.multiop"
char usage[] =
"Usage: %s filename command-sequence [path...]\n"
" command-sequence items:\n"
+" A fsetxattr(\"user.multiop\")\n"
+" a fgetxattr(\"user.multiop\")\n"
" c close\n"
" B[num] call setstripe ioctl to create stripes\n"
" C[num] create with optional stripes\n"
" d mkdir\n"
" D open(O_DIRECTORY)\n"
+" e[R|W|U] apply lease. R: Read; W: Write; U: Unlock\n"
+" E[+|-] get lease. +/-: expect lease to (not) exist\n"
" f statfs\n"
" F print FID\n"
+" H[num] create HSM released file with num stripes\n"
" G gid get grouplock\n"
" g gid put grouplock\n"
" K link path to filename\n"
#ifdef O_DIRECT
{"O_DIRECT", O_DIRECT},
#endif
+#ifdef O_NOATIME
+ {"O_NOATIME", O_NOATIME},
+#endif
{"O_LARGEFILE", O_LARGEFILE},
{"O_DIRECTORY", O_DIRECTORY},
{"O_NOFOLLOW", O_NOFOLLOW},
ts.tv_nsec = 0;
while (sem_timedwait(&sem, &ts) < 0 && errno == EINTR);
break;
+ case 'A':
+ if (fsetxattr(fd, XATTR, "multiop", 8, 0)) {
+ save_errno = errno;
+ perror("fsetxattr");
+ exit(save_errno);
+ }
+ break;
+ case 'a':
+ if (fgetxattr(fd, XATTR, NULL, 0) == -1) {
+ save_errno = errno;
+ perror("fgetxattr");
+ exit(save_errno);
+ }
+ break;
case 'c':
if (close(fd) == -1) {
save_errno = errno;
exit(save_errno);
}
break;
- case 'f':
- if (statfs(fname, &stfs) == -1) {
- save_errno = errno;
- perror("statfs()");
- exit(save_errno);
- }
- break;
+ case 'e':
+ commands++;
+ switch (*commands) {
+ case 'U':
+ flags = LL_LEASE_UNLCK;
+ break;
+ case 'R':
+ flags = LL_LEASE_RDLCK;
+ break;
+ case 'W':
+ flags = LL_LEASE_WRLCK;
+ break;
+ default:
+ errx(-1, "unknown mode: %c", *commands);
+ }
+
+ rc = ioctl(fd, LL_IOC_SET_LEASE, flags);
+ if (rc < 0)
+ err(errno, "apply lease error");
+
+ if (flags != LL_LEASE_UNLCK)
+ break;
+
+ /* F_UNLCK, interpret return code */
+ if (rc > 0) {
+ const char *str = "unknown";
+ if (rc == LL_LEASE_RDLCK)
+ str = "read";
+ else if (rc == LL_LEASE_WRLCK)
+ str = "write";
+ fprintf(stdout, "%s lease(%d) released.\n",
+ str, rc);
+ } else if (rc == 0) {
+ fprintf(stdout, "lease already broken.\n");
+ }
+ break;
+ case 'E':
+ commands++;
+ if (*commands != '-' && *commands != '+')
+ errx(-1, "unknown mode: %c\n", *commands);
+
+ rc = ioctl(fd, LL_IOC_GET_LEASE);
+ if (rc > 0) {
+ const char *str = "unknown";
+
+ if (rc == LL_LEASE_RDLCK)
+ str = "read";
+ else if (rc == LL_LEASE_WRLCK)
+ str = "write";
+ fprintf(stdout, "%s lease(%d) has applied.\n",
+ str, rc);
+ if (*commands == '-')
+ errx(-1, "expect lease to not exist");
+ } else if (rc == 0) {
+ fprintf(stdout, "no lease applied.\n");
+ if (*commands == '+')
+ errx(-1, "expect lease exists");
+ } else {
+ err(errno, "free lease error");
+ }
+ break;
+ case 'f':
+ if (statfs(fname, &stfs) == -1)
+ errx(-1, "statfs()");
+ break;
case 'F':
if (fd == -1)
rc = llapi_path2fid(fname, &fid);
exit(save_errno);
}
break;
+ case 'j':
+ if (flock(fd, LOCK_EX) == -1)
+ errx(-1, "flock()");
+ break;
case 'K':
oldpath = POP_ARG();
if (oldpath == NULL)
if (len <= 0)
len = 1;
if (bufsize < len) {
- buf = realloc(buf, len + ALIGN_LEN);
- if (buf == NULL) {
+ void *tmp;
+ tmp = realloc(buf, len + ALIGN_LEN);
+ if (tmp == NULL) {
+ free(buf);
save_errno = errno;
perror("allocating buf for read\n");
exit(save_errno);
}
+ buf = tmp;
bufsize = len;
buf_align = (char *)((long)(buf + ALIGN_LEN) &
~ALIGN_LEN);
if (len <= 0)
len = 1;
if (bufsize < len) {
- buf = realloc(buf, len + ALIGN_LEN);
- if (buf == NULL) {
+ void *tmp;
+ tmp = realloc(buf, len + ALIGN_LEN);
+ if (tmp == NULL) {
+ free(buf);
save_errno = errno;
perror("allocating buf for write\n");
exit(save_errno);
}
+ buf = tmp;
bufsize = len;
buf_align = (char *)((long)(buf + ALIGN_LEN) &
~ALIGN_LEN);
" %d\n", rc);
exit(-rc);
}
- printf("dataversion is "LPU64"\n", dv);
+ printf("dataversion is %ju\n", (uintmax_t)dv);
break;
case 'y':
if (fsync(fd) == -1) {
}
break;
case 'Y':
- if (fdatasync(fd) == -1) {
- save_errno = errno;
- perror("fdatasync");
- exit(save_errno);
- }
+ if (fdatasync(fd) == -1) {
+ save_errno = errno;
+ perror("fdatasync");
+ exit(save_errno);
+ }
+ break;
case 'z':
len = atoi(commands+1);
if (lseek(fd, len, SEEK_SET) == -1) {