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
16 main(int argc, char *argv[])
29 struct xfs_fsop_bulkreq a;
30 struct xfs_bstat *ret;
32 char fname[MAXPATHLEN];
36 while ((c = getopt(argc, argv, "r")) != -1) {
46 if ((argc - optind) != 4) {
47 fprintf(stderr, "Usage: %s iterations nfiles stride dir [options]\n", argv[0]);
48 fprintf(stderr, "Create dir with nfiles, unlink each stride'th file, sync, bulkstat\n");
53 iterations = atoi(argv[optind++]);
54 nfiles = atoi(argv[optind++]);
55 stride = atoi(argv[optind++]);
57 dirname = argv[optind++];
60 printf("Runing extended checks.\n");
62 inodelist = (ino_t *)malloc(nfiles * sizeof(ino_t));
63 ret = (struct xfs_bstat *)malloc(nfiles * sizeof(struct xfs_bstat));
65 for (k=0; k < iterations; k++) {
67 xfs_ino_t last_inode = 0;
68 int count = 0, scount = -1;
70 printf("Iteration %d ... (%d files)", k, nfiles);
72 memset(&a, 0, sizeof(struct xfs_fsop_bulkreq));
73 a.lastip = (__u64 *)&last_inode;
78 if (mkdir(dirname, 0755) < 0) {
79 printf("Warning (%s,%d), mkdir(%s) failed.\n", __FILE__, __LINE__, dirname);
84 if ((fd[nfiles] = open(dirname, O_RDONLY)) < 0) {
85 printf("Warning (%s,%d), open(%s) failed.\n", __FILE__, __LINE__, dirname);
90 if (chknb) { /* Get the original number of inodes (lazy) */
92 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
93 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
99 for (i=0; i < nfiles; i++) { /* Open the files */
100 sprintf(fname, "%s/file%06d", dirname, i);
101 if ((fd[i] = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) {
102 printf("Warning (%s,%d), open(%s) failed.\n", __FILE__, __LINE__, fname);
106 write(fd[i], fname, sizeof(fname));
107 if (fstat(fd[i], &sbuf) < 0) {
108 printf("Warning (%s,%d), fstat failed.\n", __FILE__, __LINE__);
112 inodelist[i] = sbuf.st_ino;
118 *The files are still opened (but unlink()ed) ,
119 * we should have more inodes than before
123 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
124 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
126 if (count < scount) {
127 printf("ERROR, count(%d) < scount(%d).\n", count, scount);
132 /* Close all the files */
133 for (i = 0; i < nfiles; i++) {
139 * The files are now closed, we should be back to our,
140 * previous inode count
144 if (xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a) != 0) {
145 printf("Warning (%s:%d), xfsctl(XFS_IOC_FSBULKSTAT) FAILED.\n", __FILE__, __LINE__);
147 if (count != scount) {
148 printf("ERROR, count(%d) != scount(%d).\n", count, scount);
156 if ((e = xfsctl(dirname, fd[nfiles], XFS_IOC_FSBULKSTAT, &a)) < 0) {
157 printf("Warning (%s,%d), xfsctl failed.\n", __FILE__, __LINE__);
158 perror("XFS_IOC_FSBULKSTAT:");
165 for (i=0; i < count; i++) {
166 for (j=0; j < nfiles; j += stride) {
167 if (ret[i].bs_ino == inodelist[j]) {
169 printf("failed. Unlinked inode %llu returned by bulkstat\n", (unsigned long long)inodelist[j]);
177 sprintf(fname, "rm -rf %s\n", dirname);