]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
filestore: check return values
authorSage Weil <sage@newdream.net>
Tue, 10 Nov 2009 21:12:33 +0000 (13:12 -0800)
committerSage Weil <sage@newdream.net>
Tue, 10 Nov 2009 21:12:33 +0000 (13:12 -0800)
src/os/FileStore.cc
src/os/btrfs_ioctl.h

index e21871be09b45873c1314846d7549526d2d21e66..7253982f20d27b8c3f5ea61fae266e72b9beb70a 100644 (file)
@@ -91,12 +91,6 @@ ostream& operator<<(ostream& out, btrfs_ioctl_usertrans_op& o)
   default:
     out << "unknown";
   }
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_SAVE) out << " FD_SAVE(" << o.fd_num << ")";
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_ARG0) out << " FD_ARG0";
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_ARG1) out << " FD_ARG1";
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_ARG2) out << " FD_ARG2";
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_ARG3) out << " FD_ARG3";
-  if (o.flags & BTRFS_IOC_UT_OP_FLAG_FD_ARG4) out << " FD_ARG4";
   return out;
 }
 
@@ -857,14 +851,16 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[0] = (unsigned long)fn;
          op.args[1] = O_WRONLY | O_CREAT;
          op.args[2] = 0644;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_SAVE;
-         op.fd_num = 0;
+         op.args[3] = 0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_CLOSE;
          op.args[0] = 0;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
          ops.push_back(op);
        }
        break;
@@ -891,8 +887,9 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[0] = (__s64)fn;
          op.args[1] = O_WRONLY|O_CREAT;
          op.args[2] = 0644;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_SAVE;
-         op.fd_num = 0;
+         op.args[3] = 0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          assert(len == bl.length());
@@ -905,7 +902,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
            op.args[1] = (__s64)(*it).c_str();
            op.args[2] = (__s64)(*it).length();
            op.args[3] = off;
-           op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
+           op.rval = op.args[2];
+           op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
            ops.push_back(op);
            off += op.args[2];
          }
@@ -913,7 +911,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_CLOSE;
          op.args[0] = 0;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
          ops.push_back(op);
        }
        break;
@@ -928,6 +927,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_TRUNCATE;
          op.args[0] = (__s64)fn;
          op.args[1] = t->get_length();
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
          ops.push_back(op);
        }
        break;
@@ -942,6 +943,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_UNLINK;
          op.args[0] = (__u64)fn;
+         op.rval = 0;
+         //op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
          ops.push_back(op);
        }
        break;
@@ -969,6 +972,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[2] = (__u64)bl.c_str();
          op.args[3] = bl.length();
          op.args[4] = 0;         
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE;
          ops.push_back(op);
        }
        break;
@@ -999,6 +1004,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
            op.args[2] = (__u64)p->second.c_str();
            op.args[3] = p->second.length();
            op.args[4] = 0;       
+           op.rval = 0;
+           op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
            ops.push_back(op);
          }
        }
@@ -1022,6 +1029,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_REMOVEXATTR;
          op.args[0] = (__u64)fn;
          op.args[1] = (__u64)aname;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
        }
        break;
@@ -1044,6 +1053,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
            op.op = BTRFS_IOC_UT_OP_REMOVEXATTR;
            op.args[0] = (__u64)fn;
            op.args[1] = (__u64)aname;
+           op.rval = 0;
+           op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
            ops.push_back(op);
          }
        }
@@ -1065,7 +1076,9 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_OPEN;
          op.args[0] = (__u64)fn;
          op.args[1] = O_RDONLY;
-         op.fd_num = 0;
+         op.args[2] = 0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          memset(&op, 0, sizeof(op));
@@ -1073,7 +1086,9 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[0] = (__u64)fn2;
          op.args[1] = O_WRONLY|O_CREAT|O_TRUNC;
          op.args[2] = 0644;
-         op.fd_num = 1;
+         op.args[3] = 1;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
          
          memset(&op, 0, sizeof(op));
@@ -1082,17 +1097,18 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[1] = 0;
          op.args[2] = 0;
          op.args[3] = 0;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0 | BTRFS_IOC_UT_OP_FLAG_FD_ARG1;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_CLOSE;
          op.args[0] = 0;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          op.args[0] = 1;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
          ops.push_back(op);
        }
        break;
@@ -1113,7 +1129,9 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_OPEN;
          op.args[0] = (__u64)fn;
          op.args[1] = O_RDONLY;
-         op.fd_num = 0;
+         op.args[2] = 0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          memset(&op, 0, sizeof(op));
@@ -1121,7 +1139,9 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[0] = (__u64)fn2;
          op.args[1] = O_WRONLY|O_CREAT|O_TRUNC;
          op.args[2] = 0644;
-         op.fd_num = 1;
+         op.args[3] = 1;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
          
          memset(&op, 0, sizeof(op));
@@ -1130,13 +1150,15 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.args[1] = 0;
          op.args[2] = t->get_length(); // offset
          op.args[3] = t->get_length(); // length
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0 | BTRFS_IOC_UT_OP_FLAG_FD_ARG1;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_CLOSE;
          op.args[0] = 0;
-         op.flags = BTRFS_IOC_UT_OP_FLAG_FD_ARG0;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
 
          op.args[0] = 1;
@@ -1154,6 +1176,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_MKDIR;
          op.args[0] = (__u64)fn;
          op.args[1] = 0755;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
        }
        break;
@@ -1167,6 +1191,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          memset(&op, 0, sizeof(op));
          op.op = BTRFS_IOC_UT_OP_RMDIR;
          op.args[0] = (__u64)fn;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
        }
        break;
@@ -1187,6 +1213,8 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
          op.op = BTRFS_IOC_UT_OP_LINK;
          op.args[0] = (__u64)fn;
          op.args[1] = (__u64)nfn;
+         op.rval = 0;
+         op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT;
          ops.push_back(op);
        }
        break;
@@ -1210,17 +1238,29 @@ int FileStore::_do_usertrans(list<Transaction*>& ls)
   ut.ops_ptr = (__u64)&ops[0];
   ut.num_fds = 2;
   ut.metadata_ops = ops.size();
-  ut.flags = 0;
+  ut.flags = BTRFS_IOC_UT_FLAG_WEDGEONFAIL;
 
-  dout(20) << "USERTRANS ioctl on " << ops.size() << " ops" << dendl;
+  dout(20) << "USERTRANS ioctl (" << ops.size() << " ops)" << dendl;
+  for (unsigned i=0; i<ops.size(); i++)
+    dout(20) << "USERTRANS ioctl op[" << i << "] " << ops[i] << " =? " << ops[i].rval << dendl;
+  
   int r = ::ioctl(op_fd, BTRFS_IOC_USERTRANS, &ut);
-  dout(10) << "USERTRANS ioctl on " << ops.size() << " r = " << r
-          << ", completed " << ut.ops_completed << " ops" << dendl;
+  unsigned i;
+  for (i=0; i<ut.ops_completed; i++)
+    dout(10) << "USERTRANS ioctl op[" << i << "] " << ops[i] << " = " << ops[i].rval << dendl;
   if (r >= 0) {
-    for (unsigned i=0; i<ut.ops_completed; i++)
-      dout(10) << "USERTRANS ioctl op[" << i << "] " << ops[i] << " = " << ops[i].rval << dendl;
+    dout(10) << "USERTRANS ioctl (" << ops.size() << " ops) r = " << r
+            << ", completed " << ut.ops_completed << " ops" << dendl;
     assert(ut.ops_completed == ops.size());
     r = 0;
+  } else {
+    dout(10) << "USERTRANS ioctl op[" << i << "] " << ops[i] << " = " << ops[i].rval << dendl;
+
+    char errbuf[100];
+    dout(10) << "USERTRANS ioctl (" << ops.size() << " ops) r = " << r
+            << " (" << strerror_r(errno, errbuf, sizeof(errbuf)) << ")"
+            << ", completed " << ut.ops_completed << " ops" << dendl;
+    r = --errno;
   }
   
   if (start_sync)
index 138e8979ef9cf98f8680527635c5b329877d6f75..65a9ed339d27781fe994e97c0afa37bb377fb77f 100644 (file)
@@ -69,37 +69,31 @@ struct btrfs_ioctl_clone_range_args {
                                struct btrfs_ioctl_vol_args)
 
 /* usertrans ops */
-#define BTRFS_IOC_UT_OP_OPEN         1
-#define BTRFS_IOC_UT_OP_CLOSE        2
-#define BTRFS_IOC_UT_OP_PWRITE       3
-#define BTRFS_IOC_UT_OP_UNLINK       4
-#define BTRFS_IOC_UT_OP_LINK         5
-#define BTRFS_IOC_UT_OP_MKDIR        6
-#define BTRFS_IOC_UT_OP_RMDIR        7
-#define BTRFS_IOC_UT_OP_TRUNCATE     8
-#define BTRFS_IOC_UT_OP_SETXATTR     9
-#define BTRFS_IOC_UT_OP_REMOVEXATTR 10
-#define BTRFS_IOC_UT_OP_CLONERANGE  11
+/* the 'fd' values are _indices_ into a temporary fd table, see num_fds below */
+#define BTRFS_IOC_UT_OP_OPEN         1  /* path, flags, mode, fd */
+#define BTRFS_IOC_UT_OP_CLOSE        2  /* fd */
+#define BTRFS_IOC_UT_OP_PWRITE       3  /* fd, data, length, offset */
+#define BTRFS_IOC_UT_OP_UNLINK       4  /* path */
+#define BTRFS_IOC_UT_OP_LINK         5  /* oldpath, newpath */
+#define BTRFS_IOC_UT_OP_MKDIR        6  /* path, mode */
+#define BTRFS_IOC_UT_OP_RMDIR        7  /* path */
+#define BTRFS_IOC_UT_OP_TRUNCATE     8  /* path, size */
+#define BTRFS_IOC_UT_OP_SETXATTR     9  /* path, name, data, len */
+#define BTRFS_IOC_UT_OP_REMOVEXATTR 10  /* path, name */
+#define BTRFS_IOC_UT_OP_CLONERANGE  11  /* dst fd, src fd, off, len, dst off */
 
-#define BTRFS_IOC_UT_OP_FLAG_FD_SAVE       (1<< 1)
-#define BTRFS_IOC_UT_OP_FLAG_FD_ARG0       (1<< 2)
-#define BTRFS_IOC_UT_OP_FLAG_FD_ARG1       (1<< 3)
-#define BTRFS_IOC_UT_OP_FLAG_FD_ARG2       (1<< 4)
-#define BTRFS_IOC_UT_OP_FLAG_FD_ARG3       (1<< 5)
-#define BTRFS_IOC_UT_OP_FLAG_FD_ARG4       (1<< 6)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE    (1<< 7)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_EQ    (1<< 8)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT    (1<< 9)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_GT    (1<<10)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LTE   (1<<11)
-#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_GTE   (1<<12)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE    (1<< 1)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_EQ    (1<< 2)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT    (1<< 3)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_GT    (1<< 4)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LTE   (1<< 5)
+#define BTRFS_IOC_UT_OP_FLAG_FAIL_ON_GTE   (1<< 6)
 
 struct btrfs_ioctl_usertrans_op {
        __u64 op;
        __s64 args[5];
        __s64 rval;
        __u64 flags;
-       __u64 fd_num;
 };
 
 /*
@@ -112,7 +106,7 @@ struct btrfs_ioctl_usertrans_op {
 struct btrfs_ioctl_usertrans {
        __u64 num_ops;                  /* in: # ops */
        __u64 ops_ptr;                  /* in: usertrans_op array */
-       __u64 num_fds;                  /* in: max fds we use */
+       __u64 num_fds;                  /* in: size of fd table (max fd + 1) */
        __u64 data_bytes, metadata_ops; /* in: for space reservation */
        __u64 flags;                    /* in: flags */
        __u64 ops_completed;            /* out: # ops completed */