#define ATTR_MAX 80
-#define COMMIT_SNAP_DIR "commit_snaps"
#define COMMIT_SNAP_ITEM "%lld"
#ifndef __CYGWIN__
void FileStore::get_cdir(coll_t cid, char *s)
{
- s += sprintf(s, "%s/", basedir.c_str());
+ s += sprintf(s, "%s/current/", basedir.c_str());
s += cid.print(s);
}
return -EBUSY;
// wipe
- sprintf(cmd, "test -d %s && rm -r %s/* ; mkdir -p %s",
- basedir.c_str(), basedir.c_str(), basedir.c_str());
+ sprintf(cmd, "test -d %s && ( test -d %s/current && rm -r %s/current/* %s/fsid || rm -r %s/* ) ; mkdir -p %s",
+ basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str(), basedir.c_str());
dout(5) << "wipe: " << cmd << dendl;
system(cmd);
::close(fsid_fd);
dout(10) << "mkfs fsid is " << fsid << dendl;
+ // current
+ struct btrfs_ioctl_vol_args volargs;
+ memset(&volargs, 0, sizeof(volargs));
+ int fd = ::open(basedir.c_str(), O_RDONLY);
+ volargs.fd = 0;
+ strcpy(volargs.name, "current");
+ int r = ::ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, (unsigned long int)&volargs);
+ char current_fn[PATH_MAX];
+ sprintf(current_fn, "%s/current", basedir.c_str());
+ if (r == 0) {
+ // yay
+ dout(2) << " created btrfs subvol " << current_fn << dendl;
+ ::chmod(current_fn, 0755);
+ } else if (errno == EEXIST) {
+ dout(2) << " current already exists" << dendl;
+ r = 0;
+ } else if (errno == EOPNOTSUPP || errno == ENOTTY) {
+ dout(2) << " BTRFS_IOC_SUBVOL_CREATE ioctl failed, trying mkdir " << current_fn << dendl;
+ r = ::mkdir(current_fn, 0755);
+ }
+ ::close(fd);
+ if (r < 0) {
+ char err[80];
+ dout(0) << "failed to create current: " << strerror_r(errno, err, sizeof(err)) << dendl;
+ return -errno;
+ }
+
// journal?
int err = mkjournal();
if (err)
dout(10) << "mount fsid is " << fsid << dendl;
// get epoch
- sprintf(fn, "%s/commit_op_seq", basedir.c_str());
+ sprintf(fn, "%s/current/commit_op_seq", basedir.c_str());
op_fd = ::open(fn, O_CREAT|O_RDWR, 0644);
assert(op_fd >= 0);
op_seq = 0;
btrfs_snap = false;
if (btrfs_snap) {
- char dirname[100];
- sprintf(dirname, "%s/%s", basedir.c_str(), COMMIT_SNAP_DIR);
- ::mkdir(dirname, 0755);
- snapdir_fd = ::open(dirname, O_RDONLY);
+ snapdir_fd = ::open(basedir.c_str(), O_RDONLY);
// get snap list
- DIR *dir = ::opendir(dirname);
+ DIR *dir = ::opendir(basedir.c_str());
if (!dir)
return -errno;
dout(10) << "transaction_start " << fd << dendl;
char fn[PATH_MAX];
- sprintf(fn, "%s/trans.%d", basedir.c_str(), fd);
+ sprintf(fn, "%s/current/trans.%d", basedir.c_str(), fd);
::mknod(fn, 0644, 0);
return fd;
return;
char fn[PATH_MAX];
- sprintf(fn, "%s/trans.%d", basedir.c_str(), fd);
+ sprintf(fn, "%s/current/trans.%d", basedir.c_str(), fd);
::unlink(fn);
dout(10) << "transaction_finish " << fd << dendl;
dout(10) << "list_collections" << dendl;
char fn[PATH_MAX];
- sprintf(fn, "%s", basedir.c_str());
+ sprintf(fn, "%s/current", basedir.c_str());
DIR *dir = ::opendir(fn);
if (!dir)