From 8f06f084978a5eb19c1ed9b22efa9d50d0b581e1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 14 Jan 2010 13:38:44 -0800 Subject: [PATCH] filestore: rip out usertrans experiment --- src/os/FileStore.cc | 542 ++----------------------------------------- src/os/FileStore.h | 4 +- src/os/btrfs_ioctl.h | 48 ---- 3 files changed, 18 insertions(+), 576 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 929ed1bbcac64..0c5a99c8f7b57 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -54,48 +54,6 @@ # ifndef DARWIN # include "btrfs_ioctl.h" -ostream& operator<<(ostream& out, btrfs_ioctl_usertrans_op& o) -{ - switch (o.op) { - case BTRFS_IOC_UT_OP_OPEN: - out << "open " << (const char *)o.args[0] << " " << oct << "0" << o.args[1] << dec; - break; - case BTRFS_IOC_UT_OP_CLOSE: - out << "close " << o.args[0]; - break; - case BTRFS_IOC_UT_OP_PWRITE: - out << "pwrite " << o.args[0] << " " << (void *)o.args[1] << " " << o.args[2] << "~" << o.args[3]; - break; - case BTRFS_IOC_UT_OP_UNLINK: - out << "unlink " << (const char *)o.args[0]; - break; - case BTRFS_IOC_UT_OP_LINK: - out << "link " << (const char *)o.args[0] << " " << (const char *)o.args[1]; - break; - case BTRFS_IOC_UT_OP_MKDIR: - out << "mkdir " << (const char *)o.args[0]; - break; - case BTRFS_IOC_UT_OP_RMDIR: - out << "rmdir " << (const char *)o.args[0]; - break; - case BTRFS_IOC_UT_OP_TRUNCATE: - out << "truncate " << (const char*)o.args[0] << " " << o.args[1]; - break; - case BTRFS_IOC_UT_OP_SETXATTR: - out << "setxattr " << (const char*)o.args[0] << " " << (const char *)o.args[1] << " " - << (void *)o.args[2] << " " << o.args[3]; - break; - case BTRFS_IOC_UT_OP_REMOVEXATTR: - out << "removexattr " << (const char*)o.args[0] << " " << (const char *)o.args[1]; - break; - case BTRFS_IOC_UT_OP_CLONERANGE: - out << "clonerange " << o.args[0] << " " << o.args[1] << " " << o.args[2] << "~" << o.args[3]; - break; - default: - out << "unknown"; - } - return out; -} # endif @@ -478,20 +436,12 @@ int FileStore::mount() dout(0) << " found snaps " << snaps << dendl; } - //btrfs_usertrans = false; btrfs_trans_start_end = true; // trans start/end interface - r = -1; //apply_transaction(empty, 0); + r = apply_transaction(empty, 0); if (r == 0) { - dout(0) << "mount btrfs USERTRANS ioctl is supported" << dendl; + dout(0) << "mount btrfs TRANS_START ioctl is supported" << dendl; } else { - //dout(0) << "mount btrfs USERTRANS ioctl is NOT supported: " << strerror_r(-r, buf, sizeof(buf)) << dendl; - btrfs_usertrans = false; - r = apply_transaction(empty, 0); - if (r == 0) { - dout(0) << "mount btrfs TRANS_START ioctl is supported" << dendl; - } else { - dout(0) << "mount btrfs TRANS_START ioctl is NOT supported: " << strerror_r(-r, buf, sizeof(buf)) << dendl; - } + dout(0) << "mount btrfs TRANS_START ioctl is NOT supported: " << strerror_r(-r, buf, sizeof(buf)) << dendl; } if (r == 0) { // do we have the shiny new CLONE_RANGE ioctl? @@ -570,26 +520,22 @@ unsigned FileStore::apply_transactions(list &tls, ops += (*p)->get_num_ops(); } - if (btrfs_usertrans) { - r = _do_usertrans(tls); - } else { - int id = _transaction_start(bytes, ops); - if (id < 0) { - op_journal_start(); - op_finish(); - return id; - } - - for (list::iterator p = tls.begin(); - p != tls.end(); - p++) { - r = _do_transaction(**p); - if (r < 0) - break; - } + int id = _transaction_start(bytes, ops); + if (id < 0) { + op_journal_start(); + op_finish(); + return id; + } - _transaction_finish(id); + for (list::iterator p = tls.begin(); + p != tls.end(); + p++) { + r = _do_transaction(**p); + if (r < 0) + break; } + + _transaction_finish(id); op_journal_start(); dout(10) << "op_seq is " << op_seq << dendl; @@ -789,460 +735,6 @@ unsigned FileStore::_do_transaction(Transaction& t) /*********************************************/ -int FileStore::_do_usertrans(list& ls) -{ - btrfs_ioctl_usertrans ut; - vector ops; - list str; - bool start_sync = false; - btrfs_ioctl_usertrans_op op; - - memset(&ut, 0, sizeof(ut)); - - for (list::iterator p = ls.begin(); p != ls.end(); p++) { - Transaction *t = *p; - - while (t->have_op()) { - int opcode = t->get_op(); - - memset(&op, 0, sizeof(op)); - - switch (opcode) { - case Transaction::OP_TOUCH: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), t->get_oid(), fn); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (unsigned long)fn; - op.args[1] = O_WRONLY | O_CREAT; - op.args[2] = 0644; - 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.rval = 0; - op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE; - ops.push_back(op); - } - break; - - case Transaction::OP_WRITE: - case Transaction::OP_ZERO: // write actual zeros. - { - __u64 off = t->get_length(); - __u64 len = t->get_length(); - bufferlist bl; - if (opcode == Transaction::OP_WRITE) - bl = t->get_bl(); - else { - bufferptr bp(len); - bp.zero(); - bl.push_back(bp); - } - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), t->get_oid(), fn); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (__s64)fn; - op.args[1] = O_WRONLY|O_CREAT; - op.args[2] = 0644; - 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()); - for (list::const_iterator it = bl.buffers().begin(); - it != bl.buffers().end(); - it++) { - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_PWRITE; - op.args[0] = 0; - op.args[1] = (__s64)(*it).c_str(); - op.args[2] = (__s64)(*it).length(); - op.args[3] = off; - op.rval = op.args[2]; - op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE; - ops.push_back(op); - off += op.args[2]; - } - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_CLOSE; - op.args[0] = 0; - op.rval = 0; - op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_NE; - ops.push_back(op); - } - break; - - case Transaction::OP_TRUNCATE: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), t->get_oid(), fn); - - memset(&op, 0, sizeof(op)); - 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; - - case Transaction::OP_COLL_REMOVE: - case Transaction::OP_REMOVE: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), t->get_oid(), fn); - - 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; - - case Transaction::OP_SETATTR: - case Transaction::OP_COLL_SETATTR: - { - bufferlist bl = t->get_bl(); - char *fn = new char[PATH_MAX]; - str.push_back(fn); - - if (opcode == Transaction::OP_SETATTR) - get_coname(t->get_cid(), t->get_oid(), fn); - else - get_cdir(t->get_cid(), fn); - - char *aname = new char[ATTR_MAX]; - str.push_back(aname); - sprintf(aname, "user.ceph.%s", t->get_attrname()); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_SETXATTR; - op.args[0] = (__u64)fn; - op.args[1] = (__u64)aname; - 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; - - case Transaction::OP_SETATTRS: - case Transaction::OP_COLL_SETATTRS: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - - if (opcode == Transaction::OP_SETATTRS) - get_coname(t->get_cid(), t->get_oid(), fn); - else - get_cdir(t->get_cid(), fn); - - const map& aset = t->get_attrset(); - for (map::const_iterator p = aset.begin(); - p != aset.end(); - p++) { - char *aname = new char[ATTR_MAX]; - str.push_back(aname); - sprintf(aname, "user.ceph.%s", p->first.c_str()); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_SETXATTR; - op.args[0] = (__u64)fn; - op.args[1] = (__u64)aname; - 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); - } - } - break; - - case Transaction::OP_RMATTR: - case Transaction::OP_COLL_RMATTR: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - if (opcode == Transaction::OP_RMATTR) - get_coname(t->get_cid(), t->get_oid(), fn); - else - get_cdir(t->get_cid(), fn); - - char *aname = new char[ATTR_MAX]; - str.push_back(aname); - sprintf(aname, "user.ceph.%s", t->get_attrname()); - - memset(&op, 0, sizeof(op)); - 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; - - case Transaction::OP_RMATTRS: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), t->get_oid(), fn); - - map aset; - _getattrs(fn, aset); - - for (map::iterator p = aset.begin(); p != aset.end(); p++) { - char *aname = new char[ATTR_MAX]; - str.push_back(aname); - sprintf(aname, "user.ceph.%s", p->first.c_str()); - - memset(&op, 0, sizeof(op)); - 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; - - case Transaction::OP_CLONE: - { - coll_t cid = t->get_cid(); - - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(cid, t->get_oid(), fn); - - char *fn2 = new char[PATH_MAX]; - str.push_back(fn2); - get_coname(cid, t->get_oid(), fn2); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (__u64)fn; - op.args[1] = O_RDONLY; - 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)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (__u64)fn2; - op.args[1] = O_WRONLY|O_CREAT|O_TRUNC; - op.args[2] = 0644; - 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)); - op.op = BTRFS_IOC_UT_OP_CLONERANGE; - op.args[0] = 1; - op.args[1] = 0; - op.args[2] = 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.rval = 0; - op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT; - ops.push_back(op); - - op.args[0] = 1; - ops.push_back(op); - } - break; - - case Transaction::OP_CLONERANGE: - { - coll_t cid = t->get_cid(); - - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(cid, t->get_oid(), fn); - - char *fn2 = new char[PATH_MAX]; - str.push_back(fn2); - get_coname(cid, t->get_oid(), fn2); - - memset(&op, 0, sizeof(op)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (__u64)fn; - op.args[1] = O_RDONLY; - 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)); - op.op = BTRFS_IOC_UT_OP_OPEN; - op.args[0] = (__u64)fn2; - op.args[1] = O_WRONLY|O_CREAT|O_TRUNC; - op.args[2] = 0644; - 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)); - op.op = BTRFS_IOC_UT_OP_CLONERANGE; - op.args[0] = 1; - op.args[1] = 0; - op.args[2] = t->get_length(); // offset - op.args[3] = t->get_length(); // length - 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.rval = 0; - op.flags = BTRFS_IOC_UT_OP_FLAG_FAIL_ON_LT; - ops.push_back(op); - - op.args[0] = 1; - ops.push_back(op); - } - break; - - case Transaction::OP_MKCOLL: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_cdir(t->get_cid(), fn); - - memset(&op, 0, sizeof(op)); - 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; - - case Transaction::OP_RMCOLL: - { - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_cdir(t->get_cid(), fn); - - 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; - - case Transaction::OP_COLL_ADD: - { - const sobject_t& oid = t->get_oid(); - - char *fn = new char[PATH_MAX]; - str.push_back(fn); - get_coname(t->get_cid(), oid, fn); - - char *nfn = new char[PATH_MAX]; - str.push_back(nfn); - get_coname(t->get_cid(), oid, nfn); - - memset(&op, 0, sizeof(op)); - 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; - - case Transaction::OP_STARTSYNC: - { - start_sync = true; - } - break; - - default: - cerr << "bad op " << opcode << std::endl; - assert(0); - } - } - - ut.data_bytes += t->get_num_bytes(); - } - - ut.num_ops = ops.size(); - ut.ops_ptr = (__u64)&ops[0]; - ut.num_fds = 2; - ut.metadata_ops = ops.size(); - ut.flags = BTRFS_IOC_UT_FLAG_WEDGEONFAIL; - - dout(20) << "USERTRANS ioctl (" << ops.size() << " ops)" << dendl; - for (unsigned i=0; i& tls); // ------------------ // objects diff --git a/src/os/btrfs_ioctl.h b/src/os/btrfs_ioctl.h index 65a9ed339d277..bc49914475ebb 100644 --- a/src/os/btrfs_ioctl.h +++ b/src/os/btrfs_ioctl.h @@ -67,52 +67,4 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ struct btrfs_ioctl_vol_args) - -/* usertrans ops */ -/* 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_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; -}; - -/* - * If an op fails and we cannot complete the transaction, we may want - * to lock up the file system (requiring a reboot) to prevent a - * partial result from committing. - */ -#define BTRFS_IOC_UT_FLAG_WEDGEONFAIL (1<<13) - -struct btrfs_ioctl_usertrans { - __u64 num_ops; /* in: # ops */ - __u64 ops_ptr; /* in: usertrans_op array */ - __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 */ -}; - -#define BTRFS_IOC_USERTRANS _IOW(BTRFS_IOCTL_MAGIC, 16, \ - struct btrfs_ioctl_usertrans) - #endif -- 2.39.5