2 example program to read a file in the same way that Samba does. This
3 demonstrates the problem with GPFS share modes and leases and TSM
6 Andrew Tridgell January 2008
10 gcc -Wall -o tsmread{,.c} -lgpfs_gpl
12 then to run you must symlink tsmread to smbd
18 ./smbd /gpfs/data/tsmtest/test.dat
19 ./smbd /gpfs/data/tsmtest/test.dat -S
20 ./smbd /gpfs/data/tsmtest/test.dat -L
21 ./smbd /gpfs/data/tsmtest/test.dat -L -S
25 #define _XOPEN_SOURCE 500
40 static void sigio_handler(int sig)
42 printf("Got SIGIO\n");
45 static int read_file(const char *fname, bool use_lease, bool use_sharemode, bool do_write)
51 printf("Reading '%s' with use_lease=%s use_sharemode=%s\n",
52 fname, use_lease?"yes":"no", use_sharemode?"yes":"no");
54 signal(SIGIO, sigio_handler);
56 fd = open(fname, do_write?O_RDWR:O_RDONLY);
62 if (fstat(fd, &st) != 0 || st.st_blocks != 0 || st.st_size == 0) {
63 printf("WARNING: file is not offline - test INVALID\n");
66 if (use_lease && gpfs_set_lease(fd, do_write?GPFS_LEASE_WRITE:GPFS_LEASE_READ) != 0) {
67 perror("gpfs_set_lease");
72 if (use_sharemode && gpfs_set_share(fd, 1, 2) != 0) {
73 perror("gpfs_set_share");
78 if (do_write && pwrite(fd, &c, 1, 0) != 1) {
84 if (pread(fd, &c, 1, 0) != 1) {
96 static void usage(void)
98 printf("Usage: (note, must run as 'smbd')\n");
99 printf("ln -sf tesmread smbd\n");
100 printf("./smbd [options] <files>\n");
101 printf("Options:\n");
102 printf(" -L use gpfs leases\n");
103 printf(" -S use gpfs sharemodes\n");
104 printf(" -W do a write before a read\n");
108 int main(int argc, char * const argv[])
111 bool use_lease = false, use_sharemode = false, do_write=false;
112 const char *progname = argv[0];
114 if (strstr(progname, "smbd") == NULL) {
115 printf("WARNING: you should invoke as smbd - use a symlink\n");
118 /* parse command-line options */
119 while ((opt = getopt(argc, argv, "LSWh")) != -1) {
125 use_sharemode = true;
143 for (i=0;i<argc;i++) {
144 const char *fname = argv[i];
145 if (read_file(fname, use_lease, use_sharemode, do_write) != 0) {
146 printf("Failed to read '%s'\n", fname);