-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/vfs.h>
+#include <sys/ioctl.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
-#include <libcfs/libcfs.h>
-#include <lustre/liblustreapi.h>
+#include <time.h>
+
+#include <lustre/lustre_idl.h>
+#include <lustre/lustreapi.h>
#define T1 "write data before unlink\n"
#define T2 "write data after unlink\n"
char *buf, *buf_align;
int bufsize = 0;
sem_t sem;
-#define ALIGN 65535
+#define ALIGN_LEN 65535
char usage[] =
-"Usage: %s filename command-sequence\n"
+"Usage: %s filename command-sequence [path...]\n"
" command-sequence items:\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"
" f statfs\n"
-" L link\n"
-" l symlink\n"
+" F print FID\n"
+" G gid get grouplock\n"
+" g gid put grouplock\n"
+" K link path to filename\n"
+" L link filename to path\n"
+" l symlink filename to path\n"
" m mknod\n"
" M rw mmap to EOF (must open and stat prior)\n"
-" N rename\n"
+" n rename path to filename\n"
+" N rename filename to path\n"
" o open(O_RDONLY)\n"
" O open(O_CREAT|O_RDWR)\n"
" r[num] read [optional length]\n"
" u unlink\n"
" U munmap\n"
" v verbose\n"
+" V open a volatile file\n"
" w[num] write optional length\n"
" W write entire mmap-ed region\n"
" y fsync\n"
}
struct flag_mapping {
- const char *string;
- const int flag;
+ const char *string;
+ const int flag;
} flag_table[] = {
- {"O_RDONLY", O_RDONLY},
- {"O_WRONLY", O_WRONLY},
- {"O_RDWR", O_RDWR},
- {"O_CREAT", O_CREAT},
- {"O_EXCL", O_EXCL},
- {"O_NOCTTY", O_NOCTTY},
- {"O_TRUNC", O_TRUNC},
- {"O_APPEND", O_APPEND},
- {"O_NONBLOCK", O_NONBLOCK},
- {"O_NDELAY", O_NDELAY},
- {"O_SYNC", O_SYNC},
+ {"O_RDONLY", O_RDONLY},
+ {"O_WRONLY", O_WRONLY},
+ {"O_RDWR", O_RDWR},
+ {"O_CREAT", O_CREAT},
+ {"O_EXCL", O_EXCL},
+ {"O_NOCTTY", O_NOCTTY},
+ {"O_TRUNC", O_TRUNC},
+ {"O_APPEND", O_APPEND},
+ {"O_NONBLOCK", O_NONBLOCK},
+ {"O_NDELAY", O_NDELAY},
+ {"O_SYNC", O_SYNC},
#ifdef O_DIRECT
- {"O_DIRECT", O_DIRECT},
+ {"O_DIRECT", O_DIRECT},
#endif
- {"O_LARGEFILE", O_LARGEFILE},
- {"O_DIRECTORY", O_DIRECTORY},
- {"O_NOFOLLOW", O_NOFOLLOW},
- {"", -1}
+ {"O_LARGEFILE", O_LARGEFILE},
+ {"O_DIRECTORY", O_DIRECTORY},
+ {"O_NOFOLLOW", O_NOFOLLOW},
+ {"O_LOV_DELAY_CREATE", O_LOV_DELAY_CREATE},
+ {"", -1}
};
int get_flags(char *data, int *rflags)
int main(int argc, char **argv)
{
- char *fname, *commands;
- const char *newfile;
- struct stat st;
- struct statfs stfs;
- size_t mmap_len = 0, i;
- unsigned char *mmap_ptr = NULL, junk = 0;
- int rc, len, fd = -1;
- int flags;
- int save_errno;
- int verbose = 0;
+ char *fname, *commands;
+ const char *newfile;
+ const char *oldpath;
+ struct stat st;
+ struct statfs stfs;
+ size_t mmap_len = 0, i;
+ unsigned char *mmap_ptr = NULL, junk = 0;
+ int rc, len, fd = -1;
+ int flags;
+ int save_errno;
+ int verbose = 0;
+ int gid = 0;
+ lustre_fid fid;
+ struct timespec ts;
+ struct lov_user_md_v3 lum;
if (argc < 3) {
fprintf(stderr, usage, argv[0]);
printf("PAUSING\n");
fflush(stdout);
}
- while (sem_wait(&sem) == -1 && errno == EINTR);
+ len = atoi(commands+1);
+ if (len <= 0)
+ len = 3600; /* 1 hour */
+ ts.tv_sec = time(NULL) + len;
+ ts.tv_nsec = 0;
+ while (sem_timedwait(&sem, &ts) < 0 && errno == EINTR);
break;
case 'c':
if (close(fd) == -1) {
}
fd = -1;
break;
+ case 'B':
+ lum = (struct lov_user_md_v3) {
+ .lmm_magic = LOV_USER_MAGIC_V3,
+ .lmm_stripe_count = atoi(commands + 1),
+ };
+
+ if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum) < 0) {
+ save_errno = errno;
+ perror("LL_IOC_LOV_SETSTRIPE");
+ exit(save_errno);
+ }
+ break;
case 'C':
len = atoi(commands+1);
fd = llapi_file_open(fname, O_CREAT | O_WRONLY, 0644,
exit(save_errno);
}
break;
- case 'l':
- newfile = POP_ARG();
- if (!newfile)
- newfile = fname;
- if (symlink(fname, newfile)) {
+ case 'F':
+ if (fd == -1)
+ rc = llapi_path2fid(fname, &fid);
+ else
+ rc = llapi_fd2fid(fd, &fid);
+ if (rc != 0)
+ fprintf(stderr,
+ "llapi_path/fd2fid() on %d, rc=%d\n",
+ fd, rc);
+ else
+ printf(DFID"\n", PFID(&fid));
+ break;
+ case 'G':
+ gid = atoi(commands+1);
+ if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
save_errno = errno;
- perror("symlink()");
+ perror("ioctl(GROUP_LOCK)");
+ exit(save_errno);
+ }
+ break;
+ case 'g':
+ gid = atoi(commands+1);
+ if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
+ save_errno = errno;
+ perror("ioctl(GROUP_UNLOCK)");
exit(save_errno);
}
break;
- case 'L':
+ case 'K':
+ oldpath = POP_ARG();
+ if (oldpath == NULL)
+ oldpath = fname;
+
+ if (link(oldpath, fname)) {
+ save_errno = errno;
+ perror("link()");
+ exit(save_errno);
+ }
+ break;
+ case 'l':
newfile = POP_ARG();
if (!newfile)
newfile = fname;
- if (link(fname, newfile)) {
+ if (symlink(fname, newfile)) {
save_errno = errno;
perror("symlink()");
exit(save_errno);
}
break;
+ case 'L':
+ newfile = POP_ARG();
+ if (newfile == NULL)
+ newfile = fname;
+
+ if (link(fname, newfile)) {
+ save_errno = errno;
+ perror("link()");
+ exit(save_errno);
+ }
+ break;
case 'm':
if (mknod(fname, S_IFREG | 0644, 0) == -1) {
save_errno = errno;
exit(save_errno);
}
break;
+ case 'n':
+ oldpath = POP_ARG();
+ if (oldpath == NULL)
+ oldpath = fname;
+
+ if (rename(oldpath, fname) < 0) {
+ save_errno = errno;
+ perror("rename()");
+ exit(save_errno);
+ }
+ break;
case 'N':
newfile = POP_ARG();
if (!newfile)
exit(save_errno);
}
break;
- case 'r':
- len = atoi(commands+1);
- if (len <= 0)
- len = 1;
- if (bufsize < len) {
- buf = realloc(buf, len + ALIGN);
- if (buf == NULL) {
- save_errno = errno;
- perror("allocating buf for read\n");
- exit(save_errno);
- }
- bufsize = len;
- buf_align = (char *)((long)(buf + ALIGN) &
- ~ALIGN);
- }
- while (len > 0) {
- rc = read(fd, buf_align, len);
- if (rc == -1) {
- save_errno = errno;
- perror("read");
- exit(save_errno);
- }
- if (rc < len)
- fprintf(stderr, "short read: %u/%u\n",
- rc, len);
- len -= rc;
- if (verbose >= 2)
- printf("%.*s\n", rc, buf_align);
- }
- break;
+ case 'r':
+ len = atoi(commands+1);
+ if (len <= 0)
+ len = 1;
+ if (bufsize < len) {
+ buf = realloc(buf, len + ALIGN_LEN);
+ if (buf == NULL) {
+ save_errno = errno;
+ perror("allocating buf for read\n");
+ exit(save_errno);
+ }
+ bufsize = len;
+ buf_align = (char *)((long)(buf + ALIGN_LEN) &
+ ~ALIGN_LEN);
+ }
+ while (len > 0) {
+ rc = read(fd, buf_align, len);
+ if (rc == -1) {
+ save_errno = errno;
+ perror("read");
+ exit(save_errno);
+ }
+ if (rc < len) {
+ fprintf(stderr, "short read: %u/%u\n",
+ rc, len);
+ if (rc == 0)
+ exit(ENODATA);
+ }
+ len -= rc;
+ if (verbose >= 2)
+ printf("%.*s\n", rc, buf_align);
+ }
+ break;
case 'R':
for (i = 0; i < mmap_len && mmap_ptr; i += 4096)
junk += mmap_ptr[i];
case 'v':
verbose++;
break;
- case 'w':
- len = atoi(commands+1);
- if (len <= 0)
- len = 1;
- if (bufsize < len) {
- buf = realloc(buf, len + ALIGN);
- if (buf == NULL) {
- save_errno = errno;
- perror("allocating buf for write\n");
- exit(save_errno);
- }
- bufsize = len;
- buf_align = (char *)((long)(buf + ALIGN) &
- ~ALIGN);
- strncpy(buf_align, msg, bufsize);
- }
- while (len > 0) {
- rc = write(fd, buf_align, len);
- if (rc == -1) {
- save_errno = errno;
- perror("write");
- exit(save_errno);
- }
- if (rc < len)
- fprintf(stderr, "short write: %u/%u\n",
- rc, len);
- len -= rc;
- }
- break;
+ case 'V':
+ len = get_flags(commands + 1, &flags);
+ commands += len;
+ fd = llapi_create_volatile(fname, flags);
+ if (fd < 0) {
+ perror("llapi_create_volatile");
+ exit(fd);
+ }
+ break;
+ case 'w':
+ len = atoi(commands+1);
+ if (len <= 0)
+ len = 1;
+ if (bufsize < len) {
+ buf = realloc(buf, len + ALIGN_LEN);
+ if (buf == NULL) {
+ save_errno = errno;
+ perror("allocating buf for write\n");
+ exit(save_errno);
+ }
+ bufsize = len;
+ buf_align = (char *)((long)(buf + ALIGN_LEN) &
+ ~ALIGN_LEN);
+ strncpy(buf_align, msg, bufsize);
+ }
+ while (len > 0) {
+ rc = write(fd, buf_align, len);
+ if (rc == -1) {
+ save_errno = errno;
+ perror("write");
+ exit(save_errno);
+ }
+ if (rc < len)
+ fprintf(stderr, "short write: %u/%u\n",
+ rc, len);
+ len -= rc;
+ }
+ break;
case 'W':
for (i = 0; i < mmap_len && mmap_ptr; i += 4096)
mmap_ptr[i] += junk++;
exit(save_errno);
}
break;
+ case '-':
case '0':
case '1':
case '2':