torture/locktest2.c

ソースコードを見る。

データ構造

struct  record

関数

static int try_open (struct cli_state *c, char *nfs, int fstype, const char *fname, int flags)
static BOOL try_close (struct cli_state *c, int fstype, int fd)
static BOOL try_lock (struct cli_state *c, int fstype, int fd, unsigned start, unsigned len, enum brl_type op)
static BOOL try_unlock (struct cli_state *c, int fstype, int fd, unsigned start, unsigned len)
static void print_brl (SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, enum brl_type lock_type, enum brl_flavour lock_flav, br_off start, br_off size)
static struct cli_stateconnect_one (char *share)
static void reconnect (struct cli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], char *share1, char *share2)
static BOOL test_one (struct cli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], struct record *rec)
static void close_files (struct cli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES])
static void open_files (struct cli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES])
static int retest (struct cli_state *cli[NSERVERS][NCONNECTIONS], char *nfs[NSERVERS], int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES], int n)
static void test_locks (char *share1, char *share2, char *nfspath1, char *nfspath2)
static void usage (void)
int main (int argc, char *argv[])

変数

static fstring password
static fstring username
static int got_pass
static int numops = 1000
static BOOL showall
static BOOL analyze
static BOOL hide_unlock_fails
static BOOL use_oplocks
char * optarg
int optind
static struct recordrecorded


関数

static int try_open ( struct cli_state c,
char *  nfs,
int  fstype,
const char *  fname,
int  flags 
) [static]

locktest2.c66 行で定義されています。

参照先 ccli_open()pstring_sub().

参照元 open_files()test_one().

00067 {
00068         pstring path;
00069 
00070         switch (fstype) {
00071         case FSTYPE_SMB:
00072                 return cli_open(c, fname, flags, DENY_NONE);
00073 
00074         case FSTYPE_NFS:
00075                 slprintf(path, sizeof(path), "%s%s", nfs, fname);
00076                 pstring_sub(path,"\\", "/");
00077                 return open(path, flags, 0666);
00078         }
00079 
00080         return -1;
00081 }

static BOOL try_close ( struct cli_state c,
int  fstype,
int  fd 
) [static]

locktest2.c83 行で定義されています。

参照先 ccli_close().

参照元 close_files()test_one().

00084 {
00085         switch (fstype) {
00086         case FSTYPE_SMB:
00087                 return cli_close(c, fd);
00088 
00089         case FSTYPE_NFS:
00090                 return close(fd) == 0;
00091         }
00092 
00093         return False;
00094 }

static BOOL try_lock ( struct cli_state c,
int  fstype,
int  fd,
unsigned  start,
unsigned  len,
enum brl_type  op 
) [static]

locktest2.c96 行で定義されています。

参照先 ccli_lock()READ_LOCK.

参照元 test_one().

00099 {
00100         struct flock lock;
00101 
00102         switch (fstype) {
00103         case FSTYPE_SMB:
00104                 return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op);
00105 
00106         case FSTYPE_NFS:
00107                 lock.l_type = (op==READ_LOCK) ? F_RDLCK:F_WRLCK;
00108                 lock.l_whence = SEEK_SET;
00109                 lock.l_start = start;
00110                 lock.l_len = len;
00111                 lock.l_pid = getpid();
00112                 return fcntl(fd,F_SETLK,&lock) == 0;
00113         }
00114 
00115         return False;
00116 }

static BOOL try_unlock ( struct cli_state c,
int  fstype,
int  fd,
unsigned  start,
unsigned  len 
) [static]

locktest2.c118 行で定義されています。

参照先 ccli_unlock().

参照元 test_one().

00120 {
00121         struct flock lock;
00122 
00123         switch (fstype) {
00124         case FSTYPE_SMB:
00125                 return cli_unlock(c, fd, start, len);
00126 
00127         case FSTYPE_NFS:
00128                 lock.l_type = F_UNLCK;
00129                 lock.l_whence = SEEK_SET;
00130                 lock.l_start = start;
00131                 lock.l_len = len;
00132                 lock.l_pid = getpid();
00133                 return fcntl(fd,F_SETLK,&lock) == 0;
00134         }
00135 
00136         return False;
00137 }       

static void print_brl ( SMB_DEV_T  dev,
SMB_INO_T  ino,
struct process_id  pid,
enum brl_type  lock_type,
enum brl_flavour  lock_flav,
br_off  start,
br_off  size 
) [static]

locktest2.c139 行で定義されています。

参照先 printf()procid_to_pid()READ_LOCK.

00143 {
00144         printf("%6d   %05x:%05x    %s  %.0f:%.0f(%.0f)\n", 
00145                (int)procid_to_pid(&pid), (int)dev, (int)ino, 
00146                lock_type==READ_LOCK?"R":"W",
00147                (double)start, (double)start+size-1,(double)size);
00148 
00149 }

static struct cli_state* connect_one ( char *  share  )  [static]

locktest2.c154 行で定義されています。

参照先 ccli_full_connection()got_passlp_workgroup()mynament_errstr()passwordserverstrchr_m()use_oplockscli_state::use_oplocksusername.

00155 {
00156         struct cli_state *c;
00157         char *server_n;
00158         fstring server;
00159         fstring myname;
00160         static int count;
00161         NTSTATUS nt_status;
00162 
00163         fstrcpy(server,share+2);
00164         share = strchr_m(server,'\\');
00165         if (!share) return NULL;
00166         *share = 0;
00167         share++;
00168 
00169         server_n = server;
00170         
00171         if (!got_pass) {
00172                 char *pass = getpass("Password: ");
00173                 if (pass) {
00174                         fstrcpy(password, pass);
00175                 }
00176         }
00177 
00178         slprintf(myname,sizeof(myname), "lock-%lu-%u", (unsigned long)getpid(), count++);
00179 
00180         nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", 
00181                                         username, lp_workgroup(), password, 0,
00182                                         Undefined, NULL);
00183 
00184         if (!NT_STATUS_IS_OK(nt_status)) {
00185                 DEBUG(0, ("cli_full_connection failed with error %s\n", nt_errstr(nt_status)));
00186                 return NULL;
00187         }
00188 
00189         c->use_oplocks = use_oplocks;
00190 
00191         return c;
00192 }

static void reconnect ( struct cli_state cli[NSERVERS][NCONNECTIONS],
char *  nfs[NSERVERS],
int  fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
char *  share1,
char *  share2 
) [static]

locktest2.c195 行で定義されています。

参照先 clicli_close()cli_shutdown()cli_ulogoff()connect_one()servershare.

00199 {
00200         int server, conn, f, fstype;
00201         char *share[2];
00202         share[0] = share1;
00203         share[1] = share2;
00204 
00205         fstype = FSTYPE_SMB;
00206 
00207         for (server=0;server<NSERVERS;server++)
00208         for (conn=0;conn<NCONNECTIONS;conn++) {
00209                 if (cli[server][conn]) {
00210                         for (f=0;f<NFILES;f++) {
00211                                 cli_close(cli[server][conn], fnum[server][fstype][conn][f]);
00212                         }
00213                         cli_ulogoff(cli[server][conn]);
00214                         cli_shutdown(cli[server][conn]);
00215                 }
00216                 cli[server][conn] = connect_one(share[server]);
00217                 if (!cli[server][conn]) {
00218                         DEBUG(0,("Failed to connect to %s\n", share[server]));
00219                         exit(1);
00220                 }
00221         }
00222 }

static BOOL test_one ( struct cli_state cli[NSERVERS][NCONNECTIONS],
char *  nfs[NSERVERS],
int  fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
struct record rec 
) [static]

locktest2.c226 行で定義されています。

参照先 brl_forall()clirecord::connrecord::frecord::fstypehide_unlock_failsrecord::lenlenprint_brl()printf()record::r1record::r2READ_LOCKservershowallrecord::starttry_close()try_lock()try_open()try_unlock()WRITE_LOCK.

00230 {
00231         unsigned conn = rec->conn;
00232         unsigned f = rec->f;
00233         unsigned fstype = rec->fstype;
00234         unsigned start = rec->start;
00235         unsigned len = rec->len;
00236         unsigned r1 = rec->r1;
00237         unsigned r2 = rec->r2;
00238         enum brl_type op;
00239         int server;
00240         BOOL ret[NSERVERS];
00241 
00242         if (r1 < READ_PCT) {
00243                 op = READ_LOCK; 
00244         } else {
00245                 op = WRITE_LOCK; 
00246         }
00247 
00248         if (r2 < LOCK_PCT) {
00249                 /* set a lock */
00250                 for (server=0;server<NSERVERS;server++) {
00251                         ret[server] = try_lock(cli[server][conn], fstype,
00252                                                fnum[server][fstype][conn][f],
00253                                                start, len, op);
00254                 }
00255                 if (showall || ret[0] != ret[1]) {
00256                         printf("lock   conn=%u fstype=%u f=%u range=%u:%u(%u) op=%s -> %u:%u\n",
00257                                conn, fstype, f, 
00258                                start, start+len-1, len,
00259                                op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
00260                                ret[0], ret[1]);
00261                 }
00262                 if (showall) brl_forall(print_brl);
00263                 if (ret[0] != ret[1]) return False;
00264         } else if (r2 < LOCK_PCT+UNLOCK_PCT) {
00265                 /* unset a lock */
00266                 for (server=0;server<NSERVERS;server++) {
00267                         ret[server] = try_unlock(cli[server][conn], fstype,
00268                                                  fnum[server][fstype][conn][f],
00269                                                  start, len);
00270                 }
00271                 if (showall || (!hide_unlock_fails && (ret[0] != ret[1]))) {
00272                         printf("unlock conn=%u fstype=%u f=%u range=%u:%u(%u)       -> %u:%u\n",
00273                                conn, fstype, f, 
00274                                start, start+len-1, len,
00275                                ret[0], ret[1]);
00276                 }
00277                 if (showall) brl_forall(print_brl);
00278                 if (!hide_unlock_fails && ret[0] != ret[1]) return False;
00279         } else {
00280                 /* reopen the file */
00281                 for (server=0;server<NSERVERS;server++) {
00282                         try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]);
00283                         fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME,
00284                                                                  O_RDWR|O_CREAT);
00285                         if (fnum[server][fstype][conn][f] == -1) {
00286                                 printf("failed to reopen on share1\n");
00287                                 return False;
00288                         }
00289                 }
00290                 if (showall) {
00291                         printf("reopen conn=%u fstype=%u f=%u\n",
00292                                conn, fstype, f);
00293                         brl_forall(print_brl);
00294                 }
00295         }
00296         return True;
00297 }

static void close_files ( struct cli_state cli[NSERVERS][NCONNECTIONS],
char *  nfs[NSERVERS],
int  fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES] 
) [static]

locktest2.c299 行で定義されています。

参照先 clicli_unlink()servertry_close().

00302 {
00303         int server, conn, f, fstype; 
00304 
00305         for (server=0;server<NSERVERS;server++)
00306         for (fstype=0;fstype<NUMFSTYPES;fstype++)
00307         for (conn=0;conn<NCONNECTIONS;conn++)
00308         for (f=0;f<NFILES;f++) {
00309                 if (fnum[server][fstype][conn][f] != -1) {
00310                         try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]);
00311                         fnum[server][fstype][conn][f] = -1;
00312                 }
00313         }
00314         for (server=0;server<NSERVERS;server++) {
00315                 cli_unlink(cli[server][0], FILENAME);
00316         }
00317 }

static void open_files ( struct cli_state cli[NSERVERS][NCONNECTIONS],
char *  nfs[NSERVERS],
int  fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES] 
) [static]

locktest2.c319 行で定義されています。

参照先 clifprintf()servertry_open().

00322 {
00323         int server, fstype, conn, f; 
00324 
00325         for (server=0;server<NSERVERS;server++)
00326         for (fstype=0;fstype<NUMFSTYPES;fstype++)
00327         for (conn=0;conn<NCONNECTIONS;conn++)
00328         for (f=0;f<NFILES;f++) {
00329                 fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME,
00330                                                          O_RDWR|O_CREAT);
00331                 if (fnum[server][fstype][conn][f] == -1) {
00332                         fprintf(stderr,"Failed to open fnum[%u][%u][%u][%u]\n",
00333                                 server, fstype, conn, f);
00334                         exit(1);
00335                 }
00336         }
00337 }

static int retest ( struct cli_state cli[NSERVERS][NCONNECTIONS],
char *  nfs[NSERVERS],
int  fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
int  n 
) [static]

locktest2.c340 行で定義されています。

参照先 cliprintf()recordedtest_one().

00344 {
00345         int i;
00346         printf("testing %u ...\n", n);
00347         for (i=0; i<n; i++) {
00348                 if (i && i % 100 == 0) {
00349                         printf("%u\n", i);
00350                 }
00351 
00352                 if (recorded[i].needed &&
00353                     !test_one(cli, nfs, fnum, &recorded[i])) return i;
00354         }
00355         return n;
00356 }

static void test_locks ( char *  share1,
char *  share2,
char *  nfspath1,
char *  nfspath2 
) [static]

locktest2.c365 行で定義されています。

参照先 analyzecliclose_files()record::frecord::fstypelenrecord::lenrecord::needednumopsopen_files()printf()record::r1record::r2reconnect()recordedretest()showallrecord::start.

00366 {
00367         struct cli_state *cli[NSERVERS][NCONNECTIONS];
00368         char *nfs[NSERVERS];
00369         int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES];
00370         int n, i, n1; 
00371 
00372         nfs[0] = nfspath1;
00373         nfs[1] = nfspath2;
00374 
00375         ZERO_STRUCT(fnum);
00376         ZERO_STRUCT(cli);
00377 
00378         recorded = SMB_MALLOC_ARRAY(struct record, numops);
00379 
00380         for (n=0; n<numops; n++) {
00381                 recorded[n].conn = random() % NCONNECTIONS;
00382                 recorded[n].fstype = random() % NUMFSTYPES;
00383                 recorded[n].f = random() % NFILES;
00384                 recorded[n].start = LOCKBASE + ((unsigned)random() % (LOCKRANGE-1));
00385                 recorded[n].len = 1 + 
00386                         random() % (LOCKRANGE-(recorded[n].start-LOCKBASE));
00387                 recorded[n].start *= RANGE_MULTIPLE;
00388                 recorded[n].len *= RANGE_MULTIPLE;
00389                 recorded[n].r1 = random() % 100;
00390                 recorded[n].r2 = random() % 100;
00391                 recorded[n].needed = True;
00392         }
00393 
00394         reconnect(cli, nfs, fnum, share1, share2);
00395         open_files(cli, nfs, fnum);
00396         n = retest(cli, nfs, fnum, numops);
00397 
00398         if (n == numops || !analyze) return;
00399         n++;
00400 
00401         while (1) {
00402                 n1 = n;
00403 
00404                 close_files(cli, nfs, fnum);
00405                 reconnect(cli, nfs, fnum, share1, share2);
00406                 open_files(cli, nfs, fnum);
00407 
00408                 for (i=0;i<n-1;i++) {
00409                         int m;
00410                         recorded[i].needed = False;
00411 
00412                         close_files(cli, nfs, fnum);
00413                         open_files(cli, nfs, fnum);
00414 
00415                         m = retest(cli, nfs, fnum, n);
00416                         if (m == n) {
00417                                 recorded[i].needed = True;
00418                         } else {
00419                                 if (i < m) {
00420                                         memmove(&recorded[i], &recorded[i+1],
00421                                                 (m-i)*sizeof(recorded[0]));
00422                                 }
00423                                 n = m;
00424                                 i--;
00425                         }
00426                 }
00427 
00428                 if (n1 == n) break;
00429         }
00430 
00431         close_files(cli, nfs, fnum);
00432         reconnect(cli, nfs, fnum, share1, share2);
00433         open_files(cli, nfs, fnum);
00434         showall = True;
00435         n1 = retest(cli, nfs, fnum, n);
00436         if (n1 != n-1) {
00437                 printf("ERROR - inconsistent result (%u %u)\n", n1, n);
00438         }
00439         close_files(cli, nfs, fnum);
00440 
00441         for (i=0;i<n;i++) {
00442                 printf("{%u, %u, %u, %u, %u, %u, %u, %u},\n",
00443                        recorded[i].r1,
00444                        recorded[i].r2,
00445                        recorded[i].conn,
00446                        recorded[i].fstype,
00447                        recorded[i].f,
00448                        recorded[i].start,
00449                        recorded[i].len,
00450                        recorded[i].needed);
00451         }       
00452 }

static void usage ( void   )  [static]

locktest2.c456 行で定義されています。

参照先 printf().

00457 {
00458         printf(
00459 "Usage:\n\
00460   locktest //server1/share1 //server2/share2 /path1 /path2 [options..]\n\
00461   options:\n\
00462         -U user%%pass\n\
00463         -s seed\n\
00464         -o numops\n\
00465         -u          hide unlock fails\n\
00466         -a          (show all ops)\n\
00467         -O          use oplocks\n\
00468 ");
00469 }

int main ( int  argc,
char *  argv[] 
)

locktest2.c474 行で定義されています。

参照先 all_string_sub()analyzedbfdyn_CONFIGFILEgot_passhide_unlock_failsload_interfaces()locking_init()numopsoptargoptindpasswordprintf()setup_logging()showallstrchr_m()test_locks()usage()use_oplocksusernamex_stderr.

00475 {
00476         char *share1, *share2, *nfspath1, *nfspath2;
00477         int opt;
00478         char *p;
00479         int seed;
00480 
00481         setlinebuf(stdout);
00482 
00483         dbf = x_stderr;
00484 
00485         if (argc < 5 || argv[1][0] == '-') {
00486                 usage();
00487                 exit(1);
00488         }
00489 
00490         share1 = argv[1];
00491         share2 = argv[2];
00492         nfspath1 = argv[3];
00493         nfspath2 = argv[4];
00494 
00495         all_string_sub(share1,"/","\\",0);
00496         all_string_sub(share2,"/","\\",0);
00497 
00498         setup_logging(argv[0],True);
00499 
00500         argc -= 4;
00501         argv += 4;
00502 
00503         lp_load(dyn_CONFIGFILE,True,False,False,True);
00504         load_interfaces();
00505 
00506         if (getenv("USER")) {
00507                 fstrcpy(username,getenv("USER"));
00508         }
00509 
00510         seed = time(NULL);
00511 
00512         while ((opt = getopt(argc, argv, "U:s:ho:aAW:O")) != EOF) {
00513                 switch (opt) {
00514                 case 'U':
00515                         fstrcpy(username,optarg);
00516                         p = strchr_m(username,'%');
00517                         if (p) {
00518                                 *p = 0;
00519                                 fstrcpy(password, p+1);
00520                                 got_pass = 1;
00521                         }
00522                         break;
00523                 case 's':
00524                         seed = atoi(optarg);
00525                         break;
00526                 case 'u':
00527                         hide_unlock_fails = True;
00528                         break;
00529                 case 'o':
00530                         numops = atoi(optarg);
00531                         break;
00532                 case 'O':
00533                         use_oplocks = True;
00534                         break;
00535                 case 'a':
00536                         showall = True;
00537                         break;
00538                 case 'A':
00539                         analyze = True;
00540                         break;
00541                 case 'h':
00542                         usage();
00543                         exit(1);
00544                 default:
00545                         printf("Unknown option %c (%d)\n", (char)opt, opt);
00546                         exit(1);
00547                 }
00548         }
00549 
00550         argc -= optind;
00551         argv += optind;
00552 
00553         DEBUG(0,("seed=%u\n", seed));
00554         srandom(seed);
00555 
00556         locking_init(1);
00557         test_locks(share1, share2, nfspath1, nfspath2);
00558 
00559         return(0);
00560 }


変数

fstring password [static]

locktest2.c23 行で定義されています。

fstring username [static]

locktest2.c24 行で定義されています。

int got_pass [static]

locktest2.c25 行で定義されています。

int numops = 1000 [static]

locktest2.c26 行で定義されています。

BOOL showall [static]

locktest2.c27 行で定義されています。

BOOL analyze [static]

locktest2.c28 行で定義されています。

BOOL hide_unlock_fails [static]

locktest2.c29 行で定義されています。

BOOL use_oplocks [static]

locktest2.c30 行で定義されています。

char* optarg

int optind

struct record* recorded [static]

locktest2.c64 行で定義されています。


Sambaに対してSat Aug 29 21:24:31 2009に生成されました。  doxygen 1.4.7