1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
15 #include "include/compat.h"
16 #include "include/int_types.h"
17 #include "boost/tuple/tuple.hpp"
21 #include <sys/types.h>
27 #include <sys/ioctl.h>
29 #if defined(__linux__)
36 #include "include/linux_fiemap.h"
38 #include "common/xattr.h"
39 #include "chain_xattr.h"
41 #if defined(DARWIN) || defined(__FreeBSD__)
42 #include <sys/param.h>
43 #include <sys/mount.h>
50 #include "FileStore.h"
51 #include "GenericFileStoreBackend.h"
52 #include "BtrfsFileStoreBackend.h"
53 #include "XfsFileStoreBackend.h"
54 #include "ZFSFileStoreBackend.h"
55 #include "common/BackTrace.h"
56 #include "include/types.h"
57 #include "FileJournal.h"
59 #include "osd/osd_types.h"
60 #include "include/color.h"
61 #include "include/buffer.h"
63 #include "common/Timer.h"
64 #include "common/debug.h"
65 #include "common/errno.h"
66 #include "common/run_cmd.h"
67 #include "common/safe_io.h"
68 #include "common/perf_counters.h"
69 #include "common/sync_filesystem.h"
70 #include "common/fd.h"
71 #include "HashIndex.h"
72 #include "DBObjectMap.h"
73 #include "kv/KeyValueDB.h"
75 #include "common/ceph_crypto.h"
76 using ceph::crypto::SHA1;
78 #include "include/assert.h"
80 #include "common/config.h"
81 #include "common/blkdev.h"
84 #define TRACEPOINT_DEFINE
85 #define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
86 #include "tracing/objectstore.h"
87 #undef TRACEPOINT_PROBE_DYNAMIC_LINKAGE
88 #undef TRACEPOINT_DEFINE
90 #define tracepoint(...)
93 #define dout_context cct
94 #define dout_subsys ceph_subsys_filestore
96 #define dout_prefix *_dout << "filestore(" << basedir << ") "
98 #define COMMIT_SNAP_ITEM "snap_%llu"
99 #define CLUSTER_SNAP_ITEM "clustersnap_%s"
101 #define REPLAY_GUARD_XATTR "user.cephos.seq"
102 #define GLOBAL_REPLAY_GUARD_XATTR "user.cephos.gseq"
104 // XATTR_SPILL_OUT_NAME as a xattr is used to maintain that indicates whether
105 // xattrs spill over into DBObjectMap, if XATTR_SPILL_OUT_NAME exists in file
106 // xattrs and the value is "no", it indicates no xattrs in DBObjectMap
107 #define XATTR_SPILL_OUT_NAME "user.cephos.spill_out"
108 #define XATTR_NO_SPILL_OUT "0"
109 #define XATTR_SPILL_OUT "1"
110 #define __FUNC__ __func__ << "(" << __LINE__ << ")"
112 //Initial features in new superblock.
113 static CompatSet get_fs_initial_compat_set() {
114 CompatSet::FeatureSet ceph_osd_feature_compat;
115 CompatSet::FeatureSet ceph_osd_feature_ro_compat;
116 CompatSet::FeatureSet ceph_osd_feature_incompat;
117 return CompatSet(ceph_osd_feature_compat, ceph_osd_feature_ro_compat,
118 ceph_osd_feature_incompat);
121 //Features are added here that this FileStore supports.
122 static CompatSet get_fs_supported_compat_set() {
123 CompatSet compat = get_fs_initial_compat_set();
124 //Any features here can be set in code, but not in initial superblock
125 compat.incompat.insert(CEPH_FS_FEATURE_INCOMPAT_SHARDS);
129 int FileStore::validate_hobject_key(const hobject_t &obj) const
131 unsigned len = LFNIndex::get_max_escaped_name_len(obj);
132 return len > m_filestore_max_xattr_value_size ? -ENAMETOOLONG : 0;
135 int FileStore::get_block_device_fsid(CephContext* cct, const string& path,
138 // make sure we don't try to use aio or direct_io (and get annoying
139 // error messages from failing to do so); performance implications
140 // should be irrelevant for this use
141 FileJournal j(cct, *fsid, 0, 0, path.c_str(), false, false);
142 return j.peek_fsid(*fsid);
145 void FileStore::FSPerfTracker::update_from_perfcounters(
146 PerfCounters &logger)
148 os_commit_latency.consume_next(
150 l_filestore_journal_latency));
151 os_apply_latency.consume_next(
153 l_filestore_apply_latency));
157 ostream& operator<<(ostream& out, const FileStore::OpSequencer& s)
159 return out << *s.parent;
162 int FileStore::get_cdir(const coll_t& cid, char *s, int len)
164 const string &cid_str(cid.to_str());
165 return snprintf(s, len, "%s/current/%s", basedir.c_str(), cid_str.c_str());
168 int FileStore::get_index(const coll_t& cid, Index *index)
170 int r = index_manager.get_index(cid, basedir, index);
171 assert(!m_filestore_fail_eio || r != -EIO);
175 int FileStore::init_index(const coll_t& cid)
178 get_cdir(cid, path, sizeof(path));
179 int r = index_manager.init_index(cid, path, target_version);
180 assert(!m_filestore_fail_eio || r != -EIO);
184 int FileStore::lfn_find(const ghobject_t& oid, const Index& index, IndexedPath *path)
190 assert(NULL != index.index);
191 r = (index.index)->lookup(oid, path, &exist);
193 assert(!m_filestore_fail_eio || r != -EIO);
201 int FileStore::lfn_truncate(const coll_t& cid, const ghobject_t& oid, off_t length)
204 int r = lfn_open(cid, oid, false, &fd);
207 r = ::ftruncate(**fd, length);
210 if (r >= 0 && m_filestore_sloppy_crc) {
211 int rc = backend->_crc_update_truncate(**fd, length);
215 assert(!m_filestore_fail_eio || r != -EIO);
219 int FileStore::lfn_stat(const coll_t& cid, const ghobject_t& oid, struct stat *buf)
223 int r = get_index(cid, &index);
227 assert(NULL != index.index);
228 RWLock::RLocker l((index.index)->access_lock);
230 r = lfn_find(oid, index, &path);
233 r = ::stat(path->path(), buf);
239 int FileStore::lfn_open(const coll_t& cid,
240 const ghobject_t& oid,
247 bool need_lock = true;
252 if (cct->_conf->filestore_odsync_write) {
260 if (!((*index).index)) {
261 r = get_index(cid, index);
263 dout(10) << __FUNC__ << ": could not get index r = " << r << dendl;
271 assert(NULL != (*index).index);
273 ((*index).index)->access_lock.get_write();
276 *outfd = fdcache.lookup(oid);
279 ((*index).index)->access_lock.put_write();
287 IndexedPath *path = &path2;
289 r = (*index)->lookup(oid, path, &exist);
291 derr << "could not find " << oid << " in index: "
292 << cpp_strerror(-r) << dendl;
296 r = ::open((*path)->path(), flags, 0644);
299 dout(10) << "error opening file " << (*path)->path() << " with flags="
300 << flags << ": " << cpp_strerror(-r) << dendl;
304 if (create && (!exist)) {
305 r = (*index)->created(oid, (*path)->path());
307 VOID_TEMP_FAILURE_RETRY(::close(fd));
308 derr << "error creating " << oid << " (" << (*path)->path()
309 << ") in index: " << cpp_strerror(-r) << dendl;
312 r = chain_fsetxattr<true, true>(
313 fd, XATTR_SPILL_OUT_NAME,
314 XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT));
316 VOID_TEMP_FAILURE_RETRY(::close(fd));
317 derr << "error setting spillout xattr for oid " << oid << " (" << (*path)->path()
318 << "):" << cpp_strerror(-r) << dendl;
325 *outfd = fdcache.add(oid, fd, &existed);
327 TEMP_FAILURE_RETRY(::close(fd));
330 *outfd = std::make_shared<FDCache::FD>(fd);
334 ((*index).index)->access_lock.put_write();
342 ((*index).index)->access_lock.put_write();
345 assert(!m_filestore_fail_eio || r != -EIO);
349 void FileStore::lfn_close(FDRef fd)
353 int FileStore::lfn_link(const coll_t& c, const coll_t& newcid, const ghobject_t& o, const ghobject_t& newoid)
355 Index index_new, index_old;
356 IndexedPath path_new, path_old;
359 bool index_same = false;
361 r = get_index(newcid, &index_new);
364 r = get_index(c, &index_old);
367 } else if (c == newcid) {
368 r = get_index(c, &index_old);
371 index_new = index_old;
374 r = get_index(c, &index_old);
377 r = get_index(newcid, &index_new);
382 assert(NULL != index_old.index);
383 assert(NULL != index_new.index);
387 RWLock::RLocker l1((index_old.index)->access_lock);
389 r = index_old->lookup(o, &path_old, &exist);
391 assert(!m_filestore_fail_eio || r != -EIO);
397 RWLock::WLocker l2((index_new.index)->access_lock);
399 r = index_new->lookup(newoid, &path_new, &exist);
401 assert(!m_filestore_fail_eio || r != -EIO);
407 dout(25) << __FUNC__ << ": path_old: " << path_old << dendl;
408 dout(25) << __FUNC__ << ": path_new: " << path_new << dendl;
409 r = ::link(path_old->path(), path_new->path());
413 r = index_new->created(newoid, path_new->path());
415 assert(!m_filestore_fail_eio || r != -EIO);
419 RWLock::WLocker l1((index_old.index)->access_lock);
421 r = index_old->lookup(o, &path_old, &exist);
423 assert(!m_filestore_fail_eio || r != -EIO);
429 r = index_new->lookup(newoid, &path_new, &exist);
431 assert(!m_filestore_fail_eio || r != -EIO);
437 dout(25) << __FUNC__ << ": path_old: " << path_old << dendl;
438 dout(25) << __FUNC__ << ": path_new: " << path_new << dendl;
439 r = ::link(path_old->path(), path_new->path());
443 // make sure old fd for unlinked/overwritten file is gone
444 fdcache.clear(newoid);
446 r = index_new->created(newoid, path_new->path());
448 assert(!m_filestore_fail_eio || r != -EIO);
455 int FileStore::lfn_unlink(const coll_t& cid, const ghobject_t& o,
456 const SequencerPosition &spos,
457 bool force_clear_omap)
460 int r = get_index(cid, &index);
462 dout(25) << __FUNC__ << ": get_index failed " << cpp_strerror(r) << dendl;
466 assert(NULL != index.index);
467 RWLock::WLocker l((index.index)->access_lock);
472 r = index->lookup(o, &path, &hardlink);
474 assert(!m_filestore_fail_eio || r != -EIO);
478 if (!force_clear_omap) {
479 if (hardlink == 0 || hardlink == 1) {
480 force_clear_omap = true;
483 if (force_clear_omap) {
484 dout(20) << __FUNC__ << ": clearing omap on " << o
485 << " in cid " << cid << dendl;
486 r = object_map->clear(o, &spos);
487 if (r < 0 && r != -ENOENT) {
488 dout(25) << __FUNC__ << ": omap clear failed " << cpp_strerror(r) << dendl;
489 assert(!m_filestore_fail_eio || r != -EIO);
492 if (cct->_conf->filestore_debug_inject_read_err) {
493 debug_obj_on_delete(o);
495 if (!m_disable_wbthrottle) {
496 wbthrottle.clear_object(o); // should be only non-cache ref
500 /* Ensure that replay of this op doesn't result in the object_map
503 if (!backend->can_checkpoint())
504 object_map->sync(&o, &spos);
507 if (!m_disable_wbthrottle) {
508 wbthrottle.clear_object(o); // should be only non-cache ref
513 r = index->unlink(o);
515 dout(25) << __FUNC__ << ": index unlink failed " << cpp_strerror(r) << dendl;
521 FileStore::FileStore(CephContext* cct, const std::string &base,
522 const std::string &jdev, osflagbits_t flags,
523 const char *name, bool do_update) :
524 JournalingObjectStore(cct, base),
526 basedir(base), journalpath(jdev),
527 generic_flags(flags),
529 fsid_fd(-1), op_fd(-1),
530 basedir_fd(-1), current_fd(-1),
532 index_manager(cct, do_update),
533 lock("FileStore::lock"),
535 sync_entry_timeo_lock("FileStore::sync_entry_timeo_lock"),
536 timer(cct, sync_entry_timeo_lock),
537 stop(false), sync_thread(this),
541 m_disable_wbthrottle(cct->_conf->filestore_odsync_write ||
542 !cct->_conf->filestore_wbthrottle_enable),
543 throttle_ops(cct, "filestore_ops", cct->_conf->filestore_caller_concurrency),
544 throttle_bytes(cct, "filestore_bytes", cct->_conf->filestore_caller_concurrency),
545 m_ondisk_finisher_num(cct->_conf->filestore_ondisk_finisher_threads),
546 m_apply_finisher_num(cct->_conf->filestore_apply_finisher_threads),
547 op_tp(cct, "FileStore::op_tp", "tp_fstore_op", cct->_conf->filestore_op_threads, "filestore_op_threads"),
548 op_wq(this, cct->_conf->filestore_op_thread_timeout,
549 cct->_conf->filestore_op_thread_suicide_timeout, &op_tp),
551 trace_endpoint("0.0.0.0", 0, "FileStore"),
552 read_error_lock("FileStore::read_error_lock"),
553 m_filestore_commit_timeout(cct->_conf->filestore_commit_timeout),
554 m_filestore_journal_parallel(cct->_conf->filestore_journal_parallel ),
555 m_filestore_journal_trailing(cct->_conf->filestore_journal_trailing),
556 m_filestore_journal_writeahead(cct->_conf->filestore_journal_writeahead),
557 m_filestore_fiemap_threshold(cct->_conf->filestore_fiemap_threshold),
558 m_filestore_max_sync_interval(cct->_conf->filestore_max_sync_interval),
559 m_filestore_min_sync_interval(cct->_conf->filestore_min_sync_interval),
560 m_filestore_fail_eio(cct->_conf->filestore_fail_eio),
561 m_filestore_fadvise(cct->_conf->filestore_fadvise),
562 do_update(do_update),
563 m_journal_dio(cct->_conf->journal_dio),
564 m_journal_aio(cct->_conf->journal_aio),
565 m_journal_force_aio(cct->_conf->journal_force_aio),
566 m_osd_rollback_to_cluster_snap(cct->_conf->osd_rollback_to_cluster_snap),
567 m_osd_use_stale_snap(cct->_conf->osd_use_stale_snap),
568 m_filestore_do_dump(false),
569 m_filestore_dump_fmt(true),
570 m_filestore_sloppy_crc(cct->_conf->filestore_sloppy_crc),
571 m_filestore_sloppy_crc_block_size(cct->_conf->filestore_sloppy_crc_block_size),
572 m_filestore_max_alloc_hint_size(cct->_conf->filestore_max_alloc_hint_size),
574 m_filestore_max_inline_xattr_size(0),
575 m_filestore_max_inline_xattrs(0),
576 m_filestore_max_xattr_value_size(0)
578 m_filestore_kill_at = cct->_conf->filestore_kill_at;
579 for (int i = 0; i < m_ondisk_finisher_num; ++i) {
581 oss << "filestore-ondisk-" << i;
582 Finisher *f = new Finisher(cct, oss.str(), "fn_odsk_fstore");
583 ondisk_finishers.push_back(f);
585 for (int i = 0; i < m_apply_finisher_num; ++i) {
587 oss << "filestore-apply-" << i;
588 Finisher *f = new Finisher(cct, oss.str(), "fn_appl_fstore");
589 apply_finishers.push_back(f);
593 oss << basedir << "/current";
594 current_fn = oss.str();
597 sss << basedir << "/current/commit_op_seq";
598 current_op_seq_fn = sss.str();
601 if (cct->_conf->filestore_omap_backend_path != "") {
602 omap_dir = cct->_conf->filestore_omap_backend_path;
604 omss << basedir << "/current/omap";
605 omap_dir = omss.str();
609 PerfCountersBuilder plb(cct, internal_name, l_filestore_first, l_filestore_last);
611 plb.add_u64(l_filestore_journal_queue_ops, "journal_queue_ops", "Operations in journal queue");
612 plb.add_u64(l_filestore_journal_ops, "journal_ops", "Active journal entries to be applied");
613 plb.add_u64(l_filestore_journal_queue_bytes, "journal_queue_bytes", "Size of journal queue");
614 plb.add_u64(l_filestore_journal_bytes, "journal_bytes", "Active journal operation size to be applied");
615 plb.add_time_avg(l_filestore_journal_latency, "journal_latency", "Average journal queue completing latency");
616 plb.add_u64_counter(l_filestore_journal_wr, "journal_wr", "Journal write IOs");
617 plb.add_u64_avg(l_filestore_journal_wr_bytes, "journal_wr_bytes", "Journal data written");
618 plb.add_u64(l_filestore_op_queue_max_ops, "op_queue_max_ops", "Max operations in writing to FS queue");
619 plb.add_u64(l_filestore_op_queue_ops, "op_queue_ops", "Operations in writing to FS queue");
620 plb.add_u64_counter(l_filestore_ops, "ops", "Operations written to store");
621 plb.add_u64(l_filestore_op_queue_max_bytes, "op_queue_max_bytes", "Max data in writing to FS queue");
622 plb.add_u64(l_filestore_op_queue_bytes, "op_queue_bytes", "Size of writing to FS queue");
623 plb.add_u64_counter(l_filestore_bytes, "bytes", "Data written to store");
624 plb.add_time_avg(l_filestore_apply_latency, "apply_latency", "Apply latency");
625 plb.add_u64(l_filestore_committing, "committing", "Is currently committing");
627 plb.add_u64_counter(l_filestore_commitcycle, "commitcycle", "Commit cycles");
628 plb.add_time_avg(l_filestore_commitcycle_interval, "commitcycle_interval", "Average interval between commits");
629 plb.add_time_avg(l_filestore_commitcycle_latency, "commitcycle_latency", "Average latency of commit");
630 plb.add_u64_counter(l_filestore_journal_full, "journal_full", "Journal writes while full");
631 plb.add_time_avg(l_filestore_queue_transaction_latency_avg, "queue_transaction_latency_avg", "Store operation queue latency");
632 plb.add_time(l_filestore_sync_pause_max_lat, "sync_pause_max_latency", "Max latency of op_wq pause before syncfs");
634 logger = plb.create_perf_counters();
636 cct->get_perfcounters_collection()->add(logger);
637 cct->_conf->add_observer(this);
639 superblock.compat_features = get_fs_initial_compat_set();
642 FileStore::~FileStore()
644 for (vector<Finisher*>::iterator it = ondisk_finishers.begin(); it != ondisk_finishers.end(); ++it) {
648 for (vector<Finisher*>::iterator it = apply_finishers.begin(); it != apply_finishers.end(); ++it) {
652 cct->_conf->remove_observer(this);
653 cct->get_perfcounters_collection()->remove(logger);
656 journal->logger = NULL;
659 if (m_filestore_do_dump) {
664 static void get_attrname(const char *name, char *buf, int len)
666 snprintf(buf, len, "user.ceph.%s", name);
669 bool parse_attrname(char **name)
671 if (strncmp(*name, "user.ceph.", 10) == 0) {
678 void FileStore::collect_metadata(map<string,string> *pm)
680 char partition_path[PATH_MAX];
681 char dev_node[PATH_MAX];
684 (*pm)["filestore_backend"] = backend->get_name();
686 ss << "0x" << std::hex << m_fs_type << std::dec;
687 (*pm)["filestore_f_type"] = ss.str();
689 if (cct->_conf->filestore_collect_device_partition_information) {
690 rc = get_device_by_fd(fsid_fd, partition_path, dev_node, PATH_MAX);
698 (*pm)["backend_filestore_partition_path"] = "unknown";
699 (*pm)["backend_filestore_dev_node"] = "unknown";
702 (*pm)["backend_filestore_partition_path"] = string(partition_path);
703 (*pm)["backend_filestore_dev_node"] = "unknown";
706 (*pm)["backend_filestore_partition_path"] = string(partition_path);
707 (*pm)["backend_filestore_dev_node"] = string(dev_node);
711 int FileStore::statfs(struct store_statfs_t *buf0)
715 if (::statfs(basedir.c_str(), &buf) < 0) {
717 assert(!m_filestore_fail_eio || r != -EIO);
718 assert(r != -ENOENT);
721 buf0->total = buf.f_blocks * buf.f_bsize;
722 buf0->available = buf.f_bavail * buf.f_bsize;
723 // Adjust for writes pending in the journal
725 uint64_t estimate = journal->get_journal_size_estimate();
726 if (buf0->available > estimate)
727 buf0->available -= estimate;
735 void FileStore::new_journal()
737 if (journalpath.length()) {
738 dout(10) << "open_journal at " << journalpath << dendl;
739 journal = new FileJournal(cct, fsid, &finisher, &sync_cond,
741 m_journal_dio, m_journal_aio,
742 m_journal_force_aio);
744 journal->logger = logger;
749 int FileStore::dump_journal(ostream& out)
753 if (!journalpath.length())
756 FileJournal *journal = new FileJournal(cct, fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio);
757 r = journal->dump(out);
762 FileStoreBackend *FileStoreBackend::create(long f_type, FileStore *fs)
765 #if defined(__linux__)
766 case BTRFS_SUPER_MAGIC:
767 return new BtrfsFileStoreBackend(fs);
769 case XFS_SUPER_MAGIC:
770 return new XfsFileStoreBackend(fs);
774 case ZFS_SUPER_MAGIC:
775 return new ZFSFileStoreBackend(fs);
778 return new GenericFileStoreBackend(fs);
782 void FileStore::create_backend(long f_type)
786 assert(backend == NULL);
787 backend = FileStoreBackend::create(f_type, this);
789 dout(0) << "backend " << backend->get_name()
790 << " (magic 0x" << std::hex << f_type << std::dec << ")"
794 #if defined(__linux__)
795 case BTRFS_SUPER_MAGIC:
796 if (!m_disable_wbthrottle){
797 wbthrottle.set_fs(WBThrottle::BTRFS);
801 case XFS_SUPER_MAGIC:
802 // wbthrottle is constructed with fs(WBThrottle::XFS)
807 set_xattr_limits_via_conf();
810 int FileStore::mkfs()
813 char fsid_fn[PATH_MAX];
816 uuid_d old_omap_fsid;
818 dout(1) << "mkfs in " << basedir << dendl;
819 basedir_fd = ::open(basedir.c_str(), O_RDONLY);
820 if (basedir_fd < 0) {
822 derr << __FUNC__ << ": failed to open base dir " << basedir << ": " << cpp_strerror(ret) << dendl;
827 snprintf(fsid_fn, sizeof(fsid_fn), "%s/fsid", basedir.c_str());
828 fsid_fd = ::open(fsid_fn, O_RDWR|O_CREAT, 0644);
831 derr << __FUNC__ << ": failed to open " << fsid_fn << ": " << cpp_strerror(ret) << dendl;
832 goto close_basedir_fd;
835 if (lock_fsid() < 0) {
840 if (read_fsid(fsid_fd, &old_fsid) < 0 || old_fsid.is_zero()) {
841 if (fsid.is_zero()) {
842 fsid.generate_random();
843 dout(1) << __FUNC__ << ": generated fsid " << fsid << dendl;
845 dout(1) << __FUNC__ << ": using provided fsid " << fsid << dendl;
848 fsid.print(fsid_str);
849 strcat(fsid_str, "\n");
850 ret = ::ftruncate(fsid_fd, 0);
853 derr << __FUNC__ << ": failed to truncate fsid: "
854 << cpp_strerror(ret) << dendl;
857 ret = safe_write(fsid_fd, fsid_str, strlen(fsid_str));
859 derr << __FUNC__ << ": failed to write fsid: "
860 << cpp_strerror(ret) << dendl;
863 if (::fsync(fsid_fd) < 0) {
865 derr << __FUNC__ << ": close failed: can't write fsid: "
866 << cpp_strerror(ret) << dendl;
869 dout(10) << __FUNC__ << ": fsid is " << fsid << dendl;
871 if (!fsid.is_zero() && fsid != old_fsid) {
872 derr << __FUNC__ << ": on-disk fsid " << old_fsid << " != provided " << fsid << dendl;
877 dout(1) << __FUNC__ << ": fsid is already set to " << fsid << dendl;
881 ret = write_version_stamp();
883 derr << __FUNC__ << ": write_version_stamp() failed: "
884 << cpp_strerror(ret) << dendl;
889 superblock.omap_backend = cct->_conf->filestore_omap_backend;
890 ret = write_superblock();
892 derr << __FUNC__ << ": write_superblock() failed: "
893 << cpp_strerror(ret) << dendl;
897 struct statfs basefs;
898 ret = ::fstatfs(basedir_fd, &basefs);
901 derr << __FUNC__ << ": cannot fstatfs basedir "
902 << cpp_strerror(ret) << dendl;
906 #if defined(__linux__)
907 if (basefs.f_type == BTRFS_SUPER_MAGIC &&
908 !g_ceph_context->check_experimental_feature_enabled("btrfs")) {
909 derr << __FUNC__ << ": deprecated btrfs support is not enabled" << dendl;
914 create_backend(basefs.f_type);
916 ret = backend->create_current();
918 derr << __FUNC__ << ": failed to create current/ " << cpp_strerror(ret) << dendl;
922 // write initial op_seq
924 uint64_t initial_seq = 0;
925 int fd = read_op_seq(&initial_seq);
928 derr << __FUNC__ << ": failed to create " << current_op_seq_fn << ": "
929 << cpp_strerror(ret) << dendl;
932 if (initial_seq == 0) {
933 ret = write_op_seq(fd, 1);
935 VOID_TEMP_FAILURE_RETRY(::close(fd));
936 derr << __FUNC__ << ": failed to write to " << current_op_seq_fn << ": "
937 << cpp_strerror(ret) << dendl;
941 if (backend->can_checkpoint()) {
943 current_fd = ::open(current_fn.c_str(), O_RDONLY);
944 assert(current_fd >= 0);
946 snprintf(s, sizeof(s), COMMIT_SNAP_ITEM, 1ull);
947 ret = backend->create_checkpoint(s, NULL);
948 VOID_TEMP_FAILURE_RETRY(::close(current_fd));
949 if (ret < 0 && ret != -EEXIST) {
950 VOID_TEMP_FAILURE_RETRY(::close(fd));
951 derr << __FUNC__ << ": failed to create snap_1: " << cpp_strerror(ret) << dendl;
956 VOID_TEMP_FAILURE_RETRY(::close(fd));
958 ret = KeyValueDB::test_init(superblock.omap_backend, omap_dir);
960 derr << __FUNC__ << ": failed to create " << cct->_conf->filestore_omap_backend << dendl;
963 // create fsid under omap
966 char omap_fsid_fn[PATH_MAX];
967 snprintf(omap_fsid_fn, sizeof(omap_fsid_fn), "%s/osd_uuid", omap_dir.c_str());
968 omap_fsid_fd = ::open(omap_fsid_fn, O_RDWR|O_CREAT, 0644);
969 if (omap_fsid_fd < 0) {
971 derr << __FUNC__ << ": failed to open " << omap_fsid_fn << ": " << cpp_strerror(ret) << dendl;
975 if (read_fsid(omap_fsid_fd, &old_omap_fsid) < 0 || old_omap_fsid.is_zero()) {
976 assert(!fsid.is_zero());
977 fsid.print(fsid_str);
978 strcat(fsid_str, "\n");
979 ret = ::ftruncate(omap_fsid_fd, 0);
982 derr << __FUNC__ << ": failed to truncate fsid: "
983 << cpp_strerror(ret) << dendl;
984 goto close_omap_fsid_fd;
986 ret = safe_write(omap_fsid_fd, fsid_str, strlen(fsid_str));
988 derr << __FUNC__ << ": failed to write fsid: "
989 << cpp_strerror(ret) << dendl;
990 goto close_omap_fsid_fd;
992 dout(10) << __FUNC__ << ": write success, fsid:" << fsid_str << ", ret:" << ret << dendl;
993 if (::fsync(omap_fsid_fd) < 0) {
995 derr << __FUNC__ << ": close failed: can't write fsid: "
996 << cpp_strerror(ret) << dendl;
997 goto close_omap_fsid_fd;
999 dout(10) << "mkfs omap fsid is " << fsid << dendl;
1001 if (fsid != old_omap_fsid) {
1002 derr << __FUNC__ << ": " << omap_fsid_fn
1003 << " has existed omap fsid " << old_omap_fsid
1004 << " != expected osd fsid " << fsid
1007 goto close_omap_fsid_fd;
1009 dout(1) << __FUNC__ << ": omap fsid is already set to " << fsid << dendl;
1012 dout(1) << cct->_conf->filestore_omap_backend << " db exists/created" << dendl;
1017 goto close_omap_fsid_fd;
1019 ret = write_meta("type", "filestore");
1021 goto close_omap_fsid_fd;
1023 dout(1) << "mkfs done in " << basedir << dendl;
1027 VOID_TEMP_FAILURE_RETRY(::close(omap_fsid_fd));
1029 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd));
1032 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd));
1038 int FileStore::mkjournal()
1043 snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
1044 int fd = ::open(fn, O_RDONLY, 0644);
1047 derr << __FUNC__ << ": open error: " << cpp_strerror(err) << dendl;
1050 ret = read_fsid(fd, &fsid);
1052 derr << __FUNC__ << ": read error: " << cpp_strerror(ret) << dendl;
1053 VOID_TEMP_FAILURE_RETRY(::close(fd));
1056 VOID_TEMP_FAILURE_RETRY(::close(fd));
1062 ret = journal->check();
1064 ret = journal->create();
1066 derr << __FUNC__ << ": error creating journal on " << journalpath
1067 << ": " << cpp_strerror(ret) << dendl;
1069 dout(0) << __FUNC__ << ": created journal on " << journalpath << dendl;
1077 int FileStore::read_fsid(int fd, uuid_d *uuid)
1080 memset(fsid_str, 0, sizeof(fsid_str));
1081 int ret = safe_read(fd, fsid_str, sizeof(fsid_str));
1085 // old 64-bit fsid... mirror it.
1086 *(uint64_t*)&uuid->bytes()[0] = *(uint64_t*)fsid_str;
1087 *(uint64_t*)&uuid->bytes()[8] = *(uint64_t*)fsid_str;
1095 if (!uuid->parse(fsid_str))
1100 int FileStore::lock_fsid()
1103 memset(&l, 0, sizeof(l));
1105 l.l_whence = SEEK_SET;
1108 int r = ::fcntl(fsid_fd, F_SETLK, &l);
1111 dout(0) << __FUNC__ << ": failed to lock " << basedir << "/fsid, is another ceph-osd still running? "
1112 << cpp_strerror(err) << dendl;
1118 bool FileStore::test_mount_in_use()
1120 dout(5) << __FUNC__ << ": basedir " << basedir << " journal " << journalpath << dendl;
1122 snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
1124 // verify fs isn't in use
1126 fsid_fd = ::open(fn, O_RDWR, 0644);
1128 return 0; // no fsid, ok.
1129 bool inuse = lock_fsid() < 0;
1130 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd));
1135 bool FileStore::is_rotational()
1139 rotational = backend->is_rotational();
1141 int fd = ::open(basedir.c_str(), O_RDONLY);
1145 int r = ::fstatfs(fd, &st);
1150 create_backend(st.f_type);
1151 rotational = backend->is_rotational();
1155 dout(10) << __func__ << " " << (int)rotational << dendl;
1159 bool FileStore::is_journal_rotational()
1161 bool journal_rotational;
1163 journal_rotational = backend->is_journal_rotational();
1165 int fd = ::open(journalpath.c_str(), O_RDONLY);
1169 int r = ::fstatfs(fd, &st);
1174 create_backend(st.f_type);
1175 journal_rotational = backend->is_journal_rotational();
1179 dout(10) << __func__ << " " << (int)journal_rotational << dendl;
1180 return journal_rotational;
1183 int FileStore::_detect_fs()
1186 int r = ::fstatfs(basedir_fd, &st);
1190 blk_size = st.f_bsize;
1192 #if defined(__linux__)
1193 if (st.f_type == BTRFS_SUPER_MAGIC &&
1194 !g_ceph_context->check_experimental_feature_enabled("btrfs")) {
1195 derr <<__FUNC__ << ": deprecated btrfs support is not enabled" << dendl;
1200 create_backend(st.f_type);
1202 r = backend->detect_features();
1204 derr << __FUNC__ << ": detect_features error: " << cpp_strerror(r) << dendl;
1212 snprintf(fn, sizeof(fn), "%s/xattr_test", basedir.c_str());
1213 int tmpfd = ::open(fn, O_CREAT|O_WRONLY|O_TRUNC, 0700);
1216 derr << __FUNC__ << ": unable to create " << fn << ": " << cpp_strerror(ret) << dendl;
1220 int ret = chain_fsetxattr(tmpfd, "user.test", &x, sizeof(x));
1222 ret = chain_fgetxattr(tmpfd, "user.test", &y, sizeof(y));
1223 if ((ret < 0) || (x != y)) {
1224 derr << "Extended attributes don't appear to work. ";
1226 *_dout << "Got error " + cpp_strerror(ret) + ". ";
1227 *_dout << "If you are using ext3 or ext4, be sure to mount the underlying "
1228 << "file system with the 'user_xattr' option." << dendl;
1230 VOID_TEMP_FAILURE_RETRY(::close(tmpfd));
1235 memset(buf, 0, sizeof(buf)); // shut up valgrind
1236 chain_fsetxattr(tmpfd, "user.test", &buf, sizeof(buf));
1237 chain_fsetxattr(tmpfd, "user.test2", &buf, sizeof(buf));
1238 chain_fsetxattr(tmpfd, "user.test3", &buf, sizeof(buf));
1239 chain_fsetxattr(tmpfd, "user.test4", &buf, sizeof(buf));
1240 ret = chain_fsetxattr(tmpfd, "user.test5", &buf, sizeof(buf));
1241 if (ret == -ENOSPC) {
1242 dout(0) << "limited size xattrs" << dendl;
1244 chain_fremovexattr(tmpfd, "user.test");
1245 chain_fremovexattr(tmpfd, "user.test2");
1246 chain_fremovexattr(tmpfd, "user.test3");
1247 chain_fremovexattr(tmpfd, "user.test4");
1248 chain_fremovexattr(tmpfd, "user.test5");
1251 VOID_TEMP_FAILURE_RETRY(::close(tmpfd));
1256 int FileStore::_sanity_check_fs()
1260 if (((int)m_filestore_journal_writeahead +
1261 (int)m_filestore_journal_parallel +
1262 (int)m_filestore_journal_trailing) > 1) {
1263 dout(0) << "mount ERROR: more than one of filestore journal {writeahead,parallel,trailing} enabled" << dendl;
1265 << " ** WARNING: more than one of 'filestore journal {writeahead,parallel,trailing}'\n"
1266 << " is enabled in ceph.conf. You must choose a single journal mode."
1267 << TEXT_NORMAL << std::endl;
1271 if (!backend->can_checkpoint()) {
1272 if (!journal || !m_filestore_journal_writeahead) {
1273 dout(0) << "mount WARNING: no btrfs, and no journal in writeahead mode; data may be lost" << dendl;
1275 << " ** WARNING: no btrfs AND (no journal OR journal not in writeahead mode)\n"
1276 << " For non-btrfs volumes, a writeahead journal is required to\n"
1277 << " maintain on-disk consistency in the event of a crash. Your conf\n"
1278 << " should include something like:\n"
1279 << " osd journal = /path/to/journal_device_or_file\n"
1280 << " filestore journal writeahead = true\n"
1286 dout(0) << "mount WARNING: no journal" << dendl;
1288 << " ** WARNING: No osd journal is configured: write latency may be high.\n"
1289 << " If you will not be using an osd journal, write latency may be\n"
1290 << " relatively high. It can be reduced somewhat by lowering\n"
1291 << " filestore_max_sync_interval, but lower values mean lower write\n"
1292 << " throughput, especially with spinning disks.\n"
1299 int FileStore::write_superblock()
1302 ::encode(superblock, bl);
1303 return safe_write_file(basedir.c_str(), "superblock",
1304 bl.c_str(), bl.length());
1307 int FileStore::read_superblock()
1309 bufferptr bp(PATH_MAX);
1310 int ret = safe_read_file(basedir.c_str(), "superblock",
1311 bp.c_str(), bp.length());
1313 if (ret == -ENOENT) {
1314 // If the file doesn't exist write initial CompatSet
1315 return write_superblock();
1321 bl.push_back(std::move(bp));
1322 bufferlist::iterator i = bl.begin();
1323 ::decode(superblock, i);
1327 int FileStore::update_version_stamp()
1329 return write_version_stamp();
1332 int FileStore::version_stamp_is_valid(uint32_t *version)
1334 bufferptr bp(PATH_MAX);
1335 int ret = safe_read_file(basedir.c_str(), "store_version",
1336 bp.c_str(), bp.length());
1341 bl.push_back(std::move(bp));
1342 bufferlist::iterator i = bl.begin();
1343 ::decode(*version, i);
1344 dout(10) << __FUNC__ << ": was " << *version << " vs target "
1345 << target_version << dendl;
1346 if (*version == target_version)
1352 int FileStore::write_version_stamp()
1354 dout(1) << __FUNC__ << ": " << target_version << dendl;
1356 ::encode(target_version, bl);
1358 return safe_write_file(basedir.c_str(), "store_version",
1359 bl.c_str(), bl.length());
1362 int FileStore::upgrade()
1364 dout(1) << __FUNC__ << dendl;
1366 int r = version_stamp_is_valid(&version);
1369 derr << "The store_version file doesn't exist." << dendl;
1378 derr << "ObjectStore is old at version " << version << ". Please upgrade to firefly v0.80.x, convert your store, and then upgrade." << dendl;
1382 // nothing necessary in FileStore for v3 -> v4 upgrade; we just need to
1383 // open up DBObjectMap with the do_upgrade flag, which we already did.
1384 update_version_stamp();
1388 int FileStore::read_op_seq(uint64_t *seq)
1390 int op_fd = ::open(current_op_seq_fn.c_str(), O_CREAT|O_RDWR, 0644);
1393 assert(!m_filestore_fail_eio || r != -EIO);
1397 memset(s, 0, sizeof(s));
1398 int ret = safe_read(op_fd, s, sizeof(s) - 1);
1400 derr << __FUNC__ << ": error reading " << current_op_seq_fn << ": " << cpp_strerror(ret) << dendl;
1401 VOID_TEMP_FAILURE_RETRY(::close(op_fd));
1402 assert(!m_filestore_fail_eio || ret != -EIO);
1409 int FileStore::write_op_seq(int fd, uint64_t seq)
1412 snprintf(s, sizeof(s), "%" PRId64 "\n", seq);
1413 int ret = TEMP_FAILURE_RETRY(::pwrite(fd, s, strlen(s), 0));
1416 assert(!m_filestore_fail_eio || ret != -EIO);
1421 int FileStore::mount()
1425 uint64_t initial_op_seq;
1427 set<string> cluster_snaps;
1428 CompatSet supported_compat_set = get_fs_supported_compat_set();
1430 dout(5) << "basedir " << basedir << " journal " << journalpath << dendl;
1432 ret = set_throttle_params();
1436 // make sure global base dir exists
1437 if (::access(basedir.c_str(), R_OK | W_OK)) {
1439 derr << __FUNC__ << ": unable to access basedir '" << basedir << "': "
1440 << cpp_strerror(ret) << dendl;
1445 snprintf(buf, sizeof(buf), "%s/fsid", basedir.c_str());
1446 fsid_fd = ::open(buf, O_RDWR, 0644);
1449 derr << __FUNC__ << ": error opening '" << buf << "': "
1450 << cpp_strerror(ret) << dendl;
1454 ret = read_fsid(fsid_fd, &fsid);
1456 derr << __FUNC__ << ": error reading fsid_fd: " << cpp_strerror(ret)
1461 if (lock_fsid() < 0) {
1462 derr << __FUNC__ << ": lock_fsid failed" << dendl;
1467 dout(10) << "mount fsid is " << fsid << dendl;
1470 uint32_t version_stamp;
1471 ret = version_stamp_is_valid(&version_stamp);
1473 derr << __FUNC__ << ": error in version_stamp_is_valid: "
1474 << cpp_strerror(ret) << dendl;
1476 } else if (ret == 0) {
1477 if (do_update || (int)version_stamp < cct->_conf->filestore_update_to) {
1478 derr << __FUNC__ << ": stale version stamp detected: "
1480 << ". Proceeding, do_update "
1481 << "is set, performing disk format upgrade."
1486 derr << __FUNC__ << ": stale version stamp " << version_stamp
1487 << ". Please run the FileStore update script before starting the "
1488 << "OSD, or set filestore_update_to to " << target_version
1489 << " (currently " << cct->_conf->filestore_update_to << ")"
1495 ret = read_superblock();
1500 // Check if this FileStore supports all the necessary features to mount
1501 if (supported_compat_set.compare(superblock.compat_features) == -1) {
1502 derr << __FUNC__ << ": Incompatible features set "
1503 << superblock.compat_features << dendl;
1508 // open some dir handles
1509 basedir_fd = ::open(basedir.c_str(), O_RDONLY);
1510 if (basedir_fd < 0) {
1512 derr << __FUNC__ << ": failed to open " << basedir << ": "
1513 << cpp_strerror(ret) << dendl;
1518 // test for btrfs, xattrs, etc.
1521 derr << __FUNC__ << ": error in _detect_fs: "
1522 << cpp_strerror(ret) << dendl;
1523 goto close_basedir_fd;
1528 ret = backend->list_checkpoints(ls);
1530 derr << __FUNC__ << ": error in _list_snaps: "<< cpp_strerror(ret) << dendl;
1531 goto close_basedir_fd;
1534 long long unsigned c, prev = 0;
1535 char clustersnap[NAME_MAX];
1536 for (list<string>::iterator it = ls.begin(); it != ls.end(); ++it) {
1537 if (sscanf(it->c_str(), COMMIT_SNAP_ITEM, &c) == 1) {
1541 } else if (sscanf(it->c_str(), CLUSTER_SNAP_ITEM, clustersnap) == 1)
1542 cluster_snaps.insert(*it);
1546 if (m_osd_rollback_to_cluster_snap.length() &&
1547 cluster_snaps.count(m_osd_rollback_to_cluster_snap) == 0) {
1548 derr << "rollback to cluster snapshot '" << m_osd_rollback_to_cluster_snap << "': not found" << dendl;
1550 goto close_basedir_fd;
1554 snprintf(nosnapfn, sizeof(nosnapfn), "%s/nosnap", current_fn.c_str());
1556 if (backend->can_checkpoint()) {
1557 if (snaps.empty()) {
1558 dout(0) << __FUNC__ << ": WARNING: no consistent snaps found, store may be in inconsistent state" << dendl;
1561 uint64_t curr_seq = 0;
1563 if (m_osd_rollback_to_cluster_snap.length()) {
1565 << " ** NOTE: rolling back to cluster snapshot " << m_osd_rollback_to_cluster_snap << " **"
1568 assert(cluster_snaps.count(m_osd_rollback_to_cluster_snap));
1569 snprintf(s, sizeof(s), CLUSTER_SNAP_ITEM, m_osd_rollback_to_cluster_snap.c_str());
1572 int fd = read_op_seq(&curr_seq);
1574 VOID_TEMP_FAILURE_RETRY(::close(fd));
1578 dout(10) << " current/ seq was " << curr_seq << dendl;
1580 dout(10) << " current/ missing entirely (unusual, but okay)" << dendl;
1582 uint64_t cp = snaps.back();
1583 dout(10) << " most recent snap from " << snaps << " is " << cp << dendl;
1585 // if current/ is marked as non-snapshotted, refuse to roll
1586 // back (without clear direction) to avoid throwing out new
1589 if (::stat(nosnapfn, &st) == 0) {
1590 if (!m_osd_use_stale_snap) {
1591 derr << "ERROR: " << nosnapfn << " exists, not rolling back to avoid losing new data" << dendl;
1592 derr << "Force rollback to old snapshotted version with 'osd use stale snap = true'" << dendl;
1593 derr << "config option for --osd-use-stale-snap startup argument." << dendl;
1595 goto close_basedir_fd;
1597 derr << "WARNING: user forced start with data sequence mismatch: current was " << curr_seq
1598 << ", newest snap is " << cp << dendl;
1600 << " ** WARNING: forcing the use of stale snapshot data **"
1601 << TEXT_NORMAL << std::endl;
1604 dout(10) << __FUNC__ << ": rolling back to consistent snap " << cp << dendl;
1605 snprintf(s, sizeof(s), COMMIT_SNAP_ITEM, (long long unsigned)cp);
1609 ret = backend->rollback_to(s);
1611 derr << __FUNC__ << ": error rolling back to " << s << ": "
1612 << cpp_strerror(ret) << dendl;
1613 goto close_basedir_fd;
1619 current_fd = ::open(current_fn.c_str(), O_RDONLY);
1620 if (current_fd < 0) {
1622 derr << __FUNC__ << ": error opening: " << current_fn << ": " << cpp_strerror(ret) << dendl;
1623 goto close_basedir_fd;
1626 assert(current_fd >= 0);
1628 op_fd = read_op_seq(&initial_op_seq);
1631 derr << __FUNC__ << ": read_op_seq failed" << dendl;
1632 goto close_current_fd;
1635 dout(5) << "mount op_seq is " << initial_op_seq << dendl;
1636 if (initial_op_seq == 0) {
1637 derr << "mount initial op seq is 0; something is wrong" << dendl;
1639 goto close_current_fd;
1642 if (!backend->can_checkpoint()) {
1643 // mark current/ as non-snapshotted so that we don't rollback away
1645 int r = ::creat(nosnapfn, 0644);
1648 derr << __FUNC__ << ": failed to create current/nosnap" << dendl;
1649 goto close_current_fd;
1651 VOID_TEMP_FAILURE_RETRY(::close(r));
1653 // clear nosnap marker, if present.
1657 // check fsid with omap
1660 char omap_fsid_buf[PATH_MAX];
1661 struct ::stat omap_fsid_stat;
1662 snprintf(omap_fsid_buf, sizeof(omap_fsid_buf), "%s/osd_uuid", omap_dir.c_str());
1663 // if osd_uuid not exists, assume as this omap matchs corresponding osd
1664 if (::stat(omap_fsid_buf, &omap_fsid_stat) != 0){
1665 dout(10) << __FUNC__ << ": osd_uuid not found under omap, "
1666 << "assume as matched."
1669 // if osd_uuid exists, compares osd_uuid with fsid
1670 omap_fsid_fd = ::open(omap_fsid_buf, O_RDONLY, 0644);
1671 if (omap_fsid_fd < 0) {
1673 derr << __FUNC__ << ": error opening '" << omap_fsid_buf << "': "
1674 << cpp_strerror(ret)
1676 goto close_current_fd;
1678 ret = read_fsid(omap_fsid_fd, &omap_fsid);
1679 VOID_TEMP_FAILURE_RETRY(::close(omap_fsid_fd));
1680 omap_fsid_fd = -1; // defensive
1682 derr << __FUNC__ << ": error reading omap_fsid_fd"
1683 << ", omap_fsid = " << omap_fsid
1684 << cpp_strerror(ret)
1686 goto close_current_fd;
1688 if (fsid != omap_fsid) {
1689 derr << __FUNC__ << ": " << omap_fsid_buf
1690 << " has existed omap fsid " << omap_fsid
1691 << " != expected osd fsid " << fsid
1694 goto close_current_fd;
1698 dout(0) << "start omap initiation" << dendl;
1699 if (!(generic_flags & SKIP_MOUNT_OMAP)) {
1700 KeyValueDB * omap_store = KeyValueDB::create(cct,
1701 superblock.omap_backend,
1703 if (omap_store == NULL)
1705 derr << __FUNC__ << ": Error creating " << superblock.omap_backend << dendl;
1707 goto close_current_fd;
1710 if (superblock.omap_backend == "rocksdb")
1711 ret = omap_store->init(cct->_conf->filestore_rocksdb_options);
1713 ret = omap_store->init();
1716 derr << __FUNC__ << ": Error initializing omap_store: " << cpp_strerror(ret) << dendl;
1717 goto close_current_fd;
1721 if (omap_store->create_and_open(err)) {
1723 derr << __FUNC__ << ": Error initializing " << superblock.omap_backend
1724 << " : " << err.str() << dendl;
1726 goto close_current_fd;
1729 DBObjectMap *dbomap = new DBObjectMap(cct, omap_store);
1730 ret = dbomap->init(do_update);
1733 derr << __FUNC__ << ": Error initializing DBObjectMap: " << ret << dendl;
1734 goto close_current_fd;
1738 if (cct->_conf->filestore_debug_omap_check && !dbomap->check(err2)) {
1739 derr << err2.str() << dendl;
1742 goto close_current_fd;
1744 object_map.reset(dbomap);
1750 // select journal mode?
1752 if (!m_filestore_journal_writeahead &&
1753 !m_filestore_journal_parallel &&
1754 !m_filestore_journal_trailing) {
1755 if (!backend->can_checkpoint()) {
1756 m_filestore_journal_writeahead = true;
1757 dout(0) << __FUNC__ << ": enabling WRITEAHEAD journal mode: checkpoint is not enabled" << dendl;
1759 m_filestore_journal_parallel = true;
1760 dout(0) << __FUNC__ << ": enabling PARALLEL journal mode: fs, checkpoint is enabled" << dendl;
1763 if (m_filestore_journal_writeahead)
1764 dout(0) << __FUNC__ << ": WRITEAHEAD journal mode explicitly enabled in conf" << dendl;
1765 if (m_filestore_journal_parallel)
1766 dout(0) << __FUNC__ << ": PARALLEL journal mode explicitly enabled in conf" << dendl;
1767 if (m_filestore_journal_trailing)
1768 dout(0) << __FUNC__ << ": TRAILING journal mode explicitly enabled in conf" << dendl;
1770 if (m_filestore_journal_writeahead)
1771 journal->set_wait_on_full(true);
1773 dout(0) << __FUNC__ << ": no journal" << dendl;
1776 ret = _sanity_check_fs();
1778 derr << __FUNC__ << ": _sanity_check_fs failed with error "
1780 goto close_current_fd;
1783 // Cleanup possibly invalid collections
1785 vector<coll_t> collections;
1786 ret = list_collections(collections, true);
1788 derr << "Error " << ret << " while listing collections" << dendl;
1789 goto close_current_fd;
1791 for (vector<coll_t>::iterator i = collections.begin();
1792 i != collections.end();
1795 ret = get_index(*i, &index);
1797 derr << "Unable to mount index " << *i
1798 << " with error: " << ret << dendl;
1799 goto close_current_fd;
1801 assert(NULL != index.index);
1802 RWLock::WLocker l((index.index)->access_lock);
1807 if (!m_disable_wbthrottle) {
1810 dout(0) << __FUNC__ << ": INFO: WbThrottle is disabled" << dendl;
1811 if (cct->_conf->filestore_odsync_write) {
1812 dout(0) << __FUNC__ << ": INFO: O_DSYNC write is enabled" << dendl;
1815 sync_thread.create("filestore_sync");
1817 if (!(generic_flags & SKIP_JOURNAL_REPLAY)) {
1818 ret = journal_replay(initial_op_seq);
1820 derr << __FUNC__ << ": failed to open journal " << journalpath << ": " << cpp_strerror(ret) << dendl;
1821 if (ret == -ENOTTY) {
1822 derr << "maybe journal is not pointing to a block device and its size "
1823 << "wasn't configured?" << dendl;
1832 if (cct->_conf->filestore_debug_omap_check && !object_map->check(err2)) {
1833 derr << err2.str() << dendl;
1839 init_temp_collections();
1844 for (vector<Finisher*>::iterator it = ondisk_finishers.begin(); it != ondisk_finishers.end(); ++it) {
1847 for (vector<Finisher*>::iterator it = apply_finishers.begin(); it != apply_finishers.end(); ++it) {
1854 if (cct->_conf->filestore_update_to >= (int)get_target_version()) {
1855 int err = upgrade();
1857 derr << "error converting store" << dendl;
1873 if (!m_disable_wbthrottle) {
1877 VOID_TEMP_FAILURE_RETRY(::close(current_fd));
1880 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd));
1883 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd));
1886 assert(!m_filestore_fail_eio || ret != -EIO);
1893 void FileStore::init_temp_collections()
1895 dout(10) << __FUNC__ << dendl;
1897 int r = list_collections(ls, true);
1900 dout(20) << " ls " << ls << dendl;
1902 SequencerPosition spos;
1905 for (vector<coll_t>::iterator p = ls.begin(); p != ls.end(); ++p)
1908 dout(20) << " temps " << temps << dendl;
1910 for (vector<coll_t>::iterator p = ls.begin(); p != ls.end(); ++p) {
1915 coll_t temp = p->get_temp();
1916 if (temps.count(temp)) {
1919 dout(10) << __FUNC__ << ": creating " << temp << dendl;
1920 r = _create_collection(temp, 0, spos);
1925 for (set<coll_t>::iterator p = temps.begin(); p != temps.end(); ++p) {
1926 dout(10) << __FUNC__ << ": removing stray " << *p << dendl;
1927 r = _collection_remove_recursive(*p, spos);
1932 int FileStore::umount()
1934 dout(5) << __FUNC__ << ": " << basedir << dendl;
1945 if (!m_disable_wbthrottle){
1951 if (!(generic_flags & SKIP_JOURNAL_REPLAY))
1952 journal_write_close();
1954 for (vector<Finisher*>::iterator it = ondisk_finishers.begin(); it != ondisk_finishers.end(); ++it) {
1957 for (vector<Finisher*>::iterator it = apply_finishers.begin(); it != apply_finishers.end(); ++it) {
1962 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd));
1966 VOID_TEMP_FAILURE_RETRY(::close(op_fd));
1969 if (current_fd >= 0) {
1970 VOID_TEMP_FAILURE_RETRY(::close(current_fd));
1973 if (basedir_fd >= 0) {
1974 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd));
1986 Mutex::Locker l(sync_entry_timeo_lock);
1997 /// -----------------------------
1999 FileStore::Op *FileStore::build_op(vector<Transaction>& tls,
2000 Context *onreadable,
2001 Context *onreadable_sync,
2002 TrackedOpRef osd_op)
2004 uint64_t bytes = 0, ops = 0;
2005 for (vector<Transaction>::iterator p = tls.begin();
2008 bytes += (*p).get_num_bytes();
2009 ops += (*p).get_num_ops();
2013 o->start = ceph_clock_now();
2014 o->tls = std::move(tls);
2015 o->onreadable = onreadable;
2016 o->onreadable_sync = onreadable_sync;
2025 void FileStore::queue_op(OpSequencer *osr, Op *o)
2027 // queue op on sequencer, then queue sequencer for the threadpool,
2028 // so that regardless of which order the threads pick up the
2029 // sequencer, the op order will be preserved.
2032 o->trace.event("queued");
2034 logger->inc(l_filestore_ops);
2035 logger->inc(l_filestore_bytes, o->bytes);
2037 dout(5) << __FUNC__ << ": " << o << " seq " << o->op
2039 << " " << o->bytes << " bytes"
2040 << " (queue has " << throttle_ops.get_current() << " ops and " << throttle_bytes.get_current() << " bytes)"
2045 void FileStore::op_queue_reserve_throttle(Op *o)
2048 throttle_bytes.get(o->bytes);
2050 logger->set(l_filestore_op_queue_ops, throttle_ops.get_current());
2051 logger->set(l_filestore_op_queue_bytes, throttle_bytes.get_current());
2054 void FileStore::op_queue_release_throttle(Op *o)
2057 throttle_bytes.put(o->bytes);
2058 logger->set(l_filestore_op_queue_ops, throttle_ops.get_current());
2059 logger->set(l_filestore_op_queue_bytes, throttle_bytes.get_current());
2062 void FileStore::_do_op(OpSequencer *osr, ThreadPool::TPHandle &handle)
2064 if (!m_disable_wbthrottle) {
2065 wbthrottle.throttle();
2068 if (cct->_conf->filestore_inject_stall) {
2069 int orig = cct->_conf->filestore_inject_stall;
2070 dout(5) << __FUNC__ << ": filestore_inject_stall " << orig << ", sleeping" << dendl;
2072 cct->_conf->set_val("filestore_inject_stall", "0");
2073 dout(5) << __FUNC__ << ": done stalling" << dendl;
2076 osr->apply_lock.Lock();
2077 Op *o = osr->peek_queue();
2078 o->trace.event("op_apply_start");
2079 apply_manager.op_apply_start(o->op);
2080 dout(5) << __FUNC__ << ": " << o << " seq " << o->op << " " << *osr << "/" << osr->parent << " start" << dendl;
2081 o->trace.event("_do_transactions start");
2082 int r = _do_transactions(o->tls, o->op, &handle);
2083 o->trace.event("op_apply_finish");
2084 apply_manager.op_apply_finish(o->op);
2085 dout(10) << __FUNC__ << ": " << o << " seq " << o->op << " r = " << r
2086 << ", finisher " << o->onreadable << " " << o->onreadable_sync << dendl;
2092 void FileStore::_finish_op(OpSequencer *osr)
2094 list<Context*> to_queue;
2095 Op *o = osr->dequeue(&to_queue);
2097 utime_t lat = ceph_clock_now();
2100 dout(10) << __FUNC__ << ": " << o << " seq " << o->op << " " << *osr << "/" << osr->parent << " lat " << lat << dendl;
2101 osr->apply_lock.Unlock(); // locked in _do_op
2102 o->trace.event("_finish_op");
2104 // called with tp lock held
2105 op_queue_release_throttle(o);
2107 logger->tinc(l_filestore_apply_latency, lat);
2109 if (o->onreadable_sync) {
2110 o->onreadable_sync->complete(0);
2112 if (o->onreadable) {
2113 apply_finishers[osr->id % m_apply_finisher_num]->queue(o->onreadable);
2115 if (!to_queue.empty()) {
2116 apply_finishers[osr->id % m_apply_finisher_num]->queue(to_queue);
2122 struct C_JournaledAhead : public Context {
2124 FileStore::OpSequencer *osr;
2128 C_JournaledAhead(FileStore *f, FileStore::OpSequencer *os, FileStore::Op *o, Context *ondisk):
2129 fs(f), osr(os), o(o), ondisk(ondisk) { }
2130 void finish(int r) override {
2131 fs->_journaled_ahead(osr, o, ondisk);
2135 int FileStore::queue_transactions(Sequencer *posr, vector<Transaction>& tls,
2136 TrackedOpRef osd_op,
2137 ThreadPool::TPHandle *handle)
2139 Context *onreadable;
2141 Context *onreadable_sync;
2142 ObjectStore::Transaction::collect_contexts(
2143 tls, &onreadable, &ondisk, &onreadable_sync);
2145 if (cct->_conf->objectstore_blackhole) {
2146 dout(0) << __FUNC__ << ": objectstore_blackhole = TRUE, dropping transaction"
2150 delete onreadable_sync;
2154 utime_t start = ceph_clock_now();
2155 // set up the sequencer
2159 osr = static_cast<OpSequencer *>(posr->p.get());
2160 dout(5) << __FUNC__ << ": existing " << osr << " " << *osr << dendl;
2162 osr = new OpSequencer(cct, ++next_osr_id);
2166 dout(5) << __FUNC__ << ": new " << osr << " " << *osr << dendl;
2169 // used to include osr information in tracepoints during transaction apply
2170 for (vector<Transaction>::iterator i = tls.begin(); i != tls.end(); ++i) {
2174 ZTracer::Trace trace;
2175 if (osd_op && osd_op->pg_trace) {
2176 osd_op->store_trace.init("filestore op", &trace_endpoint, &osd_op->pg_trace);
2177 trace = osd_op->store_trace;
2180 if (journal && journal->is_writeable() && !m_filestore_journal_trailing) {
2181 Op *o = build_op(tls, onreadable, onreadable_sync, osd_op);
2183 //prepare and encode transactions data out of lock
2185 int orig_len = journal->prepare_entry(o->tls, &tbl);
2188 handle->suspend_tp_timeout();
2190 op_queue_reserve_throttle(o);
2191 journal->reserve_throttle_and_backoff(tbl.length());
2194 handle->reset_tp_timeout();
2196 uint64_t op_num = submit_manager.op_submit_start();
2198 trace.keyval("opnum", op_num);
2200 if (m_filestore_do_dump)
2201 dump_transactions(o->tls, o->op, osr);
2203 if (m_filestore_journal_parallel) {
2204 dout(5) << __FUNC__ << ": (parallel) " << o->op << " " << o->tls << dendl;
2206 trace.keyval("journal mode", "parallel");
2207 trace.event("journal started");
2208 _op_journal_transactions(tbl, orig_len, o->op, ondisk, osd_op);
2210 // queue inside submit_manager op submission lock
2212 trace.event("op queued");
2213 } else if (m_filestore_journal_writeahead) {
2214 dout(5) << __FUNC__ << ": (writeahead) " << o->op << " " << o->tls << dendl;
2216 osr->queue_journal(o->op);
2218 trace.keyval("journal mode", "writeahead");
2219 trace.event("journal started");
2220 _op_journal_transactions(tbl, orig_len, o->op,
2221 new C_JournaledAhead(this, osr, o, ondisk),
2226 submit_manager.op_submit_finish(op_num);
2227 utime_t end = ceph_clock_now();
2228 logger->tinc(l_filestore_queue_transaction_latency_avg, end - start);
2233 Op *o = build_op(tls, onreadable, onreadable_sync, osd_op);
2234 dout(5) << __FUNC__ << ": (no journal) " << o << " " << tls << dendl;
2237 handle->suspend_tp_timeout();
2239 op_queue_reserve_throttle(o);
2242 handle->reset_tp_timeout();
2244 uint64_t op_num = submit_manager.op_submit_start();
2247 if (m_filestore_do_dump)
2248 dump_transactions(o->tls, o->op, osr);
2251 trace.keyval("opnum", op_num);
2252 trace.keyval("journal mode", "none");
2253 trace.event("op queued");
2256 apply_manager.add_waiter(op_num, ondisk);
2257 submit_manager.op_submit_finish(op_num);
2258 utime_t end = ceph_clock_now();
2259 logger->tinc(l_filestore_queue_transaction_latency_avg, end - start);
2264 //prepare and encode transactions data out of lock
2267 if (journal->is_writeable()) {
2268 orig_len = journal->prepare_entry(tls, &tbl);
2270 uint64_t op = submit_manager.op_submit_start();
2271 dout(5) << __FUNC__ << ": (trailing journal) " << op << " " << tls << dendl;
2273 if (m_filestore_do_dump)
2274 dump_transactions(tls, op, osr);
2276 trace.event("op_apply_start");
2277 trace.keyval("opnum", op);
2278 trace.keyval("journal mode", "trailing");
2279 apply_manager.op_apply_start(op);
2280 trace.event("do_transactions");
2281 int r = do_transactions(tls, op);
2284 trace.event("journal started");
2285 _op_journal_transactions(tbl, orig_len, op, ondisk, osd_op);
2290 // start on_readable finisher after we queue journal item, as on_readable callback
2291 // is allowed to delete the Transaction
2292 if (onreadable_sync) {
2293 onreadable_sync->complete(r);
2295 apply_finishers[osr->id % m_apply_finisher_num]->queue(onreadable, r);
2297 submit_manager.op_submit_finish(op);
2298 trace.event("op_apply_finish");
2299 apply_manager.op_apply_finish(op);
2301 utime_t end = ceph_clock_now();
2302 logger->tinc(l_filestore_queue_transaction_latency_avg, end - start);
2306 void FileStore::_journaled_ahead(OpSequencer *osr, Op *o, Context *ondisk)
2308 dout(5) << __FUNC__ << ": " << o << " seq " << o->op << " " << *osr << " " << o->tls << dendl;
2310 o->trace.event("writeahead journal finished");
2312 // this should queue in order because the journal does it's completions in order.
2315 list<Context*> to_queue;
2316 osr->dequeue_journal(&to_queue);
2318 // do ondisk completions async, to prevent any onreadable_sync completions
2319 // getting blocked behind an ondisk completion.
2321 dout(10) << " queueing ondisk " << ondisk << dendl;
2322 ondisk_finishers[osr->id % m_ondisk_finisher_num]->queue(ondisk);
2324 if (!to_queue.empty()) {
2325 ondisk_finishers[osr->id % m_ondisk_finisher_num]->queue(to_queue);
2329 int FileStore::_do_transactions(
2330 vector<Transaction> &tls,
2332 ThreadPool::TPHandle *handle)
2336 for (vector<Transaction>::iterator p = tls.begin();
2339 _do_transaction(*p, op_seq, trans_num, handle);
2341 handle->reset_tp_timeout();
2347 void FileStore::_set_global_replay_guard(const coll_t& cid,
2348 const SequencerPosition &spos)
2350 if (backend->can_checkpoint())
2353 // sync all previous operations on this sequencer
2354 int ret = object_map->sync();
2356 derr << __FUNC__ << ": omap sync error " << cpp_strerror(ret) << dendl;
2357 assert(0 == "_set_global_replay_guard failed");
2359 ret = sync_filesystem(basedir_fd);
2361 derr << __FUNC__ << ": sync_filesystem error " << cpp_strerror(ret) << dendl;
2362 assert(0 == "_set_global_replay_guard failed");
2366 get_cdir(cid, fn, sizeof(fn));
2367 int fd = ::open(fn, O_RDONLY);
2370 derr << __FUNC__ << ": " << cid << " error " << cpp_strerror(err) << dendl;
2371 assert(0 == "_set_global_replay_guard failed");
2376 // then record that we did it
2379 int r = chain_fsetxattr<true, true>(
2380 fd, GLOBAL_REPLAY_GUARD_XATTR, v.c_str(), v.length());
2382 derr << __FUNC__ << ": fsetxattr " << GLOBAL_REPLAY_GUARD_XATTR
2383 << " got " << cpp_strerror(r) << dendl;
2384 assert(0 == "fsetxattr failed");
2387 // and make sure our xattr is durable.
2392 VOID_TEMP_FAILURE_RETRY(::close(fd));
2393 dout(10) << __FUNC__ << ": " << spos << " done" << dendl;
2396 int FileStore::_check_global_replay_guard(const coll_t& cid,
2397 const SequencerPosition& spos)
2400 get_cdir(cid, fn, sizeof(fn));
2401 int fd = ::open(fn, O_RDONLY);
2403 dout(10) << __FUNC__ << ": " << cid << " dne" << dendl;
2404 return 1; // if collection does not exist, there is no guard, and we can replay.
2408 int r = chain_fgetxattr(fd, GLOBAL_REPLAY_GUARD_XATTR, buf, sizeof(buf));
2410 dout(20) << __FUNC__ << ": no xattr" << dendl;
2411 assert(!m_filestore_fail_eio || r != -EIO);
2412 VOID_TEMP_FAILURE_RETRY(::close(fd));
2413 return 1; // no xattr
2418 SequencerPosition opos;
2419 bufferlist::iterator p = bl.begin();
2422 VOID_TEMP_FAILURE_RETRY(::close(fd));
2423 return spos >= opos ? 1 : -1;
2427 void FileStore::_set_replay_guard(const coll_t& cid,
2428 const SequencerPosition &spos,
2429 bool in_progress=false)
2432 get_cdir(cid, fn, sizeof(fn));
2433 int fd = ::open(fn, O_RDONLY);
2436 derr << __FUNC__ << ": " << cid << " error " << cpp_strerror(err) << dendl;
2437 assert(0 == "_set_replay_guard failed");
2439 _set_replay_guard(fd, spos, 0, in_progress);
2440 VOID_TEMP_FAILURE_RETRY(::close(fd));
2444 void FileStore::_set_replay_guard(int fd,
2445 const SequencerPosition& spos,
2446 const ghobject_t *hoid,
2449 if (backend->can_checkpoint())
2452 dout(10) << __FUNC__ << ": " << spos << (in_progress ? " START" : "") << dendl;
2456 // first make sure the previous operation commits
2460 // sync object_map too. even if this object has a header or keys,
2461 // it have had them in the past and then removed them, so always
2463 object_map->sync(hoid, &spos);
2468 // then record that we did it
2471 ::encode(in_progress, v);
2472 int r = chain_fsetxattr<true, true>(
2473 fd, REPLAY_GUARD_XATTR, v.c_str(), v.length());
2475 derr << "fsetxattr " << REPLAY_GUARD_XATTR << " got " << cpp_strerror(r) << dendl;
2476 assert(0 == "fsetxattr failed");
2479 // and make sure our xattr is durable.
2484 dout(10) << __FUNC__ << ": " << spos << " done" << dendl;
2487 void FileStore::_close_replay_guard(const coll_t& cid,
2488 const SequencerPosition &spos)
2491 get_cdir(cid, fn, sizeof(fn));
2492 int fd = ::open(fn, O_RDONLY);
2495 derr << __FUNC__ << ": " << cid << " error " << cpp_strerror(err) << dendl;
2496 assert(0 == "_close_replay_guard failed");
2498 _close_replay_guard(fd, spos);
2499 VOID_TEMP_FAILURE_RETRY(::close(fd));
2502 void FileStore::_close_replay_guard(int fd, const SequencerPosition& spos,
2503 const ghobject_t *hoid)
2505 if (backend->can_checkpoint())
2508 dout(10) << __FUNC__ << ": " << spos << dendl;
2512 // sync object_map too. even if this object has a header or keys,
2513 // it have had them in the past and then removed them, so always
2515 object_map->sync(hoid, &spos);
2517 // then record that we are done with this operation
2520 bool in_progress = false;
2521 ::encode(in_progress, v);
2522 int r = chain_fsetxattr<true, true>(
2523 fd, REPLAY_GUARD_XATTR, v.c_str(), v.length());
2525 derr << "fsetxattr " << REPLAY_GUARD_XATTR << " got " << cpp_strerror(r) << dendl;
2526 assert(0 == "fsetxattr failed");
2529 // and make sure our xattr is durable.
2534 dout(10) << __FUNC__ << ": " << spos << " done" << dendl;
2537 int FileStore::_check_replay_guard(const coll_t& cid, const ghobject_t &oid,
2538 const SequencerPosition& spos)
2540 if (!replaying || backend->can_checkpoint())
2543 int r = _check_global_replay_guard(cid, spos);
2548 r = lfn_open(cid, oid, false, &fd);
2550 dout(10) << __FUNC__ << ": " << cid << " " << oid << " dne" << dendl;
2551 return 1; // if file does not exist, there is no guard, and we can replay.
2553 int ret = _check_replay_guard(**fd, spos);
2558 int FileStore::_check_replay_guard(const coll_t& cid, const SequencerPosition& spos)
2560 if (!replaying || backend->can_checkpoint())
2564 get_cdir(cid, fn, sizeof(fn));
2565 int fd = ::open(fn, O_RDONLY);
2567 dout(10) << __FUNC__ << ": " << cid << " dne" << dendl;
2568 return 1; // if collection does not exist, there is no guard, and we can replay.
2570 int ret = _check_replay_guard(fd, spos);
2571 VOID_TEMP_FAILURE_RETRY(::close(fd));
2575 int FileStore::_check_replay_guard(int fd, const SequencerPosition& spos)
2577 if (!replaying || backend->can_checkpoint())
2581 int r = chain_fgetxattr(fd, REPLAY_GUARD_XATTR, buf, sizeof(buf));
2583 dout(20) << __FUNC__ << ": no xattr" << dendl;
2584 assert(!m_filestore_fail_eio || r != -EIO);
2585 return 1; // no xattr
2590 SequencerPosition opos;
2591 bufferlist::iterator p = bl.begin();
2593 bool in_progress = false;
2594 if (!p.end()) // older journals don't have this
2595 ::decode(in_progress, p);
2597 dout(10) << __FUNC__ << ": object has " << opos << " > current pos " << spos
2598 << ", now or in future, SKIPPING REPLAY" << dendl;
2600 } else if (opos == spos) {
2602 dout(10) << __FUNC__ << ": object has " << opos << " == current pos " << spos
2603 << ", in_progress=true, CONDITIONAL REPLAY" << dendl;
2606 dout(10) << __FUNC__ << ": object has " << opos << " == current pos " << spos
2607 << ", in_progress=false, SKIPPING REPLAY" << dendl;
2611 dout(10) << __FUNC__ << ": object has " << opos << " < current pos " << spos
2612 << ", in past, will replay" << dendl;
2617 void FileStore::_do_transaction(
2618 Transaction& t, uint64_t op_seq, int trans_num,
2619 ThreadPool::TPHandle *handle)
2621 dout(10) << __FUNC__ << ": on " << &t << dendl;
2624 const char *osr_name = t.get_osr() ? static_cast<OpSequencer*>(t.get_osr())->get_name().c_str() : "<NULL>";
2627 Transaction::iterator i = t.begin();
2629 SequencerPosition spos(op_seq, trans_num, 0);
2630 while (i.have_op()) {
2632 handle->reset_tp_timeout();
2634 Transaction::Op *op = i.decode_op();
2640 case Transaction::OP_NOP:
2642 case Transaction::OP_TOUCH:
2644 const coll_t &_cid = i.get_cid(op->cid);
2645 const ghobject_t &oid = i.get_oid(op->oid);
2646 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2647 _cid : _cid.get_temp();
2648 tracepoint(objectstore, touch_enter, osr_name);
2649 if (_check_replay_guard(cid, oid, spos) > 0)
2650 r = _touch(cid, oid);
2651 tracepoint(objectstore, touch_exit, r);
2655 case Transaction::OP_WRITE:
2657 const coll_t &_cid = i.get_cid(op->cid);
2658 const ghobject_t &oid = i.get_oid(op->oid);
2659 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2660 _cid : _cid.get_temp();
2661 uint64_t off = op->off;
2662 uint64_t len = op->len;
2663 uint32_t fadvise_flags = i.get_fadvise_flags();
2666 tracepoint(objectstore, write_enter, osr_name, off, len);
2667 if (_check_replay_guard(cid, oid, spos) > 0)
2668 r = _write(cid, oid, off, len, bl, fadvise_flags);
2669 tracepoint(objectstore, write_exit, r);
2673 case Transaction::OP_ZERO:
2675 const coll_t &_cid = i.get_cid(op->cid);
2676 const ghobject_t &oid = i.get_oid(op->oid);
2677 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2678 _cid : _cid.get_temp();
2679 uint64_t off = op->off;
2680 uint64_t len = op->len;
2681 tracepoint(objectstore, zero_enter, osr_name, off, len);
2682 if (_check_replay_guard(cid, oid, spos) > 0)
2683 r = _zero(cid, oid, off, len);
2684 tracepoint(objectstore, zero_exit, r);
2688 case Transaction::OP_TRIMCACHE:
2690 // deprecated, no-op
2694 case Transaction::OP_TRUNCATE:
2696 const coll_t &_cid = i.get_cid(op->cid);
2697 const ghobject_t &oid = i.get_oid(op->oid);
2698 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2699 _cid : _cid.get_temp();
2700 uint64_t off = op->off;
2701 tracepoint(objectstore, truncate_enter, osr_name, off);
2702 if (_check_replay_guard(cid, oid, spos) > 0)
2703 r = _truncate(cid, oid, off);
2704 tracepoint(objectstore, truncate_exit, r);
2708 case Transaction::OP_REMOVE:
2710 const coll_t &_cid = i.get_cid(op->cid);
2711 const ghobject_t &oid = i.get_oid(op->oid);
2712 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2713 _cid : _cid.get_temp();
2714 tracepoint(objectstore, remove_enter, osr_name);
2715 if (_check_replay_guard(cid, oid, spos) > 0)
2716 r = _remove(cid, oid, spos);
2717 tracepoint(objectstore, remove_exit, r);
2721 case Transaction::OP_SETATTR:
2723 const coll_t &_cid = i.get_cid(op->cid);
2724 const ghobject_t &oid = i.get_oid(op->oid);
2725 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2726 _cid : _cid.get_temp();
2727 string name = i.decode_string();
2730 tracepoint(objectstore, setattr_enter, osr_name);
2731 if (_check_replay_guard(cid, oid, spos) > 0) {
2732 map<string, bufferptr> to_set;
2733 to_set[name] = bufferptr(bl.c_str(), bl.length());
2734 r = _setattrs(cid, oid, to_set, spos);
2736 dout(0) << " ENOSPC on setxattr on " << cid << "/" << oid
2737 << " name " << name << " size " << bl.length() << dendl;
2739 tracepoint(objectstore, setattr_exit, r);
2743 case Transaction::OP_SETATTRS:
2745 const coll_t &_cid = i.get_cid(op->cid);
2746 const ghobject_t &oid = i.get_oid(op->oid);
2747 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2748 _cid : _cid.get_temp();
2749 map<string, bufferptr> aset;
2750 i.decode_attrset(aset);
2751 tracepoint(objectstore, setattrs_enter, osr_name);
2752 if (_check_replay_guard(cid, oid, spos) > 0)
2753 r = _setattrs(cid, oid, aset, spos);
2754 tracepoint(objectstore, setattrs_exit, r);
2756 dout(0) << " ENOSPC on setxattrs on " << cid << "/" << oid << dendl;
2760 case Transaction::OP_RMATTR:
2762 const coll_t &_cid = i.get_cid(op->cid);
2763 const ghobject_t &oid = i.get_oid(op->oid);
2764 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2765 _cid : _cid.get_temp();
2766 string name = i.decode_string();
2767 tracepoint(objectstore, rmattr_enter, osr_name);
2768 if (_check_replay_guard(cid, oid, spos) > 0)
2769 r = _rmattr(cid, oid, name.c_str(), spos);
2770 tracepoint(objectstore, rmattr_exit, r);
2774 case Transaction::OP_RMATTRS:
2776 const coll_t &_cid = i.get_cid(op->cid);
2777 const ghobject_t &oid = i.get_oid(op->oid);
2778 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2779 _cid : _cid.get_temp();
2780 tracepoint(objectstore, rmattrs_enter, osr_name);
2781 if (_check_replay_guard(cid, oid, spos) > 0)
2782 r = _rmattrs(cid, oid, spos);
2783 tracepoint(objectstore, rmattrs_exit, r);
2787 case Transaction::OP_CLONE:
2789 const coll_t &_cid = i.get_cid(op->cid);
2790 const ghobject_t &oid = i.get_oid(op->oid);
2791 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2792 _cid : _cid.get_temp();
2793 const ghobject_t &noid = i.get_oid(op->dest_oid);
2794 tracepoint(objectstore, clone_enter, osr_name);
2795 r = _clone(cid, oid, noid, spos);
2796 tracepoint(objectstore, clone_exit, r);
2800 case Transaction::OP_CLONERANGE:
2802 const coll_t &_cid = i.get_cid(op->cid);
2803 const ghobject_t &oid = i.get_oid(op->oid);
2804 const ghobject_t &noid = i.get_oid(op->dest_oid);
2805 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2806 _cid : _cid.get_temp();
2807 const coll_t &ncid = !_need_temp_object_collection(_cid, noid) ?
2808 _cid : _cid.get_temp();
2809 uint64_t off = op->off;
2810 uint64_t len = op->len;
2811 tracepoint(objectstore, clone_range_enter, osr_name, len);
2812 r = _clone_range(cid, oid, ncid, noid, off, len, off, spos);
2813 tracepoint(objectstore, clone_range_exit, r);
2817 case Transaction::OP_CLONERANGE2:
2819 const coll_t &_cid = i.get_cid(op->cid);
2820 const ghobject_t &oid = i.get_oid(op->oid);
2821 const ghobject_t &noid = i.get_oid(op->dest_oid);
2822 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2823 _cid : _cid.get_temp();
2824 const coll_t &ncid = !_need_temp_object_collection(_cid, noid) ?
2825 _cid : _cid.get_temp();
2826 uint64_t srcoff = op->off;
2827 uint64_t len = op->len;
2828 uint64_t dstoff = op->dest_off;
2829 tracepoint(objectstore, clone_range2_enter, osr_name, len);
2830 r = _clone_range(cid, oid, ncid, noid, srcoff, len, dstoff, spos);
2831 tracepoint(objectstore, clone_range2_exit, r);
2835 case Transaction::OP_MKCOLL:
2837 const coll_t &cid = i.get_cid(op->cid);
2838 tracepoint(objectstore, mkcoll_enter, osr_name);
2839 if (_check_replay_guard(cid, spos) > 0)
2840 r = _create_collection(cid, op->split_bits, spos);
2841 tracepoint(objectstore, mkcoll_exit, r);
2845 case Transaction::OP_COLL_SET_BITS:
2847 const coll_t &cid = i.get_cid(op->cid);
2848 int bits = op->split_bits;
2849 r = _collection_set_bits(cid, bits);
2853 case Transaction::OP_COLL_HINT:
2855 const coll_t &cid = i.get_cid(op->cid);
2856 uint32_t type = op->hint_type;
2859 bufferlist::iterator hiter = hint.begin();
2860 if (type == Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS) {
2863 ::decode(pg_num, hiter);
2864 ::decode(num_objs, hiter);
2865 if (_check_replay_guard(cid, spos) > 0) {
2866 r = _collection_hint_expected_num_objs(cid, pg_num, num_objs, spos);
2870 dout(10) << "Unrecognized collection hint type: " << type << dendl;
2875 case Transaction::OP_RMCOLL:
2877 const coll_t &cid = i.get_cid(op->cid);
2878 tracepoint(objectstore, rmcoll_enter, osr_name);
2879 if (_check_replay_guard(cid, spos) > 0)
2880 r = _destroy_collection(cid);
2881 tracepoint(objectstore, rmcoll_exit, r);
2885 case Transaction::OP_COLL_ADD:
2887 const coll_t &ocid = i.get_cid(op->cid);
2888 const coll_t &ncid = i.get_cid(op->dest_cid);
2889 const ghobject_t &oid = i.get_oid(op->oid);
2891 assert(oid.hobj.pool >= -1);
2893 // always followed by OP_COLL_REMOVE
2894 Transaction::Op *op2 = i.decode_op();
2895 const coll_t &ocid2 = i.get_cid(op2->cid);
2896 const ghobject_t &oid2 = i.get_oid(op2->oid);
2897 assert(op2->op == Transaction::OP_COLL_REMOVE);
2898 assert(ocid2 == ocid);
2899 assert(oid2 == oid);
2901 tracepoint(objectstore, coll_add_enter);
2902 r = _collection_add(ncid, ocid, oid, spos);
2903 tracepoint(objectstore, coll_add_exit, r);
2907 tracepoint(objectstore, coll_remove_enter, osr_name);
2908 if (_check_replay_guard(ocid, oid, spos) > 0)
2909 r = _remove(ocid, oid, spos);
2910 tracepoint(objectstore, coll_remove_exit, r);
2914 case Transaction::OP_COLL_MOVE:
2916 // WARNING: this is deprecated and buggy; only here to replay old journals.
2917 const coll_t &ocid = i.get_cid(op->cid);
2918 const coll_t &ncid = i.get_cid(op->dest_cid);
2919 const ghobject_t &oid = i.get_oid(op->oid);
2920 tracepoint(objectstore, coll_move_enter);
2921 r = _collection_add(ocid, ncid, oid, spos);
2923 (_check_replay_guard(ocid, oid, spos) > 0))
2924 r = _remove(ocid, oid, spos);
2925 tracepoint(objectstore, coll_move_exit, r);
2929 case Transaction::OP_COLL_MOVE_RENAME:
2931 const coll_t &_oldcid = i.get_cid(op->cid);
2932 const ghobject_t &oldoid = i.get_oid(op->oid);
2933 const coll_t &_newcid = i.get_cid(op->dest_cid);
2934 const ghobject_t &newoid = i.get_oid(op->dest_oid);
2935 const coll_t &oldcid = !_need_temp_object_collection(_oldcid, oldoid) ?
2936 _oldcid : _oldcid.get_temp();
2937 const coll_t &newcid = !_need_temp_object_collection(_newcid, newoid) ?
2938 _oldcid : _newcid.get_temp();
2939 tracepoint(objectstore, coll_move_rename_enter);
2940 r = _collection_move_rename(oldcid, oldoid, newcid, newoid, spos);
2941 tracepoint(objectstore, coll_move_rename_exit, r);
2945 case Transaction::OP_TRY_RENAME:
2947 const coll_t &_cid = i.get_cid(op->cid);
2948 const ghobject_t &oldoid = i.get_oid(op->oid);
2949 const ghobject_t &newoid = i.get_oid(op->dest_oid);
2950 const coll_t &oldcid = !_need_temp_object_collection(_cid, oldoid) ?
2951 _cid : _cid.get_temp();
2952 const coll_t &newcid = !_need_temp_object_collection(_cid, newoid) ?
2953 _cid : _cid.get_temp();
2954 tracepoint(objectstore, coll_try_rename_enter);
2955 r = _collection_move_rename(oldcid, oldoid, newcid, newoid, spos, true);
2956 tracepoint(objectstore, coll_try_rename_exit, r);
2960 case Transaction::OP_COLL_SETATTR:
2961 case Transaction::OP_COLL_RMATTR:
2962 assert(0 == "collection attr methods no longer implemented");
2965 case Transaction::OP_STARTSYNC:
2966 tracepoint(objectstore, startsync_enter, osr_name);
2968 tracepoint(objectstore, startsync_exit);
2971 case Transaction::OP_COLL_RENAME:
2977 case Transaction::OP_OMAP_CLEAR:
2979 const coll_t &_cid = i.get_cid(op->cid);
2980 const ghobject_t &oid = i.get_oid(op->oid);
2981 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2982 _cid : _cid.get_temp();
2983 tracepoint(objectstore, omap_clear_enter, osr_name);
2984 r = _omap_clear(cid, oid, spos);
2985 tracepoint(objectstore, omap_clear_exit, r);
2988 case Transaction::OP_OMAP_SETKEYS:
2990 const coll_t &_cid = i.get_cid(op->cid);
2991 const ghobject_t &oid = i.get_oid(op->oid);
2992 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
2993 _cid : _cid.get_temp();
2994 map<string, bufferlist> aset;
2995 i.decode_attrset(aset);
2996 tracepoint(objectstore, omap_setkeys_enter, osr_name);
2997 r = _omap_setkeys(cid, oid, aset, spos);
2998 tracepoint(objectstore, omap_setkeys_exit, r);
3001 case Transaction::OP_OMAP_RMKEYS:
3003 const coll_t &_cid = i.get_cid(op->cid);
3004 const ghobject_t &oid = i.get_oid(op->oid);
3005 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
3006 _cid : _cid.get_temp();
3008 i.decode_keyset(keys);
3009 tracepoint(objectstore, omap_rmkeys_enter, osr_name);
3010 r = _omap_rmkeys(cid, oid, keys, spos);
3011 tracepoint(objectstore, omap_rmkeys_exit, r);
3014 case Transaction::OP_OMAP_RMKEYRANGE:
3016 const coll_t &_cid = i.get_cid(op->cid);
3017 const ghobject_t &oid = i.get_oid(op->oid);
3018 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
3019 _cid : _cid.get_temp();
3021 first = i.decode_string();
3022 last = i.decode_string();
3023 tracepoint(objectstore, omap_rmkeyrange_enter, osr_name);
3024 r = _omap_rmkeyrange(cid, oid, first, last, spos);
3025 tracepoint(objectstore, omap_rmkeyrange_exit, r);
3028 case Transaction::OP_OMAP_SETHEADER:
3030 const coll_t &_cid = i.get_cid(op->cid);
3031 const ghobject_t &oid = i.get_oid(op->oid);
3032 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
3033 _cid : _cid.get_temp();
3036 tracepoint(objectstore, omap_setheader_enter, osr_name);
3037 r = _omap_setheader(cid, oid, bl, spos);
3038 tracepoint(objectstore, omap_setheader_exit, r);
3041 case Transaction::OP_SPLIT_COLLECTION:
3043 assert(0 == "not legacy journal; upgrade to firefly first");
3046 case Transaction::OP_SPLIT_COLLECTION2:
3048 coll_t cid = i.get_cid(op->cid);
3049 uint32_t bits = op->split_bits;
3050 uint32_t rem = op->split_rem;
3051 coll_t dest = i.get_cid(op->dest_cid);
3052 tracepoint(objectstore, split_coll2_enter, osr_name);
3053 r = _split_collection(cid, bits, rem, dest, spos);
3054 tracepoint(objectstore, split_coll2_exit, r);
3058 case Transaction::OP_SETALLOCHINT:
3060 const coll_t &_cid = i.get_cid(op->cid);
3061 const ghobject_t &oid = i.get_oid(op->oid);
3062 const coll_t &cid = !_need_temp_object_collection(_cid, oid) ?
3063 _cid : _cid.get_temp();
3064 uint64_t expected_object_size = op->expected_object_size;
3065 uint64_t expected_write_size = op->expected_write_size;
3066 tracepoint(objectstore, setallochint_enter, osr_name);
3067 if (_check_replay_guard(cid, oid, spos) > 0)
3068 r = _set_alloc_hint(cid, oid, expected_object_size,
3069 expected_write_size);
3070 tracepoint(objectstore, setallochint_exit, r);
3075 derr << "bad op " << op->op << dendl;
3082 if (r == -ENOENT && !(op->op == Transaction::OP_CLONERANGE ||
3083 op->op == Transaction::OP_CLONE ||
3084 op->op == Transaction::OP_CLONERANGE2 ||
3085 op->op == Transaction::OP_COLL_ADD ||
3086 op->op == Transaction::OP_SETATTR ||
3087 op->op == Transaction::OP_SETATTRS ||
3088 op->op == Transaction::OP_RMATTR ||
3089 op->op == Transaction::OP_OMAP_SETKEYS ||
3090 op->op == Transaction::OP_OMAP_RMKEYS ||
3091 op->op == Transaction::OP_OMAP_RMKEYRANGE ||
3092 op->op == Transaction::OP_OMAP_SETHEADER))
3093 // -ENOENT is normally okay
3094 // ...including on a replayed OP_RMCOLL with checkpoint mode
3099 if (op->op == Transaction::OP_SETALLOCHINT)
3100 // Either EOPNOTSUPP or EINVAL most probably. EINVAL in most
3101 // cases means invalid hint size (e.g. too big, not a multiple
3102 // of block size, etc) or, at least on xfs, an attempt to set
3103 // or change it when the file is not empty. However,
3104 // OP_SETALLOCHINT is advisory, so ignore all errors.
3107 if (replaying && !backend->can_checkpoint()) {
3108 if (r == -EEXIST && op->op == Transaction::OP_MKCOLL) {
3109 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl;
3112 if (r == -EEXIST && op->op == Transaction::OP_COLL_ADD) {
3113 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl;
3116 if (r == -EEXIST && op->op == Transaction::OP_COLL_MOVE) {
3117 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl;
3121 dout(10) << "tolerating ERANGE on replay" << dendl;
3125 dout(10) << "tolerating ENOENT on replay" << dendl;
3131 const char *msg = "unexpected error code";
3133 if (r == -ENOENT && (op->op == Transaction::OP_CLONERANGE ||
3134 op->op == Transaction::OP_CLONE ||
3135 op->op == Transaction::OP_CLONERANGE2)) {
3136 msg = "ENOENT on clone suggests osd bug";
3137 } else if (r == -ENOSPC) {
3138 // For now, if we hit _any_ ENOSPC, crash, before we do any damage
3139 // by partially applying transactions.
3140 msg = "ENOSPC from disk filesystem, misconfigured cluster";
3141 } else if (r == -ENOTEMPTY) {
3142 msg = "ENOTEMPTY suggests garbage data in osd data dir";
3143 } else if (r == -EPERM) {
3144 msg = "EPERM suggests file(s) in osd data dir not owned by ceph user, or leveldb corruption";
3147 derr << " error " << cpp_strerror(r) << " not handled on operation " << op
3148 << " (" << spos << ", or op " << spos.op << ", counting from 0)" << dendl;
3149 dout(0) << msg << dendl;
3150 dout(0) << " transaction dump:\n";
3151 JSONFormatter f(true);
3152 f.open_object_section("transaction");
3162 assert(0 == "unexpected error");
3172 /*********************************************/
3176 // --------------------
3179 bool FileStore::exists(const coll_t& _cid, const ghobject_t& oid)
3181 tracepoint(objectstore, exists_enter, _cid.c_str());
3182 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
3184 bool retval = stat(cid, oid, &st) == 0;
3185 tracepoint(objectstore, exists_exit, retval);
3189 int FileStore::stat(
3190 const coll_t& _cid, const ghobject_t& oid, struct stat *st, bool allow_eio)
3192 tracepoint(objectstore, stat_enter, _cid.c_str());
3193 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
3194 int r = lfn_stat(cid, oid, st);
3195 assert(allow_eio || !m_filestore_fail_eio || r != -EIO);
3197 dout(10) << __FUNC__ << ": " << cid << "/" << oid
3198 << " = " << r << dendl;
3200 dout(10) << __FUNC__ << ": " << cid << "/" << oid
3202 << " (size " << st->st_size << ")" << dendl;
3204 if (cct->_conf->filestore_debug_inject_read_err &&
3205 debug_mdata_eio(oid)) {
3208 tracepoint(objectstore, stat_exit, r);
3213 int FileStore::set_collection_opts(
3215 const pool_opts_t& opts)
3220 int FileStore::read(
3222 const ghobject_t& oid,
3229 tracepoint(objectstore, read_enter, _cid.c_str(), offset, len);
3230 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
3232 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << dendl;
3235 int r = lfn_open(cid, oid, false, &fd);
3237 dout(10) << __FUNC__ << ": (" << cid << "/" << oid << ") open error: "
3238 << cpp_strerror(r) << dendl;
3242 if (offset == 0 && len == 0) {
3244 memset(&st, 0, sizeof(struct stat));
3245 int r = ::fstat(**fd, &st);
3250 #ifdef HAVE_POSIX_FADVISE
3251 if (op_flags & CEPH_OSD_OP_FLAG_FADVISE_RANDOM)
3252 posix_fadvise(**fd, offset, len, POSIX_FADV_RANDOM);
3253 if (op_flags & CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL)
3254 posix_fadvise(**fd, offset, len, POSIX_FADV_SEQUENTIAL);
3257 bufferptr bptr(len); // prealloc space for entire read
3258 got = safe_pread(**fd, bptr.c_str(), len, offset);
3260 dout(10) << __FUNC__ << ": (" << cid << "/" << oid << ") pread error: " << cpp_strerror(got) << dendl;
3264 bptr.set_length(got); // properly size the buffer
3266 bl.push_back(std::move(bptr)); // put it in the target bufferlist
3268 #ifdef HAVE_POSIX_FADVISE
3269 if (op_flags & CEPH_OSD_OP_FLAG_FADVISE_DONTNEED)
3270 posix_fadvise(**fd, offset, len, POSIX_FADV_DONTNEED);
3271 if (op_flags & (CEPH_OSD_OP_FLAG_FADVISE_RANDOM | CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL))
3272 posix_fadvise(**fd, offset, len, POSIX_FADV_NORMAL);
3275 if (m_filestore_sloppy_crc && (!replaying || backend->can_checkpoint())) {
3277 int errors = backend->_crc_verify_read(**fd, offset, got, bl, &ss);
3279 dout(0) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~"
3280 << got << " ... BAD CRC:\n" << ss.str() << dendl;
3281 assert(0 == "bad crc on read");
3287 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~"
3288 << got << "/" << len << dendl;
3289 if (cct->_conf->filestore_debug_inject_read_err &&
3290 debug_data_eio(oid)) {
3292 } else if (cct->_conf->filestore_debug_random_read_err &&
3293 (rand() % (int)(cct->_conf->filestore_debug_random_read_err * 100.0)) == 0) {
3294 dout(0) << __func__ << ": inject random EIO" << dendl;
3297 tracepoint(objectstore, read_exit, got);
3302 int FileStore::_do_fiemap(int fd, uint64_t offset, size_t len,
3303 map<uint64_t, uint64_t> *m)
3306 struct fiemap_extent *extent = NULL;
3307 struct fiemap *fiemap = NULL;
3311 r = backend->do_fiemap(fd, offset, len, &fiemap);
3315 if (fiemap->fm_mapped_extents == 0) {
3320 extent = &fiemap->fm_extents[0];
3322 /* start where we were asked to start */
3323 if (extent->fe_logical < offset) {
3324 extent->fe_length -= offset - extent->fe_logical;
3325 extent->fe_logical = offset;
3330 struct fiemap_extent *last = nullptr;
3331 while (i < fiemap->fm_mapped_extents) {
3332 struct fiemap_extent *next = extent + 1;
3334 dout(10) << __FUNC__ << ": fm_mapped_extents=" << fiemap->fm_mapped_extents
3335 << " fe_logical=" << extent->fe_logical << " fe_length=" << extent->fe_length << dendl;
3337 /* try to merge extents */
3338 while ((i < fiemap->fm_mapped_extents - 1) &&
3339 (extent->fe_logical + extent->fe_length == next->fe_logical)) {
3340 next->fe_length += extent->fe_length;
3341 next->fe_logical = extent->fe_logical;
3347 if (extent->fe_logical + extent->fe_length > offset + len)
3348 extent->fe_length = offset + len - extent->fe_logical;
3349 (*m)[extent->fe_logical] = extent->fe_length;
3353 uint64_t xoffset = last->fe_logical + last->fe_length - offset;
3354 offset = last->fe_logical + last->fe_length;
3356 const bool is_last = (last->fe_flags & FIEMAP_EXTENT_LAST) || (len == 0);
3365 int FileStore::_do_seek_hole_data(int fd, uint64_t offset, size_t len,
3366 map<uint64_t, uint64_t> *m)
3368 #if defined(__linux__) && defined(SEEK_HOLE) && defined(SEEK_DATA)
3369 off_t hole_pos, data_pos;
3372 // If lseek fails with errno setting to be ENXIO, this means the current
3373 // file offset is beyond the end of the file.
3374 off_t start = offset;
3375 while(start < (off_t)(offset + len)) {
3376 data_pos = lseek(fd, start, SEEK_DATA);
3382 dout(10) << "failed to lseek: " << cpp_strerror(r) << dendl;
3385 } else if (data_pos > (off_t)(offset + len)) {
3389 hole_pos = lseek(fd, data_pos, SEEK_HOLE);
3391 if (errno == ENXIO) {
3395 dout(10) << "failed to lseek: " << cpp_strerror(r) << dendl;
3400 if (hole_pos >= (off_t)(offset + len)) {
3401 (*m)[data_pos] = offset + len - data_pos;
3404 (*m)[data_pos] = hole_pos - data_pos;
3415 int FileStore::fiemap(const coll_t& _cid, const ghobject_t& oid,
3416 uint64_t offset, size_t len,
3419 map<uint64_t, uint64_t> exomap;
3420 int r = fiemap(_cid, oid, offset, len, exomap);
3422 ::encode(exomap, bl);
3427 int FileStore::fiemap(const coll_t& _cid, const ghobject_t& oid,
3428 uint64_t offset, size_t len,
3429 map<uint64_t, uint64_t>& destmap)
3431 tracepoint(objectstore, fiemap_enter, _cid.c_str(), offset, len);
3432 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
3435 if ((!backend->has_seek_data_hole() && !backend->has_fiemap()) ||
3436 len <= (size_t)m_filestore_fiemap_threshold) {
3437 destmap[offset] = len;
3441 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << dendl;
3445 int r = lfn_open(cid, oid, false, &fd);
3447 dout(10) << "read couldn't open " << cid << "/" << oid << ": " << cpp_strerror(r) << dendl;
3451 if (backend->has_seek_data_hole()) {
3452 dout(15) << "seek_data/seek_hole " << cid << "/" << oid << " " << offset << "~" << len << dendl;
3453 r = _do_seek_hole_data(**fd, offset, len, &destmap);
3454 } else if (backend->has_fiemap()) {
3455 dout(15) << "fiemap ioctl" << cid << "/" << oid << " " << offset << "~" << len << dendl;
3456 r = _do_fiemap(**fd, offset, len, &destmap);
3463 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << " = " << r << " num_extents=" << destmap.size() << " " << destmap << dendl;
3464 assert(!m_filestore_fail_eio || r != -EIO);
3465 tracepoint(objectstore, fiemap_exit, r);
3469 int FileStore::_remove(const coll_t& cid, const ghobject_t& oid,
3470 const SequencerPosition &spos)
3472 dout(15) << __FUNC__ << ": " << cid << "/" << oid << dendl;
3473 int r = lfn_unlink(cid, oid, spos);
3474 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " = " << r << dendl;
3478 int FileStore::_truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size)
3480 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " size " << size << dendl;
3481 int r = lfn_truncate(cid, oid, size);
3482 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " size " << size << " = " << r << dendl;
3487 int FileStore::_touch(const coll_t& cid, const ghobject_t& oid)
3489 dout(15) << __FUNC__ << ": " << cid << "/" << oid << dendl;
3492 int r = lfn_open(cid, oid, true, &fd);
3498 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " = " << r << dendl;
3502 int FileStore::_write(const coll_t& cid, const ghobject_t& oid,
3503 uint64_t offset, size_t len,
3504 const bufferlist& bl, uint32_t fadvise_flags)
3506 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << dendl;
3510 r = lfn_open(cid, oid, true, &fd);
3512 dout(0) << __FUNC__ << ": couldn't open " << cid << "/"
3514 << cpp_strerror(r) << dendl;
3519 r = bl.write_fd(**fd, offset);
3521 derr << __FUNC__ << ": write_fd on " << cid << "/" << oid
3522 << " error: " << cpp_strerror(r) << dendl;
3528 if (r >= 0 && m_filestore_sloppy_crc) {
3529 int rc = backend->_crc_update_write(**fd, offset, len, bl);
3533 if (replaying || m_disable_wbthrottle) {
3534 if (fadvise_flags & CEPH_OSD_OP_FLAG_FADVISE_DONTNEED) {
3535 #ifdef HAVE_POSIX_FADVISE
3536 posix_fadvise(**fd, 0, 0, POSIX_FADV_DONTNEED);
3540 wbthrottle.queue_wb(fd, oid, offset, len,
3541 fadvise_flags & CEPH_OSD_OP_FLAG_FADVISE_DONTNEED);
3547 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << " = " << r << dendl;
3551 int FileStore::_zero(const coll_t& cid, const ghobject_t& oid, uint64_t offset, size_t len)
3553 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << dendl;
3556 if (cct->_conf->filestore_punch_hole) {
3557 #ifdef CEPH_HAVE_FALLOCATE
3558 # if !defined(DARWIN) && !defined(__FreeBSD__)
3559 # ifdef FALLOC_FL_KEEP_SIZE
3560 // first try to punch a hole.
3562 ret = lfn_open(cid, oid, false, &fd);
3568 ret = ::fstat(**fd, &st);
3575 // first try fallocate
3576 ret = fallocate(**fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
3581 // ensure we extent file size, if needed
3582 if (offset + len > (uint64_t)st.st_size) {
3583 ret = ::ftruncate(**fd, offset + len);
3593 if (ret >= 0 && m_filestore_sloppy_crc) {
3594 int rc = backend->_crc_update_zero(**fd, offset, len);
3600 if (ret != -EOPNOTSUPP)
3601 goto out; // some other error
3607 // lame, kernel is old and doesn't support it.
3608 // write zeros.. yuck!
3609 dout(20) << __FUNC__ << ": falling back to writing zeros" << dendl;
3612 bl.append_zero(len);
3613 ret = _write(cid, oid, offset, len, bl);
3616 #ifdef CEPH_HAVE_FALLOCATE
3617 # if !defined(DARWIN) && !defined(__FreeBSD__)
3618 # ifdef FALLOC_FL_KEEP_SIZE
3623 dout(20) << __FUNC__ << ": " << cid << "/" << oid << " " << offset << "~" << len << " = " << ret << dendl;
3627 int FileStore::_clone(const coll_t& cid, const ghobject_t& oldoid, const ghobject_t& newoid,
3628 const SequencerPosition& spos)
3630 dout(15) << __FUNC__ << ": " << cid << "/" << oldoid << " -> " << cid << "/" << newoid << dendl;
3632 if (_check_replay_guard(cid, newoid, spos) < 0)
3639 r = lfn_open(cid, oldoid, false, &o, &index);
3643 assert(NULL != (index.index));
3644 RWLock::WLocker l((index.index)->access_lock);
3646 r = lfn_open(cid, newoid, true, &n, &index);
3650 r = ::ftruncate(**n, 0);
3656 r = ::fstat(**o, &st);
3662 r = _do_clone_range(**o, **n, 0, st.st_size, 0);
3667 dout(20) << "objectmap clone" << dendl;
3668 r = object_map->clone(oldoid, newoid, &spos);
3669 if (r < 0 && r != -ENOENT)
3675 map<string, bufferptr> aset;
3676 r = _fgetattrs(**o, aset);
3680 r = chain_fgetxattr(**o, XATTR_SPILL_OUT_NAME, buf, sizeof(buf));
3681 if (r >= 0 && !strncmp(buf, XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT))) {
3682 r = chain_fsetxattr<true, true>(**n, XATTR_SPILL_OUT_NAME, XATTR_NO_SPILL_OUT,
3683 sizeof(XATTR_NO_SPILL_OUT));
3685 r = chain_fsetxattr<true, true>(**n, XATTR_SPILL_OUT_NAME, XATTR_SPILL_OUT,
3686 sizeof(XATTR_SPILL_OUT));
3691 r = _fsetattrs(**n, aset);
3696 // clone is non-idempotent; record our work.
3697 _set_replay_guard(**n, spos, &newoid);
3704 dout(10) << __FUNC__ << ": " << cid << "/" << oldoid << " -> " << cid << "/" << newoid << " = " << r << dendl;
3705 assert(!m_filestore_fail_eio || r != -EIO);
3709 int FileStore::_do_clone_range(int from, int to, uint64_t srcoff, uint64_t len, uint64_t dstoff)
3711 dout(20) << __FUNC__ << ": copy " << srcoff << "~" << len << " to " << dstoff << dendl;
3712 return backend->clone_range(from, to, srcoff, len, dstoff);
3715 int FileStore::_do_sparse_copy_range(int from, int to, uint64_t srcoff, uint64_t len, uint64_t dstoff)
3717 dout(20) << __FUNC__ << ": " << srcoff << "~" << len << " to " << dstoff << dendl;
3719 map<uint64_t, uint64_t> exomap;
3720 // fiemap doesn't allow zero length
3724 if (backend->has_seek_data_hole()) {
3725 dout(15) << "seek_data/seek_hole " << from << " " << srcoff << "~" << len << dendl;
3726 r = _do_seek_hole_data(from, srcoff, len, &exomap);
3727 } else if (backend->has_fiemap()) {
3728 dout(15) << "fiemap ioctl" << from << " " << srcoff << "~" << len << dendl;
3729 r = _do_fiemap(from, srcoff, len, &exomap);
3733 int64_t written = 0;
3737 for (map<uint64_t, uint64_t>::iterator miter = exomap.begin(); miter != exomap.end(); ++miter) {
3738 uint64_t it_off = miter->first - srcoff + dstoff;
3739 r = _do_copy_range(from, to, miter->first, miter->second, it_off, true);
3741 derr << __FUNC__ << ": copy error at " << miter->first << "~" << miter->second
3742 << " to " << it_off << ", " << cpp_strerror(r) << dendl;
3745 written += miter->second;
3749 if (m_filestore_sloppy_crc) {
3750 int rc = backend->_crc_update_clone_range(from, to, srcoff, len, dstoff);
3754 r = ::fstat(to, &st);
3757 derr << __FUNC__ << ": fstat error at " << to << " " << cpp_strerror(r) << dendl;
3760 if (st.st_size < (int)(dstoff + len)) {
3761 r = ::ftruncate(to, dstoff + len);
3764 derr << __FUNC__ << ": ftruncate error at " << dstoff+len << " " << cpp_strerror(r) << dendl;
3772 dout(20) << __FUNC__ << ": " << srcoff << "~" << len << " to " << dstoff << " = " << r << dendl;
3776 int FileStore::_do_copy_range(int from, int to, uint64_t srcoff, uint64_t len, uint64_t dstoff, bool skip_sloppycrc)
3778 dout(20) << __FUNC__ << ": " << srcoff << "~" << len << " to " << dstoff << dendl;
3780 loff_t pos = srcoff;
3781 loff_t end = srcoff + len;
3782 int buflen = 4096 * 16; //limit by pipe max size.see fcntl
3784 #ifdef CEPH_HAVE_SPLICE
3785 if (backend->has_splice()) {
3787 if (pipe(pipefd) < 0) {
3789 derr << " pipe " << " got " << cpp_strerror(r) << dendl;
3793 loff_t dstpos = dstoff;
3795 int l = MIN(end-pos, buflen);
3796 r = safe_splice(from, &pos, pipefd[1], NULL, l, SPLICE_F_NONBLOCK);
3797 dout(10) << " safe_splice read from " << pos << "~" << l << " got " << r << dendl;
3799 derr << __FUNC__ << ": safe_splice read error at " << pos << "~" << len
3800 << ", " << cpp_strerror(r) << dendl;
3804 // hrm, bad source range, wtf.
3806 derr << __FUNC__ << ": got short read result at " << pos
3807 << " of fd " << from << " len " << len << dendl;
3811 r = safe_splice(pipefd[0], NULL, to, &dstpos, r, 0);
3812 dout(10) << " safe_splice write to " << to << " len " << r
3813 << " got " << r << dendl;
3815 derr << __FUNC__ << ": write error at " << pos << "~"
3816 << r << ", " << cpp_strerror(r) << dendl;
3827 actual = ::lseek64(from, srcoff, SEEK_SET);
3828 if (actual != (int64_t)srcoff) {
3833 derr << "lseek64 to " << srcoff << " got " << cpp_strerror(r) << dendl;
3836 actual = ::lseek64(to, dstoff, SEEK_SET);
3837 if (actual != (int64_t)dstoff) {
3842 derr << "lseek64 to " << dstoff << " got " << cpp_strerror(r) << dendl;
3848 int l = MIN(end-pos, buflen);
3849 r = ::read(from, buf, l);
3850 dout(25) << " read from " << pos << "~" << l << " got " << r << dendl;
3852 if (errno == EINTR) {
3856 derr << __FUNC__ << ": read error at " << pos << "~" << len
3857 << ", " << cpp_strerror(r) << dendl;
3862 // hrm, bad source range, wtf.
3864 derr << __FUNC__ << ": got short read result at " << pos
3865 << " of fd " << from << " len " << len << dendl;
3870 int r2 = safe_write(to, buf+op, r-op);
3871 dout(25) << " write to " << to << " len " << (r-op)
3872 << " got " << r2 << dendl;
3875 derr << __FUNC__ << ": write error at " << pos << "~"
3876 << r-op << ", " << cpp_strerror(r) << dendl;
3888 if (r < 0 && replaying) {
3889 assert(r == -ERANGE);
3890 derr << __FUNC__ << ": short source tolerated because we are replaying" << dendl;
3893 assert(replaying || pos == end);
3894 if (r >= 0 && !skip_sloppycrc && m_filestore_sloppy_crc) {
3895 int rc = backend->_crc_update_clone_range(from, to, srcoff, len, dstoff);
3898 dout(20) << __FUNC__ << ": " << srcoff << "~" << len << " to " << dstoff << " = " << r << dendl;
3902 int FileStore::_clone_range(const coll_t& oldcid, const ghobject_t& oldoid, const coll_t& newcid, const ghobject_t& newoid,
3903 uint64_t srcoff, uint64_t len, uint64_t dstoff,
3904 const SequencerPosition& spos)
3906 dout(15) << __FUNC__ << ": " << oldcid << "/" << oldoid << " -> " << newcid << "/" << newoid << " " << srcoff << "~" << len << " to " << dstoff << dendl;
3908 if (_check_replay_guard(newcid, newoid, spos) < 0)
3913 r = lfn_open(oldcid, oldoid, false, &o);
3917 r = lfn_open(newcid, newoid, true, &n);
3921 r = _do_clone_range(**o, **n, srcoff, len, dstoff);
3926 // clone is non-idempotent; record our work.
3927 _set_replay_guard(**n, spos, &newoid);
3934 dout(10) << __FUNC__ << ": " << oldcid << "/" << oldoid << " -> " << newcid << "/" << newoid << " "
3935 << srcoff << "~" << len << " to " << dstoff << " = " << r << dendl;
3939 class SyncEntryTimeout : public Context {
3942 explicit SyncEntryTimeout(CephContext* cct, int commit_timeo)
3943 : cct(cct), m_commit_timeo(commit_timeo)
3947 void finish(int r) override {
3948 BackTrace *bt = new BackTrace(1);
3949 generic_dout(-1) << "FileStore: sync_entry timed out after "
3950 << m_commit_timeo << " seconds.\n";
3960 void FileStore::sync_entry()
3964 utime_t max_interval;
3965 max_interval.set_from_double(m_filestore_max_sync_interval);
3966 utime_t min_interval;
3967 min_interval.set_from_double(m_filestore_min_sync_interval);
3969 utime_t startwait = ceph_clock_now();
3971 dout(20) << __FUNC__ << ": waiting for max_interval " << max_interval << dendl;
3972 sync_cond.WaitInterval(lock, max_interval);
3974 dout(20) << __FUNC__ << ": not waiting, force_sync set" << dendl;
3978 dout(20) << __FUNC__ << ": force_sync set" << dendl;
3981 dout(20) << __FUNC__ << ": stop set" << dendl;
3984 // wait for at least the min interval
3985 utime_t woke = ceph_clock_now();
3987 dout(20) << __FUNC__ << ": woke after " << woke << dendl;
3988 if (woke < min_interval) {
3989 utime_t t = min_interval;
3991 dout(20) << __FUNC__ << ": waiting for another " << t
3992 << " to reach min interval " << min_interval << dendl;
3993 sync_cond.WaitInterval(lock, t);
3999 fin.swap(sync_waiters);
4003 if (apply_manager.commit_start()) {
4004 utime_t start = ceph_clock_now();
4005 uint64_t cp = apply_manager.get_committing_seq();
4007 sync_entry_timeo_lock.Lock();
4008 SyncEntryTimeout *sync_entry_timeo =
4009 new SyncEntryTimeout(cct, m_filestore_commit_timeout);
4010 if (!timer.add_event_after(m_filestore_commit_timeout,
4011 sync_entry_timeo)) {
4012 sync_entry_timeo = nullptr;
4014 sync_entry_timeo_lock.Unlock();
4016 logger->set(l_filestore_committing, 1);
4018 dout(15) << __FUNC__ << ": committing " << cp << dendl;
4019 stringstream errstream;
4020 if (cct->_conf->filestore_debug_omap_check && !object_map->check(errstream)) {
4021 derr << errstream.str() << dendl;
4025 if (backend->can_checkpoint()) {
4026 int err = write_op_seq(op_fd, cp);
4028 derr << "Error during write_op_seq: " << cpp_strerror(err) << dendl;
4029 assert(0 == "error during write_op_seq");
4033 snprintf(s, sizeof(s), COMMIT_SNAP_ITEM, (long long unsigned)cp);
4035 err = backend->create_checkpoint(s, &cid);
4038 derr << "snap create '" << s << "' got error " << err << dendl;
4042 snaps.push_back(cp);
4043 apply_manager.commit_started();
4047 dout(20) << " waiting for checkpoint " << cid << " to complete" << dendl;
4048 err = backend->sync_checkpoint(cid);
4050 derr << "ioctl WAIT_SYNC got " << cpp_strerror(err) << dendl;
4051 assert(0 == "wait_sync got error");
4053 dout(20) << " done waiting for checkpoint " << cid << " to complete" << dendl;
4056 apply_manager.commit_started();
4059 int err = object_map->sync();
4061 derr << "object_map sync got " << cpp_strerror(err) << dendl;
4062 assert(0 == "object_map sync returned error");
4065 err = backend->syncfs();
4067 derr << "syncfs got " << cpp_strerror(err) << dendl;
4068 assert(0 == "syncfs returned error");
4071 err = write_op_seq(op_fd, cp);
4073 derr << "Error during write_op_seq: " << cpp_strerror(err) << dendl;
4074 assert(0 == "error during write_op_seq");
4076 err = ::fsync(op_fd);
4078 derr << "Error during fsync of op_seq: " << cpp_strerror(err) << dendl;
4079 assert(0 == "error during fsync of op_seq");
4083 utime_t done = ceph_clock_now();
4084 utime_t lat = done - start;
4085 utime_t dur = done - startwait;
4086 dout(10) << __FUNC__ << ": commit took " << lat << ", interval was " << dur << dendl;
4087 utime_t max_pause_lat = logger->tget(l_filestore_sync_pause_max_lat);
4088 if (max_pause_lat < dur - lat) {
4089 logger->tinc(l_filestore_sync_pause_max_lat, dur - lat);
4092 logger->inc(l_filestore_commitcycle);
4093 logger->tinc(l_filestore_commitcycle_latency, lat);
4094 logger->tinc(l_filestore_commitcycle_interval, dur);
4096 apply_manager.commit_finish();
4097 if (!m_disable_wbthrottle) {
4101 logger->set(l_filestore_committing, 0);
4103 // remove old snaps?
4104 if (backend->can_checkpoint()) {
4106 while (snaps.size() > 2) {
4107 snprintf(s, sizeof(s), COMMIT_SNAP_ITEM, (long long unsigned)snaps.front());
4109 dout(10) << "removing snap '" << s << "'" << dendl;
4110 int r = backend->destroy_checkpoint(s);
4113 derr << "unable to destroy snap '" << s << "' got " << cpp_strerror(err) << dendl;
4118 dout(15) << __FUNC__ << ": committed to op_seq " << cp << dendl;
4120 if (sync_entry_timeo) {
4121 Mutex::Locker lock(sync_entry_timeo_lock);
4122 timer.cancel_event(sync_entry_timeo);
4129 finish_contexts(cct, fin, 0);
4131 if (!sync_waiters.empty()) {
4132 dout(10) << __FUNC__ << ": more waiters, committing again" << dendl;
4135 if (!stop && journal && journal->should_commit_now()) {
4136 dout(10) << __FUNC__ << ": journal says we should commit again (probably is/was full)" << dendl;
4144 void FileStore::_start_sync()
4146 if (!journal) { // don't do a big sync if the journal is on
4147 dout(10) << __FUNC__ << dendl;
4150 dout(10) << __FUNC__ << ": - NOOP (journal is on)" << dendl;
4154 void FileStore::do_force_sync()
4156 dout(10) << __FUNC__ << dendl;
4157 Mutex::Locker l(lock);
4162 void FileStore::start_sync(Context *onsafe)
4164 Mutex::Locker l(lock);
4165 sync_waiters.push_back(onsafe);
4168 dout(10) << __FUNC__ << dendl;
4171 void FileStore::sync()
4173 Mutex l("FileStore::sync");
4176 C_SafeCond *fin = new C_SafeCond(&l, &c, &done);
4182 dout(10) << "sync waiting" << dendl;
4186 dout(10) << "sync done" << dendl;
4189 void FileStore::_flush_op_queue()
4191 dout(10) << __FUNC__ << ": draining op tp" << dendl;
4193 dout(10) << __FUNC__ << ": waiting for apply finisher" << dendl;
4194 for (vector<Finisher*>::iterator it = apply_finishers.begin(); it != apply_finishers.end(); ++it) {
4195 (*it)->wait_for_empty();
4200 * flush - make every queued write readable
4202 void FileStore::flush()
4204 dout(10) << __FUNC__ << dendl;
4206 if (cct->_conf->filestore_blackhole) {
4208 Mutex lock("FileStore::flush::lock");
4216 if (m_filestore_journal_writeahead) {
4219 dout(10) << __FUNC__ << ": draining ondisk finisher" << dendl;
4220 for (vector<Finisher*>::iterator it = ondisk_finishers.begin(); it != ondisk_finishers.end(); ++it) {
4221 (*it)->wait_for_empty();
4226 dout(10) << __FUNC__ << ": complete" << dendl;
4230 * sync_and_flush - make every queued write readable AND committed to disk
4232 void FileStore::sync_and_flush()
4234 dout(10) << __FUNC__ << dendl;
4236 if (m_filestore_journal_writeahead) {
4241 // includes m_filestore_journal_parallel
4245 dout(10) << __FUNC__ << ": done" << dendl;
4248 int FileStore::flush_journal()
4250 dout(10) << __FUNC__ << dendl;
4256 int FileStore::snapshot(const string& name)
4258 dout(10) << __FUNC__ << ": " << name << dendl;
4261 if (!backend->can_checkpoint()) {
4262 dout(0) << __FUNC__ << ": " << name << " failed, not supported" << dendl;
4267 snprintf(s, sizeof(s), CLUSTER_SNAP_ITEM, name.c_str());
4269 int r = backend->create_checkpoint(s, NULL);
4271 derr << __FUNC__ << ": " << name << " failed: " << cpp_strerror(r) << dendl;
4277 // -------------------------------
4280 int FileStore::_fgetattr(int fd, const char *name, bufferptr& bp)
4282 char val[CHAIN_XATTR_MAX_BLOCK_LEN];
4283 int l = chain_fgetxattr(fd, name, val, sizeof(val));
4285 bp = buffer::create(l);
4286 memcpy(bp.c_str(), val, l);
4287 } else if (l == -ERANGE) {
4288 l = chain_fgetxattr(fd, name, 0, 0);
4290 bp = buffer::create(l);
4291 l = chain_fgetxattr(fd, name, bp.c_str(), l);
4294 assert(!m_filestore_fail_eio || l != -EIO);
4298 int FileStore::_fgetattrs(int fd, map<string,bufferptr>& aset)
4302 int len = chain_flistxattr(fd, names1, sizeof(names1)-1);
4305 if (len == -ERANGE) {
4306 len = chain_flistxattr(fd, 0, 0);
4308 assert(!m_filestore_fail_eio || len != -EIO);
4311 dout(10) << " -ERANGE, len is " << len << dendl;
4312 names2 = new char[len+1];
4313 len = chain_flistxattr(fd, names2, len);
4314 dout(10) << " -ERANGE, got " << len << dendl;
4316 assert(!m_filestore_fail_eio || len != -EIO);
4321 } else if (len < 0) {
4322 assert(!m_filestore_fail_eio || len != -EIO);
4329 char *end = name + len;
4330 while (name < end) {
4331 char *attrname = name;
4332 if (parse_attrname(&name)) {
4334 dout(20) << __FUNC__ << ": " << fd << " getting '" << name << "'" << dendl;
4335 int r = _fgetattr(fd, attrname, aset[name]);
4342 name += strlen(name) + 1;
4349 int FileStore::_fsetattrs(int fd, map<string, bufferptr> &aset)
4351 for (map<string, bufferptr>::iterator p = aset.begin();
4354 char n[CHAIN_XATTR_MAX_NAME_LEN];
4355 get_attrname(p->first.c_str(), n, CHAIN_XATTR_MAX_NAME_LEN);
4357 if (p->second.length())
4358 val = p->second.c_str();
4361 // ??? Why do we skip setting all the other attrs if one fails?
4362 int r = chain_fsetxattr(fd, n, val, p->second.length());
4364 derr << __FUNC__ << ": chain_setxattr returned " << r << dendl;
4371 // debug EIO injection
4372 void FileStore::inject_data_error(const ghobject_t &oid) {
4373 Mutex::Locker l(read_error_lock);
4374 dout(10) << __FUNC__ << ": init error on " << oid << dendl;
4375 data_error_set.insert(oid);
4377 void FileStore::inject_mdata_error(const ghobject_t &oid) {
4378 Mutex::Locker l(read_error_lock);
4379 dout(10) << __FUNC__ << ": init error on " << oid << dendl;
4380 mdata_error_set.insert(oid);
4383 void FileStore::debug_obj_on_delete(const ghobject_t &oid) {
4384 Mutex::Locker l(read_error_lock);
4385 dout(10) << __FUNC__ << ": clear error on " << oid << dendl;
4386 data_error_set.erase(oid);
4387 mdata_error_set.erase(oid);
4389 bool FileStore::debug_data_eio(const ghobject_t &oid) {
4390 Mutex::Locker l(read_error_lock);
4391 if (data_error_set.count(oid)) {
4392 dout(10) << __FUNC__ << ": inject error on " << oid << dendl;
4398 bool FileStore::debug_mdata_eio(const ghobject_t &oid) {
4399 Mutex::Locker l(read_error_lock);
4400 if (mdata_error_set.count(oid)) {
4401 dout(10) << __FUNC__ << ": inject error on " << oid << dendl;
4411 int FileStore::getattr(const coll_t& _cid, const ghobject_t& oid, const char *name, bufferptr &bp)
4413 tracepoint(objectstore, getattr_enter, _cid.c_str());
4414 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
4415 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " '" << name << "'" << dendl;
4417 int r = lfn_open(cid, oid, false, &fd);
4421 char n[CHAIN_XATTR_MAX_NAME_LEN];
4422 get_attrname(name, n, CHAIN_XATTR_MAX_NAME_LEN);
4423 r = _fgetattr(**fd, n, bp);
4425 if (r == -ENODATA) {
4426 map<string, bufferlist> got;
4428 to_get.insert(string(name));
4430 r = get_index(cid, &index);
4432 dout(10) << __FUNC__ << ": could not get index r = " << r << dendl;
4435 r = object_map->get_xattrs(oid, to_get, &got);
4436 if (r < 0 && r != -ENOENT) {
4437 dout(10) << __FUNC__ << ": get_xattrs err r =" << r << dendl;
4441 dout(10) << __FUNC__ << ": got.size() is 0" << dendl;
4444 bp = bufferptr(got.begin()->second.c_str(),
4445 got.begin()->second.length());
4449 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " '" << name << "' = " << r << dendl;
4450 assert(!m_filestore_fail_eio || r != -EIO);
4451 if (cct->_conf->filestore_debug_inject_read_err &&
4452 debug_mdata_eio(oid)) {
4455 tracepoint(objectstore, getattr_exit, r);
4456 return r < 0 ? r : 0;
4460 int FileStore::getattrs(const coll_t& _cid, const ghobject_t& oid, map<string,bufferptr>& aset)
4462 tracepoint(objectstore, getattrs_enter, _cid.c_str());
4463 const coll_t& cid = !_need_temp_object_collection(_cid, oid) ? _cid : _cid.get_temp();
4464 set<string> omap_attrs;
4465 map<string, bufferlist> omap_aset;
4467 dout(15) << __FUNC__ << ": " << cid << "/" << oid << dendl;
4469 bool spill_out = true;
4472 int r = lfn_open(cid, oid, false, &fd);
4477 r = chain_fgetxattr(**fd, XATTR_SPILL_OUT_NAME, buf, sizeof(buf));
4478 if (r >= 0 && !strncmp(buf, XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT)))
4481 r = _fgetattrs(**fd, aset);
4483 fd = FDRef(); // defensive
4489 dout(10) << __FUNC__ << ": no xattr exists in object_map r = " << r << dendl;
4493 r = get_index(cid, &index);
4495 dout(10) << __FUNC__ << ": could not get index r = " << r << dendl;
4499 r = object_map->get_all_xattrs(oid, &omap_attrs);
4500 if (r < 0 && r != -ENOENT) {
4501 dout(10) << __FUNC__ << ": could not get omap_attrs r = " << r << dendl;
4505 r = object_map->get_xattrs(oid, omap_attrs, &omap_aset);
4506 if (r < 0 && r != -ENOENT) {
4507 dout(10) << __FUNC__ << ": could not get omap_attrs r = " << r << dendl;
4513 assert(omap_attrs.size() == omap_aset.size());
4514 for (map<string, bufferlist>::iterator i = omap_aset.begin();
4515 i != omap_aset.end();
4517 string key(i->first);
4518 aset.insert(make_pair(key,
4519 bufferptr(i->second.c_str(), i->second.length())));
4522 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " = " << r << dendl;
4523 assert(!m_filestore_fail_eio || r != -EIO);
4525 if (cct->_conf->filestore_debug_inject_read_err &&
4526 debug_mdata_eio(oid)) {
4529 tracepoint(objectstore, getattrs_exit, r);
4534 int FileStore::_setattrs(const coll_t& cid, const ghobject_t& oid, map<string,bufferptr>& aset,
4535 const SequencerPosition &spos)
4537 map<string, bufferlist> omap_set;
4538 set<string> omap_remove;
4539 map<string, bufferptr> inline_set;
4540 map<string, bufferptr> inline_to_set;
4543 bool incomplete_inline = false;
4545 int r = lfn_open(cid, oid, false, &fd);
4551 r = chain_fgetxattr(**fd, XATTR_SPILL_OUT_NAME, buf, sizeof(buf));
4552 if (r >= 0 && !strncmp(buf, XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT)))
4557 r = _fgetattrs(**fd, inline_set);
4558 incomplete_inline = (r == -E2BIG);
4559 assert(!m_filestore_fail_eio || r != -EIO);
4560 dout(15) << __FUNC__ << ": " << cid << "/" << oid
4561 << (incomplete_inline ? " (incomplete_inline, forcing omap)" : "")
4564 for (map<string,bufferptr>::iterator p = aset.begin();
4567 char n[CHAIN_XATTR_MAX_NAME_LEN];
4568 get_attrname(p->first.c_str(), n, CHAIN_XATTR_MAX_NAME_LEN);
4570 if (incomplete_inline) {
4571 chain_fremovexattr(**fd, n); // ignore any error
4572 omap_set[p->first].push_back(p->second);
4576 if (p->second.length() > m_filestore_max_inline_xattr_size) {
4577 if (inline_set.count(p->first)) {
4578 inline_set.erase(p->first);
4579 r = chain_fremovexattr(**fd, n);
4583 omap_set[p->first].push_back(p->second);
4587 if (!inline_set.count(p->first) &&
4588 inline_set.size() >= m_filestore_max_inline_xattrs) {
4589 omap_set[p->first].push_back(p->second);
4592 omap_remove.insert(p->first);
4593 inline_set.insert(*p);
4595 inline_to_set.insert(*p);
4598 if (spill_out != 1 && !omap_set.empty()) {
4599 chain_fsetxattr(**fd, XATTR_SPILL_OUT_NAME, XATTR_SPILL_OUT,
4600 sizeof(XATTR_SPILL_OUT));
4603 r = _fsetattrs(**fd, inline_to_set);
4607 if (spill_out && !omap_remove.empty()) {
4608 r = object_map->remove_xattrs(oid, omap_remove, &spos);
4609 if (r < 0 && r != -ENOENT) {
4610 dout(10) << __FUNC__ << ": could not remove_xattrs r = " << r << dendl;
4611 assert(!m_filestore_fail_eio || r != -EIO);
4614 r = 0; // don't confuse the debug output
4618 if (!omap_set.empty()) {
4619 r = object_map->set_xattrs(oid, omap_set, &spos);
4621 dout(10) << __FUNC__ << ": could not set_xattrs r = " << r << dendl;
4622 assert(!m_filestore_fail_eio || r != -EIO);
4629 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " = " << r << dendl;
4634 int FileStore::_rmattr(const coll_t& cid, const ghobject_t& oid, const char *name,
4635 const SequencerPosition &spos)
4637 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " '" << name << "'" << dendl;
4639 bool spill_out = true;
4641 int r = lfn_open(cid, oid, false, &fd);
4647 r = chain_fgetxattr(**fd, XATTR_SPILL_OUT_NAME, buf, sizeof(buf));
4648 if (r >= 0 && !strncmp(buf, XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT))) {
4652 char n[CHAIN_XATTR_MAX_NAME_LEN];
4653 get_attrname(name, n, CHAIN_XATTR_MAX_NAME_LEN);
4654 r = chain_fremovexattr(**fd, n);
4655 if (r == -ENODATA && spill_out) {
4657 r = get_index(cid, &index);
4659 dout(10) << __FUNC__ << ": could not get index r = " << r << dendl;
4662 set<string> to_remove;
4663 to_remove.insert(string(name));
4664 r = object_map->remove_xattrs(oid, to_remove, &spos);
4665 if (r < 0 && r != -ENOENT) {
4666 dout(10) << __FUNC__ << ": could not remove_xattrs index r = " << r << dendl;
4667 assert(!m_filestore_fail_eio || r != -EIO);
4674 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " '" << name << "' = " << r << dendl;
4678 int FileStore::_rmattrs(const coll_t& cid, const ghobject_t& oid,
4679 const SequencerPosition &spos)
4681 dout(15) << __FUNC__ << ": " << cid << "/" << oid << dendl;
4683 map<string,bufferptr> aset;
4685 set<string> omap_attrs;
4687 bool spill_out = true;
4689 int r = lfn_open(cid, oid, false, &fd);
4695 r = chain_fgetxattr(**fd, XATTR_SPILL_OUT_NAME, buf, sizeof(buf));
4696 if (r >= 0 && !strncmp(buf, XATTR_NO_SPILL_OUT, sizeof(XATTR_NO_SPILL_OUT))) {
4700 r = _fgetattrs(**fd, aset);
4702 for (map<string,bufferptr>::iterator p = aset.begin(); p != aset.end(); ++p) {
4703 char n[CHAIN_XATTR_MAX_NAME_LEN];
4704 get_attrname(p->first.c_str(), n, CHAIN_XATTR_MAX_NAME_LEN);
4705 r = chain_fremovexattr(**fd, n);
4707 dout(10) << __FUNC__ << ": could not remove xattr r = " << r << dendl;
4714 dout(10) << __FUNC__ << ": no xattr exists in object_map r = " << r << dendl;
4718 r = get_index(cid, &index);
4720 dout(10) << __FUNC__ << ": could not get index r = " << r << dendl;
4724 r = object_map->get_all_xattrs(oid, &omap_attrs);
4725 if (r < 0 && r != -ENOENT) {
4726 dout(10) << __FUNC__ << ": could not get omap_attrs r = " << r << dendl;
4727 assert(!m_filestore_fail_eio || r != -EIO);
4730 r = object_map->remove_xattrs(oid, omap_attrs, &spos);
4731 if (r < 0 && r != -ENOENT) {
4732 dout(10) << __FUNC__ << ": could not remove omap_attrs r = " << r << dendl;
4737 chain_fsetxattr(**fd, XATTR_SPILL_OUT_NAME, XATTR_NO_SPILL_OUT,
4738 sizeof(XATTR_NO_SPILL_OUT));
4744 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " = " << r << dendl;
4751 int FileStore::_collection_remove_recursive(const coll_t &cid,
4752 const SequencerPosition &spos)
4755 int r = collection_stat(cid, &st);
4762 vector<ghobject_t> objects;
4764 while (!max.is_max()) {
4765 r = collection_list(cid, max, ghobject_t::get_max(),
4766 300, &objects, &max);
4769 for (vector<ghobject_t>::iterator i = objects.begin();
4772 assert(_check_replay_guard(cid, *i, spos));
4773 r = _remove(cid, *i, spos);
4779 return _destroy_collection(cid);
4782 // --------------------------
4785 int FileStore::list_collections(vector<coll_t>& ls)
4787 return list_collections(ls, false);
4790 int FileStore::list_collections(vector<coll_t>& ls, bool include_temp)
4792 tracepoint(objectstore, list_collections_enter);
4793 dout(10) << __FUNC__ << dendl;
4796 snprintf(fn, sizeof(fn), "%s/current", basedir.c_str());
4799 DIR *dir = ::opendir(fn);
4802 derr << "tried opening directory " << fn << ": " << cpp_strerror(-r) << dendl;
4803 assert(!m_filestore_fail_eio || r != -EIO);
4807 struct dirent *de = nullptr;
4808 while ((de = ::readdir(dir))) {
4809 if (de->d_type == DT_UNKNOWN) {
4810 // d_type not supported (non-ext[234], btrfs), must stat
4812 char filename[PATH_MAX];
4813 snprintf(filename, sizeof(filename), "%s/%s", fn, de->d_name);
4815 r = ::stat(filename, &sb);
4818 derr << "stat on " << filename << ": " << cpp_strerror(-r) << dendl;
4819 assert(!m_filestore_fail_eio || r != -EIO);
4822 if (!S_ISDIR(sb.st_mode)) {
4825 } else if (de->d_type != DT_DIR) {
4828 if (strcmp(de->d_name, "omap") == 0) {
4831 if (de->d_name[0] == '.' &&
4832 (de->d_name[1] == '\0' ||
4833 (de->d_name[1] == '.' &&
4834 de->d_name[2] == '\0')))
4837 if (!cid.parse(de->d_name)) {
4838 derr << "ignoring invalid collection '" << de->d_name << "'" << dendl;
4841 if (!cid.is_temp() || include_temp)
4846 derr << "trying readdir " << fn << ": " << cpp_strerror(r) << dendl;
4851 assert(!m_filestore_fail_eio || r != -EIO);
4852 tracepoint(objectstore, list_collections_exit, r);
4856 int FileStore::collection_stat(const coll_t& c, struct stat *st)
4858 tracepoint(objectstore, collection_stat_enter, c.c_str());
4860 get_cdir(c, fn, sizeof(fn));
4861 dout(15) << __FUNC__ << ": " << fn << dendl;
4862 int r = ::stat(fn, st);
4865 dout(10) << __FUNC__ << ": " << fn << " = " << r << dendl;
4866 assert(!m_filestore_fail_eio || r != -EIO);
4867 tracepoint(objectstore, collection_stat_exit, r);
4871 bool FileStore::collection_exists(const coll_t& c)
4873 tracepoint(objectstore, collection_exists_enter, c.c_str());
4875 bool ret = collection_stat(c, &st) == 0;
4876 tracepoint(objectstore, collection_exists_exit, ret);
4880 int FileStore::collection_empty(const coll_t& c, bool *empty)
4882 tracepoint(objectstore, collection_empty_enter, c.c_str());
4883 dout(15) << __FUNC__ << ": " << c << dendl;
4885 int r = get_index(c, &index);
4887 derr << __FUNC__ << ": get_index returned: " << cpp_strerror(r)
4892 assert(NULL != index.index);
4893 RWLock::RLocker l((index.index)->access_lock);
4895 vector<ghobject_t> ls;
4896 r = index->collection_list_partial(ghobject_t(), ghobject_t::get_max(),
4899 derr << __FUNC__ << ": collection_list_partial returned: "
4900 << cpp_strerror(r) << dendl;
4901 assert(!m_filestore_fail_eio || r != -EIO);
4904 *empty = ls.empty();
4905 tracepoint(objectstore, collection_empty_exit, *empty);
4909 int FileStore::_collection_set_bits(const coll_t& c, int bits)
4912 get_cdir(c, fn, sizeof(fn));
4913 dout(10) << __FUNC__ << ": " << fn << " " << bits << dendl;
4917 int fd = ::open(fn, O_RDONLY);
4922 get_attrname("bits", n, PATH_MAX);
4923 r = chain_fsetxattr(fd, n, (char*)&v, sizeof(v));
4924 VOID_TEMP_FAILURE_RETRY(::close(fd));
4926 dout(10) << __FUNC__ << ": " << fn << " " << bits << " = " << r << dendl;
4930 int FileStore::collection_bits(const coll_t& c)
4933 get_cdir(c, fn, sizeof(fn));
4934 dout(15) << __FUNC__ << ": " << fn << dendl;
4938 int fd = ::open(fn, O_RDONLY);
4943 get_attrname("bits", n, PATH_MAX);
4944 r = chain_fgetxattr(fd, n, (char*)&bits, sizeof(bits));
4945 VOID_TEMP_FAILURE_RETRY(::close(fd));
4951 dout(10) << __FUNC__ << ": " << fn << " = " << bits << dendl;
4955 int FileStore::collection_list(const coll_t& c,
4956 const ghobject_t& orig_start,
4957 const ghobject_t& end,
4959 vector<ghobject_t> *ls, ghobject_t *next)
4961 ghobject_t start = orig_start;
4965 ghobject_t temp_next;
4968 // figure out the pool id. we need this in order to generate a
4969 // meaningful 'next' value.
4974 if (c.is_temp(&pgid)) {
4975 pool = -2 - pgid.pool();
4977 } else if (c.is_pg(&pgid)) {
4980 } else if (c.is_meta()) {
4982 shard = shard_id_t::NO_SHARD;
4984 // hrm, the caller is test code! we should get kill it off. for now,
4987 shard = shard_id_t::NO_SHARD;
4989 dout(20) << __FUNC__ << ": pool is " << pool << " shard is " << shard
4990 << " pgid " << pgid << dendl;
4994 sep.set_shard(shard);
4995 if (!c.is_temp() && !c.is_meta()) {
4997 dout(10) << __FUNC__ << ": first checking temp pool" << dendl;
4998 coll_t temp = c.get_temp();
4999 int r = collection_list(temp, start, end, max, ls, next);
5002 if (*next != ghobject_t::get_max())
5005 dout(10) << __FUNC__ << ": fall through to non-temp collection, start "
5008 dout(10) << __FUNC__ << ": start " << start << " >= sep " << sep << dendl;
5013 int r = get_index(c, &index);
5017 assert(NULL != index.index);
5018 RWLock::RLocker l((index.index)->access_lock);
5020 r = index->collection_list_partial(start, end, max, ls, next);
5023 assert(!m_filestore_fail_eio || r != -EIO);
5026 dout(20) << "objects: " << *ls << dendl;
5028 // HashIndex doesn't know the pool when constructing a 'next' value
5029 if (next && !next->is_max()) {
5030 next->hobj.pool = pool;
5031 next->set_shard(shard);
5032 dout(20) << " next " << *next << dendl;
5038 int FileStore::omap_get(const coll_t& _c, const ghobject_t &hoid,
5040 map<string, bufferlist> *out)
5042 tracepoint(objectstore, omap_get_enter, _c.c_str());
5043 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5044 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5046 int r = get_index(c, &index);
5050 assert(NULL != index.index);
5051 RWLock::RLocker l((index.index)->access_lock);
5052 r = lfn_find(hoid, index);
5056 r = object_map->get(hoid, header, out);
5057 if (r < 0 && r != -ENOENT) {
5058 assert(!m_filestore_fail_eio || r != -EIO);
5061 tracepoint(objectstore, omap_get_exit, 0);
5065 int FileStore::omap_get_header(
5067 const ghobject_t &hoid,
5071 tracepoint(objectstore, omap_get_header_enter, _c.c_str());
5072 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5073 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5075 int r = get_index(c, &index);
5079 assert(NULL != index.index);
5080 RWLock::RLocker l((index.index)->access_lock);
5081 r = lfn_find(hoid, index);
5085 r = object_map->get_header(hoid, bl);
5086 if (r < 0 && r != -ENOENT) {
5087 assert(allow_eio || !m_filestore_fail_eio || r != -EIO);
5090 tracepoint(objectstore, omap_get_header_exit, 0);
5094 int FileStore::omap_get_keys(const coll_t& _c, const ghobject_t &hoid, set<string> *keys)
5096 tracepoint(objectstore, omap_get_keys_enter, _c.c_str());
5097 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5098 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5100 int r = get_index(c, &index);
5104 assert(NULL != index.index);
5105 RWLock::RLocker l((index.index)->access_lock);
5106 r = lfn_find(hoid, index);
5110 r = object_map->get_keys(hoid, keys);
5111 if (r < 0 && r != -ENOENT) {
5112 assert(!m_filestore_fail_eio || r != -EIO);
5115 tracepoint(objectstore, omap_get_keys_exit, 0);
5119 int FileStore::omap_get_values(const coll_t& _c, const ghobject_t &hoid,
5120 const set<string> &keys,
5121 map<string, bufferlist> *out)
5123 tracepoint(objectstore, omap_get_values_enter, _c.c_str());
5124 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5125 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5127 const char *where = "()";
5128 int r = get_index(c, &index);
5130 where = " (get_index)";
5134 assert(NULL != index.index);
5135 RWLock::RLocker l((index.index)->access_lock);
5136 r = lfn_find(hoid, index);
5138 where = " (lfn_find)";
5142 r = object_map->get_values(hoid, keys, out);
5143 if (r < 0 && r != -ENOENT) {
5144 assert(!m_filestore_fail_eio || r != -EIO);
5145 where = " (get_values)";
5150 tracepoint(objectstore, omap_get_values_exit, r);
5151 dout(15) << __FUNC__ << ": " << c << "/" << hoid << " = " << r
5156 int FileStore::omap_check_keys(const coll_t& _c, const ghobject_t &hoid,
5157 const set<string> &keys,
5160 tracepoint(objectstore, omap_check_keys_enter, _c.c_str());
5161 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5162 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5165 int r = get_index(c, &index);
5169 assert(NULL != index.index);
5170 RWLock::RLocker l((index.index)->access_lock);
5171 r = lfn_find(hoid, index);
5175 r = object_map->check_keys(hoid, keys, out);
5176 if (r < 0 && r != -ENOENT) {
5177 assert(!m_filestore_fail_eio || r != -EIO);
5180 tracepoint(objectstore, omap_check_keys_exit, 0);
5184 ObjectMap::ObjectMapIterator FileStore::get_omap_iterator(const coll_t& _c,
5185 const ghobject_t &hoid)
5187 tracepoint(objectstore, get_omap_iterator, _c.c_str());
5188 const coll_t& c = !_need_temp_object_collection(_c, hoid) ? _c : _c.get_temp();
5189 dout(15) << __FUNC__ << ": " << c << "/" << hoid << dendl;
5191 int r = get_index(c, &index);
5193 dout(10) << __FUNC__ << ": " << c << "/" << hoid << " = 0 "
5194 << "(get_index failed with " << cpp_strerror(r) << ")" << dendl;
5195 return ObjectMap::ObjectMapIterator();
5198 assert(NULL != index.index);
5199 RWLock::RLocker l((index.index)->access_lock);
5200 r = lfn_find(hoid, index);
5202 dout(10) << __FUNC__ << ": " << c << "/" << hoid << " = 0 "
5203 << "(lfn_find failed with " << cpp_strerror(r) << ")" << dendl;
5204 return ObjectMap::ObjectMapIterator();
5207 return object_map->get_iterator(hoid);
5210 int FileStore::_collection_hint_expected_num_objs(const coll_t& c, uint32_t pg_num,
5211 uint64_t expected_num_objs,
5212 const SequencerPosition &spos)
5214 dout(15) << __FUNC__ << ": collection: " << c << " pg number: "
5215 << pg_num << " expected number of objects: " << expected_num_objs << dendl;
5218 int ret = collection_empty(c, &empty);
5221 if (!empty && !replaying) {
5222 dout(0) << "Failed to give an expected number of objects hint to collection : "
5223 << c << ", only empty collection can take such type of hint. " << dendl;
5228 ret = get_index(c, &index);
5231 // Pre-hash the collection
5232 ret = index->pre_hash_collection(pg_num, expected_num_objs);
5233 dout(10) << "pre_hash_collection " << c << " = " << ret << dendl;
5236 _set_replay_guard(c, spos);
5241 int FileStore::_create_collection(
5244 const SequencerPosition &spos)
5247 get_cdir(c, fn, sizeof(fn));
5248 dout(15) << __FUNC__ << ": " << fn << dendl;
5249 int r = ::mkdir(fn, 0755);
5252 if (r == -EEXIST && replaying)
5254 dout(10) << __FUNC__ << ": " << fn << " = " << r << dendl;
5261 r = _collection_set_bits(c, bits);
5264 // create parallel temp collection, too
5265 if (!c.is_meta() && !c.is_temp()) {
5266 coll_t temp = c.get_temp();
5267 r = _create_collection(temp, 0, spos);
5272 _set_replay_guard(c, spos);
5276 int FileStore::_destroy_collection(const coll_t& c)
5280 get_cdir(c, fn, sizeof(fn));
5281 dout(15) << __FUNC__ << ": " << fn << dendl;
5284 r = get_index(c, &from);
5287 assert(NULL != from.index);
5288 RWLock::WLocker l((from.index)->access_lock);
5290 r = from->prep_delete();
5301 // destroy parallel temp collection, too
5302 if (!c.is_meta() && !c.is_temp()) {
5303 coll_t temp = c.get_temp();
5304 int r2 = _destroy_collection(temp);
5312 dout(10) << __FUNC__ << ": " << fn << " = " << r << dendl;
5317 int FileStore::_collection_add(const coll_t& c, const coll_t& oldcid, const ghobject_t& o,
5318 const SequencerPosition& spos)
5320 dout(15) << __FUNC__ << ": " << c << "/" << o << " from " << oldcid << "/" << o << dendl;
5322 int dstcmp = _check_replay_guard(c, o, spos);
5326 // check the src name too; it might have a newer guard, and we don't
5327 // want to clobber it
5328 int srccmp = _check_replay_guard(oldcid, o, spos);
5332 // open guard on object so we don't any previous operations on the
5333 // new name that will modify the source inode.
5335 int r = lfn_open(oldcid, o, 0, &fd);
5337 // the source collection/object does not exist. If we are replaying, we
5338 // should be safe, so just return 0 and move on.
5340 dout(10) << __FUNC__ << ": " << c << "/" << o << " from "
5341 << oldcid << "/" << o << " (dne, continue replay) " << dendl;
5344 if (dstcmp > 0) { // if dstcmp == 0 the guard already says "in-progress"
5345 _set_replay_guard(**fd, spos, &o, true);
5348 r = lfn_link(oldcid, c, o, o);
5349 if (replaying && !backend->can_checkpoint() &&
5350 r == -EEXIST) // crashed between link() and set_replay_guard()
5355 // close guard on object so we don't do this again
5357 _close_replay_guard(**fd, spos);
5361 dout(10) << __FUNC__ << ": " << c << "/" << o << " from " << oldcid << "/" << o << " = " << r << dendl;
5365 int FileStore::_collection_move_rename(const coll_t& oldcid, const ghobject_t& oldoid,
5366 coll_t c, const ghobject_t& o,
5367 const SequencerPosition& spos,
5370 dout(15) << __FUNC__ << ": " << c << "/" << o << " from " << oldcid << "/" << oldoid << dendl;
5375 /* If the destination collection doesn't exist during replay,
5376 * we need to delete the src object and continue on
5378 if (!collection_exists(c))
5382 dstcmp = _check_replay_guard(c, o, spos);
5386 // check the src name too; it might have a newer guard, and we don't
5387 // want to clobber it
5388 srccmp = _check_replay_guard(oldcid, oldoid, spos);
5393 // open guard on object so we don't any previous operations on the
5394 // new name that will modify the source inode.
5396 r = lfn_open(oldcid, oldoid, 0, &fd);
5398 // the source collection/object does not exist. If we are replaying, we
5399 // should be safe, so just return 0 and move on.
5401 dout(10) << __FUNC__ << ": " << c << "/" << o << " from "
5402 << oldcid << "/" << oldoid << " (dne, continue replay) " << dendl;
5403 } else if (allow_enoent) {
5404 dout(10) << __FUNC__ << ": " << c << "/" << o << " from "
5405 << oldcid << "/" << oldoid << " (dne, ignoring enoent)"
5408 assert(0 == "ERROR: source must exist");
5414 if (allow_enoent && dstcmp > 0) { // if dstcmp == 0, try_rename was started.
5418 r = 0; // don't know if object_map was cloned
5420 if (dstcmp > 0) { // if dstcmp == 0 the guard already says "in-progress"
5421 _set_replay_guard(**fd, spos, &o, true);
5424 r = lfn_link(oldcid, c, oldoid, o);
5425 if (replaying && !backend->can_checkpoint() &&
5426 r == -EEXIST) // crashed between link() and set_replay_guard()
5436 // the name changed; link the omap content
5437 r = object_map->rename(oldoid, o, &spos);
5445 r = lfn_unlink(oldcid, oldoid, spos, true);
5448 r = lfn_open(c, o, 0, &fd);
5450 // close guard on object so we don't do this again
5452 _close_replay_guard(**fd, spos, &o);
5457 dout(10) << __FUNC__ << ": " << c << "/" << o << " from " << oldcid << "/" << oldoid
5458 << " = " << r << dendl;
5463 if (_check_replay_guard(oldcid, oldoid, spos) > 0) {
5464 r = lfn_unlink(oldcid, oldoid, spos, true);
5467 dout(10) << __FUNC__ << ": " << c << "/" << o << " from " << oldcid << "/" << oldoid
5468 << " = " << r << dendl;
5472 void FileStore::_inject_failure()
5474 if (m_filestore_kill_at) {
5475 int final = --m_filestore_kill_at;
5476 dout(5) << __FUNC__ << ": " << (final+1) << " -> " << final << dendl;
5478 derr << __FUNC__ << ": KILLING" << dendl;
5485 int FileStore::_omap_clear(const coll_t& cid, const ghobject_t &hoid,
5486 const SequencerPosition &spos) {
5487 dout(15) << __FUNC__ << ": " << cid << "/" << hoid << dendl;
5489 int r = get_index(cid, &index);
5493 assert(NULL != index.index);
5494 RWLock::RLocker l((index.index)->access_lock);
5495 r = lfn_find(hoid, index);
5499 r = object_map->clear_keys_header(hoid, &spos);
5500 if (r < 0 && r != -ENOENT)
5505 int FileStore::_omap_setkeys(const coll_t& cid, const ghobject_t &hoid,
5506 const map<string, bufferlist> &aset,
5507 const SequencerPosition &spos) {
5508 dout(15) << __FUNC__ << ": " << cid << "/" << hoid << dendl;
5511 //treat pgmeta as a logical object, skip to check exist
5512 if (hoid.is_pgmeta())
5515 r = get_index(cid, &index);
5517 dout(20) << __FUNC__ << ": get_index got " << cpp_strerror(r) << dendl;
5521 assert(NULL != index.index);
5522 RWLock::RLocker l((index.index)->access_lock);
5523 r = lfn_find(hoid, index);
5525 dout(20) << __FUNC__ << ": lfn_find got " << cpp_strerror(r) << dendl;
5530 if (g_conf->subsys.should_gather(ceph_subsys_filestore, 20)) {
5531 for (auto& p : aset) {
5532 dout(20) << __FUNC__ << ": set " << p.first << dendl;
5535 r = object_map->set_keys(hoid, aset, &spos);
5536 dout(20) << __FUNC__ << ": " << cid << "/" << hoid << " = " << r << dendl;
5540 int FileStore::_omap_rmkeys(const coll_t& cid, const ghobject_t &hoid,
5541 const set<string> &keys,
5542 const SequencerPosition &spos) {
5543 dout(15) << __FUNC__ << ": " << cid << "/" << hoid << dendl;
5546 //treat pgmeta as a logical object, skip to check exist
5547 if (hoid.is_pgmeta())
5550 r = get_index(cid, &index);
5554 assert(NULL != index.index);
5555 RWLock::RLocker l((index.index)->access_lock);
5556 r = lfn_find(hoid, index);
5561 r = object_map->rm_keys(hoid, keys, &spos);
5562 if (r < 0 && r != -ENOENT)
5567 int FileStore::_omap_rmkeyrange(const coll_t& cid, const ghobject_t &hoid,
5568 const string& first, const string& last,
5569 const SequencerPosition &spos) {
5570 dout(15) << __FUNC__ << ": " << cid << "/" << hoid << " [" << first << "," << last << "]" << dendl;
5573 ObjectMap::ObjectMapIterator iter = get_omap_iterator(cid, hoid);
5576 for (iter->lower_bound(first); iter->valid() && iter->key() < last;
5578 keys.insert(iter->key());
5581 return _omap_rmkeys(cid, hoid, keys, spos);
5584 int FileStore::_omap_setheader(const coll_t& cid, const ghobject_t &hoid,
5585 const bufferlist &bl,
5586 const SequencerPosition &spos)
5588 dout(15) << __FUNC__ << ": " << cid << "/" << hoid << dendl;
5590 int r = get_index(cid, &index);
5594 assert(NULL != index.index);
5595 RWLock::RLocker l((index.index)->access_lock);
5596 r = lfn_find(hoid, index);
5600 return object_map->set_header(hoid, bl, &spos);
5603 int FileStore::_split_collection(const coll_t& cid,
5607 const SequencerPosition &spos)
5611 dout(15) << __FUNC__ << ": " << cid << " bits: " << bits << dendl;
5612 if (!collection_exists(cid)) {
5613 dout(2) << __FUNC__ << ": " << cid << " DNE" << dendl;
5617 if (!collection_exists(dest)) {
5618 dout(2) << __FUNC__ << ": " << dest << " DNE" << dendl;
5623 int dstcmp = _check_replay_guard(dest, spos);
5627 int srccmp = _check_replay_guard(cid, spos);
5631 _set_global_replay_guard(cid, spos);
5632 _set_replay_guard(cid, spos, true);
5633 _set_replay_guard(dest, spos, true);
5636 r = get_index(cid, &from);
5640 r = get_index(dest, &to);
5643 assert(NULL != from.index);
5644 RWLock::WLocker l1((from.index)->access_lock);
5646 assert(NULL != to.index);
5647 RWLock::WLocker l2((to.index)->access_lock);
5649 r = from->split(rem, bits, to.index);
5652 _close_replay_guard(cid, spos);
5653 _close_replay_guard(dest, spos);
5655 _collection_set_bits(cid, bits);
5656 if (!r && cct->_conf->filestore_debug_verify_split) {
5657 vector<ghobject_t> objects;
5662 next, ghobject_t::get_max(),
5663 get_ideal_list_max(),
5666 if (objects.empty())
5668 for (vector<ghobject_t>::iterator i = objects.begin();
5671 dout(20) << __FUNC__ << ": " << *i << " still in source "
5673 assert(!i->match(bits, rem));
5677 next = ghobject_t();
5681 next, ghobject_t::get_max(),
5682 get_ideal_list_max(),
5685 if (objects.empty())
5687 for (vector<ghobject_t>::iterator i = objects.begin();
5690 dout(20) << __FUNC__ << ": " << *i << " now in dest "
5692 assert(i->match(bits, rem));
5700 int FileStore::_set_alloc_hint(const coll_t& cid, const ghobject_t& oid,
5701 uint64_t expected_object_size,
5702 uint64_t expected_write_size)
5704 dout(15) << __FUNC__ << ": " << cid << "/" << oid << " object_size " << expected_object_size << " write_size " << expected_write_size << dendl;
5709 if (expected_object_size == 0 || expected_write_size == 0)
5712 ret = lfn_open(cid, oid, false, &fd);
5717 // TODO: a more elaborate hint calculation
5718 uint64_t hint = MIN(expected_write_size, m_filestore_max_alloc_hint_size);
5720 ret = backend->set_alloc_hint(**fd, hint);
5721 dout(20) << __FUNC__ << ": hint " << hint << " ret " << ret << dendl;
5726 dout(10) << __FUNC__ << ": " << cid << "/" << oid << " object_size " << expected_object_size << " write_size " << expected_write_size << " = " << ret << dendl;
5727 assert(!m_filestore_fail_eio || ret != -EIO);
5731 const char** FileStore::get_tracked_conf_keys() const
5733 static const char* KEYS[] = {
5734 "filestore_max_inline_xattr_size",
5735 "filestore_max_inline_xattr_size_xfs",
5736 "filestore_max_inline_xattr_size_btrfs",
5737 "filestore_max_inline_xattr_size_other",
5738 "filestore_max_inline_xattrs",
5739 "filestore_max_inline_xattrs_xfs",
5740 "filestore_max_inline_xattrs_btrfs",
5741 "filestore_max_inline_xattrs_other",
5742 "filestore_max_xattr_value_size",
5743 "filestore_max_xattr_value_size_xfs",
5744 "filestore_max_xattr_value_size_btrfs",
5745 "filestore_max_xattr_value_size_other",
5746 "filestore_min_sync_interval",
5747 "filestore_max_sync_interval",
5748 "filestore_queue_max_ops",
5749 "filestore_queue_max_bytes",
5750 "filestore_expected_throughput_bytes",
5751 "filestore_expected_throughput_ops",
5752 "filestore_queue_low_threshhold",
5753 "filestore_queue_high_threshhold",
5754 "filestore_queue_high_delay_multiple",
5755 "filestore_queue_max_delay_multiple",
5756 "filestore_commit_timeout",
5757 "filestore_dump_file",
5758 "filestore_kill_at",
5759 "filestore_fail_eio",
5760 "filestore_fadvise",
5761 "filestore_sloppy_crc",
5762 "filestore_sloppy_crc_block_size",
5763 "filestore_max_alloc_hint_size",
5769 void FileStore::handle_conf_change(const struct md_config_t *conf,
5770 const std::set <std::string> &changed)
5772 if (changed.count("filestore_max_inline_xattr_size") ||
5773 changed.count("filestore_max_inline_xattr_size_xfs") ||
5774 changed.count("filestore_max_inline_xattr_size_btrfs") ||
5775 changed.count("filestore_max_inline_xattr_size_other") ||
5776 changed.count("filestore_max_inline_xattrs") ||
5777 changed.count("filestore_max_inline_xattrs_xfs") ||
5778 changed.count("filestore_max_inline_xattrs_btrfs") ||
5779 changed.count("filestore_max_inline_xattrs_other") ||
5780 changed.count("filestore_max_xattr_value_size") ||
5781 changed.count("filestore_max_xattr_value_size_xfs") ||
5782 changed.count("filestore_max_xattr_value_size_btrfs") ||
5783 changed.count("filestore_max_xattr_value_size_other")) {
5785 Mutex::Locker l(lock);
5786 set_xattr_limits_via_conf();
5790 if (changed.count("filestore_queue_max_bytes") ||
5791 changed.count("filestore_queue_max_ops") ||
5792 changed.count("filestore_expected_throughput_bytes") ||
5793 changed.count("filestore_expected_throughput_ops") ||
5794 changed.count("filestore_queue_low_threshhold") ||
5795 changed.count("filestore_queue_high_threshhold") ||
5796 changed.count("filestore_queue_high_delay_multiple") ||
5797 changed.count("filestore_queue_max_delay_multiple")) {
5798 Mutex::Locker l(lock);
5799 set_throttle_params();
5802 if (changed.count("filestore_min_sync_interval") ||
5803 changed.count("filestore_max_sync_interval") ||
5804 changed.count("filestore_kill_at") ||
5805 changed.count("filestore_fail_eio") ||
5806 changed.count("filestore_sloppy_crc") ||
5807 changed.count("filestore_sloppy_crc_block_size") ||
5808 changed.count("filestore_max_alloc_hint_size") ||
5809 changed.count("filestore_fadvise")) {
5810 Mutex::Locker l(lock);
5811 m_filestore_min_sync_interval = conf->filestore_min_sync_interval;
5812 m_filestore_max_sync_interval = conf->filestore_max_sync_interval;
5813 m_filestore_kill_at = conf->filestore_kill_at;
5814 m_filestore_fail_eio = conf->filestore_fail_eio;
5815 m_filestore_fadvise = conf->filestore_fadvise;
5816 m_filestore_sloppy_crc = conf->filestore_sloppy_crc;
5817 m_filestore_sloppy_crc_block_size = conf->filestore_sloppy_crc_block_size;
5818 m_filestore_max_alloc_hint_size = conf->filestore_max_alloc_hint_size;
5820 if (changed.count("filestore_commit_timeout")) {
5821 Mutex::Locker l(sync_entry_timeo_lock);
5822 m_filestore_commit_timeout = conf->filestore_commit_timeout;
5824 if (changed.count("filestore_dump_file")) {
5825 if (conf->filestore_dump_file.length() &&
5826 conf->filestore_dump_file != "-") {
5827 dump_start(conf->filestore_dump_file);
5834 int FileStore::set_throttle_params()
5837 bool valid = throttle_bytes.set_params(
5838 cct->_conf->filestore_queue_low_threshhold,
5839 cct->_conf->filestore_queue_high_threshhold,
5840 cct->_conf->filestore_expected_throughput_bytes,
5841 cct->_conf->filestore_queue_high_delay_multiple,
5842 cct->_conf->filestore_queue_max_delay_multiple,
5843 cct->_conf->filestore_queue_max_bytes,
5846 valid &= throttle_ops.set_params(
5847 cct->_conf->filestore_queue_low_threshhold,
5848 cct->_conf->filestore_queue_high_threshhold,
5849 cct->_conf->filestore_expected_throughput_ops,
5850 cct->_conf->filestore_queue_high_delay_multiple,
5851 cct->_conf->filestore_queue_max_delay_multiple,
5852 cct->_conf->filestore_queue_max_ops,
5855 logger->set(l_filestore_op_queue_max_ops, throttle_ops.get_max());
5856 logger->set(l_filestore_op_queue_max_bytes, throttle_bytes.get_max());
5859 derr << "tried to set invalid params: "
5863 return valid ? 0 : -EINVAL;
5866 void FileStore::dump_start(const std::string& file)
5868 dout(10) << __FUNC__ << ": " << file << dendl;
5869 if (m_filestore_do_dump) {
5872 m_filestore_dump_fmt.reset();
5873 m_filestore_dump_fmt.open_array_section("dump");
5874 m_filestore_dump.open(file.c_str());
5875 m_filestore_do_dump = true;
5878 void FileStore::dump_stop()
5880 dout(10) << __FUNC__ << dendl;
5881 m_filestore_do_dump = false;
5882 if (m_filestore_dump.is_open()) {
5883 m_filestore_dump_fmt.close_section();
5884 m_filestore_dump_fmt.flush(m_filestore_dump);
5885 m_filestore_dump.flush();
5886 m_filestore_dump.close();
5890 void FileStore::dump_transactions(vector<ObjectStore::Transaction>& ls, uint64_t seq, OpSequencer *osr)
5892 m_filestore_dump_fmt.open_array_section("transactions");
5893 unsigned trans_num = 0;
5894 for (vector<ObjectStore::Transaction>::iterator i = ls.begin(); i != ls.end(); ++i, ++trans_num) {
5895 m_filestore_dump_fmt.open_object_section("transaction");
5896 m_filestore_dump_fmt.dump_string("osr", osr->get_name());
5897 m_filestore_dump_fmt.dump_unsigned("seq", seq);
5898 m_filestore_dump_fmt.dump_unsigned("trans_num", trans_num);
5899 (*i).dump(&m_filestore_dump_fmt);
5900 m_filestore_dump_fmt.close_section();
5902 m_filestore_dump_fmt.close_section();
5903 m_filestore_dump_fmt.flush(m_filestore_dump);
5904 m_filestore_dump.flush();
5907 void FileStore::set_xattr_limits_via_conf()
5909 uint32_t fs_xattr_size;
5911 uint32_t fs_xattr_max_value_size;
5913 switch (m_fs_type) {
5914 #if defined(__linux__)
5915 case XFS_SUPER_MAGIC:
5916 fs_xattr_size = cct->_conf->filestore_max_inline_xattr_size_xfs;
5917 fs_xattrs = cct->_conf->filestore_max_inline_xattrs_xfs;
5918 fs_xattr_max_value_size = cct->_conf->filestore_max_xattr_value_size_xfs;
5920 case BTRFS_SUPER_MAGIC:
5921 fs_xattr_size = cct->_conf->filestore_max_inline_xattr_size_btrfs;
5922 fs_xattrs = cct->_conf->filestore_max_inline_xattrs_btrfs;
5923 fs_xattr_max_value_size = cct->_conf->filestore_max_xattr_value_size_btrfs;
5927 fs_xattr_size = cct->_conf->filestore_max_inline_xattr_size_other;
5928 fs_xattrs = cct->_conf->filestore_max_inline_xattrs_other;
5929 fs_xattr_max_value_size = cct->_conf->filestore_max_xattr_value_size_other;
5933 // Use override value if set
5934 if (cct->_conf->filestore_max_inline_xattr_size)
5935 m_filestore_max_inline_xattr_size = cct->_conf->filestore_max_inline_xattr_size;
5937 m_filestore_max_inline_xattr_size = fs_xattr_size;
5939 // Use override value if set
5940 if (cct->_conf->filestore_max_inline_xattrs)
5941 m_filestore_max_inline_xattrs = cct->_conf->filestore_max_inline_xattrs;
5943 m_filestore_max_inline_xattrs = fs_xattrs;
5945 // Use override value if set
5946 if (cct->_conf->filestore_max_xattr_value_size)
5947 m_filestore_max_xattr_value_size = cct->_conf->filestore_max_xattr_value_size;
5949 m_filestore_max_xattr_value_size = fs_xattr_max_value_size;
5951 if (m_filestore_max_xattr_value_size < cct->_conf->osd_max_object_name_len) {
5952 derr << "WARNING: max attr value size ("
5953 << m_filestore_max_xattr_value_size
5954 << ") is smaller than osd_max_object_name_len ("
5955 << cct->_conf->osd_max_object_name_len
5956 << "). Your backend filesystem appears to not support attrs large "
5957 << "enough to handle the configured max rados name size. You may get "
5958 << "unexpected ENAMETOOLONG errors on rados operations or buggy "
5964 uint64_t FileStore::estimate_objects_overhead(uint64_t num_objects)
5966 uint64_t res = num_objects * blk_size / 2; //assumes that each object uses ( in average ) additional 1/2 block due to FS allocation granularity.
5970 int FileStore::apply_layout_settings(const coll_t &cid)
5972 dout(20) << __FUNC__ << ": " << cid << dendl;
5974 int r = get_index(cid, &index);
5976 dout(10) << "Error getting index for " << cid << ": " << cpp_strerror(r)
5981 return index->apply_layout_settings();
5985 // -- FSSuperblock --
5987 void FSSuperblock::encode(bufferlist &bl) const
5989 ENCODE_START(2, 1, bl);
5990 compat_features.encode(bl);
5991 ::encode(omap_backend, bl);
5995 void FSSuperblock::decode(bufferlist::iterator &bl)
5997 DECODE_START(2, bl);
5998 compat_features.decode(bl);
6000 ::decode(omap_backend, bl);
6002 omap_backend = "leveldb";
6006 void FSSuperblock::dump(Formatter *f) const
6008 f->open_object_section("compat");
6009 compat_features.dump(f);
6010 f->dump_string("omap_backend", omap_backend);
6014 void FSSuperblock::generate_test_instances(list<FSSuperblock*>& o)
6017 o.push_back(new FSSuperblock(z));
6018 CompatSet::FeatureSet feature_compat;
6019 CompatSet::FeatureSet feature_ro_compat;
6020 CompatSet::FeatureSet feature_incompat;
6021 feature_incompat.insert(CEPH_FS_FEATURE_INCOMPAT_SHARDS);
6022 z.compat_features = CompatSet(feature_compat, feature_ro_compat,
6024 o.push_back(new FSSuperblock(z));
6025 z.omap_backend = "rocksdb";
6026 o.push_back(new FSSuperblock(z));