From: Sage Weil Date: Wed, 30 Nov 2011 05:49:49 +0000 (-0800) Subject: filestore: make fsid uuid_d instead of uint64_t X-Git-Tag: v0.40~137^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c8c5e5d6cccc476cbef948b9f44d7d640126a87f;p=ceph.git filestore: make fsid uuid_d instead of uint64_t Signed-off-by: Sage Weil --- diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 5e8b285b7c9e..60fc6575bcbe 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -325,7 +325,7 @@ int FileJournal::create() int64_t needed_space; int ret; buffer::ptr bp; - dout(2) << "create " << fn << dendl; + dout(2) << "create " << fn << " fsid " << fsid << dendl; ret = _open(true, true); if (ret < 0) @@ -396,7 +396,7 @@ done: int FileJournal::open(uint64_t fs_op_seq) { - dout(2) << "open " << fn << " fs_op_seq " << fs_op_seq << dendl; + dout(2) << "open " << fn << " fsid " << fsid << " fs_op_seq " << fs_op_seq << dendl; last_committed_seq = fs_op_seq; uint64_t next_seq = fs_op_seq + 1; @@ -417,8 +417,8 @@ int FileJournal::open(uint64_t fs_op_seq) //<< " vs expected fsid = " << fsid << dendl; if (header.fsid != fsid) { - derr << "FileJournal::open: open fsid doesn't match, invalid " - << "(someone else's?) journal" << dendl; + derr << "FileJournal::open: ondisk fsid " << header.fsid << " doesn't match expected " << fsid + << ", invalid (someone else's?) journal" << dendl; return -EINVAL; } if (header.max_size > max_size) { diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 0cc89f02b39f..534ad2cf07ce 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -584,7 +584,6 @@ done: FileStore::FileStore(const std::string &base, const std::string &jdev) : basedir(base), journalpath(jdev), - fsid(0), btrfs(false), btrfs_stable_commits(false), blk_size(0), @@ -753,7 +752,7 @@ int FileStore::open_journal() { if (journalpath.length()) { dout(10) << "open_journal at " << journalpath << dendl; - journal = new FileJournal(fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio); + journal = new FileJournal(*(uint64_t*)&fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio); if (journal) journal->logger = logger; } @@ -892,10 +891,13 @@ int FileStore::mkfs() } // fsid - srand(time(0) + getpid()); - fsid = rand(); - ret = safe_write(fsid_fd, &fsid, sizeof(fsid)); - if (ret) { + fsid.generate_random(); + + char fsid_str[40]; + fsid.print(fsid_str); + strcat(fsid_str, "\n"); + ret = safe_write(fsid_fd, fsid_str, strlen(fsid_str)); + if (ret < 0) { derr << "FileStore::mkfs: failed to write fsid: " << cpp_strerror(ret) << dendl; goto close_fsid_fd; @@ -1002,7 +1004,7 @@ int FileStore::mkjournal() derr << "FileStore::mkjournal: open error: " << cpp_strerror(err) << dendl; return -err; } - ret = safe_read(fd, &fsid, sizeof(fsid)); + ret = read_fsid(fd); if (ret < 0) { derr << "FileStore::mkjournal: read error: " << cpp_strerror(ret) << dendl; TEMP_FAILURE_RETRY(::close(fd)); @@ -1029,6 +1031,26 @@ int FileStore::mkjournal() return ret; } +int FileStore::read_fsid(int fd) +{ + char fsid_str[40]; + int ret = safe_read(fd, fsid_str, sizeof(fsid_str)); + if (ret < 0) + return ret; + if (ret == 8) { + // old 64-bit fsid... mirror it. + *(uint64_t*)&fsid.uuid[0] = *(uint64_t*)fsid_str; + *(uint64_t*)&fsid.uuid[8] = *(uint64_t*)fsid_str; + return 0; + } + + if (ret > 36) + fsid_str[36] = 0; + if (!fsid.parse(fsid_str)) + return -EINVAL; + return 0; +} + int FileStore::lock_fsid() { struct flock l; @@ -1433,7 +1455,7 @@ int FileStore::mount() // get fsid snprintf(buf, sizeof(buf), "%s/fsid", basedir.c_str()); - fsid_fd = ::open(buf, O_RDWR|O_CREAT, 0644); + fsid_fd = ::open(buf, O_RDWR, 0644); if (fsid_fd < 0) { ret = -errno; derr << "FileStore::mount: error opening '" << buf << "': " @@ -1441,9 +1463,8 @@ int FileStore::mount() goto done; } - fsid = 0; - ret = safe_read_exact(fsid_fd, &fsid, sizeof(fsid)); - if (ret) { + ret = read_fsid(fsid_fd); + if (ret < 0) { derr << "FileStore::mount: error reading fsid_fd: " << cpp_strerror(ret) << dendl; goto close_fsid_fd; @@ -1725,7 +1746,6 @@ close_basedir_fd: TEMP_FAILURE_RETRY(::close(basedir_fd)); basedir_fd = -1; close_fsid_fd: - fsid = 0; TEMP_FAILURE_RETRY(::close(fsid_fd)); fsid_fd = -1; done: diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 0d21c4214cda..299d81fe3274 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -28,6 +28,8 @@ #include "Fake.h" +#include "include/uuid.h" + #include #include using namespace std; @@ -45,7 +47,7 @@ class FileStore : public JournalingObjectStore, string basedir, journalpath; std::string current_fn; std::string current_op_seq_fn; - uint64_t fsid; + uuid_d fsid; bool btrfs; ///< fs is btrfs bool btrfs_stable_commits; ///< we are using btrfs snapshots for a stable journal refernce @@ -80,6 +82,7 @@ class FileStore : public JournalingObjectStore, // helper fns int get_cdir(coll_t cid, char *s, int len); + int read_fsid(int fd); int lock_fsid(); // sync thread @@ -320,6 +323,8 @@ public: void flush(); void sync_and_flush(); + uuid_d get_fsid() { return fsid; } + int snapshot(const string& name); // attrs diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 60d035cd1547..9996f143c521 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -665,6 +665,7 @@ public: virtual void _fake_writes(bool b) {}; virtual void _get_frag_stat(FragmentationStat& st) {}; + virtual uuid_d get_fsid() = 0; }; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index fbbb83c4a618..99d76df81b6f 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -265,9 +265,7 @@ int OSD::mkfs(const std::string &dev, const std::string &jdev, uuid_d fsid, int OSDSuperblock sb; sb.cluster_fsid = fsid; - sb.whoami = whoami; - sb.osd_fsid.generate_random(); try { store = create_object_store(dev, jdev); @@ -280,6 +278,8 @@ int OSD::mkfs(const std::string &dev, const std::string &jdev, uuid_d fsid, int derr << "OSD::mkfs: FileStore::mkfs failed with error " << ret << dendl; goto free_store; } + sb.osd_fsid = store->get_fsid(); + ret = store->mount(); if (ret) { derr << "OSD::mkfs: couldn't mount FileStore: error " << ret << dendl; @@ -460,10 +460,6 @@ int OSD::write_meta(const std::string &base, uuid_d& cluster_fsid, uuid_d& osd_f strcat(val, "\n"); write_meta(base, "ceph_fsid", val, strlen(val)); - osd_fsid.print(val); - strcat(val, "\n"); - write_meta(base, "osd_fsid", val, strlen(val)); - return 0; } @@ -489,7 +485,7 @@ int OSD::peek_meta(const std::string &dev, std::string& magic, val[36] = 0; cluster_fsid.parse(val); - if (read_meta(dev, "osd_fsid", val, sizeof(val)) < 0) + if (read_meta(dev, "fsid", val, sizeof(val)) < 0) osd_fsid = uuid_d(); else { if (strlen(val) > 36)