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_uuid(get_fsid(), "PARTUUID", partition_path
,
699 (*pm
)["backend_filestore_partition_path"] = "unknown";
700 (*pm
)["backend_filestore_dev_node"] = "unknown";
703 (*pm
)["backend_filestore_partition_path"] = string(partition_path
);
704 (*pm
)["backend_filestore_dev_node"] = "unknown";
707 (*pm
)["backend_filestore_partition_path"] = string(partition_path
);
708 (*pm
)["backend_filestore_dev_node"] = string(dev_node
);
712 int FileStore::statfs(struct store_statfs_t
*buf0
)
716 if (::statfs(basedir
.c_str(), &buf
) < 0) {
718 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
719 assert(r
!= -ENOENT
);
722 buf0
->total
= buf
.f_blocks
* buf
.f_bsize
;
723 buf0
->available
= buf
.f_bavail
* buf
.f_bsize
;
724 // Adjust for writes pending in the journal
726 uint64_t estimate
= journal
->get_journal_size_estimate();
727 if (buf0
->available
> estimate
)
728 buf0
->available
-= estimate
;
736 void FileStore::new_journal()
738 if (journalpath
.length()) {
739 dout(10) << "open_journal at " << journalpath
<< dendl
;
740 journal
= new FileJournal(cct
, fsid
, &finisher
, &sync_cond
,
742 m_journal_dio
, m_journal_aio
,
743 m_journal_force_aio
);
745 journal
->logger
= logger
;
750 int FileStore::dump_journal(ostream
& out
)
754 if (!journalpath
.length())
757 FileJournal
*journal
= new FileJournal(cct
, fsid
, &finisher
, &sync_cond
, journalpath
.c_str(), m_journal_dio
);
758 r
= journal
->dump(out
);
763 FileStoreBackend
*FileStoreBackend::create(long f_type
, FileStore
*fs
)
766 #if defined(__linux__)
767 case BTRFS_SUPER_MAGIC
:
768 return new BtrfsFileStoreBackend(fs
);
770 case XFS_SUPER_MAGIC
:
771 return new XfsFileStoreBackend(fs
);
775 case ZFS_SUPER_MAGIC
:
776 return new ZFSFileStoreBackend(fs
);
779 return new GenericFileStoreBackend(fs
);
783 void FileStore::create_backend(long f_type
)
787 assert(backend
== NULL
);
788 backend
= FileStoreBackend::create(f_type
, this);
790 dout(0) << "backend " << backend
->get_name()
791 << " (magic 0x" << std::hex
<< f_type
<< std::dec
<< ")"
795 #if defined(__linux__)
796 case BTRFS_SUPER_MAGIC
:
797 if (!m_disable_wbthrottle
){
798 wbthrottle
.set_fs(WBThrottle::BTRFS
);
802 case XFS_SUPER_MAGIC
:
803 // wbthrottle is constructed with fs(WBThrottle::XFS)
808 set_xattr_limits_via_conf();
811 int FileStore::mkfs()
814 char fsid_fn
[PATH_MAX
];
817 uuid_d old_omap_fsid
;
819 dout(1) << "mkfs in " << basedir
<< dendl
;
820 basedir_fd
= ::open(basedir
.c_str(), O_RDONLY
);
821 if (basedir_fd
< 0) {
823 derr
<< __FUNC__
<< ": failed to open base dir " << basedir
<< ": " << cpp_strerror(ret
) << dendl
;
828 snprintf(fsid_fn
, sizeof(fsid_fn
), "%s/fsid", basedir
.c_str());
829 fsid_fd
= ::open(fsid_fn
, O_RDWR
|O_CREAT
, 0644);
832 derr
<< __FUNC__
<< ": failed to open " << fsid_fn
<< ": " << cpp_strerror(ret
) << dendl
;
833 goto close_basedir_fd
;
836 if (lock_fsid() < 0) {
841 if (read_fsid(fsid_fd
, &old_fsid
) < 0 || old_fsid
.is_zero()) {
842 if (fsid
.is_zero()) {
843 fsid
.generate_random();
844 dout(1) << __FUNC__
<< ": generated fsid " << fsid
<< dendl
;
846 dout(1) << __FUNC__
<< ": using provided fsid " << fsid
<< dendl
;
849 fsid
.print(fsid_str
);
850 strcat(fsid_str
, "\n");
851 ret
= ::ftruncate(fsid_fd
, 0);
854 derr
<< __FUNC__
<< ": failed to truncate fsid: "
855 << cpp_strerror(ret
) << dendl
;
858 ret
= safe_write(fsid_fd
, fsid_str
, strlen(fsid_str
));
860 derr
<< __FUNC__
<< ": failed to write fsid: "
861 << cpp_strerror(ret
) << dendl
;
864 if (::fsync(fsid_fd
) < 0) {
866 derr
<< __FUNC__
<< ": close failed: can't write fsid: "
867 << cpp_strerror(ret
) << dendl
;
870 dout(10) << __FUNC__
<< ": fsid is " << fsid
<< dendl
;
872 if (!fsid
.is_zero() && fsid
!= old_fsid
) {
873 derr
<< __FUNC__
<< ": on-disk fsid " << old_fsid
<< " != provided " << fsid
<< dendl
;
878 dout(1) << __FUNC__
<< ": fsid is already set to " << fsid
<< dendl
;
882 ret
= write_version_stamp();
884 derr
<< __FUNC__
<< ": write_version_stamp() failed: "
885 << cpp_strerror(ret
) << dendl
;
890 superblock
.omap_backend
= cct
->_conf
->filestore_omap_backend
;
891 ret
= write_superblock();
893 derr
<< __FUNC__
<< ": write_superblock() failed: "
894 << cpp_strerror(ret
) << dendl
;
898 struct statfs basefs
;
899 ret
= ::fstatfs(basedir_fd
, &basefs
);
902 derr
<< __FUNC__
<< ": cannot fstatfs basedir "
903 << cpp_strerror(ret
) << dendl
;
907 #if defined(__linux__)
908 if (basefs
.f_type
== BTRFS_SUPER_MAGIC
&&
909 !g_ceph_context
->check_experimental_feature_enabled("btrfs")) {
910 derr
<< __FUNC__
<< ": deprecated btrfs support is not enabled" << dendl
;
915 create_backend(basefs
.f_type
);
917 ret
= backend
->create_current();
919 derr
<< __FUNC__
<< ": failed to create current/ " << cpp_strerror(ret
) << dendl
;
923 // write initial op_seq
925 uint64_t initial_seq
= 0;
926 int fd
= read_op_seq(&initial_seq
);
929 derr
<< __FUNC__
<< ": failed to create " << current_op_seq_fn
<< ": "
930 << cpp_strerror(ret
) << dendl
;
933 if (initial_seq
== 0) {
934 ret
= write_op_seq(fd
, 1);
936 VOID_TEMP_FAILURE_RETRY(::close(fd
));
937 derr
<< __FUNC__
<< ": failed to write to " << current_op_seq_fn
<< ": "
938 << cpp_strerror(ret
) << dendl
;
942 if (backend
->can_checkpoint()) {
944 current_fd
= ::open(current_fn
.c_str(), O_RDONLY
);
945 assert(current_fd
>= 0);
947 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, 1ull);
948 ret
= backend
->create_checkpoint(s
, NULL
);
949 VOID_TEMP_FAILURE_RETRY(::close(current_fd
));
950 if (ret
< 0 && ret
!= -EEXIST
) {
951 VOID_TEMP_FAILURE_RETRY(::close(fd
));
952 derr
<< __FUNC__
<< ": failed to create snap_1: " << cpp_strerror(ret
) << dendl
;
957 VOID_TEMP_FAILURE_RETRY(::close(fd
));
959 ret
= KeyValueDB::test_init(superblock
.omap_backend
, omap_dir
);
961 derr
<< __FUNC__
<< ": failed to create " << cct
->_conf
->filestore_omap_backend
<< dendl
;
964 // create fsid under omap
967 char omap_fsid_fn
[PATH_MAX
];
968 snprintf(omap_fsid_fn
, sizeof(omap_fsid_fn
), "%s/osd_uuid", omap_dir
.c_str());
969 omap_fsid_fd
= ::open(omap_fsid_fn
, O_RDWR
|O_CREAT
, 0644);
970 if (omap_fsid_fd
< 0) {
972 derr
<< __FUNC__
<< ": failed to open " << omap_fsid_fn
<< ": " << cpp_strerror(ret
) << dendl
;
976 if (read_fsid(omap_fsid_fd
, &old_omap_fsid
) < 0 || old_omap_fsid
.is_zero()) {
977 assert(!fsid
.is_zero());
978 fsid
.print(fsid_str
);
979 strcat(fsid_str
, "\n");
980 ret
= ::ftruncate(omap_fsid_fd
, 0);
983 derr
<< __FUNC__
<< ": failed to truncate fsid: "
984 << cpp_strerror(ret
) << dendl
;
985 goto close_omap_fsid_fd
;
987 ret
= safe_write(omap_fsid_fd
, fsid_str
, strlen(fsid_str
));
989 derr
<< __FUNC__
<< ": failed to write fsid: "
990 << cpp_strerror(ret
) << dendl
;
991 goto close_omap_fsid_fd
;
993 dout(10) << __FUNC__
<< ": write success, fsid:" << fsid_str
<< ", ret:" << ret
<< dendl
;
994 if (::fsync(omap_fsid_fd
) < 0) {
996 derr
<< __FUNC__
<< ": close failed: can't write fsid: "
997 << cpp_strerror(ret
) << dendl
;
998 goto close_omap_fsid_fd
;
1000 dout(10) << "mkfs omap fsid is " << fsid
<< dendl
;
1002 if (fsid
!= old_omap_fsid
) {
1003 derr
<< __FUNC__
<< ": " << omap_fsid_fn
1004 << " has existed omap fsid " << old_omap_fsid
1005 << " != expected osd fsid " << fsid
1008 goto close_omap_fsid_fd
;
1010 dout(1) << __FUNC__
<< ": omap fsid is already set to " << fsid
<< dendl
;
1013 dout(1) << cct
->_conf
->filestore_omap_backend
<< " db exists/created" << dendl
;
1018 goto close_omap_fsid_fd
;
1020 ret
= write_meta("type", "filestore");
1022 goto close_omap_fsid_fd
;
1024 dout(1) << "mkfs done in " << basedir
<< dendl
;
1028 VOID_TEMP_FAILURE_RETRY(::close(omap_fsid_fd
));
1030 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1033 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd
));
1039 int FileStore::mkjournal()
1044 snprintf(fn
, sizeof(fn
), "%s/fsid", basedir
.c_str());
1045 int fd
= ::open(fn
, O_RDONLY
, 0644);
1048 derr
<< __FUNC__
<< ": open error: " << cpp_strerror(err
) << dendl
;
1051 ret
= read_fsid(fd
, &fsid
);
1053 derr
<< __FUNC__
<< ": read error: " << cpp_strerror(ret
) << dendl
;
1054 VOID_TEMP_FAILURE_RETRY(::close(fd
));
1057 VOID_TEMP_FAILURE_RETRY(::close(fd
));
1063 ret
= journal
->check();
1065 ret
= journal
->create();
1067 derr
<< __FUNC__
<< ": error creating journal on " << journalpath
1068 << ": " << cpp_strerror(ret
) << dendl
;
1070 dout(0) << __FUNC__
<< ": created journal on " << journalpath
<< dendl
;
1078 int FileStore::read_fsid(int fd
, uuid_d
*uuid
)
1081 memset(fsid_str
, 0, sizeof(fsid_str
));
1082 int ret
= safe_read(fd
, fsid_str
, sizeof(fsid_str
));
1086 // old 64-bit fsid... mirror it.
1087 *(uint64_t*)&uuid
->bytes()[0] = *(uint64_t*)fsid_str
;
1088 *(uint64_t*)&uuid
->bytes()[8] = *(uint64_t*)fsid_str
;
1096 if (!uuid
->parse(fsid_str
))
1101 int FileStore::lock_fsid()
1104 memset(&l
, 0, sizeof(l
));
1106 l
.l_whence
= SEEK_SET
;
1109 int r
= ::fcntl(fsid_fd
, F_SETLK
, &l
);
1112 dout(0) << __FUNC__
<< ": failed to lock " << basedir
<< "/fsid, is another ceph-osd still running? "
1113 << cpp_strerror(err
) << dendl
;
1119 bool FileStore::test_mount_in_use()
1121 dout(5) << __FUNC__
<< ": basedir " << basedir
<< " journal " << journalpath
<< dendl
;
1123 snprintf(fn
, sizeof(fn
), "%s/fsid", basedir
.c_str());
1125 // verify fs isn't in use
1127 fsid_fd
= ::open(fn
, O_RDWR
, 0644);
1129 return 0; // no fsid, ok.
1130 bool inuse
= lock_fsid() < 0;
1131 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1136 bool FileStore::is_rotational()
1140 rotational
= backend
->is_rotational();
1142 int fd
= ::open(basedir
.c_str(), O_RDONLY
);
1146 int r
= ::fstatfs(fd
, &st
);
1151 create_backend(st
.f_type
);
1152 rotational
= backend
->is_rotational();
1156 dout(10) << __func__
<< " " << (int)rotational
<< dendl
;
1160 int FileStore::_detect_fs()
1163 int r
= ::fstatfs(basedir_fd
, &st
);
1167 blk_size
= st
.f_bsize
;
1169 #if defined(__linux__)
1170 if (st
.f_type
== BTRFS_SUPER_MAGIC
&&
1171 !g_ceph_context
->check_experimental_feature_enabled("btrfs")) {
1172 derr
<<__FUNC__
<< ": deprecated btrfs support is not enabled" << dendl
;
1177 create_backend(st
.f_type
);
1179 r
= backend
->detect_features();
1181 derr
<< __FUNC__
<< ": detect_features error: " << cpp_strerror(r
) << dendl
;
1189 snprintf(fn
, sizeof(fn
), "%s/xattr_test", basedir
.c_str());
1190 int tmpfd
= ::open(fn
, O_CREAT
|O_WRONLY
|O_TRUNC
, 0700);
1193 derr
<< __FUNC__
<< ": unable to create " << fn
<< ": " << cpp_strerror(ret
) << dendl
;
1197 int ret
= chain_fsetxattr(tmpfd
, "user.test", &x
, sizeof(x
));
1199 ret
= chain_fgetxattr(tmpfd
, "user.test", &y
, sizeof(y
));
1200 if ((ret
< 0) || (x
!= y
)) {
1201 derr
<< "Extended attributes don't appear to work. ";
1203 *_dout
<< "Got error " + cpp_strerror(ret
) + ". ";
1204 *_dout
<< "If you are using ext3 or ext4, be sure to mount the underlying "
1205 << "file system with the 'user_xattr' option." << dendl
;
1207 VOID_TEMP_FAILURE_RETRY(::close(tmpfd
));
1212 memset(buf
, 0, sizeof(buf
)); // shut up valgrind
1213 chain_fsetxattr(tmpfd
, "user.test", &buf
, sizeof(buf
));
1214 chain_fsetxattr(tmpfd
, "user.test2", &buf
, sizeof(buf
));
1215 chain_fsetxattr(tmpfd
, "user.test3", &buf
, sizeof(buf
));
1216 chain_fsetxattr(tmpfd
, "user.test4", &buf
, sizeof(buf
));
1217 ret
= chain_fsetxattr(tmpfd
, "user.test5", &buf
, sizeof(buf
));
1218 if (ret
== -ENOSPC
) {
1219 dout(0) << "limited size xattrs" << dendl
;
1221 chain_fremovexattr(tmpfd
, "user.test");
1222 chain_fremovexattr(tmpfd
, "user.test2");
1223 chain_fremovexattr(tmpfd
, "user.test3");
1224 chain_fremovexattr(tmpfd
, "user.test4");
1225 chain_fremovexattr(tmpfd
, "user.test5");
1228 VOID_TEMP_FAILURE_RETRY(::close(tmpfd
));
1233 int FileStore::_sanity_check_fs()
1237 if (((int)m_filestore_journal_writeahead
+
1238 (int)m_filestore_journal_parallel
+
1239 (int)m_filestore_journal_trailing
) > 1) {
1240 dout(0) << "mount ERROR: more than one of filestore journal {writeahead,parallel,trailing} enabled" << dendl
;
1242 << " ** WARNING: more than one of 'filestore journal {writeahead,parallel,trailing}'\n"
1243 << " is enabled in ceph.conf. You must choose a single journal mode."
1244 << TEXT_NORMAL
<< std::endl
;
1248 if (!backend
->can_checkpoint()) {
1249 if (!journal
|| !m_filestore_journal_writeahead
) {
1250 dout(0) << "mount WARNING: no btrfs, and no journal in writeahead mode; data may be lost" << dendl
;
1252 << " ** WARNING: no btrfs AND (no journal OR journal not in writeahead mode)\n"
1253 << " For non-btrfs volumes, a writeahead journal is required to\n"
1254 << " maintain on-disk consistency in the event of a crash. Your conf\n"
1255 << " should include something like:\n"
1256 << " osd journal = /path/to/journal_device_or_file\n"
1257 << " filestore journal writeahead = true\n"
1263 dout(0) << "mount WARNING: no journal" << dendl
;
1265 << " ** WARNING: No osd journal is configured: write latency may be high.\n"
1266 << " If you will not be using an osd journal, write latency may be\n"
1267 << " relatively high. It can be reduced somewhat by lowering\n"
1268 << " filestore_max_sync_interval, but lower values mean lower write\n"
1269 << " throughput, especially with spinning disks.\n"
1276 int FileStore::write_superblock()
1279 ::encode(superblock
, bl
);
1280 return safe_write_file(basedir
.c_str(), "superblock",
1281 bl
.c_str(), bl
.length());
1284 int FileStore::read_superblock()
1286 bufferptr
bp(PATH_MAX
);
1287 int ret
= safe_read_file(basedir
.c_str(), "superblock",
1288 bp
.c_str(), bp
.length());
1290 if (ret
== -ENOENT
) {
1291 // If the file doesn't exist write initial CompatSet
1292 return write_superblock();
1298 bl
.push_back(std::move(bp
));
1299 bufferlist::iterator i
= bl
.begin();
1300 ::decode(superblock
, i
);
1304 int FileStore::update_version_stamp()
1306 return write_version_stamp();
1309 int FileStore::version_stamp_is_valid(uint32_t *version
)
1311 bufferptr
bp(PATH_MAX
);
1312 int ret
= safe_read_file(basedir
.c_str(), "store_version",
1313 bp
.c_str(), bp
.length());
1318 bl
.push_back(std::move(bp
));
1319 bufferlist::iterator i
= bl
.begin();
1320 ::decode(*version
, i
);
1321 dout(10) << __FUNC__
<< ": was " << *version
<< " vs target "
1322 << target_version
<< dendl
;
1323 if (*version
== target_version
)
1329 int FileStore::write_version_stamp()
1331 dout(1) << __FUNC__
<< ": " << target_version
<< dendl
;
1333 ::encode(target_version
, bl
);
1335 return safe_write_file(basedir
.c_str(), "store_version",
1336 bl
.c_str(), bl
.length());
1339 int FileStore::upgrade()
1341 dout(1) << __FUNC__
<< dendl
;
1343 int r
= version_stamp_is_valid(&version
);
1346 derr
<< "The store_version file doesn't exist." << dendl
;
1355 derr
<< "ObjectStore is old at version " << version
<< ". Please upgrade to firefly v0.80.x, convert your store, and then upgrade." << dendl
;
1359 // nothing necessary in FileStore for v3 -> v4 upgrade; we just need to
1360 // open up DBObjectMap with the do_upgrade flag, which we already did.
1361 update_version_stamp();
1365 int FileStore::read_op_seq(uint64_t *seq
)
1367 int op_fd
= ::open(current_op_seq_fn
.c_str(), O_CREAT
|O_RDWR
, 0644);
1370 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
1374 memset(s
, 0, sizeof(s
));
1375 int ret
= safe_read(op_fd
, s
, sizeof(s
) - 1);
1377 derr
<< __FUNC__
<< ": error reading " << current_op_seq_fn
<< ": " << cpp_strerror(ret
) << dendl
;
1378 VOID_TEMP_FAILURE_RETRY(::close(op_fd
));
1379 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1386 int FileStore::write_op_seq(int fd
, uint64_t seq
)
1389 snprintf(s
, sizeof(s
), "%" PRId64
"\n", seq
);
1390 int ret
= TEMP_FAILURE_RETRY(::pwrite(fd
, s
, strlen(s
), 0));
1393 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1398 int FileStore::mount()
1402 uint64_t initial_op_seq
;
1404 set
<string
> cluster_snaps
;
1405 CompatSet supported_compat_set
= get_fs_supported_compat_set();
1407 dout(5) << "basedir " << basedir
<< " journal " << journalpath
<< dendl
;
1409 ret
= set_throttle_params();
1413 // make sure global base dir exists
1414 if (::access(basedir
.c_str(), R_OK
| W_OK
)) {
1416 derr
<< __FUNC__
<< ": unable to access basedir '" << basedir
<< "': "
1417 << cpp_strerror(ret
) << dendl
;
1422 snprintf(buf
, sizeof(buf
), "%s/fsid", basedir
.c_str());
1423 fsid_fd
= ::open(buf
, O_RDWR
, 0644);
1426 derr
<< __FUNC__
<< ": error opening '" << buf
<< "': "
1427 << cpp_strerror(ret
) << dendl
;
1431 ret
= read_fsid(fsid_fd
, &fsid
);
1433 derr
<< __FUNC__
<< ": error reading fsid_fd: " << cpp_strerror(ret
)
1438 if (lock_fsid() < 0) {
1439 derr
<< __FUNC__
<< ": lock_fsid failed" << dendl
;
1444 dout(10) << "mount fsid is " << fsid
<< dendl
;
1447 uint32_t version_stamp
;
1448 ret
= version_stamp_is_valid(&version_stamp
);
1450 derr
<< __FUNC__
<< ": error in version_stamp_is_valid: "
1451 << cpp_strerror(ret
) << dendl
;
1453 } else if (ret
== 0) {
1454 if (do_update
|| (int)version_stamp
< cct
->_conf
->filestore_update_to
) {
1455 derr
<< __FUNC__
<< ": stale version stamp detected: "
1457 << ". Proceeding, do_update "
1458 << "is set, performing disk format upgrade."
1463 derr
<< __FUNC__
<< ": stale version stamp " << version_stamp
1464 << ". Please run the FileStore update script before starting the "
1465 << "OSD, or set filestore_update_to to " << target_version
1466 << " (currently " << cct
->_conf
->filestore_update_to
<< ")"
1472 ret
= read_superblock();
1477 // Check if this FileStore supports all the necessary features to mount
1478 if (supported_compat_set
.compare(superblock
.compat_features
) == -1) {
1479 derr
<< __FUNC__
<< ": Incompatible features set "
1480 << superblock
.compat_features
<< dendl
;
1485 // open some dir handles
1486 basedir_fd
= ::open(basedir
.c_str(), O_RDONLY
);
1487 if (basedir_fd
< 0) {
1489 derr
<< __FUNC__
<< ": failed to open " << basedir
<< ": "
1490 << cpp_strerror(ret
) << dendl
;
1495 // test for btrfs, xattrs, etc.
1498 derr
<< __FUNC__
<< ": error in _detect_fs: "
1499 << cpp_strerror(ret
) << dendl
;
1500 goto close_basedir_fd
;
1505 ret
= backend
->list_checkpoints(ls
);
1507 derr
<< __FUNC__
<< ": error in _list_snaps: "<< cpp_strerror(ret
) << dendl
;
1508 goto close_basedir_fd
;
1511 long long unsigned c
, prev
= 0;
1512 char clustersnap
[NAME_MAX
];
1513 for (list
<string
>::iterator it
= ls
.begin(); it
!= ls
.end(); ++it
) {
1514 if (sscanf(it
->c_str(), COMMIT_SNAP_ITEM
, &c
) == 1) {
1518 } else if (sscanf(it
->c_str(), CLUSTER_SNAP_ITEM
, clustersnap
) == 1)
1519 cluster_snaps
.insert(*it
);
1523 if (m_osd_rollback_to_cluster_snap
.length() &&
1524 cluster_snaps
.count(m_osd_rollback_to_cluster_snap
) == 0) {
1525 derr
<< "rollback to cluster snapshot '" << m_osd_rollback_to_cluster_snap
<< "': not found" << dendl
;
1527 goto close_basedir_fd
;
1531 snprintf(nosnapfn
, sizeof(nosnapfn
), "%s/nosnap", current_fn
.c_str());
1533 if (backend
->can_checkpoint()) {
1534 if (snaps
.empty()) {
1535 dout(0) << __FUNC__
<< ": WARNING: no consistent snaps found, store may be in inconsistent state" << dendl
;
1538 uint64_t curr_seq
= 0;
1540 if (m_osd_rollback_to_cluster_snap
.length()) {
1542 << " ** NOTE: rolling back to cluster snapshot " << m_osd_rollback_to_cluster_snap
<< " **"
1545 assert(cluster_snaps
.count(m_osd_rollback_to_cluster_snap
));
1546 snprintf(s
, sizeof(s
), CLUSTER_SNAP_ITEM
, m_osd_rollback_to_cluster_snap
.c_str());
1549 int fd
= read_op_seq(&curr_seq
);
1551 VOID_TEMP_FAILURE_RETRY(::close(fd
));
1555 dout(10) << " current/ seq was " << curr_seq
<< dendl
;
1557 dout(10) << " current/ missing entirely (unusual, but okay)" << dendl
;
1559 uint64_t cp
= snaps
.back();
1560 dout(10) << " most recent snap from " << snaps
<< " is " << cp
<< dendl
;
1562 // if current/ is marked as non-snapshotted, refuse to roll
1563 // back (without clear direction) to avoid throwing out new
1566 if (::stat(nosnapfn
, &st
) == 0) {
1567 if (!m_osd_use_stale_snap
) {
1568 derr
<< "ERROR: " << nosnapfn
<< " exists, not rolling back to avoid losing new data" << dendl
;
1569 derr
<< "Force rollback to old snapshotted version with 'osd use stale snap = true'" << dendl
;
1570 derr
<< "config option for --osd-use-stale-snap startup argument." << dendl
;
1572 goto close_basedir_fd
;
1574 derr
<< "WARNING: user forced start with data sequence mismatch: current was " << curr_seq
1575 << ", newest snap is " << cp
<< dendl
;
1577 << " ** WARNING: forcing the use of stale snapshot data **"
1578 << TEXT_NORMAL
<< std::endl
;
1581 dout(10) << __FUNC__
<< ": rolling back to consistent snap " << cp
<< dendl
;
1582 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)cp
);
1586 ret
= backend
->rollback_to(s
);
1588 derr
<< __FUNC__
<< ": error rolling back to " << s
<< ": "
1589 << cpp_strerror(ret
) << dendl
;
1590 goto close_basedir_fd
;
1596 current_fd
= ::open(current_fn
.c_str(), O_RDONLY
);
1597 if (current_fd
< 0) {
1599 derr
<< __FUNC__
<< ": error opening: " << current_fn
<< ": " << cpp_strerror(ret
) << dendl
;
1600 goto close_basedir_fd
;
1603 assert(current_fd
>= 0);
1605 op_fd
= read_op_seq(&initial_op_seq
);
1608 derr
<< __FUNC__
<< ": read_op_seq failed" << dendl
;
1609 goto close_current_fd
;
1612 dout(5) << "mount op_seq is " << initial_op_seq
<< dendl
;
1613 if (initial_op_seq
== 0) {
1614 derr
<< "mount initial op seq is 0; something is wrong" << dendl
;
1616 goto close_current_fd
;
1619 if (!backend
->can_checkpoint()) {
1620 // mark current/ as non-snapshotted so that we don't rollback away
1622 int r
= ::creat(nosnapfn
, 0644);
1625 derr
<< __FUNC__
<< ": failed to create current/nosnap" << dendl
;
1626 goto close_current_fd
;
1628 VOID_TEMP_FAILURE_RETRY(::close(r
));
1630 // clear nosnap marker, if present.
1634 // check fsid with omap
1637 char omap_fsid_buf
[PATH_MAX
];
1638 struct ::stat omap_fsid_stat
;
1639 snprintf(omap_fsid_buf
, sizeof(omap_fsid_buf
), "%s/osd_uuid", omap_dir
.c_str());
1640 // if osd_uuid not exists, assume as this omap matchs corresponding osd
1641 if (::stat(omap_fsid_buf
, &omap_fsid_stat
) != 0){
1642 dout(10) << __FUNC__
<< ": osd_uuid not found under omap, "
1643 << "assume as matched."
1646 // if osd_uuid exists, compares osd_uuid with fsid
1647 omap_fsid_fd
= ::open(omap_fsid_buf
, O_RDONLY
, 0644);
1648 if (omap_fsid_fd
< 0) {
1650 derr
<< __FUNC__
<< ": error opening '" << omap_fsid_buf
<< "': "
1651 << cpp_strerror(ret
)
1653 goto close_current_fd
;
1655 ret
= read_fsid(omap_fsid_fd
, &omap_fsid
);
1656 VOID_TEMP_FAILURE_RETRY(::close(omap_fsid_fd
));
1657 omap_fsid_fd
= -1; // defensive
1659 derr
<< __FUNC__
<< ": error reading omap_fsid_fd"
1660 << ", omap_fsid = " << omap_fsid
1661 << cpp_strerror(ret
)
1663 goto close_current_fd
;
1665 if (fsid
!= omap_fsid
) {
1666 derr
<< __FUNC__
<< ": " << omap_fsid_buf
1667 << " has existed omap fsid " << omap_fsid
1668 << " != expected osd fsid " << fsid
1671 goto close_current_fd
;
1675 dout(0) << "start omap initiation" << dendl
;
1676 if (!(generic_flags
& SKIP_MOUNT_OMAP
)) {
1677 KeyValueDB
* omap_store
= KeyValueDB::create(cct
,
1678 superblock
.omap_backend
,
1680 if (omap_store
== NULL
)
1682 derr
<< __FUNC__
<< ": Error creating " << superblock
.omap_backend
<< dendl
;
1684 goto close_current_fd
;
1687 if (superblock
.omap_backend
== "rocksdb")
1688 ret
= omap_store
->init(cct
->_conf
->filestore_rocksdb_options
);
1690 ret
= omap_store
->init();
1693 derr
<< __FUNC__
<< ": Error initializing omap_store: " << cpp_strerror(ret
) << dendl
;
1694 goto close_current_fd
;
1698 if (omap_store
->create_and_open(err
)) {
1700 derr
<< __FUNC__
<< ": Error initializing " << superblock
.omap_backend
1701 << " : " << err
.str() << dendl
;
1703 goto close_current_fd
;
1706 DBObjectMap
*dbomap
= new DBObjectMap(cct
, omap_store
);
1707 ret
= dbomap
->init(do_update
);
1710 derr
<< __FUNC__
<< ": Error initializing DBObjectMap: " << ret
<< dendl
;
1711 goto close_current_fd
;
1715 if (cct
->_conf
->filestore_debug_omap_check
&& !dbomap
->check(err2
)) {
1716 derr
<< err2
.str() << dendl
;
1719 goto close_current_fd
;
1721 object_map
.reset(dbomap
);
1727 // select journal mode?
1729 if (!m_filestore_journal_writeahead
&&
1730 !m_filestore_journal_parallel
&&
1731 !m_filestore_journal_trailing
) {
1732 if (!backend
->can_checkpoint()) {
1733 m_filestore_journal_writeahead
= true;
1734 dout(0) << __FUNC__
<< ": enabling WRITEAHEAD journal mode: checkpoint is not enabled" << dendl
;
1736 m_filestore_journal_parallel
= true;
1737 dout(0) << __FUNC__
<< ": enabling PARALLEL journal mode: fs, checkpoint is enabled" << dendl
;
1740 if (m_filestore_journal_writeahead
)
1741 dout(0) << __FUNC__
<< ": WRITEAHEAD journal mode explicitly enabled in conf" << dendl
;
1742 if (m_filestore_journal_parallel
)
1743 dout(0) << __FUNC__
<< ": PARALLEL journal mode explicitly enabled in conf" << dendl
;
1744 if (m_filestore_journal_trailing
)
1745 dout(0) << __FUNC__
<< ": TRAILING journal mode explicitly enabled in conf" << dendl
;
1747 if (m_filestore_journal_writeahead
)
1748 journal
->set_wait_on_full(true);
1750 dout(0) << __FUNC__
<< ": no journal" << dendl
;
1753 ret
= _sanity_check_fs();
1755 derr
<< __FUNC__
<< ": _sanity_check_fs failed with error "
1757 goto close_current_fd
;
1760 // Cleanup possibly invalid collections
1762 vector
<coll_t
> collections
;
1763 ret
= list_collections(collections
, true);
1765 derr
<< "Error " << ret
<< " while listing collections" << dendl
;
1766 goto close_current_fd
;
1768 for (vector
<coll_t
>::iterator i
= collections
.begin();
1769 i
!= collections
.end();
1772 ret
= get_index(*i
, &index
);
1774 derr
<< "Unable to mount index " << *i
1775 << " with error: " << ret
<< dendl
;
1776 goto close_current_fd
;
1778 assert(NULL
!= index
.index
);
1779 RWLock::WLocker
l((index
.index
)->access_lock
);
1784 if (!m_disable_wbthrottle
) {
1787 dout(0) << __FUNC__
<< ": INFO: WbThrottle is disabled" << dendl
;
1788 if (cct
->_conf
->filestore_odsync_write
) {
1789 dout(0) << __FUNC__
<< ": INFO: O_DSYNC write is enabled" << dendl
;
1792 sync_thread
.create("filestore_sync");
1794 if (!(generic_flags
& SKIP_JOURNAL_REPLAY
)) {
1795 ret
= journal_replay(initial_op_seq
);
1797 derr
<< __FUNC__
<< ": failed to open journal " << journalpath
<< ": " << cpp_strerror(ret
) << dendl
;
1798 if (ret
== -ENOTTY
) {
1799 derr
<< "maybe journal is not pointing to a block device and its size "
1800 << "wasn't configured?" << dendl
;
1809 if (cct
->_conf
->filestore_debug_omap_check
&& !object_map
->check(err2
)) {
1810 derr
<< err2
.str() << dendl
;
1816 init_temp_collections();
1821 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
1824 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
1831 if (cct
->_conf
->filestore_update_to
>= (int)get_target_version()) {
1832 int err
= upgrade();
1834 derr
<< "error converting store" << dendl
;
1850 if (!m_disable_wbthrottle
) {
1854 VOID_TEMP_FAILURE_RETRY(::close(current_fd
));
1857 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd
));
1860 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1863 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1870 void FileStore::init_temp_collections()
1872 dout(10) << __FUNC__
<< dendl
;
1874 int r
= list_collections(ls
, true);
1877 dout(20) << " ls " << ls
<< dendl
;
1879 SequencerPosition spos
;
1882 for (vector
<coll_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
)
1885 dout(20) << " temps " << temps
<< dendl
;
1887 for (vector
<coll_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
1892 coll_t temp
= p
->get_temp();
1893 if (temps
.count(temp
)) {
1896 dout(10) << __FUNC__
<< ": creating " << temp
<< dendl
;
1897 r
= _create_collection(temp
, 0, spos
);
1902 for (set
<coll_t
>::iterator p
= temps
.begin(); p
!= temps
.end(); ++p
) {
1903 dout(10) << __FUNC__
<< ": removing stray " << *p
<< dendl
;
1904 r
= _collection_remove_recursive(*p
, spos
);
1909 int FileStore::umount()
1911 dout(5) << __FUNC__
<< ": " << basedir
<< dendl
;
1922 if (!m_disable_wbthrottle
){
1928 if (!(generic_flags
& SKIP_JOURNAL_REPLAY
))
1929 journal_write_close();
1931 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
1934 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
1939 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1943 VOID_TEMP_FAILURE_RETRY(::close(op_fd
));
1946 if (current_fd
>= 0) {
1947 VOID_TEMP_FAILURE_RETRY(::close(current_fd
));
1950 if (basedir_fd
>= 0) {
1951 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd
));
1963 Mutex::Locker
l(sync_entry_timeo_lock
);
1974 /// -----------------------------
1976 FileStore::Op
*FileStore::build_op(vector
<Transaction
>& tls
,
1977 Context
*onreadable
,
1978 Context
*onreadable_sync
,
1979 TrackedOpRef osd_op
)
1981 uint64_t bytes
= 0, ops
= 0;
1982 for (vector
<Transaction
>::iterator p
= tls
.begin();
1985 bytes
+= (*p
).get_num_bytes();
1986 ops
+= (*p
).get_num_ops();
1990 o
->start
= ceph_clock_now();
1991 o
->tls
= std::move(tls
);
1992 o
->onreadable
= onreadable
;
1993 o
->onreadable_sync
= onreadable_sync
;
2002 void FileStore::queue_op(OpSequencer
*osr
, Op
*o
)
2004 // queue op on sequencer, then queue sequencer for the threadpool,
2005 // so that regardless of which order the threads pick up the
2006 // sequencer, the op order will be preserved.
2009 o
->trace
.event("queued");
2011 logger
->inc(l_filestore_ops
);
2012 logger
->inc(l_filestore_bytes
, o
->bytes
);
2014 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
2016 << " " << o
->bytes
<< " bytes"
2017 << " (queue has " << throttle_ops
.get_current() << " ops and " << throttle_bytes
.get_current() << " bytes)"
2022 void FileStore::op_queue_reserve_throttle(Op
*o
)
2025 throttle_bytes
.get(o
->bytes
);
2027 logger
->set(l_filestore_op_queue_ops
, throttle_ops
.get_current());
2028 logger
->set(l_filestore_op_queue_bytes
, throttle_bytes
.get_current());
2031 void FileStore::op_queue_release_throttle(Op
*o
)
2034 throttle_bytes
.put(o
->bytes
);
2035 logger
->set(l_filestore_op_queue_ops
, throttle_ops
.get_current());
2036 logger
->set(l_filestore_op_queue_bytes
, throttle_bytes
.get_current());
2039 void FileStore::_do_op(OpSequencer
*osr
, ThreadPool::TPHandle
&handle
)
2041 if (!m_disable_wbthrottle
) {
2042 wbthrottle
.throttle();
2045 if (cct
->_conf
->filestore_inject_stall
) {
2046 int orig
= cct
->_conf
->filestore_inject_stall
;
2047 dout(5) << __FUNC__
<< ": filestore_inject_stall " << orig
<< ", sleeping" << dendl
;
2049 cct
->_conf
->set_val("filestore_inject_stall", "0");
2050 dout(5) << __FUNC__
<< ": done stalling" << dendl
;
2053 osr
->apply_lock
.Lock();
2054 Op
*o
= osr
->peek_queue();
2055 o
->trace
.event("op_apply_start");
2056 apply_manager
.op_apply_start(o
->op
);
2057 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< "/" << osr
->parent
<< " start" << dendl
;
2058 o
->trace
.event("_do_transactions start");
2059 int r
= _do_transactions(o
->tls
, o
->op
, &handle
);
2060 o
->trace
.event("op_apply_finish");
2061 apply_manager
.op_apply_finish(o
->op
);
2062 dout(10) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " r = " << r
2063 << ", finisher " << o
->onreadable
<< " " << o
->onreadable_sync
<< dendl
;
2069 void FileStore::_finish_op(OpSequencer
*osr
)
2071 list
<Context
*> to_queue
;
2072 Op
*o
= osr
->dequeue(&to_queue
);
2074 utime_t lat
= ceph_clock_now();
2077 dout(10) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< "/" << osr
->parent
<< " lat " << lat
<< dendl
;
2078 osr
->apply_lock
.Unlock(); // locked in _do_op
2079 o
->trace
.event("_finish_op");
2081 // called with tp lock held
2082 op_queue_release_throttle(o
);
2084 logger
->tinc(l_filestore_apply_latency
, lat
);
2086 if (o
->onreadable_sync
) {
2087 o
->onreadable_sync
->complete(0);
2089 if (o
->onreadable
) {
2090 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(o
->onreadable
);
2092 if (!to_queue
.empty()) {
2093 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(to_queue
);
2099 struct C_JournaledAhead
: public Context
{
2101 FileStore::OpSequencer
*osr
;
2105 C_JournaledAhead(FileStore
*f
, FileStore::OpSequencer
*os
, FileStore::Op
*o
, Context
*ondisk
):
2106 fs(f
), osr(os
), o(o
), ondisk(ondisk
) { }
2107 void finish(int r
) override
{
2108 fs
->_journaled_ahead(osr
, o
, ondisk
);
2112 int FileStore::queue_transactions(Sequencer
*posr
, vector
<Transaction
>& tls
,
2113 TrackedOpRef osd_op
,
2114 ThreadPool::TPHandle
*handle
)
2116 Context
*onreadable
;
2118 Context
*onreadable_sync
;
2119 ObjectStore::Transaction::collect_contexts(
2120 tls
, &onreadable
, &ondisk
, &onreadable_sync
);
2122 if (cct
->_conf
->objectstore_blackhole
) {
2123 dout(0) << __FUNC__
<< ": objectstore_blackhole = TRUE, dropping transaction"
2127 delete onreadable_sync
;
2131 utime_t start
= ceph_clock_now();
2132 // set up the sequencer
2136 osr
= static_cast<OpSequencer
*>(posr
->p
.get());
2137 dout(5) << __FUNC__
<< ": existing " << osr
<< " " << *osr
<< dendl
;
2139 osr
= new OpSequencer(cct
, ++next_osr_id
);
2143 dout(5) << __FUNC__
<< ": new " << osr
<< " " << *osr
<< dendl
;
2146 // used to include osr information in tracepoints during transaction apply
2147 for (vector
<Transaction
>::iterator i
= tls
.begin(); i
!= tls
.end(); ++i
) {
2151 ZTracer::Trace trace
;
2152 if (osd_op
&& osd_op
->pg_trace
) {
2153 osd_op
->store_trace
.init("filestore op", &trace_endpoint
, &osd_op
->pg_trace
);
2154 trace
= osd_op
->store_trace
;
2157 if (journal
&& journal
->is_writeable() && !m_filestore_journal_trailing
) {
2158 Op
*o
= build_op(tls
, onreadable
, onreadable_sync
, osd_op
);
2160 //prepare and encode transactions data out of lock
2162 int orig_len
= journal
->prepare_entry(o
->tls
, &tbl
);
2165 handle
->suspend_tp_timeout();
2167 op_queue_reserve_throttle(o
);
2168 journal
->reserve_throttle_and_backoff(tbl
.length());
2171 handle
->reset_tp_timeout();
2173 uint64_t op_num
= submit_manager
.op_submit_start();
2175 trace
.keyval("opnum", op_num
);
2177 if (m_filestore_do_dump
)
2178 dump_transactions(o
->tls
, o
->op
, osr
);
2180 if (m_filestore_journal_parallel
) {
2181 dout(5) << __FUNC__
<< ": (parallel) " << o
->op
<< " " << o
->tls
<< dendl
;
2183 trace
.keyval("journal mode", "parallel");
2184 trace
.event("journal started");
2185 _op_journal_transactions(tbl
, orig_len
, o
->op
, ondisk
, osd_op
);
2187 // queue inside submit_manager op submission lock
2189 trace
.event("op queued");
2190 } else if (m_filestore_journal_writeahead
) {
2191 dout(5) << __FUNC__
<< ": (writeahead) " << o
->op
<< " " << o
->tls
<< dendl
;
2193 osr
->queue_journal(o
->op
);
2195 trace
.keyval("journal mode", "writeahead");
2196 trace
.event("journal started");
2197 _op_journal_transactions(tbl
, orig_len
, o
->op
,
2198 new C_JournaledAhead(this, osr
, o
, ondisk
),
2203 submit_manager
.op_submit_finish(op_num
);
2204 utime_t end
= ceph_clock_now();
2205 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2210 Op
*o
= build_op(tls
, onreadable
, onreadable_sync
, osd_op
);
2211 dout(5) << __FUNC__
<< ": (no journal) " << o
<< " " << tls
<< dendl
;
2214 handle
->suspend_tp_timeout();
2216 op_queue_reserve_throttle(o
);
2219 handle
->reset_tp_timeout();
2221 uint64_t op_num
= submit_manager
.op_submit_start();
2224 if (m_filestore_do_dump
)
2225 dump_transactions(o
->tls
, o
->op
, osr
);
2228 trace
.keyval("opnum", op_num
);
2229 trace
.keyval("journal mode", "none");
2230 trace
.event("op queued");
2233 apply_manager
.add_waiter(op_num
, ondisk
);
2234 submit_manager
.op_submit_finish(op_num
);
2235 utime_t end
= ceph_clock_now();
2236 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2241 //prepare and encode transactions data out of lock
2244 if (journal
->is_writeable()) {
2245 orig_len
= journal
->prepare_entry(tls
, &tbl
);
2247 uint64_t op
= submit_manager
.op_submit_start();
2248 dout(5) << __FUNC__
<< ": (trailing journal) " << op
<< " " << tls
<< dendl
;
2250 if (m_filestore_do_dump
)
2251 dump_transactions(tls
, op
, osr
);
2253 trace
.event("op_apply_start");
2254 trace
.keyval("opnum", op
);
2255 trace
.keyval("journal mode", "trailing");
2256 apply_manager
.op_apply_start(op
);
2257 trace
.event("do_transactions");
2258 int r
= do_transactions(tls
, op
);
2261 trace
.event("journal started");
2262 _op_journal_transactions(tbl
, orig_len
, op
, ondisk
, osd_op
);
2267 // start on_readable finisher after we queue journal item, as on_readable callback
2268 // is allowed to delete the Transaction
2269 if (onreadable_sync
) {
2270 onreadable_sync
->complete(r
);
2272 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(onreadable
, r
);
2274 submit_manager
.op_submit_finish(op
);
2275 trace
.event("op_apply_finish");
2276 apply_manager
.op_apply_finish(op
);
2278 utime_t end
= ceph_clock_now();
2279 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2283 void FileStore::_journaled_ahead(OpSequencer
*osr
, Op
*o
, Context
*ondisk
)
2285 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< " " << o
->tls
<< dendl
;
2287 o
->trace
.event("writeahead journal finished");
2289 // this should queue in order because the journal does it's completions in order.
2292 list
<Context
*> to_queue
;
2293 osr
->dequeue_journal(&to_queue
);
2295 // do ondisk completions async, to prevent any onreadable_sync completions
2296 // getting blocked behind an ondisk completion.
2298 dout(10) << " queueing ondisk " << ondisk
<< dendl
;
2299 ondisk_finishers
[osr
->id
% m_ondisk_finisher_num
]->queue(ondisk
);
2301 if (!to_queue
.empty()) {
2302 ondisk_finishers
[osr
->id
% m_ondisk_finisher_num
]->queue(to_queue
);
2306 int FileStore::_do_transactions(
2307 vector
<Transaction
> &tls
,
2309 ThreadPool::TPHandle
*handle
)
2313 for (vector
<Transaction
>::iterator p
= tls
.begin();
2316 _do_transaction(*p
, op_seq
, trans_num
, handle
);
2318 handle
->reset_tp_timeout();
2324 void FileStore::_set_global_replay_guard(const coll_t
& cid
,
2325 const SequencerPosition
&spos
)
2327 if (backend
->can_checkpoint())
2330 // sync all previous operations on this sequencer
2331 int ret
= object_map
->sync();
2333 derr
<< __FUNC__
<< ": omap sync error " << cpp_strerror(ret
) << dendl
;
2334 assert(0 == "_set_global_replay_guard failed");
2336 ret
= sync_filesystem(basedir_fd
);
2338 derr
<< __FUNC__
<< ": sync_filesystem error " << cpp_strerror(ret
) << dendl
;
2339 assert(0 == "_set_global_replay_guard failed");
2343 get_cdir(cid
, fn
, sizeof(fn
));
2344 int fd
= ::open(fn
, O_RDONLY
);
2347 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2348 assert(0 == "_set_global_replay_guard failed");
2353 // then record that we did it
2356 int r
= chain_fsetxattr
<true, true>(
2357 fd
, GLOBAL_REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2359 derr
<< __FUNC__
<< ": fsetxattr " << GLOBAL_REPLAY_GUARD_XATTR
2360 << " got " << cpp_strerror(r
) << dendl
;
2361 assert(0 == "fsetxattr failed");
2364 // and make sure our xattr is durable.
2369 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2370 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2373 int FileStore::_check_global_replay_guard(const coll_t
& cid
,
2374 const SequencerPosition
& spos
)
2377 get_cdir(cid
, fn
, sizeof(fn
));
2378 int fd
= ::open(fn
, O_RDONLY
);
2380 dout(10) << __FUNC__
<< ": " << cid
<< " dne" << dendl
;
2381 return 1; // if collection does not exist, there is no guard, and we can replay.
2385 int r
= chain_fgetxattr(fd
, GLOBAL_REPLAY_GUARD_XATTR
, buf
, sizeof(buf
));
2387 dout(20) << __FUNC__
<< ": no xattr" << dendl
;
2388 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
2389 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2390 return 1; // no xattr
2395 SequencerPosition opos
;
2396 bufferlist::iterator p
= bl
.begin();
2399 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2400 return spos
>= opos
? 1 : -1;
2404 void FileStore::_set_replay_guard(const coll_t
& cid
,
2405 const SequencerPosition
&spos
,
2406 bool in_progress
=false)
2409 get_cdir(cid
, fn
, sizeof(fn
));
2410 int fd
= ::open(fn
, O_RDONLY
);
2413 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2414 assert(0 == "_set_replay_guard failed");
2416 _set_replay_guard(fd
, spos
, 0, in_progress
);
2417 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2421 void FileStore::_set_replay_guard(int fd
,
2422 const SequencerPosition
& spos
,
2423 const ghobject_t
*hoid
,
2426 if (backend
->can_checkpoint())
2429 dout(10) << __FUNC__
<< ": " << spos
<< (in_progress
? " START" : "") << dendl
;
2433 // first make sure the previous operation commits
2437 // sync object_map too. even if this object has a header or keys,
2438 // it have had them in the past and then removed them, so always
2440 object_map
->sync(hoid
, &spos
);
2445 // then record that we did it
2448 ::encode(in_progress
, v
);
2449 int r
= chain_fsetxattr
<true, true>(
2450 fd
, REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2452 derr
<< "fsetxattr " << REPLAY_GUARD_XATTR
<< " got " << cpp_strerror(r
) << dendl
;
2453 assert(0 == "fsetxattr failed");
2456 // and make sure our xattr is durable.
2461 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2464 void FileStore::_close_replay_guard(const coll_t
& cid
,
2465 const SequencerPosition
&spos
)
2468 get_cdir(cid
, fn
, sizeof(fn
));
2469 int fd
= ::open(fn
, O_RDONLY
);
2472 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2473 assert(0 == "_close_replay_guard failed");
2475 _close_replay_guard(fd
, spos
);
2476 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2479 void FileStore::_close_replay_guard(int fd
, const SequencerPosition
& spos
,
2480 const ghobject_t
*hoid
)
2482 if (backend
->can_checkpoint())
2485 dout(10) << __FUNC__
<< ": " << spos
<< dendl
;
2489 // sync object_map too. even if this object has a header or keys,
2490 // it have had them in the past and then removed them, so always
2492 object_map
->sync(hoid
, &spos
);
2494 // then record that we are done with this operation
2497 bool in_progress
= false;
2498 ::encode(in_progress
, v
);
2499 int r
= chain_fsetxattr
<true, true>(
2500 fd
, REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2502 derr
<< "fsetxattr " << REPLAY_GUARD_XATTR
<< " got " << cpp_strerror(r
) << dendl
;
2503 assert(0 == "fsetxattr failed");
2506 // and make sure our xattr is durable.
2511 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2514 int FileStore::_check_replay_guard(const coll_t
& cid
, const ghobject_t
&oid
,
2515 const SequencerPosition
& spos
)
2517 if (!replaying
|| backend
->can_checkpoint())
2520 int r
= _check_global_replay_guard(cid
, spos
);
2525 r
= lfn_open(cid
, oid
, false, &fd
);
2527 dout(10) << __FUNC__
<< ": " << cid
<< " " << oid
<< " dne" << dendl
;
2528 return 1; // if file does not exist, there is no guard, and we can replay.
2530 int ret
= _check_replay_guard(**fd
, spos
);
2535 int FileStore::_check_replay_guard(const coll_t
& cid
, const SequencerPosition
& spos
)
2537 if (!replaying
|| backend
->can_checkpoint())
2541 get_cdir(cid
, fn
, sizeof(fn
));
2542 int fd
= ::open(fn
, O_RDONLY
);
2544 dout(10) << __FUNC__
<< ": " << cid
<< " dne" << dendl
;
2545 return 1; // if collection does not exist, there is no guard, and we can replay.
2547 int ret
= _check_replay_guard(fd
, spos
);
2548 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2552 int FileStore::_check_replay_guard(int fd
, const SequencerPosition
& spos
)
2554 if (!replaying
|| backend
->can_checkpoint())
2558 int r
= chain_fgetxattr(fd
, REPLAY_GUARD_XATTR
, buf
, sizeof(buf
));
2560 dout(20) << __FUNC__
<< ": no xattr" << dendl
;
2561 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
2562 return 1; // no xattr
2567 SequencerPosition opos
;
2568 bufferlist::iterator p
= bl
.begin();
2570 bool in_progress
= false;
2571 if (!p
.end()) // older journals don't have this
2572 ::decode(in_progress
, p
);
2574 dout(10) << __FUNC__
<< ": object has " << opos
<< " > current pos " << spos
2575 << ", now or in future, SKIPPING REPLAY" << dendl
;
2577 } else if (opos
== spos
) {
2579 dout(10) << __FUNC__
<< ": object has " << opos
<< " == current pos " << spos
2580 << ", in_progress=true, CONDITIONAL REPLAY" << dendl
;
2583 dout(10) << __FUNC__
<< ": object has " << opos
<< " == current pos " << spos
2584 << ", in_progress=false, SKIPPING REPLAY" << dendl
;
2588 dout(10) << __FUNC__
<< ": object has " << opos
<< " < current pos " << spos
2589 << ", in past, will replay" << dendl
;
2594 void FileStore::_do_transaction(
2595 Transaction
& t
, uint64_t op_seq
, int trans_num
,
2596 ThreadPool::TPHandle
*handle
)
2598 dout(10) << __FUNC__
<< ": on " << &t
<< dendl
;
2601 const char *osr_name
= t
.get_osr() ? static_cast<OpSequencer
*>(t
.get_osr())->get_name().c_str() : "<NULL>";
2604 Transaction::iterator i
= t
.begin();
2606 SequencerPosition
spos(op_seq
, trans_num
, 0);
2607 while (i
.have_op()) {
2609 handle
->reset_tp_timeout();
2611 Transaction::Op
*op
= i
.decode_op();
2617 case Transaction::OP_NOP
:
2619 case Transaction::OP_TOUCH
:
2621 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2622 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2623 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2624 _cid
: _cid
.get_temp();
2625 tracepoint(objectstore
, touch_enter
, osr_name
);
2626 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2627 r
= _touch(cid
, oid
);
2628 tracepoint(objectstore
, touch_exit
, r
);
2632 case Transaction::OP_WRITE
:
2634 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2635 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2636 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2637 _cid
: _cid
.get_temp();
2638 uint64_t off
= op
->off
;
2639 uint64_t len
= op
->len
;
2640 uint32_t fadvise_flags
= i
.get_fadvise_flags();
2643 tracepoint(objectstore
, write_enter
, osr_name
, off
, len
);
2644 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2645 r
= _write(cid
, oid
, off
, len
, bl
, fadvise_flags
);
2646 tracepoint(objectstore
, write_exit
, r
);
2650 case Transaction::OP_ZERO
:
2652 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2653 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2654 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2655 _cid
: _cid
.get_temp();
2656 uint64_t off
= op
->off
;
2657 uint64_t len
= op
->len
;
2658 tracepoint(objectstore
, zero_enter
, osr_name
, off
, len
);
2659 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2660 r
= _zero(cid
, oid
, off
, len
);
2661 tracepoint(objectstore
, zero_exit
, r
);
2665 case Transaction::OP_TRIMCACHE
:
2667 // deprecated, no-op
2671 case Transaction::OP_TRUNCATE
:
2673 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2674 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2675 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2676 _cid
: _cid
.get_temp();
2677 uint64_t off
= op
->off
;
2678 tracepoint(objectstore
, truncate_enter
, osr_name
, off
);
2679 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2680 r
= _truncate(cid
, oid
, off
);
2681 tracepoint(objectstore
, truncate_exit
, r
);
2685 case Transaction::OP_REMOVE
:
2687 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2688 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2689 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2690 _cid
: _cid
.get_temp();
2691 tracepoint(objectstore
, remove_enter
, osr_name
);
2692 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2693 r
= _remove(cid
, oid
, spos
);
2694 tracepoint(objectstore
, remove_exit
, r
);
2698 case Transaction::OP_SETATTR
:
2700 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2701 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2702 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2703 _cid
: _cid
.get_temp();
2704 string name
= i
.decode_string();
2707 tracepoint(objectstore
, setattr_enter
, osr_name
);
2708 if (_check_replay_guard(cid
, oid
, spos
) > 0) {
2709 map
<string
, bufferptr
> to_set
;
2710 to_set
[name
] = bufferptr(bl
.c_str(), bl
.length());
2711 r
= _setattrs(cid
, oid
, to_set
, spos
);
2713 dout(0) << " ENOSPC on setxattr on " << cid
<< "/" << oid
2714 << " name " << name
<< " size " << bl
.length() << dendl
;
2716 tracepoint(objectstore
, setattr_exit
, r
);
2720 case Transaction::OP_SETATTRS
:
2722 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2723 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2724 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2725 _cid
: _cid
.get_temp();
2726 map
<string
, bufferptr
> aset
;
2727 i
.decode_attrset(aset
);
2728 tracepoint(objectstore
, setattrs_enter
, osr_name
);
2729 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2730 r
= _setattrs(cid
, oid
, aset
, spos
);
2731 tracepoint(objectstore
, setattrs_exit
, r
);
2733 dout(0) << " ENOSPC on setxattrs on " << cid
<< "/" << oid
<< dendl
;
2737 case Transaction::OP_RMATTR
:
2739 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2740 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2741 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2742 _cid
: _cid
.get_temp();
2743 string name
= i
.decode_string();
2744 tracepoint(objectstore
, rmattr_enter
, osr_name
);
2745 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2746 r
= _rmattr(cid
, oid
, name
.c_str(), spos
);
2747 tracepoint(objectstore
, rmattr_exit
, r
);
2751 case Transaction::OP_RMATTRS
:
2753 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2754 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2755 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2756 _cid
: _cid
.get_temp();
2757 tracepoint(objectstore
, rmattrs_enter
, osr_name
);
2758 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2759 r
= _rmattrs(cid
, oid
, spos
);
2760 tracepoint(objectstore
, rmattrs_exit
, r
);
2764 case Transaction::OP_CLONE
:
2766 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2767 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2768 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2769 _cid
: _cid
.get_temp();
2770 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2771 tracepoint(objectstore
, clone_enter
, osr_name
);
2772 r
= _clone(cid
, oid
, noid
, spos
);
2773 tracepoint(objectstore
, clone_exit
, r
);
2777 case Transaction::OP_CLONERANGE
:
2779 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2780 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2781 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2782 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2783 _cid
: _cid
.get_temp();
2784 const coll_t
&ncid
= !_need_temp_object_collection(_cid
, noid
) ?
2785 _cid
: _cid
.get_temp();
2786 uint64_t off
= op
->off
;
2787 uint64_t len
= op
->len
;
2788 tracepoint(objectstore
, clone_range_enter
, osr_name
, len
);
2789 r
= _clone_range(cid
, oid
, ncid
, noid
, off
, len
, off
, spos
);
2790 tracepoint(objectstore
, clone_range_exit
, r
);
2794 case Transaction::OP_CLONERANGE2
:
2796 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2797 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2798 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2799 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2800 _cid
: _cid
.get_temp();
2801 const coll_t
&ncid
= !_need_temp_object_collection(_cid
, noid
) ?
2802 _cid
: _cid
.get_temp();
2803 uint64_t srcoff
= op
->off
;
2804 uint64_t len
= op
->len
;
2805 uint64_t dstoff
= op
->dest_off
;
2806 tracepoint(objectstore
, clone_range2_enter
, osr_name
, len
);
2807 r
= _clone_range(cid
, oid
, ncid
, noid
, srcoff
, len
, dstoff
, spos
);
2808 tracepoint(objectstore
, clone_range2_exit
, r
);
2812 case Transaction::OP_MKCOLL
:
2814 const coll_t
&cid
= i
.get_cid(op
->cid
);
2815 tracepoint(objectstore
, mkcoll_enter
, osr_name
);
2816 if (_check_replay_guard(cid
, spos
) > 0)
2817 r
= _create_collection(cid
, op
->split_bits
, spos
);
2818 tracepoint(objectstore
, mkcoll_exit
, r
);
2822 case Transaction::OP_COLL_SET_BITS
:
2824 const coll_t
&cid
= i
.get_cid(op
->cid
);
2825 int bits
= op
->split_bits
;
2826 r
= _collection_set_bits(cid
, bits
);
2830 case Transaction::OP_COLL_HINT
:
2832 const coll_t
&cid
= i
.get_cid(op
->cid
);
2833 uint32_t type
= op
->hint_type
;
2836 bufferlist::iterator hiter
= hint
.begin();
2837 if (type
== Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS
) {
2840 ::decode(pg_num
, hiter
);
2841 ::decode(num_objs
, hiter
);
2842 if (_check_replay_guard(cid
, spos
) > 0) {
2843 r
= _collection_hint_expected_num_objs(cid
, pg_num
, num_objs
, spos
);
2847 dout(10) << "Unrecognized collection hint type: " << type
<< dendl
;
2852 case Transaction::OP_RMCOLL
:
2854 const coll_t
&cid
= i
.get_cid(op
->cid
);
2855 tracepoint(objectstore
, rmcoll_enter
, osr_name
);
2856 if (_check_replay_guard(cid
, spos
) > 0)
2857 r
= _destroy_collection(cid
);
2858 tracepoint(objectstore
, rmcoll_exit
, r
);
2862 case Transaction::OP_COLL_ADD
:
2864 const coll_t
&ocid
= i
.get_cid(op
->cid
);
2865 const coll_t
&ncid
= i
.get_cid(op
->dest_cid
);
2866 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2868 assert(oid
.hobj
.pool
>= -1);
2870 // always followed by OP_COLL_REMOVE
2871 Transaction::Op
*op2
= i
.decode_op();
2872 const coll_t
&ocid2
= i
.get_cid(op2
->cid
);
2873 const ghobject_t
&oid2
= i
.get_oid(op2
->oid
);
2874 assert(op2
->op
== Transaction::OP_COLL_REMOVE
);
2875 assert(ocid2
== ocid
);
2876 assert(oid2
== oid
);
2878 tracepoint(objectstore
, coll_add_enter
);
2879 r
= _collection_add(ncid
, ocid
, oid
, spos
);
2880 tracepoint(objectstore
, coll_add_exit
, r
);
2884 tracepoint(objectstore
, coll_remove_enter
, osr_name
);
2885 if (_check_replay_guard(ocid
, oid
, spos
) > 0)
2886 r
= _remove(ocid
, oid
, spos
);
2887 tracepoint(objectstore
, coll_remove_exit
, r
);
2891 case Transaction::OP_COLL_MOVE
:
2893 // WARNING: this is deprecated and buggy; only here to replay old journals.
2894 const coll_t
&ocid
= i
.get_cid(op
->cid
);
2895 const coll_t
&ncid
= i
.get_cid(op
->dest_cid
);
2896 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2897 tracepoint(objectstore
, coll_move_enter
);
2898 r
= _collection_add(ocid
, ncid
, oid
, spos
);
2900 (_check_replay_guard(ocid
, oid
, spos
) > 0))
2901 r
= _remove(ocid
, oid
, spos
);
2902 tracepoint(objectstore
, coll_move_exit
, r
);
2906 case Transaction::OP_COLL_MOVE_RENAME
:
2908 const coll_t
&_oldcid
= i
.get_cid(op
->cid
);
2909 const ghobject_t
&oldoid
= i
.get_oid(op
->oid
);
2910 const coll_t
&_newcid
= i
.get_cid(op
->dest_cid
);
2911 const ghobject_t
&newoid
= i
.get_oid(op
->dest_oid
);
2912 const coll_t
&oldcid
= !_need_temp_object_collection(_oldcid
, oldoid
) ?
2913 _oldcid
: _oldcid
.get_temp();
2914 const coll_t
&newcid
= !_need_temp_object_collection(_newcid
, newoid
) ?
2915 _oldcid
: _newcid
.get_temp();
2916 tracepoint(objectstore
, coll_move_rename_enter
);
2917 r
= _collection_move_rename(oldcid
, oldoid
, newcid
, newoid
, spos
);
2918 tracepoint(objectstore
, coll_move_rename_exit
, r
);
2922 case Transaction::OP_TRY_RENAME
:
2924 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2925 const ghobject_t
&oldoid
= i
.get_oid(op
->oid
);
2926 const ghobject_t
&newoid
= i
.get_oid(op
->dest_oid
);
2927 const coll_t
&oldcid
= !_need_temp_object_collection(_cid
, oldoid
) ?
2928 _cid
: _cid
.get_temp();
2929 const coll_t
&newcid
= !_need_temp_object_collection(_cid
, newoid
) ?
2930 _cid
: _cid
.get_temp();
2931 tracepoint(objectstore
, coll_try_rename_enter
);
2932 r
= _collection_move_rename(oldcid
, oldoid
, newcid
, newoid
, spos
, true);
2933 tracepoint(objectstore
, coll_try_rename_exit
, r
);
2937 case Transaction::OP_COLL_SETATTR
:
2938 case Transaction::OP_COLL_RMATTR
:
2939 assert(0 == "collection attr methods no longer implemented");
2942 case Transaction::OP_STARTSYNC
:
2943 tracepoint(objectstore
, startsync_enter
, osr_name
);
2945 tracepoint(objectstore
, startsync_exit
);
2948 case Transaction::OP_COLL_RENAME
:
2954 case Transaction::OP_OMAP_CLEAR
:
2956 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2957 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2958 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2959 _cid
: _cid
.get_temp();
2960 tracepoint(objectstore
, omap_clear_enter
, osr_name
);
2961 r
= _omap_clear(cid
, oid
, spos
);
2962 tracepoint(objectstore
, omap_clear_exit
, r
);
2965 case Transaction::OP_OMAP_SETKEYS
:
2967 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2968 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2969 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2970 _cid
: _cid
.get_temp();
2971 map
<string
, bufferlist
> aset
;
2972 i
.decode_attrset(aset
);
2973 tracepoint(objectstore
, omap_setkeys_enter
, osr_name
);
2974 r
= _omap_setkeys(cid
, oid
, aset
, spos
);
2975 tracepoint(objectstore
, omap_setkeys_exit
, r
);
2978 case Transaction::OP_OMAP_RMKEYS
:
2980 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2981 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2982 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2983 _cid
: _cid
.get_temp();
2985 i
.decode_keyset(keys
);
2986 tracepoint(objectstore
, omap_rmkeys_enter
, osr_name
);
2987 r
= _omap_rmkeys(cid
, oid
, keys
, spos
);
2988 tracepoint(objectstore
, omap_rmkeys_exit
, r
);
2991 case Transaction::OP_OMAP_RMKEYRANGE
:
2993 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2994 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2995 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2996 _cid
: _cid
.get_temp();
2998 first
= i
.decode_string();
2999 last
= i
.decode_string();
3000 tracepoint(objectstore
, omap_rmkeyrange_enter
, osr_name
);
3001 r
= _omap_rmkeyrange(cid
, oid
, first
, last
, spos
);
3002 tracepoint(objectstore
, omap_rmkeyrange_exit
, r
);
3005 case Transaction::OP_OMAP_SETHEADER
:
3007 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3008 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3009 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3010 _cid
: _cid
.get_temp();
3013 tracepoint(objectstore
, omap_setheader_enter
, osr_name
);
3014 r
= _omap_setheader(cid
, oid
, bl
, spos
);
3015 tracepoint(objectstore
, omap_setheader_exit
, r
);
3018 case Transaction::OP_SPLIT_COLLECTION
:
3020 assert(0 == "not legacy journal; upgrade to firefly first");
3023 case Transaction::OP_SPLIT_COLLECTION2
:
3025 coll_t cid
= i
.get_cid(op
->cid
);
3026 uint32_t bits
= op
->split_bits
;
3027 uint32_t rem
= op
->split_rem
;
3028 coll_t dest
= i
.get_cid(op
->dest_cid
);
3029 tracepoint(objectstore
, split_coll2_enter
, osr_name
);
3030 r
= _split_collection(cid
, bits
, rem
, dest
, spos
);
3031 tracepoint(objectstore
, split_coll2_exit
, r
);
3035 case Transaction::OP_SETALLOCHINT
:
3037 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3038 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3039 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3040 _cid
: _cid
.get_temp();
3041 uint64_t expected_object_size
= op
->expected_object_size
;
3042 uint64_t expected_write_size
= op
->expected_write_size
;
3043 tracepoint(objectstore
, setallochint_enter
, osr_name
);
3044 if (_check_replay_guard(cid
, oid
, spos
) > 0)
3045 r
= _set_alloc_hint(cid
, oid
, expected_object_size
,
3046 expected_write_size
);
3047 tracepoint(objectstore
, setallochint_exit
, r
);
3052 derr
<< "bad op " << op
->op
<< dendl
;
3059 if (r
== -ENOENT
&& !(op
->op
== Transaction::OP_CLONERANGE
||
3060 op
->op
== Transaction::OP_CLONE
||
3061 op
->op
== Transaction::OP_CLONERANGE2
||
3062 op
->op
== Transaction::OP_COLL_ADD
||
3063 op
->op
== Transaction::OP_SETATTR
||
3064 op
->op
== Transaction::OP_SETATTRS
||
3065 op
->op
== Transaction::OP_RMATTR
||
3066 op
->op
== Transaction::OP_OMAP_SETKEYS
||
3067 op
->op
== Transaction::OP_OMAP_RMKEYS
||
3068 op
->op
== Transaction::OP_OMAP_RMKEYRANGE
||
3069 op
->op
== Transaction::OP_OMAP_SETHEADER
))
3070 // -ENOENT is normally okay
3071 // ...including on a replayed OP_RMCOLL with checkpoint mode
3076 if (op
->op
== Transaction::OP_SETALLOCHINT
)
3077 // Either EOPNOTSUPP or EINVAL most probably. EINVAL in most
3078 // cases means invalid hint size (e.g. too big, not a multiple
3079 // of block size, etc) or, at least on xfs, an attempt to set
3080 // or change it when the file is not empty. However,
3081 // OP_SETALLOCHINT is advisory, so ignore all errors.
3084 if (replaying
&& !backend
->can_checkpoint()) {
3085 if (r
== -EEXIST
&& op
->op
== Transaction::OP_MKCOLL
) {
3086 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3089 if (r
== -EEXIST
&& op
->op
== Transaction::OP_COLL_ADD
) {
3090 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3093 if (r
== -EEXIST
&& op
->op
== Transaction::OP_COLL_MOVE
) {
3094 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3098 dout(10) << "tolerating ERANGE on replay" << dendl
;
3102 dout(10) << "tolerating ENOENT on replay" << dendl
;
3108 const char *msg
= "unexpected error code";
3110 if (r
== -ENOENT
&& (op
->op
== Transaction::OP_CLONERANGE
||
3111 op
->op
== Transaction::OP_CLONE
||
3112 op
->op
== Transaction::OP_CLONERANGE2
)) {
3113 msg
= "ENOENT on clone suggests osd bug";
3114 } else if (r
== -ENOSPC
) {
3115 // For now, if we hit _any_ ENOSPC, crash, before we do any damage
3116 // by partially applying transactions.
3117 msg
= "ENOSPC from disk filesystem, misconfigured cluster";
3118 } else if (r
== -ENOTEMPTY
) {
3119 msg
= "ENOTEMPTY suggests garbage data in osd data dir";
3120 } else if (r
== -EPERM
) {
3121 msg
= "EPERM suggests file(s) in osd data dir not owned by ceph user, or leveldb corruption";
3124 derr
<< " error " << cpp_strerror(r
) << " not handled on operation " << op
3125 << " (" << spos
<< ", or op " << spos
.op
<< ", counting from 0)" << dendl
;
3126 dout(0) << msg
<< dendl
;
3127 dout(0) << " transaction dump:\n";
3128 JSONFormatter
f(true);
3129 f
.open_object_section("transaction");
3139 assert(0 == "unexpected error");
3149 /*********************************************/
3153 // --------------------
3156 bool FileStore::exists(const coll_t
& _cid
, const ghobject_t
& oid
)
3158 tracepoint(objectstore
, exists_enter
, _cid
.c_str());
3159 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3161 bool retval
= stat(cid
, oid
, &st
) == 0;
3162 tracepoint(objectstore
, exists_exit
, retval
);
3166 int FileStore::stat(
3167 const coll_t
& _cid
, const ghobject_t
& oid
, struct stat
*st
, bool allow_eio
)
3169 tracepoint(objectstore
, stat_enter
, _cid
.c_str());
3170 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3171 int r
= lfn_stat(cid
, oid
, st
);
3172 assert(allow_eio
|| !m_filestore_fail_eio
|| r
!= -EIO
);
3174 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
3175 << " = " << r
<< dendl
;
3177 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
3179 << " (size " << st
->st_size
<< ")" << dendl
;
3181 if (cct
->_conf
->filestore_debug_inject_read_err
&&
3182 debug_mdata_eio(oid
)) {
3185 tracepoint(objectstore
, stat_exit
, r
);
3190 int FileStore::set_collection_opts(
3192 const pool_opts_t
& opts
)
3197 int FileStore::read(
3199 const ghobject_t
& oid
,
3206 tracepoint(objectstore
, read_enter
, _cid
.c_str(), offset
, len
);
3207 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3209 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3212 int r
= lfn_open(cid
, oid
, false, &fd
);
3214 dout(10) << __FUNC__
<< ": (" << cid
<< "/" << oid
<< ") open error: "
3215 << cpp_strerror(r
) << dendl
;
3219 if (offset
== 0 && len
== 0) {
3221 memset(&st
, 0, sizeof(struct stat
));
3222 int r
= ::fstat(**fd
, &st
);
3227 #ifdef HAVE_POSIX_FADVISE
3228 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_RANDOM
)
3229 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_RANDOM
);
3230 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
)
3231 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_SEQUENTIAL
);
3234 bufferptr
bptr(len
); // prealloc space for entire read
3235 got
= safe_pread(**fd
, bptr
.c_str(), len
, offset
);
3237 dout(10) << __FUNC__
<< ": (" << cid
<< "/" << oid
<< ") pread error: " << cpp_strerror(got
) << dendl
;
3241 bptr
.set_length(got
); // properly size the buffer
3243 bl
.push_back(std::move(bptr
)); // put it in the target bufferlist
3245 #ifdef HAVE_POSIX_FADVISE
3246 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
)
3247 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_DONTNEED
);
3248 if (op_flags
& (CEPH_OSD_OP_FLAG_FADVISE_RANDOM
| CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
))
3249 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_NORMAL
);
3252 if (m_filestore_sloppy_crc
&& (!replaying
|| backend
->can_checkpoint())) {
3254 int errors
= backend
->_crc_verify_read(**fd
, offset
, got
, bl
, &ss
);
3256 dout(0) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~"
3257 << got
<< " ... BAD CRC:\n" << ss
.str() << dendl
;
3258 assert(0 == "bad crc on read");
3264 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~"
3265 << got
<< "/" << len
<< dendl
;
3266 if (cct
->_conf
->filestore_debug_inject_read_err
&&
3267 debug_data_eio(oid
)) {
3269 } else if (cct
->_conf
->filestore_debug_random_read_err
&&
3270 (rand() % (int)(cct
->_conf
->filestore_debug_random_read_err
* 100.0)) == 0) {
3271 dout(0) << __func__
<< ": inject random EIO" << dendl
;
3274 tracepoint(objectstore
, read_exit
, got
);
3279 int FileStore::_do_fiemap(int fd
, uint64_t offset
, size_t len
,
3280 map
<uint64_t, uint64_t> *m
)
3283 struct fiemap_extent
*extent
= NULL
;
3284 struct fiemap
*fiemap
= NULL
;
3288 r
= backend
->do_fiemap(fd
, offset
, len
, &fiemap
);
3292 if (fiemap
->fm_mapped_extents
== 0) {
3297 extent
= &fiemap
->fm_extents
[0];
3299 /* start where we were asked to start */
3300 if (extent
->fe_logical
< offset
) {
3301 extent
->fe_length
-= offset
- extent
->fe_logical
;
3302 extent
->fe_logical
= offset
;
3307 struct fiemap_extent
*last
= nullptr;
3308 while (i
< fiemap
->fm_mapped_extents
) {
3309 struct fiemap_extent
*next
= extent
+ 1;
3311 dout(10) << __FUNC__
<< ": fm_mapped_extents=" << fiemap
->fm_mapped_extents
3312 << " fe_logical=" << extent
->fe_logical
<< " fe_length=" << extent
->fe_length
<< dendl
;
3314 /* try to merge extents */
3315 while ((i
< fiemap
->fm_mapped_extents
- 1) &&
3316 (extent
->fe_logical
+ extent
->fe_length
== next
->fe_logical
)) {
3317 next
->fe_length
+= extent
->fe_length
;
3318 next
->fe_logical
= extent
->fe_logical
;
3324 if (extent
->fe_logical
+ extent
->fe_length
> offset
+ len
)
3325 extent
->fe_length
= offset
+ len
- extent
->fe_logical
;
3326 (*m
)[extent
->fe_logical
] = extent
->fe_length
;
3330 uint64_t xoffset
= last
->fe_logical
+ last
->fe_length
- offset
;
3331 offset
= last
->fe_logical
+ last
->fe_length
;
3333 const bool is_last
= (last
->fe_flags
& FIEMAP_EXTENT_LAST
) || (len
== 0);
3342 int FileStore::_do_seek_hole_data(int fd
, uint64_t offset
, size_t len
,
3343 map
<uint64_t, uint64_t> *m
)
3345 #if defined(__linux__) && defined(SEEK_HOLE) && defined(SEEK_DATA)
3346 off_t hole_pos
, data_pos
;
3349 // If lseek fails with errno setting to be ENXIO, this means the current
3350 // file offset is beyond the end of the file.
3351 off_t start
= offset
;
3352 while(start
< (off_t
)(offset
+ len
)) {
3353 data_pos
= lseek(fd
, start
, SEEK_DATA
);
3359 dout(10) << "failed to lseek: " << cpp_strerror(r
) << dendl
;
3362 } else if (data_pos
> (off_t
)(offset
+ len
)) {
3366 hole_pos
= lseek(fd
, data_pos
, SEEK_HOLE
);
3368 if (errno
== ENXIO
) {
3372 dout(10) << "failed to lseek: " << cpp_strerror(r
) << dendl
;
3377 if (hole_pos
>= (off_t
)(offset
+ len
)) {
3378 (*m
)[data_pos
] = offset
+ len
- data_pos
;
3381 (*m
)[data_pos
] = hole_pos
- data_pos
;
3392 int FileStore::fiemap(const coll_t
& _cid
, const ghobject_t
& oid
,
3393 uint64_t offset
, size_t len
,
3396 map
<uint64_t, uint64_t> exomap
;
3397 int r
= fiemap(_cid
, oid
, offset
, len
, exomap
);
3399 ::encode(exomap
, bl
);
3404 int FileStore::fiemap(const coll_t
& _cid
, const ghobject_t
& oid
,
3405 uint64_t offset
, size_t len
,
3406 map
<uint64_t, uint64_t>& destmap
)
3408 tracepoint(objectstore
, fiemap_enter
, _cid
.c_str(), offset
, len
);
3409 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3412 if ((!backend
->has_seek_data_hole() && !backend
->has_fiemap()) ||
3413 len
<= (size_t)m_filestore_fiemap_threshold
) {
3414 destmap
[offset
] = len
;
3418 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3422 int r
= lfn_open(cid
, oid
, false, &fd
);
3424 dout(10) << "read couldn't open " << cid
<< "/" << oid
<< ": " << cpp_strerror(r
) << dendl
;
3428 if (backend
->has_seek_data_hole()) {
3429 dout(15) << "seek_data/seek_hole " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3430 r
= _do_seek_hole_data(**fd
, offset
, len
, &destmap
);
3431 } else if (backend
->has_fiemap()) {
3432 dout(15) << "fiemap ioctl" << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3433 r
= _do_fiemap(**fd
, offset
, len
, &destmap
);
3440 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << r
<< " num_extents=" << destmap
.size() << " " << destmap
<< dendl
;
3441 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
3442 tracepoint(objectstore
, fiemap_exit
, r
);
3446 int FileStore::_remove(const coll_t
& cid
, const ghobject_t
& oid
,
3447 const SequencerPosition
&spos
)
3449 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
3450 int r
= lfn_unlink(cid
, oid
, spos
);
3451 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
3455 int FileStore::_truncate(const coll_t
& cid
, const ghobject_t
& oid
, uint64_t size
)
3457 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " size " << size
<< dendl
;
3458 int r
= lfn_truncate(cid
, oid
, size
);
3459 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " size " << size
<< " = " << r
<< dendl
;
3464 int FileStore::_touch(const coll_t
& cid
, const ghobject_t
& oid
)
3466 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
3469 int r
= lfn_open(cid
, oid
, true, &fd
);
3475 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
3479 int FileStore::_write(const coll_t
& cid
, const ghobject_t
& oid
,
3480 uint64_t offset
, size_t len
,
3481 const bufferlist
& bl
, uint32_t fadvise_flags
)
3483 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3487 r
= lfn_open(cid
, oid
, true, &fd
);
3489 dout(0) << __FUNC__
<< ": couldn't open " << cid
<< "/"
3491 << cpp_strerror(r
) << dendl
;
3496 r
= bl
.write_fd(**fd
, offset
);
3498 derr
<< __FUNC__
<< ": write_fd on " << cid
<< "/" << oid
3499 << " error: " << cpp_strerror(r
) << dendl
;
3505 if (r
>= 0 && m_filestore_sloppy_crc
) {
3506 int rc
= backend
->_crc_update_write(**fd
, offset
, len
, bl
);
3510 if (replaying
|| m_disable_wbthrottle
) {
3511 if (fadvise_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
) {
3512 #ifdef HAVE_POSIX_FADVISE
3513 posix_fadvise(**fd
, 0, 0, POSIX_FADV_DONTNEED
);
3517 wbthrottle
.queue_wb(fd
, oid
, offset
, len
,
3518 fadvise_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
);
3524 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << r
<< dendl
;
3528 int FileStore::_zero(const coll_t
& cid
, const ghobject_t
& oid
, uint64_t offset
, size_t len
)
3530 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3533 if (cct
->_conf
->filestore_punch_hole
) {
3534 #ifdef CEPH_HAVE_FALLOCATE
3535 # if !defined(DARWIN) && !defined(__FreeBSD__)
3536 # ifdef FALLOC_FL_KEEP_SIZE
3537 // first try to punch a hole.
3539 ret
= lfn_open(cid
, oid
, false, &fd
);
3545 ret
= ::fstat(**fd
, &st
);
3552 // first try fallocate
3553 ret
= fallocate(**fd
, FALLOC_FL_KEEP_SIZE
| FALLOC_FL_PUNCH_HOLE
,
3558 // ensure we extent file size, if needed
3559 if (offset
+ len
> (uint64_t)st
.st_size
) {
3560 ret
= ::ftruncate(**fd
, offset
+ len
);
3570 if (ret
>= 0 && m_filestore_sloppy_crc
) {
3571 int rc
= backend
->_crc_update_zero(**fd
, offset
, len
);
3577 if (ret
!= -EOPNOTSUPP
)
3578 goto out
; // some other error
3584 // lame, kernel is old and doesn't support it.
3585 // write zeros.. yuck!
3586 dout(20) << __FUNC__
<< ": falling back to writing zeros" << dendl
;
3589 bl
.append_zero(len
);
3590 ret
= _write(cid
, oid
, offset
, len
, bl
);
3593 #ifdef CEPH_HAVE_FALLOCATE
3594 # if !defined(DARWIN) && !defined(__FreeBSD__)
3595 # ifdef FALLOC_FL_KEEP_SIZE
3600 dout(20) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << ret
<< dendl
;
3604 int FileStore::_clone(const coll_t
& cid
, const ghobject_t
& oldoid
, const ghobject_t
& newoid
,
3605 const SequencerPosition
& spos
)
3607 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oldoid
<< " -> " << cid
<< "/" << newoid
<< dendl
;
3609 if (_check_replay_guard(cid
, newoid
, spos
) < 0)
3616 r
= lfn_open(cid
, oldoid
, false, &o
, &index
);
3620 assert(NULL
!= (index
.index
));
3621 RWLock::WLocker
l((index
.index
)->access_lock
);
3623 r
= lfn_open(cid
, newoid
, true, &n
, &index
);
3627 r
= ::ftruncate(**n
, 0);
3633 r
= ::fstat(**o
, &st
);
3639 r
= _do_clone_range(**o
, **n
, 0, st
.st_size
, 0);
3644 dout(20) << "objectmap clone" << dendl
;
3645 r
= object_map
->clone(oldoid
, newoid
, &spos
);
3646 if (r
< 0 && r
!= -ENOENT
)
3652 map
<string
, bufferptr
> aset
;
3653 r
= _fgetattrs(**o
, aset
);
3657 r
= chain_fgetxattr(**o
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
3658 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
3659 r
= chain_fsetxattr
<true, true>(**n
, XATTR_SPILL_OUT_NAME
, XATTR_NO_SPILL_OUT
,
3660 sizeof(XATTR_NO_SPILL_OUT
));
3662 r
= chain_fsetxattr
<true, true>(**n
, XATTR_SPILL_OUT_NAME
, XATTR_SPILL_OUT
,
3663 sizeof(XATTR_SPILL_OUT
));
3668 r
= _fsetattrs(**n
, aset
);
3673 // clone is non-idempotent; record our work.
3674 _set_replay_guard(**n
, spos
, &newoid
);
3681 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oldoid
<< " -> " << cid
<< "/" << newoid
<< " = " << r
<< dendl
;
3682 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
3686 int FileStore::_do_clone_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
)
3688 dout(20) << __FUNC__
<< ": copy " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3689 return backend
->clone_range(from
, to
, srcoff
, len
, dstoff
);
3692 int FileStore::_do_sparse_copy_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
)
3694 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3696 map
<uint64_t, uint64_t> exomap
;
3697 // fiemap doesn't allow zero length
3701 if (backend
->has_seek_data_hole()) {
3702 dout(15) << "seek_data/seek_hole " << from
<< " " << srcoff
<< "~" << len
<< dendl
;
3703 r
= _do_seek_hole_data(from
, srcoff
, len
, &exomap
);
3704 } else if (backend
->has_fiemap()) {
3705 dout(15) << "fiemap ioctl" << from
<< " " << srcoff
<< "~" << len
<< dendl
;
3706 r
= _do_fiemap(from
, srcoff
, len
, &exomap
);
3710 int64_t written
= 0;
3714 for (map
<uint64_t, uint64_t>::iterator miter
= exomap
.begin(); miter
!= exomap
.end(); ++miter
) {
3715 uint64_t it_off
= miter
->first
- srcoff
+ dstoff
;
3716 r
= _do_copy_range(from
, to
, miter
->first
, miter
->second
, it_off
, true);
3718 derr
<< __FUNC__
<< ": copy error at " << miter
->first
<< "~" << miter
->second
3719 << " to " << it_off
<< ", " << cpp_strerror(r
) << dendl
;
3722 written
+= miter
->second
;
3726 if (m_filestore_sloppy_crc
) {
3727 int rc
= backend
->_crc_update_clone_range(from
, to
, srcoff
, len
, dstoff
);
3731 r
= ::fstat(to
, &st
);
3734 derr
<< __FUNC__
<< ": fstat error at " << to
<< " " << cpp_strerror(r
) << dendl
;
3737 if (st
.st_size
< (int)(dstoff
+ len
)) {
3738 r
= ::ftruncate(to
, dstoff
+ len
);
3741 derr
<< __FUNC__
<< ": ftruncate error at " << dstoff
+len
<< " " << cpp_strerror(r
) << dendl
;
3749 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3753 int FileStore::_do_copy_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
, bool skip_sloppycrc
)
3755 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3757 loff_t pos
= srcoff
;
3758 loff_t end
= srcoff
+ len
;
3759 int buflen
= 4096 * 16; //limit by pipe max size.see fcntl
3761 #ifdef CEPH_HAVE_SPLICE
3762 if (backend
->has_splice()) {
3764 if (pipe(pipefd
) < 0) {
3766 derr
<< " pipe " << " got " << cpp_strerror(r
) << dendl
;
3770 loff_t dstpos
= dstoff
;
3772 int l
= MIN(end
-pos
, buflen
);
3773 r
= safe_splice(from
, &pos
, pipefd
[1], NULL
, l
, SPLICE_F_NONBLOCK
);
3774 dout(10) << " safe_splice read from " << pos
<< "~" << l
<< " got " << r
<< dendl
;
3776 derr
<< __FUNC__
<< ": safe_splice read error at " << pos
<< "~" << len
3777 << ", " << cpp_strerror(r
) << dendl
;
3781 // hrm, bad source range, wtf.
3783 derr
<< __FUNC__
<< ": got short read result at " << pos
3784 << " of fd " << from
<< " len " << len
<< dendl
;
3788 r
= safe_splice(pipefd
[0], NULL
, to
, &dstpos
, r
, 0);
3789 dout(10) << " safe_splice write to " << to
<< " len " << r
3790 << " got " << r
<< dendl
;
3792 derr
<< __FUNC__
<< ": write error at " << pos
<< "~"
3793 << r
<< ", " << cpp_strerror(r
) << dendl
;
3804 actual
= ::lseek64(from
, srcoff
, SEEK_SET
);
3805 if (actual
!= (int64_t)srcoff
) {
3810 derr
<< "lseek64 to " << srcoff
<< " got " << cpp_strerror(r
) << dendl
;
3813 actual
= ::lseek64(to
, dstoff
, SEEK_SET
);
3814 if (actual
!= (int64_t)dstoff
) {
3819 derr
<< "lseek64 to " << dstoff
<< " got " << cpp_strerror(r
) << dendl
;
3825 int l
= MIN(end
-pos
, buflen
);
3826 r
= ::read(from
, buf
, l
);
3827 dout(25) << " read from " << pos
<< "~" << l
<< " got " << r
<< dendl
;
3829 if (errno
== EINTR
) {
3833 derr
<< __FUNC__
<< ": read error at " << pos
<< "~" << len
3834 << ", " << cpp_strerror(r
) << dendl
;
3839 // hrm, bad source range, wtf.
3841 derr
<< __FUNC__
<< ": got short read result at " << pos
3842 << " of fd " << from
<< " len " << len
<< dendl
;
3847 int r2
= safe_write(to
, buf
+op
, r
-op
);
3848 dout(25) << " write to " << to
<< " len " << (r
-op
)
3849 << " got " << r2
<< dendl
;
3852 derr
<< __FUNC__
<< ": write error at " << pos
<< "~"
3853 << r
-op
<< ", " << cpp_strerror(r
) << dendl
;
3865 if (r
< 0 && replaying
) {
3866 assert(r
== -ERANGE
);
3867 derr
<< __FUNC__
<< ": short source tolerated because we are replaying" << dendl
;
3870 assert(replaying
|| pos
== end
);
3871 if (r
>= 0 && !skip_sloppycrc
&& m_filestore_sloppy_crc
) {
3872 int rc
= backend
->_crc_update_clone_range(from
, to
, srcoff
, len
, dstoff
);
3875 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3879 int FileStore::_clone_range(const coll_t
& oldcid
, const ghobject_t
& oldoid
, const coll_t
& newcid
, const ghobject_t
& newoid
,
3880 uint64_t srcoff
, uint64_t len
, uint64_t dstoff
,
3881 const SequencerPosition
& spos
)
3883 dout(15) << __FUNC__
<< ": " << oldcid
<< "/" << oldoid
<< " -> " << newcid
<< "/" << newoid
<< " " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3885 if (_check_replay_guard(newcid
, newoid
, spos
) < 0)
3890 r
= lfn_open(oldcid
, oldoid
, false, &o
);
3894 r
= lfn_open(newcid
, newoid
, true, &n
);
3898 r
= _do_clone_range(**o
, **n
, srcoff
, len
, dstoff
);
3903 // clone is non-idempotent; record our work.
3904 _set_replay_guard(**n
, spos
, &newoid
);
3911 dout(10) << __FUNC__
<< ": " << oldcid
<< "/" << oldoid
<< " -> " << newcid
<< "/" << newoid
<< " "
3912 << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3916 class SyncEntryTimeout
: public Context
{
3919 explicit SyncEntryTimeout(CephContext
* cct
, int commit_timeo
)
3920 : cct(cct
), m_commit_timeo(commit_timeo
)
3924 void finish(int r
) override
{
3925 BackTrace
*bt
= new BackTrace(1);
3926 generic_dout(-1) << "FileStore: sync_entry timed out after "
3927 << m_commit_timeo
<< " seconds.\n";
3937 void FileStore::sync_entry()
3941 utime_t max_interval
;
3942 max_interval
.set_from_double(m_filestore_max_sync_interval
);
3943 utime_t min_interval
;
3944 min_interval
.set_from_double(m_filestore_min_sync_interval
);
3946 utime_t startwait
= ceph_clock_now();
3948 dout(20) << __FUNC__
<< ": waiting for max_interval " << max_interval
<< dendl
;
3949 sync_cond
.WaitInterval(lock
, max_interval
);
3951 dout(20) << __FUNC__
<< ": not waiting, force_sync set" << dendl
;
3955 dout(20) << __FUNC__
<< ": force_sync set" << dendl
;
3958 dout(20) << __FUNC__
<< ": stop set" << dendl
;
3961 // wait for at least the min interval
3962 utime_t woke
= ceph_clock_now();
3964 dout(20) << __FUNC__
<< ": woke after " << woke
<< dendl
;
3965 if (woke
< min_interval
) {
3966 utime_t t
= min_interval
;
3968 dout(20) << __FUNC__
<< ": waiting for another " << t
3969 << " to reach min interval " << min_interval
<< dendl
;
3970 sync_cond
.WaitInterval(lock
, t
);
3976 fin
.swap(sync_waiters
);
3980 if (apply_manager
.commit_start()) {
3981 utime_t start
= ceph_clock_now();
3982 uint64_t cp
= apply_manager
.get_committing_seq();
3984 sync_entry_timeo_lock
.Lock();
3985 SyncEntryTimeout
*sync_entry_timeo
=
3986 new SyncEntryTimeout(cct
, m_filestore_commit_timeout
);
3987 if (!timer
.add_event_after(m_filestore_commit_timeout
,
3988 sync_entry_timeo
)) {
3989 sync_entry_timeo
= nullptr;
3991 sync_entry_timeo_lock
.Unlock();
3993 logger
->set(l_filestore_committing
, 1);
3995 dout(15) << __FUNC__
<< ": committing " << cp
<< dendl
;
3996 stringstream errstream
;
3997 if (cct
->_conf
->filestore_debug_omap_check
&& !object_map
->check(errstream
)) {
3998 derr
<< errstream
.str() << dendl
;
4002 if (backend
->can_checkpoint()) {
4003 int err
= write_op_seq(op_fd
, cp
);
4005 derr
<< "Error during write_op_seq: " << cpp_strerror(err
) << dendl
;
4006 assert(0 == "error during write_op_seq");
4010 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)cp
);
4012 err
= backend
->create_checkpoint(s
, &cid
);
4015 derr
<< "snap create '" << s
<< "' got error " << err
<< dendl
;
4019 snaps
.push_back(cp
);
4020 apply_manager
.commit_started();
4024 dout(20) << " waiting for checkpoint " << cid
<< " to complete" << dendl
;
4025 err
= backend
->sync_checkpoint(cid
);
4027 derr
<< "ioctl WAIT_SYNC got " << cpp_strerror(err
) << dendl
;
4028 assert(0 == "wait_sync got error");
4030 dout(20) << " done waiting for checkpoint " << cid
<< " to complete" << dendl
;
4033 apply_manager
.commit_started();
4036 int err
= object_map
->sync();
4038 derr
<< "object_map sync got " << cpp_strerror(err
) << dendl
;
4039 assert(0 == "object_map sync returned error");
4042 err
= backend
->syncfs();
4044 derr
<< "syncfs got " << cpp_strerror(err
) << dendl
;
4045 assert(0 == "syncfs returned error");
4048 err
= write_op_seq(op_fd
, cp
);
4050 derr
<< "Error during write_op_seq: " << cpp_strerror(err
) << dendl
;
4051 assert(0 == "error during write_op_seq");
4053 err
= ::fsync(op_fd
);
4055 derr
<< "Error during fsync of op_seq: " << cpp_strerror(err
) << dendl
;
4056 assert(0 == "error during fsync of op_seq");
4060 utime_t done
= ceph_clock_now();
4061 utime_t lat
= done
- start
;
4062 utime_t dur
= done
- startwait
;
4063 dout(10) << __FUNC__
<< ": commit took " << lat
<< ", interval was " << dur
<< dendl
;
4064 utime_t max_pause_lat
= logger
->tget(l_filestore_sync_pause_max_lat
);
4065 if (max_pause_lat
< dur
- lat
) {
4066 logger
->tinc(l_filestore_sync_pause_max_lat
, dur
- lat
);
4069 logger
->inc(l_filestore_commitcycle
);
4070 logger
->tinc(l_filestore_commitcycle_latency
, lat
);
4071 logger
->tinc(l_filestore_commitcycle_interval
, dur
);
4073 apply_manager
.commit_finish();
4074 if (!m_disable_wbthrottle
) {
4078 logger
->set(l_filestore_committing
, 0);
4080 // remove old snaps?
4081 if (backend
->can_checkpoint()) {
4083 while (snaps
.size() > 2) {
4084 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)snaps
.front());
4086 dout(10) << "removing snap '" << s
<< "'" << dendl
;
4087 int r
= backend
->destroy_checkpoint(s
);
4090 derr
<< "unable to destroy snap '" << s
<< "' got " << cpp_strerror(err
) << dendl
;
4095 dout(15) << __FUNC__
<< ": committed to op_seq " << cp
<< dendl
;
4097 if (sync_entry_timeo
) {
4098 Mutex::Locker
lock(sync_entry_timeo_lock
);
4099 timer
.cancel_event(sync_entry_timeo
);
4106 finish_contexts(cct
, fin
, 0);
4108 if (!sync_waiters
.empty()) {
4109 dout(10) << __FUNC__
<< ": more waiters, committing again" << dendl
;
4112 if (!stop
&& journal
&& journal
->should_commit_now()) {
4113 dout(10) << __FUNC__
<< ": journal says we should commit again (probably is/was full)" << dendl
;
4121 void FileStore::_start_sync()
4123 if (!journal
) { // don't do a big sync if the journal is on
4124 dout(10) << __FUNC__
<< dendl
;
4127 dout(10) << __FUNC__
<< ": - NOOP (journal is on)" << dendl
;
4131 void FileStore::do_force_sync()
4133 dout(10) << __FUNC__
<< dendl
;
4134 Mutex::Locker
l(lock
);
4139 void FileStore::start_sync(Context
*onsafe
)
4141 Mutex::Locker
l(lock
);
4142 sync_waiters
.push_back(onsafe
);
4145 dout(10) << __FUNC__
<< dendl
;
4148 void FileStore::sync()
4150 Mutex
l("FileStore::sync");
4153 C_SafeCond
*fin
= new C_SafeCond(&l
, &c
, &done
);
4159 dout(10) << "sync waiting" << dendl
;
4163 dout(10) << "sync done" << dendl
;
4166 void FileStore::_flush_op_queue()
4168 dout(10) << __FUNC__
<< ": draining op tp" << dendl
;
4170 dout(10) << __FUNC__
<< ": waiting for apply finisher" << dendl
;
4171 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
4172 (*it
)->wait_for_empty();
4177 * flush - make every queued write readable
4179 void FileStore::flush()
4181 dout(10) << __FUNC__
<< dendl
;
4183 if (cct
->_conf
->filestore_blackhole
) {
4185 Mutex
lock("FileStore::flush::lock");
4193 if (m_filestore_journal_writeahead
) {
4196 dout(10) << __FUNC__
<< ": draining ondisk finisher" << dendl
;
4197 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
4198 (*it
)->wait_for_empty();
4203 dout(10) << __FUNC__
<< ": complete" << dendl
;
4207 * sync_and_flush - make every queued write readable AND committed to disk
4209 void FileStore::sync_and_flush()
4211 dout(10) << __FUNC__
<< dendl
;
4213 if (m_filestore_journal_writeahead
) {
4218 // includes m_filestore_journal_parallel
4222 dout(10) << __FUNC__
<< ": done" << dendl
;
4225 int FileStore::flush_journal()
4227 dout(10) << __FUNC__
<< dendl
;
4233 int FileStore::snapshot(const string
& name
)
4235 dout(10) << __FUNC__
<< ": " << name
<< dendl
;
4238 if (!backend
->can_checkpoint()) {
4239 dout(0) << __FUNC__
<< ": " << name
<< " failed, not supported" << dendl
;
4244 snprintf(s
, sizeof(s
), CLUSTER_SNAP_ITEM
, name
.c_str());
4246 int r
= backend
->create_checkpoint(s
, NULL
);
4248 derr
<< __FUNC__
<< ": " << name
<< " failed: " << cpp_strerror(r
) << dendl
;
4254 // -------------------------------
4257 int FileStore::_fgetattr(int fd
, const char *name
, bufferptr
& bp
)
4259 char val
[CHAIN_XATTR_MAX_BLOCK_LEN
];
4260 int l
= chain_fgetxattr(fd
, name
, val
, sizeof(val
));
4262 bp
= buffer::create(l
);
4263 memcpy(bp
.c_str(), val
, l
);
4264 } else if (l
== -ERANGE
) {
4265 l
= chain_fgetxattr(fd
, name
, 0, 0);
4267 bp
= buffer::create(l
);
4268 l
= chain_fgetxattr(fd
, name
, bp
.c_str(), l
);
4271 assert(!m_filestore_fail_eio
|| l
!= -EIO
);
4275 int FileStore::_fgetattrs(int fd
, map
<string
,bufferptr
>& aset
)
4279 int len
= chain_flistxattr(fd
, names1
, sizeof(names1
)-1);
4282 if (len
== -ERANGE
) {
4283 len
= chain_flistxattr(fd
, 0, 0);
4285 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4288 dout(10) << " -ERANGE, len is " << len
<< dendl
;
4289 names2
= new char[len
+1];
4290 len
= chain_flistxattr(fd
, names2
, len
);
4291 dout(10) << " -ERANGE, got " << len
<< dendl
;
4293 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4298 } else if (len
< 0) {
4299 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4306 char *end
= name
+ len
;
4307 while (name
< end
) {
4308 char *attrname
= name
;
4309 if (parse_attrname(&name
)) {
4311 dout(20) << __FUNC__
<< ": " << fd
<< " getting '" << name
<< "'" << dendl
;
4312 int r
= _fgetattr(fd
, attrname
, aset
[name
]);
4319 name
+= strlen(name
) + 1;
4326 int FileStore::_fsetattrs(int fd
, map
<string
, bufferptr
> &aset
)
4328 for (map
<string
, bufferptr
>::iterator p
= aset
.begin();
4331 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4332 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4334 if (p
->second
.length())
4335 val
= p
->second
.c_str();
4338 // ??? Why do we skip setting all the other attrs if one fails?
4339 int r
= chain_fsetxattr(fd
, n
, val
, p
->second
.length());
4341 derr
<< __FUNC__
<< ": chain_setxattr returned " << r
<< dendl
;
4348 // debug EIO injection
4349 void FileStore::inject_data_error(const ghobject_t
&oid
) {
4350 Mutex::Locker
l(read_error_lock
);
4351 dout(10) << __FUNC__
<< ": init error on " << oid
<< dendl
;
4352 data_error_set
.insert(oid
);
4354 void FileStore::inject_mdata_error(const ghobject_t
&oid
) {
4355 Mutex::Locker
l(read_error_lock
);
4356 dout(10) << __FUNC__
<< ": init error on " << oid
<< dendl
;
4357 mdata_error_set
.insert(oid
);
4360 void FileStore::debug_obj_on_delete(const ghobject_t
&oid
) {
4361 Mutex::Locker
l(read_error_lock
);
4362 dout(10) << __FUNC__
<< ": clear error on " << oid
<< dendl
;
4363 data_error_set
.erase(oid
);
4364 mdata_error_set
.erase(oid
);
4366 bool FileStore::debug_data_eio(const ghobject_t
&oid
) {
4367 Mutex::Locker
l(read_error_lock
);
4368 if (data_error_set
.count(oid
)) {
4369 dout(10) << __FUNC__
<< ": inject error on " << oid
<< dendl
;
4375 bool FileStore::debug_mdata_eio(const ghobject_t
&oid
) {
4376 Mutex::Locker
l(read_error_lock
);
4377 if (mdata_error_set
.count(oid
)) {
4378 dout(10) << __FUNC__
<< ": inject error on " << oid
<< dendl
;
4388 int FileStore::getattr(const coll_t
& _cid
, const ghobject_t
& oid
, const char *name
, bufferptr
&bp
)
4390 tracepoint(objectstore
, getattr_enter
, _cid
.c_str());
4391 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
4392 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "'" << dendl
;
4394 int r
= lfn_open(cid
, oid
, false, &fd
);
4398 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4399 get_attrname(name
, n
, CHAIN_XATTR_MAX_NAME_LEN
);
4400 r
= _fgetattr(**fd
, n
, bp
);
4402 if (r
== -ENODATA
) {
4403 map
<string
, bufferlist
> got
;
4405 to_get
.insert(string(name
));
4407 r
= get_index(cid
, &index
);
4409 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4412 r
= object_map
->get_xattrs(oid
, to_get
, &got
);
4413 if (r
< 0 && r
!= -ENOENT
) {
4414 dout(10) << __FUNC__
<< ": get_xattrs err r =" << r
<< dendl
;
4418 dout(10) << __FUNC__
<< ": got.size() is 0" << dendl
;
4421 bp
= bufferptr(got
.begin()->second
.c_str(),
4422 got
.begin()->second
.length());
4426 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "' = " << r
<< dendl
;
4427 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4428 if (cct
->_conf
->filestore_debug_inject_read_err
&&
4429 debug_mdata_eio(oid
)) {
4432 tracepoint(objectstore
, getattr_exit
, r
);
4433 return r
< 0 ? r
: 0;
4437 int FileStore::getattrs(const coll_t
& _cid
, const ghobject_t
& oid
, map
<string
,bufferptr
>& aset
)
4439 tracepoint(objectstore
, getattrs_enter
, _cid
.c_str());
4440 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
4441 set
<string
> omap_attrs
;
4442 map
<string
, bufferlist
> omap_aset
;
4444 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
4446 bool spill_out
= true;
4449 int r
= lfn_open(cid
, oid
, false, &fd
);
4454 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4455 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
)))
4458 r
= _fgetattrs(**fd
, aset
);
4460 fd
= FDRef(); // defensive
4466 dout(10) << __FUNC__
<< ": no xattr exists in object_map r = " << r
<< dendl
;
4470 r
= get_index(cid
, &index
);
4472 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4476 r
= object_map
->get_all_xattrs(oid
, &omap_attrs
);
4477 if (r
< 0 && r
!= -ENOENT
) {
4478 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4482 r
= object_map
->get_xattrs(oid
, omap_attrs
, &omap_aset
);
4483 if (r
< 0 && r
!= -ENOENT
) {
4484 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4490 assert(omap_attrs
.size() == omap_aset
.size());
4491 for (map
<string
, bufferlist
>::iterator i
= omap_aset
.begin();
4492 i
!= omap_aset
.end();
4494 string
key(i
->first
);
4495 aset
.insert(make_pair(key
,
4496 bufferptr(i
->second
.c_str(), i
->second
.length())));
4499 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4500 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4502 if (cct
->_conf
->filestore_debug_inject_read_err
&&
4503 debug_mdata_eio(oid
)) {
4506 tracepoint(objectstore
, getattrs_exit
, r
);
4511 int FileStore::_setattrs(const coll_t
& cid
, const ghobject_t
& oid
, map
<string
,bufferptr
>& aset
,
4512 const SequencerPosition
&spos
)
4514 map
<string
, bufferlist
> omap_set
;
4515 set
<string
> omap_remove
;
4516 map
<string
, bufferptr
> inline_set
;
4517 map
<string
, bufferptr
> inline_to_set
;
4520 bool incomplete_inline
= false;
4522 int r
= lfn_open(cid
, oid
, false, &fd
);
4528 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4529 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
)))
4534 r
= _fgetattrs(**fd
, inline_set
);
4535 incomplete_inline
= (r
== -E2BIG
);
4536 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4537 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
4538 << (incomplete_inline
? " (incomplete_inline, forcing omap)" : "")
4541 for (map
<string
,bufferptr
>::iterator p
= aset
.begin();
4544 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4545 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4547 if (incomplete_inline
) {
4548 chain_fremovexattr(**fd
, n
); // ignore any error
4549 omap_set
[p
->first
].push_back(p
->second
);
4553 if (p
->second
.length() > m_filestore_max_inline_xattr_size
) {
4554 if (inline_set
.count(p
->first
)) {
4555 inline_set
.erase(p
->first
);
4556 r
= chain_fremovexattr(**fd
, n
);
4560 omap_set
[p
->first
].push_back(p
->second
);
4564 if (!inline_set
.count(p
->first
) &&
4565 inline_set
.size() >= m_filestore_max_inline_xattrs
) {
4566 omap_set
[p
->first
].push_back(p
->second
);
4569 omap_remove
.insert(p
->first
);
4570 inline_set
.insert(*p
);
4572 inline_to_set
.insert(*p
);
4575 if (spill_out
!= 1 && !omap_set
.empty()) {
4576 chain_fsetxattr(**fd
, XATTR_SPILL_OUT_NAME
, XATTR_SPILL_OUT
,
4577 sizeof(XATTR_SPILL_OUT
));
4580 r
= _fsetattrs(**fd
, inline_to_set
);
4584 if (spill_out
&& !omap_remove
.empty()) {
4585 r
= object_map
->remove_xattrs(oid
, omap_remove
, &spos
);
4586 if (r
< 0 && r
!= -ENOENT
) {
4587 dout(10) << __FUNC__
<< ": could not remove_xattrs r = " << r
<< dendl
;
4588 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4591 r
= 0; // don't confuse the debug output
4595 if (!omap_set
.empty()) {
4596 r
= object_map
->set_xattrs(oid
, omap_set
, &spos
);
4598 dout(10) << __FUNC__
<< ": could not set_xattrs r = " << r
<< dendl
;
4599 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4606 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4611 int FileStore::_rmattr(const coll_t
& cid
, const ghobject_t
& oid
, const char *name
,
4612 const SequencerPosition
&spos
)
4614 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "'" << dendl
;
4616 bool spill_out
= true;
4618 int r
= lfn_open(cid
, oid
, false, &fd
);
4624 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4625 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
4629 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4630 get_attrname(name
, n
, CHAIN_XATTR_MAX_NAME_LEN
);
4631 r
= chain_fremovexattr(**fd
, n
);
4632 if (r
== -ENODATA
&& spill_out
) {
4634 r
= get_index(cid
, &index
);
4636 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4639 set
<string
> to_remove
;
4640 to_remove
.insert(string(name
));
4641 r
= object_map
->remove_xattrs(oid
, to_remove
, &spos
);
4642 if (r
< 0 && r
!= -ENOENT
) {
4643 dout(10) << __FUNC__
<< ": could not remove_xattrs index r = " << r
<< dendl
;
4644 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4651 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "' = " << r
<< dendl
;
4655 int FileStore::_rmattrs(const coll_t
& cid
, const ghobject_t
& oid
,
4656 const SequencerPosition
&spos
)
4658 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
4660 map
<string
,bufferptr
> aset
;
4662 set
<string
> omap_attrs
;
4664 bool spill_out
= true;
4666 int r
= lfn_open(cid
, oid
, false, &fd
);
4672 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4673 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
4677 r
= _fgetattrs(**fd
, aset
);
4679 for (map
<string
,bufferptr
>::iterator p
= aset
.begin(); p
!= aset
.end(); ++p
) {
4680 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4681 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4682 r
= chain_fremovexattr(**fd
, n
);
4684 dout(10) << __FUNC__
<< ": could not remove xattr r = " << r
<< dendl
;
4691 dout(10) << __FUNC__
<< ": no xattr exists in object_map r = " << r
<< dendl
;
4695 r
= get_index(cid
, &index
);
4697 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4701 r
= object_map
->get_all_xattrs(oid
, &omap_attrs
);
4702 if (r
< 0 && r
!= -ENOENT
) {
4703 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4704 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4707 r
= object_map
->remove_xattrs(oid
, omap_attrs
, &spos
);
4708 if (r
< 0 && r
!= -ENOENT
) {
4709 dout(10) << __FUNC__
<< ": could not remove omap_attrs r = " << r
<< dendl
;
4714 chain_fsetxattr(**fd
, XATTR_SPILL_OUT_NAME
, XATTR_NO_SPILL_OUT
,
4715 sizeof(XATTR_NO_SPILL_OUT
));
4721 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4728 int FileStore::_collection_remove_recursive(const coll_t
&cid
,
4729 const SequencerPosition
&spos
)
4732 int r
= collection_stat(cid
, &st
);
4739 vector
<ghobject_t
> objects
;
4741 while (!max
.is_max()) {
4742 r
= collection_list(cid
, max
, ghobject_t::get_max(),
4743 300, &objects
, &max
);
4746 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
4749 assert(_check_replay_guard(cid
, *i
, spos
));
4750 r
= _remove(cid
, *i
, spos
);
4756 return _destroy_collection(cid
);
4759 // --------------------------
4762 int FileStore::list_collections(vector
<coll_t
>& ls
)
4764 return list_collections(ls
, false);
4767 int FileStore::list_collections(vector
<coll_t
>& ls
, bool include_temp
)
4769 tracepoint(objectstore
, list_collections_enter
);
4770 dout(10) << __FUNC__
<< dendl
;
4773 snprintf(fn
, sizeof(fn
), "%s/current", basedir
.c_str());
4776 DIR *dir
= ::opendir(fn
);
4779 derr
<< "tried opening directory " << fn
<< ": " << cpp_strerror(-r
) << dendl
;
4780 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4784 struct dirent
*de
= nullptr;
4785 while ((de
= ::readdir(dir
))) {
4786 if (de
->d_type
== DT_UNKNOWN
) {
4787 // d_type not supported (non-ext[234], btrfs), must stat
4789 char filename
[PATH_MAX
];
4790 snprintf(filename
, sizeof(filename
), "%s/%s", fn
, de
->d_name
);
4792 r
= ::stat(filename
, &sb
);
4795 derr
<< "stat on " << filename
<< ": " << cpp_strerror(-r
) << dendl
;
4796 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4799 if (!S_ISDIR(sb
.st_mode
)) {
4802 } else if (de
->d_type
!= DT_DIR
) {
4805 if (strcmp(de
->d_name
, "omap") == 0) {
4808 if (de
->d_name
[0] == '.' &&
4809 (de
->d_name
[1] == '\0' ||
4810 (de
->d_name
[1] == '.' &&
4811 de
->d_name
[2] == '\0')))
4814 if (!cid
.parse(de
->d_name
)) {
4815 derr
<< "ignoring invalid collection '" << de
->d_name
<< "'" << dendl
;
4818 if (!cid
.is_temp() || include_temp
)
4823 derr
<< "trying readdir " << fn
<< ": " << cpp_strerror(r
) << dendl
;
4828 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4829 tracepoint(objectstore
, list_collections_exit
, r
);
4833 int FileStore::collection_stat(const coll_t
& c
, struct stat
*st
)
4835 tracepoint(objectstore
, collection_stat_enter
, c
.c_str());
4837 get_cdir(c
, fn
, sizeof(fn
));
4838 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
4839 int r
= ::stat(fn
, st
);
4842 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
4843 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4844 tracepoint(objectstore
, collection_stat_exit
, r
);
4848 bool FileStore::collection_exists(const coll_t
& c
)
4850 tracepoint(objectstore
, collection_exists_enter
, c
.c_str());
4852 bool ret
= collection_stat(c
, &st
) == 0;
4853 tracepoint(objectstore
, collection_exists_exit
, ret
);
4857 int FileStore::collection_empty(const coll_t
& c
, bool *empty
)
4859 tracepoint(objectstore
, collection_empty_enter
, c
.c_str());
4860 dout(15) << __FUNC__
<< ": " << c
<< dendl
;
4862 int r
= get_index(c
, &index
);
4864 derr
<< __FUNC__
<< ": get_index returned: " << cpp_strerror(r
)
4869 assert(NULL
!= index
.index
);
4870 RWLock::RLocker
l((index
.index
)->access_lock
);
4872 vector
<ghobject_t
> ls
;
4873 r
= index
->collection_list_partial(ghobject_t(), ghobject_t::get_max(),
4876 derr
<< __FUNC__
<< ": collection_list_partial returned: "
4877 << cpp_strerror(r
) << dendl
;
4878 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4881 *empty
= ls
.empty();
4882 tracepoint(objectstore
, collection_empty_exit
, *empty
);
4886 int FileStore::_collection_set_bits(const coll_t
& c
, int bits
)
4889 get_cdir(c
, fn
, sizeof(fn
));
4890 dout(10) << __FUNC__
<< ": " << fn
<< " " << bits
<< dendl
;
4894 int fd
= ::open(fn
, O_RDONLY
);
4899 get_attrname("bits", n
, PATH_MAX
);
4900 r
= chain_fsetxattr(fd
, n
, (char*)&v
, sizeof(v
));
4901 VOID_TEMP_FAILURE_RETRY(::close(fd
));
4903 dout(10) << __FUNC__
<< ": " << fn
<< " " << bits
<< " = " << r
<< dendl
;
4907 int FileStore::collection_bits(const coll_t
& c
)
4910 get_cdir(c
, fn
, sizeof(fn
));
4911 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
4915 int fd
= ::open(fn
, O_RDONLY
);
4920 get_attrname("bits", n
, PATH_MAX
);
4921 r
= chain_fgetxattr(fd
, n
, (char*)&bits
, sizeof(bits
));
4922 VOID_TEMP_FAILURE_RETRY(::close(fd
));
4928 dout(10) << __FUNC__
<< ": " << fn
<< " = " << bits
<< dendl
;
4932 int FileStore::collection_list(const coll_t
& c
,
4933 const ghobject_t
& orig_start
,
4934 const ghobject_t
& end
,
4936 vector
<ghobject_t
> *ls
, ghobject_t
*next
)
4938 ghobject_t start
= orig_start
;
4942 ghobject_t temp_next
;
4945 // figure out the pool id. we need this in order to generate a
4946 // meaningful 'next' value.
4951 if (c
.is_temp(&pgid
)) {
4952 pool
= -2 - pgid
.pool();
4954 } else if (c
.is_pg(&pgid
)) {
4957 } else if (c
.is_meta()) {
4959 shard
= shard_id_t::NO_SHARD
;
4961 // hrm, the caller is test code! we should get kill it off. for now,
4964 shard
= shard_id_t::NO_SHARD
;
4966 dout(20) << __FUNC__
<< ": pool is " << pool
<< " shard is " << shard
4967 << " pgid " << pgid
<< dendl
;
4971 sep
.set_shard(shard
);
4972 if (!c
.is_temp() && !c
.is_meta()) {
4974 dout(10) << __FUNC__
<< ": first checking temp pool" << dendl
;
4975 coll_t temp
= c
.get_temp();
4976 int r
= collection_list(temp
, start
, end
, max
, ls
, next
);
4979 if (*next
!= ghobject_t::get_max())
4982 dout(10) << __FUNC__
<< ": fall through to non-temp collection, start "
4985 dout(10) << __FUNC__
<< ": start " << start
<< " >= sep " << sep
<< dendl
;
4990 int r
= get_index(c
, &index
);
4994 assert(NULL
!= index
.index
);
4995 RWLock::RLocker
l((index
.index
)->access_lock
);
4997 r
= index
->collection_list_partial(start
, end
, max
, ls
, next
);
5000 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5003 dout(20) << "objects: " << *ls
<< dendl
;
5005 // HashIndex doesn't know the pool when constructing a 'next' value
5006 if (next
&& !next
->is_max()) {
5007 next
->hobj
.pool
= pool
;
5008 next
->set_shard(shard
);
5009 dout(20) << " next " << *next
<< dendl
;
5015 int FileStore::omap_get(const coll_t
& _c
, const ghobject_t
&hoid
,
5017 map
<string
, bufferlist
> *out
)
5019 tracepoint(objectstore
, omap_get_enter
, _c
.c_str());
5020 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5021 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5023 int r
= get_index(c
, &index
);
5027 assert(NULL
!= index
.index
);
5028 RWLock::RLocker
l((index
.index
)->access_lock
);
5029 r
= lfn_find(hoid
, index
);
5033 r
= object_map
->get(hoid
, header
, out
);
5034 if (r
< 0 && r
!= -ENOENT
) {
5035 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5038 tracepoint(objectstore
, omap_get_exit
, 0);
5042 int FileStore::omap_get_header(
5044 const ghobject_t
&hoid
,
5048 tracepoint(objectstore
, omap_get_header_enter
, _c
.c_str());
5049 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5050 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5052 int r
= get_index(c
, &index
);
5056 assert(NULL
!= index
.index
);
5057 RWLock::RLocker
l((index
.index
)->access_lock
);
5058 r
= lfn_find(hoid
, index
);
5062 r
= object_map
->get_header(hoid
, bl
);
5063 if (r
< 0 && r
!= -ENOENT
) {
5064 assert(allow_eio
|| !m_filestore_fail_eio
|| r
!= -EIO
);
5067 tracepoint(objectstore
, omap_get_header_exit
, 0);
5071 int FileStore::omap_get_keys(const coll_t
& _c
, const ghobject_t
&hoid
, set
<string
> *keys
)
5073 tracepoint(objectstore
, omap_get_keys_enter
, _c
.c_str());
5074 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5075 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5077 int r
= get_index(c
, &index
);
5081 assert(NULL
!= index
.index
);
5082 RWLock::RLocker
l((index
.index
)->access_lock
);
5083 r
= lfn_find(hoid
, index
);
5087 r
= object_map
->get_keys(hoid
, keys
);
5088 if (r
< 0 && r
!= -ENOENT
) {
5089 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5092 tracepoint(objectstore
, omap_get_keys_exit
, 0);
5096 int FileStore::omap_get_values(const coll_t
& _c
, const ghobject_t
&hoid
,
5097 const set
<string
> &keys
,
5098 map
<string
, bufferlist
> *out
)
5100 tracepoint(objectstore
, omap_get_values_enter
, _c
.c_str());
5101 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5102 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5104 const char *where
= "()";
5105 int r
= get_index(c
, &index
);
5107 where
= " (get_index)";
5111 assert(NULL
!= index
.index
);
5112 RWLock::RLocker
l((index
.index
)->access_lock
);
5113 r
= lfn_find(hoid
, index
);
5115 where
= " (lfn_find)";
5119 r
= object_map
->get_values(hoid
, keys
, out
);
5120 if (r
< 0 && r
!= -ENOENT
) {
5121 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5122 where
= " (get_values)";
5127 tracepoint(objectstore
, omap_get_values_exit
, r
);
5128 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = " << r
5133 int FileStore::omap_check_keys(const coll_t
& _c
, const ghobject_t
&hoid
,
5134 const set
<string
> &keys
,
5137 tracepoint(objectstore
, omap_check_keys_enter
, _c
.c_str());
5138 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5139 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5142 int r
= get_index(c
, &index
);
5146 assert(NULL
!= index
.index
);
5147 RWLock::RLocker
l((index
.index
)->access_lock
);
5148 r
= lfn_find(hoid
, index
);
5152 r
= object_map
->check_keys(hoid
, keys
, out
);
5153 if (r
< 0 && r
!= -ENOENT
) {
5154 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5157 tracepoint(objectstore
, omap_check_keys_exit
, 0);
5161 ObjectMap::ObjectMapIterator
FileStore::get_omap_iterator(const coll_t
& _c
,
5162 const ghobject_t
&hoid
)
5164 tracepoint(objectstore
, get_omap_iterator
, _c
.c_str());
5165 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5166 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5168 int r
= get_index(c
, &index
);
5170 dout(10) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = 0 "
5171 << "(get_index failed with " << cpp_strerror(r
) << ")" << dendl
;
5172 return ObjectMap::ObjectMapIterator();
5175 assert(NULL
!= index
.index
);
5176 RWLock::RLocker
l((index
.index
)->access_lock
);
5177 r
= lfn_find(hoid
, index
);
5179 dout(10) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = 0 "
5180 << "(lfn_find failed with " << cpp_strerror(r
) << ")" << dendl
;
5181 return ObjectMap::ObjectMapIterator();
5184 return object_map
->get_iterator(hoid
);
5187 int FileStore::_collection_hint_expected_num_objs(const coll_t
& c
, uint32_t pg_num
,
5188 uint64_t expected_num_objs
,
5189 const SequencerPosition
&spos
)
5191 dout(15) << __FUNC__
<< ": collection: " << c
<< " pg number: "
5192 << pg_num
<< " expected number of objects: " << expected_num_objs
<< dendl
;
5195 int ret
= collection_empty(c
, &empty
);
5198 if (!empty
&& !replaying
) {
5199 dout(0) << "Failed to give an expected number of objects hint to collection : "
5200 << c
<< ", only empty collection can take such type of hint. " << dendl
;
5205 ret
= get_index(c
, &index
);
5208 // Pre-hash the collection
5209 ret
= index
->pre_hash_collection(pg_num
, expected_num_objs
);
5210 dout(10) << "pre_hash_collection " << c
<< " = " << ret
<< dendl
;
5213 _set_replay_guard(c
, spos
);
5218 int FileStore::_create_collection(
5221 const SequencerPosition
&spos
)
5224 get_cdir(c
, fn
, sizeof(fn
));
5225 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
5226 int r
= ::mkdir(fn
, 0755);
5229 if (r
== -EEXIST
&& replaying
)
5231 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
5238 r
= _collection_set_bits(c
, bits
);
5241 // create parallel temp collection, too
5242 if (!c
.is_meta() && !c
.is_temp()) {
5243 coll_t temp
= c
.get_temp();
5244 r
= _create_collection(temp
, 0, spos
);
5249 _set_replay_guard(c
, spos
);
5253 int FileStore::_destroy_collection(const coll_t
& c
)
5257 get_cdir(c
, fn
, sizeof(fn
));
5258 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
5261 r
= get_index(c
, &from
);
5264 assert(NULL
!= from
.index
);
5265 RWLock::WLocker
l((from
.index
)->access_lock
);
5267 r
= from
->prep_delete();
5278 // destroy parallel temp collection, too
5279 if (!c
.is_meta() && !c
.is_temp()) {
5280 coll_t temp
= c
.get_temp();
5281 int r2
= _destroy_collection(temp
);
5289 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
5294 int FileStore::_collection_add(const coll_t
& c
, const coll_t
& oldcid
, const ghobject_t
& o
,
5295 const SequencerPosition
& spos
)
5297 dout(15) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << o
<< dendl
;
5299 int dstcmp
= _check_replay_guard(c
, o
, spos
);
5303 // check the src name too; it might have a newer guard, and we don't
5304 // want to clobber it
5305 int srccmp
= _check_replay_guard(oldcid
, o
, spos
);
5309 // open guard on object so we don't any previous operations on the
5310 // new name that will modify the source inode.
5312 int r
= lfn_open(oldcid
, o
, 0, &fd
);
5314 // the source collection/object does not exist. If we are replaying, we
5315 // should be safe, so just return 0 and move on.
5317 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5318 << oldcid
<< "/" << o
<< " (dne, continue replay) " << dendl
;
5321 if (dstcmp
> 0) { // if dstcmp == 0 the guard already says "in-progress"
5322 _set_replay_guard(**fd
, spos
, &o
, true);
5325 r
= lfn_link(oldcid
, c
, o
, o
);
5326 if (replaying
&& !backend
->can_checkpoint() &&
5327 r
== -EEXIST
) // crashed between link() and set_replay_guard()
5332 // close guard on object so we don't do this again
5334 _close_replay_guard(**fd
, spos
);
5338 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << o
<< " = " << r
<< dendl
;
5342 int FileStore::_collection_move_rename(const coll_t
& oldcid
, const ghobject_t
& oldoid
,
5343 coll_t c
, const ghobject_t
& o
,
5344 const SequencerPosition
& spos
,
5347 dout(15) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
<< dendl
;
5352 /* If the destination collection doesn't exist during replay,
5353 * we need to delete the src object and continue on
5355 if (!collection_exists(c
))
5359 dstcmp
= _check_replay_guard(c
, o
, spos
);
5363 // check the src name too; it might have a newer guard, and we don't
5364 // want to clobber it
5365 srccmp
= _check_replay_guard(oldcid
, oldoid
, spos
);
5370 // open guard on object so we don't any previous operations on the
5371 // new name that will modify the source inode.
5373 r
= lfn_open(oldcid
, oldoid
, 0, &fd
);
5375 // the source collection/object does not exist. If we are replaying, we
5376 // should be safe, so just return 0 and move on.
5378 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5379 << oldcid
<< "/" << oldoid
<< " (dne, continue replay) " << dendl
;
5380 } else if (allow_enoent
) {
5381 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5382 << oldcid
<< "/" << oldoid
<< " (dne, ignoring enoent)"
5385 assert(0 == "ERROR: source must exist");
5391 if (allow_enoent
&& dstcmp
> 0) { // if dstcmp == 0, try_rename was started.
5395 r
= 0; // don't know if object_map was cloned
5397 if (dstcmp
> 0) { // if dstcmp == 0 the guard already says "in-progress"
5398 _set_replay_guard(**fd
, spos
, &o
, true);
5401 r
= lfn_link(oldcid
, c
, oldoid
, o
);
5402 if (replaying
&& !backend
->can_checkpoint() &&
5403 r
== -EEXIST
) // crashed between link() and set_replay_guard()
5413 // the name changed; link the omap content
5414 r
= object_map
->rename(oldoid
, o
, &spos
);
5422 r
= lfn_unlink(oldcid
, oldoid
, spos
, true);
5425 r
= lfn_open(c
, o
, 0, &fd
);
5427 // close guard on object so we don't do this again
5429 _close_replay_guard(**fd
, spos
, &o
);
5434 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
5435 << " = " << r
<< dendl
;
5440 if (_check_replay_guard(oldcid
, oldoid
, spos
) > 0) {
5441 r
= lfn_unlink(oldcid
, oldoid
, spos
, true);
5444 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
5445 << " = " << r
<< dendl
;
5449 void FileStore::_inject_failure()
5451 if (m_filestore_kill_at
) {
5452 int final
= --m_filestore_kill_at
;
5453 dout(5) << __FUNC__
<< ": " << (final
+1) << " -> " << final
<< dendl
;
5455 derr
<< __FUNC__
<< ": KILLING" << dendl
;
5462 int FileStore::_omap_clear(const coll_t
& cid
, const ghobject_t
&hoid
,
5463 const SequencerPosition
&spos
) {
5464 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5466 int r
= get_index(cid
, &index
);
5470 assert(NULL
!= index
.index
);
5471 RWLock::RLocker
l((index
.index
)->access_lock
);
5472 r
= lfn_find(hoid
, index
);
5476 r
= object_map
->clear_keys_header(hoid
, &spos
);
5477 if (r
< 0 && r
!= -ENOENT
)
5482 int FileStore::_omap_setkeys(const coll_t
& cid
, const ghobject_t
&hoid
,
5483 const map
<string
, bufferlist
> &aset
,
5484 const SequencerPosition
&spos
) {
5485 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5488 //treat pgmeta as a logical object, skip to check exist
5489 if (hoid
.is_pgmeta())
5492 r
= get_index(cid
, &index
);
5494 dout(20) << __FUNC__
<< ": get_index got " << cpp_strerror(r
) << dendl
;
5498 assert(NULL
!= index
.index
);
5499 RWLock::RLocker
l((index
.index
)->access_lock
);
5500 r
= lfn_find(hoid
, index
);
5502 dout(20) << __FUNC__
<< ": lfn_find got " << cpp_strerror(r
) << dendl
;
5507 if (g_conf
->subsys
.should_gather(ceph_subsys_filestore
, 20)) {
5508 for (auto& p
: aset
) {
5509 dout(20) << __FUNC__
<< ": set " << p
.first
<< dendl
;
5512 r
= object_map
->set_keys(hoid
, aset
, &spos
);
5513 dout(20) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< " = " << r
<< dendl
;
5517 int FileStore::_omap_rmkeys(const coll_t
& cid
, const ghobject_t
&hoid
,
5518 const set
<string
> &keys
,
5519 const SequencerPosition
&spos
) {
5520 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5523 //treat pgmeta as a logical object, skip to check exist
5524 if (hoid
.is_pgmeta())
5527 r
= get_index(cid
, &index
);
5531 assert(NULL
!= index
.index
);
5532 RWLock::RLocker
l((index
.index
)->access_lock
);
5533 r
= lfn_find(hoid
, index
);
5538 r
= object_map
->rm_keys(hoid
, keys
, &spos
);
5539 if (r
< 0 && r
!= -ENOENT
)
5544 int FileStore::_omap_rmkeyrange(const coll_t
& cid
, const ghobject_t
&hoid
,
5545 const string
& first
, const string
& last
,
5546 const SequencerPosition
&spos
) {
5547 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< " [" << first
<< "," << last
<< "]" << dendl
;
5550 ObjectMap::ObjectMapIterator iter
= get_omap_iterator(cid
, hoid
);
5553 for (iter
->lower_bound(first
); iter
->valid() && iter
->key() < last
;
5555 keys
.insert(iter
->key());
5558 return _omap_rmkeys(cid
, hoid
, keys
, spos
);
5561 int FileStore::_omap_setheader(const coll_t
& cid
, const ghobject_t
&hoid
,
5562 const bufferlist
&bl
,
5563 const SequencerPosition
&spos
)
5565 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5567 int r
= get_index(cid
, &index
);
5571 assert(NULL
!= index
.index
);
5572 RWLock::RLocker
l((index
.index
)->access_lock
);
5573 r
= lfn_find(hoid
, index
);
5577 return object_map
->set_header(hoid
, bl
, &spos
);
5580 int FileStore::_split_collection(const coll_t
& cid
,
5584 const SequencerPosition
&spos
)
5588 dout(15) << __FUNC__
<< ": " << cid
<< " bits: " << bits
<< dendl
;
5589 if (!collection_exists(cid
)) {
5590 dout(2) << __FUNC__
<< ": " << cid
<< " DNE" << dendl
;
5594 if (!collection_exists(dest
)) {
5595 dout(2) << __FUNC__
<< ": " << dest
<< " DNE" << dendl
;
5600 int dstcmp
= _check_replay_guard(dest
, spos
);
5604 int srccmp
= _check_replay_guard(cid
, spos
);
5608 _set_global_replay_guard(cid
, spos
);
5609 _set_replay_guard(cid
, spos
, true);
5610 _set_replay_guard(dest
, spos
, true);
5613 r
= get_index(cid
, &from
);
5617 r
= get_index(dest
, &to
);
5620 assert(NULL
!= from
.index
);
5621 RWLock::WLocker
l1((from
.index
)->access_lock
);
5623 assert(NULL
!= to
.index
);
5624 RWLock::WLocker
l2((to
.index
)->access_lock
);
5626 r
= from
->split(rem
, bits
, to
.index
);
5629 _close_replay_guard(cid
, spos
);
5630 _close_replay_guard(dest
, spos
);
5632 _collection_set_bits(cid
, bits
);
5633 if (!r
&& cct
->_conf
->filestore_debug_verify_split
) {
5634 vector
<ghobject_t
> objects
;
5639 next
, ghobject_t::get_max(),
5640 get_ideal_list_max(),
5643 if (objects
.empty())
5645 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
5648 dout(20) << __FUNC__
<< ": " << *i
<< " still in source "
5650 assert(!i
->match(bits
, rem
));
5654 next
= ghobject_t();
5658 next
, ghobject_t::get_max(),
5659 get_ideal_list_max(),
5662 if (objects
.empty())
5664 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
5667 dout(20) << __FUNC__
<< ": " << *i
<< " now in dest "
5669 assert(i
->match(bits
, rem
));
5677 int FileStore::_set_alloc_hint(const coll_t
& cid
, const ghobject_t
& oid
,
5678 uint64_t expected_object_size
,
5679 uint64_t expected_write_size
)
5681 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " object_size " << expected_object_size
<< " write_size " << expected_write_size
<< dendl
;
5686 if (expected_object_size
== 0 || expected_write_size
== 0)
5689 ret
= lfn_open(cid
, oid
, false, &fd
);
5694 // TODO: a more elaborate hint calculation
5695 uint64_t hint
= MIN(expected_write_size
, m_filestore_max_alloc_hint_size
);
5697 ret
= backend
->set_alloc_hint(**fd
, hint
);
5698 dout(20) << __FUNC__
<< ": hint " << hint
<< " ret " << ret
<< dendl
;
5703 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " object_size " << expected_object_size
<< " write_size " << expected_write_size
<< " = " << ret
<< dendl
;
5704 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
5708 const char** FileStore::get_tracked_conf_keys() const
5710 static const char* KEYS
[] = {
5711 "filestore_max_inline_xattr_size",
5712 "filestore_max_inline_xattr_size_xfs",
5713 "filestore_max_inline_xattr_size_btrfs",
5714 "filestore_max_inline_xattr_size_other",
5715 "filestore_max_inline_xattrs",
5716 "filestore_max_inline_xattrs_xfs",
5717 "filestore_max_inline_xattrs_btrfs",
5718 "filestore_max_inline_xattrs_other",
5719 "filestore_max_xattr_value_size",
5720 "filestore_max_xattr_value_size_xfs",
5721 "filestore_max_xattr_value_size_btrfs",
5722 "filestore_max_xattr_value_size_other",
5723 "filestore_min_sync_interval",
5724 "filestore_max_sync_interval",
5725 "filestore_queue_max_ops",
5726 "filestore_queue_max_bytes",
5727 "filestore_expected_throughput_bytes",
5728 "filestore_expected_throughput_ops",
5729 "filestore_queue_low_threshhold",
5730 "filestore_queue_high_threshhold",
5731 "filestore_queue_high_delay_multiple",
5732 "filestore_queue_max_delay_multiple",
5733 "filestore_commit_timeout",
5734 "filestore_dump_file",
5735 "filestore_kill_at",
5736 "filestore_fail_eio",
5737 "filestore_fadvise",
5738 "filestore_sloppy_crc",
5739 "filestore_sloppy_crc_block_size",
5740 "filestore_max_alloc_hint_size",
5746 void FileStore::handle_conf_change(const struct md_config_t
*conf
,
5747 const std::set
<std::string
> &changed
)
5749 if (changed
.count("filestore_max_inline_xattr_size") ||
5750 changed
.count("filestore_max_inline_xattr_size_xfs") ||
5751 changed
.count("filestore_max_inline_xattr_size_btrfs") ||
5752 changed
.count("filestore_max_inline_xattr_size_other") ||
5753 changed
.count("filestore_max_inline_xattrs") ||
5754 changed
.count("filestore_max_inline_xattrs_xfs") ||
5755 changed
.count("filestore_max_inline_xattrs_btrfs") ||
5756 changed
.count("filestore_max_inline_xattrs_other") ||
5757 changed
.count("filestore_max_xattr_value_size") ||
5758 changed
.count("filestore_max_xattr_value_size_xfs") ||
5759 changed
.count("filestore_max_xattr_value_size_btrfs") ||
5760 changed
.count("filestore_max_xattr_value_size_other")) {
5762 Mutex::Locker
l(lock
);
5763 set_xattr_limits_via_conf();
5767 if (changed
.count("filestore_queue_max_bytes") ||
5768 changed
.count("filestore_queue_max_ops") ||
5769 changed
.count("filestore_expected_throughput_bytes") ||
5770 changed
.count("filestore_expected_throughput_ops") ||
5771 changed
.count("filestore_queue_low_threshhold") ||
5772 changed
.count("filestore_queue_high_threshhold") ||
5773 changed
.count("filestore_queue_high_delay_multiple") ||
5774 changed
.count("filestore_queue_max_delay_multiple")) {
5775 Mutex::Locker
l(lock
);
5776 set_throttle_params();
5779 if (changed
.count("filestore_min_sync_interval") ||
5780 changed
.count("filestore_max_sync_interval") ||
5781 changed
.count("filestore_kill_at") ||
5782 changed
.count("filestore_fail_eio") ||
5783 changed
.count("filestore_sloppy_crc") ||
5784 changed
.count("filestore_sloppy_crc_block_size") ||
5785 changed
.count("filestore_max_alloc_hint_size") ||
5786 changed
.count("filestore_fadvise")) {
5787 Mutex::Locker
l(lock
);
5788 m_filestore_min_sync_interval
= conf
->filestore_min_sync_interval
;
5789 m_filestore_max_sync_interval
= conf
->filestore_max_sync_interval
;
5790 m_filestore_kill_at
= conf
->filestore_kill_at
;
5791 m_filestore_fail_eio
= conf
->filestore_fail_eio
;
5792 m_filestore_fadvise
= conf
->filestore_fadvise
;
5793 m_filestore_sloppy_crc
= conf
->filestore_sloppy_crc
;
5794 m_filestore_sloppy_crc_block_size
= conf
->filestore_sloppy_crc_block_size
;
5795 m_filestore_max_alloc_hint_size
= conf
->filestore_max_alloc_hint_size
;
5797 if (changed
.count("filestore_commit_timeout")) {
5798 Mutex::Locker
l(sync_entry_timeo_lock
);
5799 m_filestore_commit_timeout
= conf
->filestore_commit_timeout
;
5801 if (changed
.count("filestore_dump_file")) {
5802 if (conf
->filestore_dump_file
.length() &&
5803 conf
->filestore_dump_file
!= "-") {
5804 dump_start(conf
->filestore_dump_file
);
5811 int FileStore::set_throttle_params()
5814 bool valid
= throttle_bytes
.set_params(
5815 cct
->_conf
->filestore_queue_low_threshhold
,
5816 cct
->_conf
->filestore_queue_high_threshhold
,
5817 cct
->_conf
->filestore_expected_throughput_bytes
,
5818 cct
->_conf
->filestore_queue_high_delay_multiple
,
5819 cct
->_conf
->filestore_queue_max_delay_multiple
,
5820 cct
->_conf
->filestore_queue_max_bytes
,
5823 valid
&= throttle_ops
.set_params(
5824 cct
->_conf
->filestore_queue_low_threshhold
,
5825 cct
->_conf
->filestore_queue_high_threshhold
,
5826 cct
->_conf
->filestore_expected_throughput_ops
,
5827 cct
->_conf
->filestore_queue_high_delay_multiple
,
5828 cct
->_conf
->filestore_queue_max_delay_multiple
,
5829 cct
->_conf
->filestore_queue_max_ops
,
5832 logger
->set(l_filestore_op_queue_max_ops
, throttle_ops
.get_max());
5833 logger
->set(l_filestore_op_queue_max_bytes
, throttle_bytes
.get_max());
5836 derr
<< "tried to set invalid params: "
5840 return valid
? 0 : -EINVAL
;
5843 void FileStore::dump_start(const std::string
& file
)
5845 dout(10) << __FUNC__
<< ": " << file
<< dendl
;
5846 if (m_filestore_do_dump
) {
5849 m_filestore_dump_fmt
.reset();
5850 m_filestore_dump_fmt
.open_array_section("dump");
5851 m_filestore_dump
.open(file
.c_str());
5852 m_filestore_do_dump
= true;
5855 void FileStore::dump_stop()
5857 dout(10) << __FUNC__
<< dendl
;
5858 m_filestore_do_dump
= false;
5859 if (m_filestore_dump
.is_open()) {
5860 m_filestore_dump_fmt
.close_section();
5861 m_filestore_dump_fmt
.flush(m_filestore_dump
);
5862 m_filestore_dump
.flush();
5863 m_filestore_dump
.close();
5867 void FileStore::dump_transactions(vector
<ObjectStore::Transaction
>& ls
, uint64_t seq
, OpSequencer
*osr
)
5869 m_filestore_dump_fmt
.open_array_section("transactions");
5870 unsigned trans_num
= 0;
5871 for (vector
<ObjectStore::Transaction
>::iterator i
= ls
.begin(); i
!= ls
.end(); ++i
, ++trans_num
) {
5872 m_filestore_dump_fmt
.open_object_section("transaction");
5873 m_filestore_dump_fmt
.dump_string("osr", osr
->get_name());
5874 m_filestore_dump_fmt
.dump_unsigned("seq", seq
);
5875 m_filestore_dump_fmt
.dump_unsigned("trans_num", trans_num
);
5876 (*i
).dump(&m_filestore_dump_fmt
);
5877 m_filestore_dump_fmt
.close_section();
5879 m_filestore_dump_fmt
.close_section();
5880 m_filestore_dump_fmt
.flush(m_filestore_dump
);
5881 m_filestore_dump
.flush();
5884 void FileStore::set_xattr_limits_via_conf()
5886 uint32_t fs_xattr_size
;
5888 uint32_t fs_xattr_max_value_size
;
5890 switch (m_fs_type
) {
5891 #if defined(__linux__)
5892 case XFS_SUPER_MAGIC
:
5893 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_xfs
;
5894 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_xfs
;
5895 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_xfs
;
5897 case BTRFS_SUPER_MAGIC
:
5898 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_btrfs
;
5899 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_btrfs
;
5900 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_btrfs
;
5904 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_other
;
5905 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_other
;
5906 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_other
;
5910 // Use override value if set
5911 if (cct
->_conf
->filestore_max_inline_xattr_size
)
5912 m_filestore_max_inline_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size
;
5914 m_filestore_max_inline_xattr_size
= fs_xattr_size
;
5916 // Use override value if set
5917 if (cct
->_conf
->filestore_max_inline_xattrs
)
5918 m_filestore_max_inline_xattrs
= cct
->_conf
->filestore_max_inline_xattrs
;
5920 m_filestore_max_inline_xattrs
= fs_xattrs
;
5922 // Use override value if set
5923 if (cct
->_conf
->filestore_max_xattr_value_size
)
5924 m_filestore_max_xattr_value_size
= cct
->_conf
->filestore_max_xattr_value_size
;
5926 m_filestore_max_xattr_value_size
= fs_xattr_max_value_size
;
5928 if (m_filestore_max_xattr_value_size
< cct
->_conf
->osd_max_object_name_len
) {
5929 derr
<< "WARNING: max attr value size ("
5930 << m_filestore_max_xattr_value_size
5931 << ") is smaller than osd_max_object_name_len ("
5932 << cct
->_conf
->osd_max_object_name_len
5933 << "). Your backend filesystem appears to not support attrs large "
5934 << "enough to handle the configured max rados name size. You may get "
5935 << "unexpected ENAMETOOLONG errors on rados operations or buggy "
5941 uint64_t FileStore::estimate_objects_overhead(uint64_t num_objects
)
5943 uint64_t res
= num_objects
* blk_size
/ 2; //assumes that each object uses ( in average ) additional 1/2 block due to FS allocation granularity.
5947 int FileStore::apply_layout_settings(const coll_t
&cid
)
5949 dout(20) << __FUNC__
<< ": " << cid
<< dendl
;
5951 int r
= get_index(cid
, &index
);
5953 dout(10) << "Error getting index for " << cid
<< ": " << cpp_strerror(r
)
5958 return index
->apply_layout_settings();
5962 // -- FSSuperblock --
5964 void FSSuperblock::encode(bufferlist
&bl
) const
5966 ENCODE_START(2, 1, bl
);
5967 compat_features
.encode(bl
);
5968 ::encode(omap_backend
, bl
);
5972 void FSSuperblock::decode(bufferlist::iterator
&bl
)
5974 DECODE_START(2, bl
);
5975 compat_features
.decode(bl
);
5977 ::decode(omap_backend
, bl
);
5979 omap_backend
= "leveldb";
5983 void FSSuperblock::dump(Formatter
*f
) const
5985 f
->open_object_section("compat");
5986 compat_features
.dump(f
);
5987 f
->dump_string("omap_backend", omap_backend
);
5991 void FSSuperblock::generate_test_instances(list
<FSSuperblock
*>& o
)
5994 o
.push_back(new FSSuperblock(z
));
5995 CompatSet::FeatureSet feature_compat
;
5996 CompatSet::FeatureSet feature_ro_compat
;
5997 CompatSet::FeatureSet feature_incompat
;
5998 feature_incompat
.insert(CEPH_FS_FEATURE_INCOMPAT_SHARDS
);
5999 z
.compat_features
= CompatSet(feature_compat
, feature_ro_compat
,
6001 o
.push_back(new FSSuperblock(z
));
6002 z
.omap_backend
= "rocksdb";
6003 o
.push_back(new FSSuperblock(z
));