2 * $Id: bulkstat_unlink_test.c,v 1.3 2007/10/30 03:07:42 mohamedb.longdrop.melbourne.sgi.com Exp $
3 * Test bulkstat doesn't returned unlinked inodes.
4 * Mark Goodwin <markgw@sgi.com> Fri Jul 20 09:13:57 EST 2007
14 main(int argc, char *argv[])
30 char fname[MAXPATHLEN];
34 while ((c = getopt(argc, argv, "r")) != -1) {
44 if ((argc - optind) != 4) {
45 fprintf(stderr, "Usage: %s iterations nfiles stride dir [options]\n", argv[0]);
46 fprintf(stderr, "Create dir with nfiles, unlink each stride'th file, sync, bulkstat\n");
51 iterations = atoi(argv[optind++]);
52 nfiles = atoi(argv[optind++]);
53 stride = atoi(argv[optind++]);
55 dirname = argv[optind++];
58 printf("Runing extended checks.\n");
60 inodelist = (ino_t *)malloc(nfiles * sizeof(ino_t));
61 ret = (xfs_bstat_t *)malloc(nfiles * sizeof(xfs_bstat_t));
63 for (k=0; k < iterations; k++) {
65 xfs_ino_t last_inode = 0;
66 int count = 0, scount = -1;
68 printf("Iteration %d ... (%d files)", k, nfiles);
70 memset(&a, 0, sizeof(xfs_fsop_bulkreq_t));
71 a.lastip = (__u64 *)&last_inode;
76 if (mkdir(dirname, 0755) < 0) {
77 printf("Warning (%s,%d), mkdir(%s) failed.\n", __FILE__, __LINE__, dirname);
82 if ((fd[nfiles] = open(dirname, O_RDONLY)) < 0) {
83 printf("Warning (%s,%d), open(%s) failed.\n", __FILE__, __LINE__, dirname);
88 if (chknb) { /* Get the original number of inodes (lazy) */
90 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
91 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
97 for (i=0; i < nfiles; i++) { /* Open the files */
98 sprintf(fname, "%s/file%06d", dirname, i);
99 if ((fd[i] = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) {
100 printf("Warning (%s,%d), open(%s) failed.\n", __FILE__, __LINE__, fname);
104 write(fd[i], fname, sizeof(fname));
105 if (fstat(fd[i], &sbuf) < 0) {
106 printf("Warning (%s,%d), fstat failed.\n", __FILE__, __LINE__);
110 inodelist[i] = sbuf.st_ino;
116 *The files are still opened (but unlink()ed) ,
117 * we should have more inodes than before
121 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
122 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
124 if (count < scount) {
125 printf("ERROR, count(%d) < scount(%d).\n", count, scount);
130 /* Close all the files */
131 for (i = 0; i < nfiles; i++) {
137 * The files are now closed, we should be back to our,
138 * previous inode count
142 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
143 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
145 if (count != scount) {
146 printf("ERROR, count(%d) != scount(%d).\n", count, scount);
154 if ((e = xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a)) < 0) {
155 printf("Warning (%s,%d), xfsctl failed.\n", __FILE__, __LINE__);
156 perror("XFS_IOC_FSBULKSTAT:");
163 for (i=0; i < count; i++) {
164 for (j=0; j < nfiles; j += stride) {
165 if (ret[i].bs_ino == inodelist[j]) {
167 printf("failed. Unlinked inode %llu returned by bulkstat\n", (unsigned long long)inodelist[j]);
175 sprintf(fname, "rm -rf %s\n", dirname);