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 bool FileStore::is_journal_rotational()
1162 bool journal_rotational
;
1164 journal_rotational
= backend
->is_journal_rotational();
1166 int fd
= ::open(journalpath
.c_str(), O_RDONLY
);
1170 int r
= ::fstatfs(fd
, &st
);
1175 create_backend(st
.f_type
);
1176 journal_rotational
= backend
->is_journal_rotational();
1180 dout(10) << __func__
<< " " << (int)journal_rotational
<< dendl
;
1181 return journal_rotational
;
1184 int FileStore::_detect_fs()
1187 int r
= ::fstatfs(basedir_fd
, &st
);
1191 blk_size
= st
.f_bsize
;
1193 #if defined(__linux__)
1194 if (st
.f_type
== BTRFS_SUPER_MAGIC
&&
1195 !g_ceph_context
->check_experimental_feature_enabled("btrfs")) {
1196 derr
<<__FUNC__
<< ": deprecated btrfs support is not enabled" << dendl
;
1201 create_backend(st
.f_type
);
1203 r
= backend
->detect_features();
1205 derr
<< __FUNC__
<< ": detect_features error: " << cpp_strerror(r
) << dendl
;
1213 snprintf(fn
, sizeof(fn
), "%s/xattr_test", basedir
.c_str());
1214 int tmpfd
= ::open(fn
, O_CREAT
|O_WRONLY
|O_TRUNC
, 0700);
1217 derr
<< __FUNC__
<< ": unable to create " << fn
<< ": " << cpp_strerror(ret
) << dendl
;
1221 int ret
= chain_fsetxattr(tmpfd
, "user.test", &x
, sizeof(x
));
1223 ret
= chain_fgetxattr(tmpfd
, "user.test", &y
, sizeof(y
));
1224 if ((ret
< 0) || (x
!= y
)) {
1225 derr
<< "Extended attributes don't appear to work. ";
1227 *_dout
<< "Got error " + cpp_strerror(ret
) + ". ";
1228 *_dout
<< "If you are using ext3 or ext4, be sure to mount the underlying "
1229 << "file system with the 'user_xattr' option." << dendl
;
1231 VOID_TEMP_FAILURE_RETRY(::close(tmpfd
));
1236 memset(buf
, 0, sizeof(buf
)); // shut up valgrind
1237 chain_fsetxattr(tmpfd
, "user.test", &buf
, sizeof(buf
));
1238 chain_fsetxattr(tmpfd
, "user.test2", &buf
, sizeof(buf
));
1239 chain_fsetxattr(tmpfd
, "user.test3", &buf
, sizeof(buf
));
1240 chain_fsetxattr(tmpfd
, "user.test4", &buf
, sizeof(buf
));
1241 ret
= chain_fsetxattr(tmpfd
, "user.test5", &buf
, sizeof(buf
));
1242 if (ret
== -ENOSPC
) {
1243 dout(0) << "limited size xattrs" << dendl
;
1245 chain_fremovexattr(tmpfd
, "user.test");
1246 chain_fremovexattr(tmpfd
, "user.test2");
1247 chain_fremovexattr(tmpfd
, "user.test3");
1248 chain_fremovexattr(tmpfd
, "user.test4");
1249 chain_fremovexattr(tmpfd
, "user.test5");
1252 VOID_TEMP_FAILURE_RETRY(::close(tmpfd
));
1257 int FileStore::_sanity_check_fs()
1261 if (((int)m_filestore_journal_writeahead
+
1262 (int)m_filestore_journal_parallel
+
1263 (int)m_filestore_journal_trailing
) > 1) {
1264 dout(0) << "mount ERROR: more than one of filestore journal {writeahead,parallel,trailing} enabled" << dendl
;
1266 << " ** WARNING: more than one of 'filestore journal {writeahead,parallel,trailing}'\n"
1267 << " is enabled in ceph.conf. You must choose a single journal mode."
1268 << TEXT_NORMAL
<< std::endl
;
1272 if (!backend
->can_checkpoint()) {
1273 if (!journal
|| !m_filestore_journal_writeahead
) {
1274 dout(0) << "mount WARNING: no btrfs, and no journal in writeahead mode; data may be lost" << dendl
;
1276 << " ** WARNING: no btrfs AND (no journal OR journal not in writeahead mode)\n"
1277 << " For non-btrfs volumes, a writeahead journal is required to\n"
1278 << " maintain on-disk consistency in the event of a crash. Your conf\n"
1279 << " should include something like:\n"
1280 << " osd journal = /path/to/journal_device_or_file\n"
1281 << " filestore journal writeahead = true\n"
1287 dout(0) << "mount WARNING: no journal" << dendl
;
1289 << " ** WARNING: No osd journal is configured: write latency may be high.\n"
1290 << " If you will not be using an osd journal, write latency may be\n"
1291 << " relatively high. It can be reduced somewhat by lowering\n"
1292 << " filestore_max_sync_interval, but lower values mean lower write\n"
1293 << " throughput, especially with spinning disks.\n"
1300 int FileStore::write_superblock()
1303 ::encode(superblock
, bl
);
1304 return safe_write_file(basedir
.c_str(), "superblock",
1305 bl
.c_str(), bl
.length());
1308 int FileStore::read_superblock()
1310 bufferptr
bp(PATH_MAX
);
1311 int ret
= safe_read_file(basedir
.c_str(), "superblock",
1312 bp
.c_str(), bp
.length());
1314 if (ret
== -ENOENT
) {
1315 // If the file doesn't exist write initial CompatSet
1316 return write_superblock();
1322 bl
.push_back(std::move(bp
));
1323 bufferlist::iterator i
= bl
.begin();
1324 ::decode(superblock
, i
);
1328 int FileStore::update_version_stamp()
1330 return write_version_stamp();
1333 int FileStore::version_stamp_is_valid(uint32_t *version
)
1335 bufferptr
bp(PATH_MAX
);
1336 int ret
= safe_read_file(basedir
.c_str(), "store_version",
1337 bp
.c_str(), bp
.length());
1342 bl
.push_back(std::move(bp
));
1343 bufferlist::iterator i
= bl
.begin();
1344 ::decode(*version
, i
);
1345 dout(10) << __FUNC__
<< ": was " << *version
<< " vs target "
1346 << target_version
<< dendl
;
1347 if (*version
== target_version
)
1353 int FileStore::write_version_stamp()
1355 dout(1) << __FUNC__
<< ": " << target_version
<< dendl
;
1357 ::encode(target_version
, bl
);
1359 return safe_write_file(basedir
.c_str(), "store_version",
1360 bl
.c_str(), bl
.length());
1363 int FileStore::upgrade()
1365 dout(1) << __FUNC__
<< dendl
;
1367 int r
= version_stamp_is_valid(&version
);
1370 derr
<< "The store_version file doesn't exist." << dendl
;
1379 derr
<< "ObjectStore is old at version " << version
<< ". Please upgrade to firefly v0.80.x, convert your store, and then upgrade." << dendl
;
1383 // nothing necessary in FileStore for v3 -> v4 upgrade; we just need to
1384 // open up DBObjectMap with the do_upgrade flag, which we already did.
1385 update_version_stamp();
1389 int FileStore::read_op_seq(uint64_t *seq
)
1391 int op_fd
= ::open(current_op_seq_fn
.c_str(), O_CREAT
|O_RDWR
, 0644);
1394 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
1398 memset(s
, 0, sizeof(s
));
1399 int ret
= safe_read(op_fd
, s
, sizeof(s
) - 1);
1401 derr
<< __FUNC__
<< ": error reading " << current_op_seq_fn
<< ": " << cpp_strerror(ret
) << dendl
;
1402 VOID_TEMP_FAILURE_RETRY(::close(op_fd
));
1403 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1410 int FileStore::write_op_seq(int fd
, uint64_t seq
)
1413 snprintf(s
, sizeof(s
), "%" PRId64
"\n", seq
);
1414 int ret
= TEMP_FAILURE_RETRY(::pwrite(fd
, s
, strlen(s
), 0));
1417 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1422 int FileStore::mount()
1426 uint64_t initial_op_seq
;
1428 set
<string
> cluster_snaps
;
1429 CompatSet supported_compat_set
= get_fs_supported_compat_set();
1431 dout(5) << "basedir " << basedir
<< " journal " << journalpath
<< dendl
;
1433 ret
= set_throttle_params();
1437 // make sure global base dir exists
1438 if (::access(basedir
.c_str(), R_OK
| W_OK
)) {
1440 derr
<< __FUNC__
<< ": unable to access basedir '" << basedir
<< "': "
1441 << cpp_strerror(ret
) << dendl
;
1446 snprintf(buf
, sizeof(buf
), "%s/fsid", basedir
.c_str());
1447 fsid_fd
= ::open(buf
, O_RDWR
, 0644);
1450 derr
<< __FUNC__
<< ": error opening '" << buf
<< "': "
1451 << cpp_strerror(ret
) << dendl
;
1455 ret
= read_fsid(fsid_fd
, &fsid
);
1457 derr
<< __FUNC__
<< ": error reading fsid_fd: " << cpp_strerror(ret
)
1462 if (lock_fsid() < 0) {
1463 derr
<< __FUNC__
<< ": lock_fsid failed" << dendl
;
1468 dout(10) << "mount fsid is " << fsid
<< dendl
;
1471 uint32_t version_stamp
;
1472 ret
= version_stamp_is_valid(&version_stamp
);
1474 derr
<< __FUNC__
<< ": error in version_stamp_is_valid: "
1475 << cpp_strerror(ret
) << dendl
;
1477 } else if (ret
== 0) {
1478 if (do_update
|| (int)version_stamp
< cct
->_conf
->filestore_update_to
) {
1479 derr
<< __FUNC__
<< ": stale version stamp detected: "
1481 << ". Proceeding, do_update "
1482 << "is set, performing disk format upgrade."
1487 derr
<< __FUNC__
<< ": stale version stamp " << version_stamp
1488 << ". Please run the FileStore update script before starting the "
1489 << "OSD, or set filestore_update_to to " << target_version
1490 << " (currently " << cct
->_conf
->filestore_update_to
<< ")"
1496 ret
= read_superblock();
1501 // Check if this FileStore supports all the necessary features to mount
1502 if (supported_compat_set
.compare(superblock
.compat_features
) == -1) {
1503 derr
<< __FUNC__
<< ": Incompatible features set "
1504 << superblock
.compat_features
<< dendl
;
1509 // open some dir handles
1510 basedir_fd
= ::open(basedir
.c_str(), O_RDONLY
);
1511 if (basedir_fd
< 0) {
1513 derr
<< __FUNC__
<< ": failed to open " << basedir
<< ": "
1514 << cpp_strerror(ret
) << dendl
;
1519 // test for btrfs, xattrs, etc.
1522 derr
<< __FUNC__
<< ": error in _detect_fs: "
1523 << cpp_strerror(ret
) << dendl
;
1524 goto close_basedir_fd
;
1529 ret
= backend
->list_checkpoints(ls
);
1531 derr
<< __FUNC__
<< ": error in _list_snaps: "<< cpp_strerror(ret
) << dendl
;
1532 goto close_basedir_fd
;
1535 long long unsigned c
, prev
= 0;
1536 char clustersnap
[NAME_MAX
];
1537 for (list
<string
>::iterator it
= ls
.begin(); it
!= ls
.end(); ++it
) {
1538 if (sscanf(it
->c_str(), COMMIT_SNAP_ITEM
, &c
) == 1) {
1542 } else if (sscanf(it
->c_str(), CLUSTER_SNAP_ITEM
, clustersnap
) == 1)
1543 cluster_snaps
.insert(*it
);
1547 if (m_osd_rollback_to_cluster_snap
.length() &&
1548 cluster_snaps
.count(m_osd_rollback_to_cluster_snap
) == 0) {
1549 derr
<< "rollback to cluster snapshot '" << m_osd_rollback_to_cluster_snap
<< "': not found" << dendl
;
1551 goto close_basedir_fd
;
1555 snprintf(nosnapfn
, sizeof(nosnapfn
), "%s/nosnap", current_fn
.c_str());
1557 if (backend
->can_checkpoint()) {
1558 if (snaps
.empty()) {
1559 dout(0) << __FUNC__
<< ": WARNING: no consistent snaps found, store may be in inconsistent state" << dendl
;
1562 uint64_t curr_seq
= 0;
1564 if (m_osd_rollback_to_cluster_snap
.length()) {
1566 << " ** NOTE: rolling back to cluster snapshot " << m_osd_rollback_to_cluster_snap
<< " **"
1569 assert(cluster_snaps
.count(m_osd_rollback_to_cluster_snap
));
1570 snprintf(s
, sizeof(s
), CLUSTER_SNAP_ITEM
, m_osd_rollback_to_cluster_snap
.c_str());
1573 int fd
= read_op_seq(&curr_seq
);
1575 VOID_TEMP_FAILURE_RETRY(::close(fd
));
1579 dout(10) << " current/ seq was " << curr_seq
<< dendl
;
1581 dout(10) << " current/ missing entirely (unusual, but okay)" << dendl
;
1583 uint64_t cp
= snaps
.back();
1584 dout(10) << " most recent snap from " << snaps
<< " is " << cp
<< dendl
;
1586 // if current/ is marked as non-snapshotted, refuse to roll
1587 // back (without clear direction) to avoid throwing out new
1590 if (::stat(nosnapfn
, &st
) == 0) {
1591 if (!m_osd_use_stale_snap
) {
1592 derr
<< "ERROR: " << nosnapfn
<< " exists, not rolling back to avoid losing new data" << dendl
;
1593 derr
<< "Force rollback to old snapshotted version with 'osd use stale snap = true'" << dendl
;
1594 derr
<< "config option for --osd-use-stale-snap startup argument." << dendl
;
1596 goto close_basedir_fd
;
1598 derr
<< "WARNING: user forced start with data sequence mismatch: current was " << curr_seq
1599 << ", newest snap is " << cp
<< dendl
;
1601 << " ** WARNING: forcing the use of stale snapshot data **"
1602 << TEXT_NORMAL
<< std::endl
;
1605 dout(10) << __FUNC__
<< ": rolling back to consistent snap " << cp
<< dendl
;
1606 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)cp
);
1610 ret
= backend
->rollback_to(s
);
1612 derr
<< __FUNC__
<< ": error rolling back to " << s
<< ": "
1613 << cpp_strerror(ret
) << dendl
;
1614 goto close_basedir_fd
;
1620 current_fd
= ::open(current_fn
.c_str(), O_RDONLY
);
1621 if (current_fd
< 0) {
1623 derr
<< __FUNC__
<< ": error opening: " << current_fn
<< ": " << cpp_strerror(ret
) << dendl
;
1624 goto close_basedir_fd
;
1627 assert(current_fd
>= 0);
1629 op_fd
= read_op_seq(&initial_op_seq
);
1632 derr
<< __FUNC__
<< ": read_op_seq failed" << dendl
;
1633 goto close_current_fd
;
1636 dout(5) << "mount op_seq is " << initial_op_seq
<< dendl
;
1637 if (initial_op_seq
== 0) {
1638 derr
<< "mount initial op seq is 0; something is wrong" << dendl
;
1640 goto close_current_fd
;
1643 if (!backend
->can_checkpoint()) {
1644 // mark current/ as non-snapshotted so that we don't rollback away
1646 int r
= ::creat(nosnapfn
, 0644);
1649 derr
<< __FUNC__
<< ": failed to create current/nosnap" << dendl
;
1650 goto close_current_fd
;
1652 VOID_TEMP_FAILURE_RETRY(::close(r
));
1654 // clear nosnap marker, if present.
1658 // check fsid with omap
1661 char omap_fsid_buf
[PATH_MAX
];
1662 struct ::stat omap_fsid_stat
;
1663 snprintf(omap_fsid_buf
, sizeof(omap_fsid_buf
), "%s/osd_uuid", omap_dir
.c_str());
1664 // if osd_uuid not exists, assume as this omap matchs corresponding osd
1665 if (::stat(omap_fsid_buf
, &omap_fsid_stat
) != 0){
1666 dout(10) << __FUNC__
<< ": osd_uuid not found under omap, "
1667 << "assume as matched."
1670 // if osd_uuid exists, compares osd_uuid with fsid
1671 omap_fsid_fd
= ::open(omap_fsid_buf
, O_RDONLY
, 0644);
1672 if (omap_fsid_fd
< 0) {
1674 derr
<< __FUNC__
<< ": error opening '" << omap_fsid_buf
<< "': "
1675 << cpp_strerror(ret
)
1677 goto close_current_fd
;
1679 ret
= read_fsid(omap_fsid_fd
, &omap_fsid
);
1680 VOID_TEMP_FAILURE_RETRY(::close(omap_fsid_fd
));
1681 omap_fsid_fd
= -1; // defensive
1683 derr
<< __FUNC__
<< ": error reading omap_fsid_fd"
1684 << ", omap_fsid = " << omap_fsid
1685 << cpp_strerror(ret
)
1687 goto close_current_fd
;
1689 if (fsid
!= omap_fsid
) {
1690 derr
<< __FUNC__
<< ": " << omap_fsid_buf
1691 << " has existed omap fsid " << omap_fsid
1692 << " != expected osd fsid " << fsid
1695 goto close_current_fd
;
1699 dout(0) << "start omap initiation" << dendl
;
1700 if (!(generic_flags
& SKIP_MOUNT_OMAP
)) {
1701 KeyValueDB
* omap_store
= KeyValueDB::create(cct
,
1702 superblock
.omap_backend
,
1704 if (omap_store
== NULL
)
1706 derr
<< __FUNC__
<< ": Error creating " << superblock
.omap_backend
<< dendl
;
1708 goto close_current_fd
;
1711 if (superblock
.omap_backend
== "rocksdb")
1712 ret
= omap_store
->init(cct
->_conf
->filestore_rocksdb_options
);
1714 ret
= omap_store
->init();
1717 derr
<< __FUNC__
<< ": Error initializing omap_store: " << cpp_strerror(ret
) << dendl
;
1718 goto close_current_fd
;
1722 if (omap_store
->create_and_open(err
)) {
1724 derr
<< __FUNC__
<< ": Error initializing " << superblock
.omap_backend
1725 << " : " << err
.str() << dendl
;
1727 goto close_current_fd
;
1730 DBObjectMap
*dbomap
= new DBObjectMap(cct
, omap_store
);
1731 ret
= dbomap
->init(do_update
);
1734 derr
<< __FUNC__
<< ": Error initializing DBObjectMap: " << ret
<< dendl
;
1735 goto close_current_fd
;
1739 if (cct
->_conf
->filestore_debug_omap_check
&& !dbomap
->check(err2
)) {
1740 derr
<< err2
.str() << dendl
;
1743 goto close_current_fd
;
1745 object_map
.reset(dbomap
);
1751 // select journal mode?
1753 if (!m_filestore_journal_writeahead
&&
1754 !m_filestore_journal_parallel
&&
1755 !m_filestore_journal_trailing
) {
1756 if (!backend
->can_checkpoint()) {
1757 m_filestore_journal_writeahead
= true;
1758 dout(0) << __FUNC__
<< ": enabling WRITEAHEAD journal mode: checkpoint is not enabled" << dendl
;
1760 m_filestore_journal_parallel
= true;
1761 dout(0) << __FUNC__
<< ": enabling PARALLEL journal mode: fs, checkpoint is enabled" << dendl
;
1764 if (m_filestore_journal_writeahead
)
1765 dout(0) << __FUNC__
<< ": WRITEAHEAD journal mode explicitly enabled in conf" << dendl
;
1766 if (m_filestore_journal_parallel
)
1767 dout(0) << __FUNC__
<< ": PARALLEL journal mode explicitly enabled in conf" << dendl
;
1768 if (m_filestore_journal_trailing
)
1769 dout(0) << __FUNC__
<< ": TRAILING journal mode explicitly enabled in conf" << dendl
;
1771 if (m_filestore_journal_writeahead
)
1772 journal
->set_wait_on_full(true);
1774 dout(0) << __FUNC__
<< ": no journal" << dendl
;
1777 ret
= _sanity_check_fs();
1779 derr
<< __FUNC__
<< ": _sanity_check_fs failed with error "
1781 goto close_current_fd
;
1784 // Cleanup possibly invalid collections
1786 vector
<coll_t
> collections
;
1787 ret
= list_collections(collections
, true);
1789 derr
<< "Error " << ret
<< " while listing collections" << dendl
;
1790 goto close_current_fd
;
1792 for (vector
<coll_t
>::iterator i
= collections
.begin();
1793 i
!= collections
.end();
1796 ret
= get_index(*i
, &index
);
1798 derr
<< "Unable to mount index " << *i
1799 << " with error: " << ret
<< dendl
;
1800 goto close_current_fd
;
1802 assert(NULL
!= index
.index
);
1803 RWLock::WLocker
l((index
.index
)->access_lock
);
1808 if (!m_disable_wbthrottle
) {
1811 dout(0) << __FUNC__
<< ": INFO: WbThrottle is disabled" << dendl
;
1812 if (cct
->_conf
->filestore_odsync_write
) {
1813 dout(0) << __FUNC__
<< ": INFO: O_DSYNC write is enabled" << dendl
;
1816 sync_thread
.create("filestore_sync");
1818 if (!(generic_flags
& SKIP_JOURNAL_REPLAY
)) {
1819 ret
= journal_replay(initial_op_seq
);
1821 derr
<< __FUNC__
<< ": failed to open journal " << journalpath
<< ": " << cpp_strerror(ret
) << dendl
;
1822 if (ret
== -ENOTTY
) {
1823 derr
<< "maybe journal is not pointing to a block device and its size "
1824 << "wasn't configured?" << dendl
;
1833 if (cct
->_conf
->filestore_debug_omap_check
&& !object_map
->check(err2
)) {
1834 derr
<< err2
.str() << dendl
;
1840 init_temp_collections();
1845 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
1848 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
1855 if (cct
->_conf
->filestore_update_to
>= (int)get_target_version()) {
1856 int err
= upgrade();
1858 derr
<< "error converting store" << dendl
;
1874 if (!m_disable_wbthrottle
) {
1878 VOID_TEMP_FAILURE_RETRY(::close(current_fd
));
1881 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd
));
1884 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1887 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
1894 void FileStore::init_temp_collections()
1896 dout(10) << __FUNC__
<< dendl
;
1898 int r
= list_collections(ls
, true);
1901 dout(20) << " ls " << ls
<< dendl
;
1903 SequencerPosition spos
;
1906 for (vector
<coll_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
)
1909 dout(20) << " temps " << temps
<< dendl
;
1911 for (vector
<coll_t
>::iterator p
= ls
.begin(); p
!= ls
.end(); ++p
) {
1916 coll_t temp
= p
->get_temp();
1917 if (temps
.count(temp
)) {
1920 dout(10) << __FUNC__
<< ": creating " << temp
<< dendl
;
1921 r
= _create_collection(temp
, 0, spos
);
1926 for (set
<coll_t
>::iterator p
= temps
.begin(); p
!= temps
.end(); ++p
) {
1927 dout(10) << __FUNC__
<< ": removing stray " << *p
<< dendl
;
1928 r
= _collection_remove_recursive(*p
, spos
);
1933 int FileStore::umount()
1935 dout(5) << __FUNC__
<< ": " << basedir
<< dendl
;
1946 if (!m_disable_wbthrottle
){
1952 if (!(generic_flags
& SKIP_JOURNAL_REPLAY
))
1953 journal_write_close();
1955 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
1958 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
1963 VOID_TEMP_FAILURE_RETRY(::close(fsid_fd
));
1967 VOID_TEMP_FAILURE_RETRY(::close(op_fd
));
1970 if (current_fd
>= 0) {
1971 VOID_TEMP_FAILURE_RETRY(::close(current_fd
));
1974 if (basedir_fd
>= 0) {
1975 VOID_TEMP_FAILURE_RETRY(::close(basedir_fd
));
1987 Mutex::Locker
l(sync_entry_timeo_lock
);
1998 /// -----------------------------
2000 FileStore::Op
*FileStore::build_op(vector
<Transaction
>& tls
,
2001 Context
*onreadable
,
2002 Context
*onreadable_sync
,
2003 TrackedOpRef osd_op
)
2005 uint64_t bytes
= 0, ops
= 0;
2006 for (vector
<Transaction
>::iterator p
= tls
.begin();
2009 bytes
+= (*p
).get_num_bytes();
2010 ops
+= (*p
).get_num_ops();
2014 o
->start
= ceph_clock_now();
2015 o
->tls
= std::move(tls
);
2016 o
->onreadable
= onreadable
;
2017 o
->onreadable_sync
= onreadable_sync
;
2026 void FileStore::queue_op(OpSequencer
*osr
, Op
*o
)
2028 // queue op on sequencer, then queue sequencer for the threadpool,
2029 // so that regardless of which order the threads pick up the
2030 // sequencer, the op order will be preserved.
2033 o
->trace
.event("queued");
2035 logger
->inc(l_filestore_ops
);
2036 logger
->inc(l_filestore_bytes
, o
->bytes
);
2038 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
2040 << " " << o
->bytes
<< " bytes"
2041 << " (queue has " << throttle_ops
.get_current() << " ops and " << throttle_bytes
.get_current() << " bytes)"
2046 void FileStore::op_queue_reserve_throttle(Op
*o
)
2049 throttle_bytes
.get(o
->bytes
);
2051 logger
->set(l_filestore_op_queue_ops
, throttle_ops
.get_current());
2052 logger
->set(l_filestore_op_queue_bytes
, throttle_bytes
.get_current());
2055 void FileStore::op_queue_release_throttle(Op
*o
)
2058 throttle_bytes
.put(o
->bytes
);
2059 logger
->set(l_filestore_op_queue_ops
, throttle_ops
.get_current());
2060 logger
->set(l_filestore_op_queue_bytes
, throttle_bytes
.get_current());
2063 void FileStore::_do_op(OpSequencer
*osr
, ThreadPool::TPHandle
&handle
)
2065 if (!m_disable_wbthrottle
) {
2066 wbthrottle
.throttle();
2069 if (cct
->_conf
->filestore_inject_stall
) {
2070 int orig
= cct
->_conf
->filestore_inject_stall
;
2071 dout(5) << __FUNC__
<< ": filestore_inject_stall " << orig
<< ", sleeping" << dendl
;
2073 cct
->_conf
->set_val("filestore_inject_stall", "0");
2074 dout(5) << __FUNC__
<< ": done stalling" << dendl
;
2077 osr
->apply_lock
.Lock();
2078 Op
*o
= osr
->peek_queue();
2079 o
->trace
.event("op_apply_start");
2080 apply_manager
.op_apply_start(o
->op
);
2081 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< "/" << osr
->parent
<< " start" << dendl
;
2082 o
->trace
.event("_do_transactions start");
2083 int r
= _do_transactions(o
->tls
, o
->op
, &handle
);
2084 o
->trace
.event("op_apply_finish");
2085 apply_manager
.op_apply_finish(o
->op
);
2086 dout(10) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " r = " << r
2087 << ", finisher " << o
->onreadable
<< " " << o
->onreadable_sync
<< dendl
;
2093 void FileStore::_finish_op(OpSequencer
*osr
)
2095 list
<Context
*> to_queue
;
2096 Op
*o
= osr
->dequeue(&to_queue
);
2098 utime_t lat
= ceph_clock_now();
2101 dout(10) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< "/" << osr
->parent
<< " lat " << lat
<< dendl
;
2102 osr
->apply_lock
.Unlock(); // locked in _do_op
2103 o
->trace
.event("_finish_op");
2105 // called with tp lock held
2106 op_queue_release_throttle(o
);
2108 logger
->tinc(l_filestore_apply_latency
, lat
);
2110 if (o
->onreadable_sync
) {
2111 o
->onreadable_sync
->complete(0);
2113 if (o
->onreadable
) {
2114 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(o
->onreadable
);
2116 if (!to_queue
.empty()) {
2117 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(to_queue
);
2123 struct C_JournaledAhead
: public Context
{
2125 FileStore::OpSequencer
*osr
;
2129 C_JournaledAhead(FileStore
*f
, FileStore::OpSequencer
*os
, FileStore::Op
*o
, Context
*ondisk
):
2130 fs(f
), osr(os
), o(o
), ondisk(ondisk
) { }
2131 void finish(int r
) override
{
2132 fs
->_journaled_ahead(osr
, o
, ondisk
);
2136 int FileStore::queue_transactions(Sequencer
*posr
, vector
<Transaction
>& tls
,
2137 TrackedOpRef osd_op
,
2138 ThreadPool::TPHandle
*handle
)
2140 Context
*onreadable
;
2142 Context
*onreadable_sync
;
2143 ObjectStore::Transaction::collect_contexts(
2144 tls
, &onreadable
, &ondisk
, &onreadable_sync
);
2146 if (cct
->_conf
->objectstore_blackhole
) {
2147 dout(0) << __FUNC__
<< ": objectstore_blackhole = TRUE, dropping transaction"
2151 delete onreadable_sync
;
2155 utime_t start
= ceph_clock_now();
2156 // set up the sequencer
2160 osr
= static_cast<OpSequencer
*>(posr
->p
.get());
2161 dout(5) << __FUNC__
<< ": existing " << osr
<< " " << *osr
<< dendl
;
2163 osr
= new OpSequencer(cct
, ++next_osr_id
);
2167 dout(5) << __FUNC__
<< ": new " << osr
<< " " << *osr
<< dendl
;
2170 // used to include osr information in tracepoints during transaction apply
2171 for (vector
<Transaction
>::iterator i
= tls
.begin(); i
!= tls
.end(); ++i
) {
2175 ZTracer::Trace trace
;
2176 if (osd_op
&& osd_op
->pg_trace
) {
2177 osd_op
->store_trace
.init("filestore op", &trace_endpoint
, &osd_op
->pg_trace
);
2178 trace
= osd_op
->store_trace
;
2181 if (journal
&& journal
->is_writeable() && !m_filestore_journal_trailing
) {
2182 Op
*o
= build_op(tls
, onreadable
, onreadable_sync
, osd_op
);
2184 //prepare and encode transactions data out of lock
2186 int orig_len
= journal
->prepare_entry(o
->tls
, &tbl
);
2189 handle
->suspend_tp_timeout();
2191 op_queue_reserve_throttle(o
);
2192 journal
->reserve_throttle_and_backoff(tbl
.length());
2195 handle
->reset_tp_timeout();
2197 uint64_t op_num
= submit_manager
.op_submit_start();
2199 trace
.keyval("opnum", op_num
);
2201 if (m_filestore_do_dump
)
2202 dump_transactions(o
->tls
, o
->op
, osr
);
2204 if (m_filestore_journal_parallel
) {
2205 dout(5) << __FUNC__
<< ": (parallel) " << o
->op
<< " " << o
->tls
<< dendl
;
2207 trace
.keyval("journal mode", "parallel");
2208 trace
.event("journal started");
2209 _op_journal_transactions(tbl
, orig_len
, o
->op
, ondisk
, osd_op
);
2211 // queue inside submit_manager op submission lock
2213 trace
.event("op queued");
2214 } else if (m_filestore_journal_writeahead
) {
2215 dout(5) << __FUNC__
<< ": (writeahead) " << o
->op
<< " " << o
->tls
<< dendl
;
2217 osr
->queue_journal(o
->op
);
2219 trace
.keyval("journal mode", "writeahead");
2220 trace
.event("journal started");
2221 _op_journal_transactions(tbl
, orig_len
, o
->op
,
2222 new C_JournaledAhead(this, osr
, o
, ondisk
),
2227 submit_manager
.op_submit_finish(op_num
);
2228 utime_t end
= ceph_clock_now();
2229 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2234 Op
*o
= build_op(tls
, onreadable
, onreadable_sync
, osd_op
);
2235 dout(5) << __FUNC__
<< ": (no journal) " << o
<< " " << tls
<< dendl
;
2238 handle
->suspend_tp_timeout();
2240 op_queue_reserve_throttle(o
);
2243 handle
->reset_tp_timeout();
2245 uint64_t op_num
= submit_manager
.op_submit_start();
2248 if (m_filestore_do_dump
)
2249 dump_transactions(o
->tls
, o
->op
, osr
);
2252 trace
.keyval("opnum", op_num
);
2253 trace
.keyval("journal mode", "none");
2254 trace
.event("op queued");
2257 apply_manager
.add_waiter(op_num
, ondisk
);
2258 submit_manager
.op_submit_finish(op_num
);
2259 utime_t end
= ceph_clock_now();
2260 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2265 //prepare and encode transactions data out of lock
2268 if (journal
->is_writeable()) {
2269 orig_len
= journal
->prepare_entry(tls
, &tbl
);
2271 uint64_t op
= submit_manager
.op_submit_start();
2272 dout(5) << __FUNC__
<< ": (trailing journal) " << op
<< " " << tls
<< dendl
;
2274 if (m_filestore_do_dump
)
2275 dump_transactions(tls
, op
, osr
);
2277 trace
.event("op_apply_start");
2278 trace
.keyval("opnum", op
);
2279 trace
.keyval("journal mode", "trailing");
2280 apply_manager
.op_apply_start(op
);
2281 trace
.event("do_transactions");
2282 int r
= do_transactions(tls
, op
);
2285 trace
.event("journal started");
2286 _op_journal_transactions(tbl
, orig_len
, op
, ondisk
, osd_op
);
2291 // start on_readable finisher after we queue journal item, as on_readable callback
2292 // is allowed to delete the Transaction
2293 if (onreadable_sync
) {
2294 onreadable_sync
->complete(r
);
2296 apply_finishers
[osr
->id
% m_apply_finisher_num
]->queue(onreadable
, r
);
2298 submit_manager
.op_submit_finish(op
);
2299 trace
.event("op_apply_finish");
2300 apply_manager
.op_apply_finish(op
);
2302 utime_t end
= ceph_clock_now();
2303 logger
->tinc(l_filestore_queue_transaction_latency_avg
, end
- start
);
2307 void FileStore::_journaled_ahead(OpSequencer
*osr
, Op
*o
, Context
*ondisk
)
2309 dout(5) << __FUNC__
<< ": " << o
<< " seq " << o
->op
<< " " << *osr
<< " " << o
->tls
<< dendl
;
2311 o
->trace
.event("writeahead journal finished");
2313 // this should queue in order because the journal does it's completions in order.
2316 list
<Context
*> to_queue
;
2317 osr
->dequeue_journal(&to_queue
);
2319 // do ondisk completions async, to prevent any onreadable_sync completions
2320 // getting blocked behind an ondisk completion.
2322 dout(10) << " queueing ondisk " << ondisk
<< dendl
;
2323 ondisk_finishers
[osr
->id
% m_ondisk_finisher_num
]->queue(ondisk
);
2325 if (!to_queue
.empty()) {
2326 ondisk_finishers
[osr
->id
% m_ondisk_finisher_num
]->queue(to_queue
);
2330 int FileStore::_do_transactions(
2331 vector
<Transaction
> &tls
,
2333 ThreadPool::TPHandle
*handle
)
2337 for (vector
<Transaction
>::iterator p
= tls
.begin();
2340 _do_transaction(*p
, op_seq
, trans_num
, handle
);
2342 handle
->reset_tp_timeout();
2348 void FileStore::_set_global_replay_guard(const coll_t
& cid
,
2349 const SequencerPosition
&spos
)
2351 if (backend
->can_checkpoint())
2354 // sync all previous operations on this sequencer
2355 int ret
= object_map
->sync();
2357 derr
<< __FUNC__
<< ": omap sync error " << cpp_strerror(ret
) << dendl
;
2358 assert(0 == "_set_global_replay_guard failed");
2360 ret
= sync_filesystem(basedir_fd
);
2362 derr
<< __FUNC__
<< ": sync_filesystem error " << cpp_strerror(ret
) << dendl
;
2363 assert(0 == "_set_global_replay_guard failed");
2367 get_cdir(cid
, fn
, sizeof(fn
));
2368 int fd
= ::open(fn
, O_RDONLY
);
2371 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2372 assert(0 == "_set_global_replay_guard failed");
2377 // then record that we did it
2380 int r
= chain_fsetxattr
<true, true>(
2381 fd
, GLOBAL_REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2383 derr
<< __FUNC__
<< ": fsetxattr " << GLOBAL_REPLAY_GUARD_XATTR
2384 << " got " << cpp_strerror(r
) << dendl
;
2385 assert(0 == "fsetxattr failed");
2388 // and make sure our xattr is durable.
2393 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2394 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2397 int FileStore::_check_global_replay_guard(const coll_t
& cid
,
2398 const SequencerPosition
& spos
)
2401 get_cdir(cid
, fn
, sizeof(fn
));
2402 int fd
= ::open(fn
, O_RDONLY
);
2404 dout(10) << __FUNC__
<< ": " << cid
<< " dne" << dendl
;
2405 return 1; // if collection does not exist, there is no guard, and we can replay.
2409 int r
= chain_fgetxattr(fd
, GLOBAL_REPLAY_GUARD_XATTR
, buf
, sizeof(buf
));
2411 dout(20) << __FUNC__
<< ": no xattr" << dendl
;
2412 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
2413 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2414 return 1; // no xattr
2419 SequencerPosition opos
;
2420 bufferlist::iterator p
= bl
.begin();
2423 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2424 return spos
>= opos
? 1 : -1;
2428 void FileStore::_set_replay_guard(const coll_t
& cid
,
2429 const SequencerPosition
&spos
,
2430 bool in_progress
=false)
2433 get_cdir(cid
, fn
, sizeof(fn
));
2434 int fd
= ::open(fn
, O_RDONLY
);
2437 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2438 assert(0 == "_set_replay_guard failed");
2440 _set_replay_guard(fd
, spos
, 0, in_progress
);
2441 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2445 void FileStore::_set_replay_guard(int fd
,
2446 const SequencerPosition
& spos
,
2447 const ghobject_t
*hoid
,
2450 if (backend
->can_checkpoint())
2453 dout(10) << __FUNC__
<< ": " << spos
<< (in_progress
? " START" : "") << dendl
;
2457 // first make sure the previous operation commits
2461 // sync object_map too. even if this object has a header or keys,
2462 // it have had them in the past and then removed them, so always
2464 object_map
->sync(hoid
, &spos
);
2469 // then record that we did it
2472 ::encode(in_progress
, v
);
2473 int r
= chain_fsetxattr
<true, true>(
2474 fd
, REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2476 derr
<< "fsetxattr " << REPLAY_GUARD_XATTR
<< " got " << cpp_strerror(r
) << dendl
;
2477 assert(0 == "fsetxattr failed");
2480 // and make sure our xattr is durable.
2485 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2488 void FileStore::_close_replay_guard(const coll_t
& cid
,
2489 const SequencerPosition
&spos
)
2492 get_cdir(cid
, fn
, sizeof(fn
));
2493 int fd
= ::open(fn
, O_RDONLY
);
2496 derr
<< __FUNC__
<< ": " << cid
<< " error " << cpp_strerror(err
) << dendl
;
2497 assert(0 == "_close_replay_guard failed");
2499 _close_replay_guard(fd
, spos
);
2500 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2503 void FileStore::_close_replay_guard(int fd
, const SequencerPosition
& spos
,
2504 const ghobject_t
*hoid
)
2506 if (backend
->can_checkpoint())
2509 dout(10) << __FUNC__
<< ": " << spos
<< dendl
;
2513 // sync object_map too. even if this object has a header or keys,
2514 // it have had them in the past and then removed them, so always
2516 object_map
->sync(hoid
, &spos
);
2518 // then record that we are done with this operation
2521 bool in_progress
= false;
2522 ::encode(in_progress
, v
);
2523 int r
= chain_fsetxattr
<true, true>(
2524 fd
, REPLAY_GUARD_XATTR
, v
.c_str(), v
.length());
2526 derr
<< "fsetxattr " << REPLAY_GUARD_XATTR
<< " got " << cpp_strerror(r
) << dendl
;
2527 assert(0 == "fsetxattr failed");
2530 // and make sure our xattr is durable.
2535 dout(10) << __FUNC__
<< ": " << spos
<< " done" << dendl
;
2538 int FileStore::_check_replay_guard(const coll_t
& cid
, const ghobject_t
&oid
,
2539 const SequencerPosition
& spos
)
2541 if (!replaying
|| backend
->can_checkpoint())
2544 int r
= _check_global_replay_guard(cid
, spos
);
2549 r
= lfn_open(cid
, oid
, false, &fd
);
2551 dout(10) << __FUNC__
<< ": " << cid
<< " " << oid
<< " dne" << dendl
;
2552 return 1; // if file does not exist, there is no guard, and we can replay.
2554 int ret
= _check_replay_guard(**fd
, spos
);
2559 int FileStore::_check_replay_guard(const coll_t
& cid
, const SequencerPosition
& spos
)
2561 if (!replaying
|| backend
->can_checkpoint())
2565 get_cdir(cid
, fn
, sizeof(fn
));
2566 int fd
= ::open(fn
, O_RDONLY
);
2568 dout(10) << __FUNC__
<< ": " << cid
<< " dne" << dendl
;
2569 return 1; // if collection does not exist, there is no guard, and we can replay.
2571 int ret
= _check_replay_guard(fd
, spos
);
2572 VOID_TEMP_FAILURE_RETRY(::close(fd
));
2576 int FileStore::_check_replay_guard(int fd
, const SequencerPosition
& spos
)
2578 if (!replaying
|| backend
->can_checkpoint())
2582 int r
= chain_fgetxattr(fd
, REPLAY_GUARD_XATTR
, buf
, sizeof(buf
));
2584 dout(20) << __FUNC__
<< ": no xattr" << dendl
;
2585 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
2586 return 1; // no xattr
2591 SequencerPosition opos
;
2592 bufferlist::iterator p
= bl
.begin();
2594 bool in_progress
= false;
2595 if (!p
.end()) // older journals don't have this
2596 ::decode(in_progress
, p
);
2598 dout(10) << __FUNC__
<< ": object has " << opos
<< " > current pos " << spos
2599 << ", now or in future, SKIPPING REPLAY" << dendl
;
2601 } else if (opos
== spos
) {
2603 dout(10) << __FUNC__
<< ": object has " << opos
<< " == current pos " << spos
2604 << ", in_progress=true, CONDITIONAL REPLAY" << dendl
;
2607 dout(10) << __FUNC__
<< ": object has " << opos
<< " == current pos " << spos
2608 << ", in_progress=false, SKIPPING REPLAY" << dendl
;
2612 dout(10) << __FUNC__
<< ": object has " << opos
<< " < current pos " << spos
2613 << ", in past, will replay" << dendl
;
2618 void FileStore::_do_transaction(
2619 Transaction
& t
, uint64_t op_seq
, int trans_num
,
2620 ThreadPool::TPHandle
*handle
)
2622 dout(10) << __FUNC__
<< ": on " << &t
<< dendl
;
2625 const char *osr_name
= t
.get_osr() ? static_cast<OpSequencer
*>(t
.get_osr())->get_name().c_str() : "<NULL>";
2628 Transaction::iterator i
= t
.begin();
2630 SequencerPosition
spos(op_seq
, trans_num
, 0);
2631 while (i
.have_op()) {
2633 handle
->reset_tp_timeout();
2635 Transaction::Op
*op
= i
.decode_op();
2641 case Transaction::OP_NOP
:
2643 case Transaction::OP_TOUCH
:
2645 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2646 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2647 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2648 _cid
: _cid
.get_temp();
2649 tracepoint(objectstore
, touch_enter
, osr_name
);
2650 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2651 r
= _touch(cid
, oid
);
2652 tracepoint(objectstore
, touch_exit
, r
);
2656 case Transaction::OP_WRITE
:
2658 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2659 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2660 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2661 _cid
: _cid
.get_temp();
2662 uint64_t off
= op
->off
;
2663 uint64_t len
= op
->len
;
2664 uint32_t fadvise_flags
= i
.get_fadvise_flags();
2667 tracepoint(objectstore
, write_enter
, osr_name
, off
, len
);
2668 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2669 r
= _write(cid
, oid
, off
, len
, bl
, fadvise_flags
);
2670 tracepoint(objectstore
, write_exit
, r
);
2674 case Transaction::OP_ZERO
:
2676 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2677 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2678 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2679 _cid
: _cid
.get_temp();
2680 uint64_t off
= op
->off
;
2681 uint64_t len
= op
->len
;
2682 tracepoint(objectstore
, zero_enter
, osr_name
, off
, len
);
2683 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2684 r
= _zero(cid
, oid
, off
, len
);
2685 tracepoint(objectstore
, zero_exit
, r
);
2689 case Transaction::OP_TRIMCACHE
:
2691 // deprecated, no-op
2695 case Transaction::OP_TRUNCATE
:
2697 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2698 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2699 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2700 _cid
: _cid
.get_temp();
2701 uint64_t off
= op
->off
;
2702 tracepoint(objectstore
, truncate_enter
, osr_name
, off
);
2703 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2704 r
= _truncate(cid
, oid
, off
);
2705 tracepoint(objectstore
, truncate_exit
, r
);
2709 case Transaction::OP_REMOVE
:
2711 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2712 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2713 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2714 _cid
: _cid
.get_temp();
2715 tracepoint(objectstore
, remove_enter
, osr_name
);
2716 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2717 r
= _remove(cid
, oid
, spos
);
2718 tracepoint(objectstore
, remove_exit
, r
);
2722 case Transaction::OP_SETATTR
:
2724 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2725 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2726 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2727 _cid
: _cid
.get_temp();
2728 string name
= i
.decode_string();
2731 tracepoint(objectstore
, setattr_enter
, osr_name
);
2732 if (_check_replay_guard(cid
, oid
, spos
) > 0) {
2733 map
<string
, bufferptr
> to_set
;
2734 to_set
[name
] = bufferptr(bl
.c_str(), bl
.length());
2735 r
= _setattrs(cid
, oid
, to_set
, spos
);
2737 dout(0) << " ENOSPC on setxattr on " << cid
<< "/" << oid
2738 << " name " << name
<< " size " << bl
.length() << dendl
;
2740 tracepoint(objectstore
, setattr_exit
, r
);
2744 case Transaction::OP_SETATTRS
:
2746 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2747 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2748 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2749 _cid
: _cid
.get_temp();
2750 map
<string
, bufferptr
> aset
;
2751 i
.decode_attrset(aset
);
2752 tracepoint(objectstore
, setattrs_enter
, osr_name
);
2753 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2754 r
= _setattrs(cid
, oid
, aset
, spos
);
2755 tracepoint(objectstore
, setattrs_exit
, r
);
2757 dout(0) << " ENOSPC on setxattrs on " << cid
<< "/" << oid
<< dendl
;
2761 case Transaction::OP_RMATTR
:
2763 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2764 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2765 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2766 _cid
: _cid
.get_temp();
2767 string name
= i
.decode_string();
2768 tracepoint(objectstore
, rmattr_enter
, osr_name
);
2769 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2770 r
= _rmattr(cid
, oid
, name
.c_str(), spos
);
2771 tracepoint(objectstore
, rmattr_exit
, r
);
2775 case Transaction::OP_RMATTRS
:
2777 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2778 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2779 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2780 _cid
: _cid
.get_temp();
2781 tracepoint(objectstore
, rmattrs_enter
, osr_name
);
2782 if (_check_replay_guard(cid
, oid
, spos
) > 0)
2783 r
= _rmattrs(cid
, oid
, spos
);
2784 tracepoint(objectstore
, rmattrs_exit
, r
);
2788 case Transaction::OP_CLONE
:
2790 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2791 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2792 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2793 _cid
: _cid
.get_temp();
2794 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2795 tracepoint(objectstore
, clone_enter
, osr_name
);
2796 r
= _clone(cid
, oid
, noid
, spos
);
2797 tracepoint(objectstore
, clone_exit
, r
);
2801 case Transaction::OP_CLONERANGE
:
2803 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2804 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2805 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2806 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2807 _cid
: _cid
.get_temp();
2808 const coll_t
&ncid
= !_need_temp_object_collection(_cid
, noid
) ?
2809 _cid
: _cid
.get_temp();
2810 uint64_t off
= op
->off
;
2811 uint64_t len
= op
->len
;
2812 tracepoint(objectstore
, clone_range_enter
, osr_name
, len
);
2813 r
= _clone_range(cid
, oid
, ncid
, noid
, off
, len
, off
, spos
);
2814 tracepoint(objectstore
, clone_range_exit
, r
);
2818 case Transaction::OP_CLONERANGE2
:
2820 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2821 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2822 const ghobject_t
&noid
= i
.get_oid(op
->dest_oid
);
2823 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2824 _cid
: _cid
.get_temp();
2825 const coll_t
&ncid
= !_need_temp_object_collection(_cid
, noid
) ?
2826 _cid
: _cid
.get_temp();
2827 uint64_t srcoff
= op
->off
;
2828 uint64_t len
= op
->len
;
2829 uint64_t dstoff
= op
->dest_off
;
2830 tracepoint(objectstore
, clone_range2_enter
, osr_name
, len
);
2831 r
= _clone_range(cid
, oid
, ncid
, noid
, srcoff
, len
, dstoff
, spos
);
2832 tracepoint(objectstore
, clone_range2_exit
, r
);
2836 case Transaction::OP_MKCOLL
:
2838 const coll_t
&cid
= i
.get_cid(op
->cid
);
2839 tracepoint(objectstore
, mkcoll_enter
, osr_name
);
2840 if (_check_replay_guard(cid
, spos
) > 0)
2841 r
= _create_collection(cid
, op
->split_bits
, spos
);
2842 tracepoint(objectstore
, mkcoll_exit
, r
);
2846 case Transaction::OP_COLL_SET_BITS
:
2848 const coll_t
&cid
= i
.get_cid(op
->cid
);
2849 int bits
= op
->split_bits
;
2850 r
= _collection_set_bits(cid
, bits
);
2854 case Transaction::OP_COLL_HINT
:
2856 const coll_t
&cid
= i
.get_cid(op
->cid
);
2857 uint32_t type
= op
->hint_type
;
2860 bufferlist::iterator hiter
= hint
.begin();
2861 if (type
== Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS
) {
2864 ::decode(pg_num
, hiter
);
2865 ::decode(num_objs
, hiter
);
2866 if (_check_replay_guard(cid
, spos
) > 0) {
2867 r
= _collection_hint_expected_num_objs(cid
, pg_num
, num_objs
, spos
);
2871 dout(10) << "Unrecognized collection hint type: " << type
<< dendl
;
2876 case Transaction::OP_RMCOLL
:
2878 const coll_t
&cid
= i
.get_cid(op
->cid
);
2879 tracepoint(objectstore
, rmcoll_enter
, osr_name
);
2880 if (_check_replay_guard(cid
, spos
) > 0)
2881 r
= _destroy_collection(cid
);
2882 tracepoint(objectstore
, rmcoll_exit
, r
);
2886 case Transaction::OP_COLL_ADD
:
2888 const coll_t
&ocid
= i
.get_cid(op
->cid
);
2889 const coll_t
&ncid
= i
.get_cid(op
->dest_cid
);
2890 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2892 assert(oid
.hobj
.pool
>= -1);
2894 // always followed by OP_COLL_REMOVE
2895 Transaction::Op
*op2
= i
.decode_op();
2896 const coll_t
&ocid2
= i
.get_cid(op2
->cid
);
2897 const ghobject_t
&oid2
= i
.get_oid(op2
->oid
);
2898 assert(op2
->op
== Transaction::OP_COLL_REMOVE
);
2899 assert(ocid2
== ocid
);
2900 assert(oid2
== oid
);
2902 tracepoint(objectstore
, coll_add_enter
);
2903 r
= _collection_add(ncid
, ocid
, oid
, spos
);
2904 tracepoint(objectstore
, coll_add_exit
, r
);
2908 tracepoint(objectstore
, coll_remove_enter
, osr_name
);
2909 if (_check_replay_guard(ocid
, oid
, spos
) > 0)
2910 r
= _remove(ocid
, oid
, spos
);
2911 tracepoint(objectstore
, coll_remove_exit
, r
);
2915 case Transaction::OP_COLL_MOVE
:
2917 // WARNING: this is deprecated and buggy; only here to replay old journals.
2918 const coll_t
&ocid
= i
.get_cid(op
->cid
);
2919 const coll_t
&ncid
= i
.get_cid(op
->dest_cid
);
2920 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2921 tracepoint(objectstore
, coll_move_enter
);
2922 r
= _collection_add(ocid
, ncid
, oid
, spos
);
2924 (_check_replay_guard(ocid
, oid
, spos
) > 0))
2925 r
= _remove(ocid
, oid
, spos
);
2926 tracepoint(objectstore
, coll_move_exit
, r
);
2930 case Transaction::OP_COLL_MOVE_RENAME
:
2932 const coll_t
&_oldcid
= i
.get_cid(op
->cid
);
2933 const ghobject_t
&oldoid
= i
.get_oid(op
->oid
);
2934 const coll_t
&_newcid
= i
.get_cid(op
->dest_cid
);
2935 const ghobject_t
&newoid
= i
.get_oid(op
->dest_oid
);
2936 const coll_t
&oldcid
= !_need_temp_object_collection(_oldcid
, oldoid
) ?
2937 _oldcid
: _oldcid
.get_temp();
2938 const coll_t
&newcid
= !_need_temp_object_collection(_newcid
, newoid
) ?
2939 _oldcid
: _newcid
.get_temp();
2940 tracepoint(objectstore
, coll_move_rename_enter
);
2941 r
= _collection_move_rename(oldcid
, oldoid
, newcid
, newoid
, spos
);
2942 tracepoint(objectstore
, coll_move_rename_exit
, r
);
2946 case Transaction::OP_TRY_RENAME
:
2948 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2949 const ghobject_t
&oldoid
= i
.get_oid(op
->oid
);
2950 const ghobject_t
&newoid
= i
.get_oid(op
->dest_oid
);
2951 const coll_t
&oldcid
= !_need_temp_object_collection(_cid
, oldoid
) ?
2952 _cid
: _cid
.get_temp();
2953 const coll_t
&newcid
= !_need_temp_object_collection(_cid
, newoid
) ?
2954 _cid
: _cid
.get_temp();
2955 tracepoint(objectstore
, coll_try_rename_enter
);
2956 r
= _collection_move_rename(oldcid
, oldoid
, newcid
, newoid
, spos
, true);
2957 tracepoint(objectstore
, coll_try_rename_exit
, r
);
2961 case Transaction::OP_COLL_SETATTR
:
2962 case Transaction::OP_COLL_RMATTR
:
2963 assert(0 == "collection attr methods no longer implemented");
2966 case Transaction::OP_STARTSYNC
:
2967 tracepoint(objectstore
, startsync_enter
, osr_name
);
2969 tracepoint(objectstore
, startsync_exit
);
2972 case Transaction::OP_COLL_RENAME
:
2978 case Transaction::OP_OMAP_CLEAR
:
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();
2984 tracepoint(objectstore
, omap_clear_enter
, osr_name
);
2985 r
= _omap_clear(cid
, oid
, spos
);
2986 tracepoint(objectstore
, omap_clear_exit
, r
);
2989 case Transaction::OP_OMAP_SETKEYS
:
2991 const coll_t
&_cid
= i
.get_cid(op
->cid
);
2992 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
2993 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
2994 _cid
: _cid
.get_temp();
2995 map
<string
, bufferlist
> aset
;
2996 i
.decode_attrset(aset
);
2997 tracepoint(objectstore
, omap_setkeys_enter
, osr_name
);
2998 r
= _omap_setkeys(cid
, oid
, aset
, spos
);
2999 tracepoint(objectstore
, omap_setkeys_exit
, r
);
3002 case Transaction::OP_OMAP_RMKEYS
:
3004 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3005 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3006 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3007 _cid
: _cid
.get_temp();
3009 i
.decode_keyset(keys
);
3010 tracepoint(objectstore
, omap_rmkeys_enter
, osr_name
);
3011 r
= _omap_rmkeys(cid
, oid
, keys
, spos
);
3012 tracepoint(objectstore
, omap_rmkeys_exit
, r
);
3015 case Transaction::OP_OMAP_RMKEYRANGE
:
3017 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3018 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3019 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3020 _cid
: _cid
.get_temp();
3022 first
= i
.decode_string();
3023 last
= i
.decode_string();
3024 tracepoint(objectstore
, omap_rmkeyrange_enter
, osr_name
);
3025 r
= _omap_rmkeyrange(cid
, oid
, first
, last
, spos
);
3026 tracepoint(objectstore
, omap_rmkeyrange_exit
, r
);
3029 case Transaction::OP_OMAP_SETHEADER
:
3031 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3032 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3033 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3034 _cid
: _cid
.get_temp();
3037 tracepoint(objectstore
, omap_setheader_enter
, osr_name
);
3038 r
= _omap_setheader(cid
, oid
, bl
, spos
);
3039 tracepoint(objectstore
, omap_setheader_exit
, r
);
3042 case Transaction::OP_SPLIT_COLLECTION
:
3044 assert(0 == "not legacy journal; upgrade to firefly first");
3047 case Transaction::OP_SPLIT_COLLECTION2
:
3049 coll_t cid
= i
.get_cid(op
->cid
);
3050 uint32_t bits
= op
->split_bits
;
3051 uint32_t rem
= op
->split_rem
;
3052 coll_t dest
= i
.get_cid(op
->dest_cid
);
3053 tracepoint(objectstore
, split_coll2_enter
, osr_name
);
3054 r
= _split_collection(cid
, bits
, rem
, dest
, spos
);
3055 tracepoint(objectstore
, split_coll2_exit
, r
);
3059 case Transaction::OP_SETALLOCHINT
:
3061 const coll_t
&_cid
= i
.get_cid(op
->cid
);
3062 const ghobject_t
&oid
= i
.get_oid(op
->oid
);
3063 const coll_t
&cid
= !_need_temp_object_collection(_cid
, oid
) ?
3064 _cid
: _cid
.get_temp();
3065 uint64_t expected_object_size
= op
->expected_object_size
;
3066 uint64_t expected_write_size
= op
->expected_write_size
;
3067 tracepoint(objectstore
, setallochint_enter
, osr_name
);
3068 if (_check_replay_guard(cid
, oid
, spos
) > 0)
3069 r
= _set_alloc_hint(cid
, oid
, expected_object_size
,
3070 expected_write_size
);
3071 tracepoint(objectstore
, setallochint_exit
, r
);
3076 derr
<< "bad op " << op
->op
<< dendl
;
3083 if (r
== -ENOENT
&& !(op
->op
== Transaction::OP_CLONERANGE
||
3084 op
->op
== Transaction::OP_CLONE
||
3085 op
->op
== Transaction::OP_CLONERANGE2
||
3086 op
->op
== Transaction::OP_COLL_ADD
||
3087 op
->op
== Transaction::OP_SETATTR
||
3088 op
->op
== Transaction::OP_SETATTRS
||
3089 op
->op
== Transaction::OP_RMATTR
||
3090 op
->op
== Transaction::OP_OMAP_SETKEYS
||
3091 op
->op
== Transaction::OP_OMAP_RMKEYS
||
3092 op
->op
== Transaction::OP_OMAP_RMKEYRANGE
||
3093 op
->op
== Transaction::OP_OMAP_SETHEADER
))
3094 // -ENOENT is normally okay
3095 // ...including on a replayed OP_RMCOLL with checkpoint mode
3100 if (op
->op
== Transaction::OP_SETALLOCHINT
)
3101 // Either EOPNOTSUPP or EINVAL most probably. EINVAL in most
3102 // cases means invalid hint size (e.g. too big, not a multiple
3103 // of block size, etc) or, at least on xfs, an attempt to set
3104 // or change it when the file is not empty. However,
3105 // OP_SETALLOCHINT is advisory, so ignore all errors.
3108 if (replaying
&& !backend
->can_checkpoint()) {
3109 if (r
== -EEXIST
&& op
->op
== Transaction::OP_MKCOLL
) {
3110 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3113 if (r
== -EEXIST
&& op
->op
== Transaction::OP_COLL_ADD
) {
3114 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3117 if (r
== -EEXIST
&& op
->op
== Transaction::OP_COLL_MOVE
) {
3118 dout(10) << "tolerating EEXIST during journal replay since checkpoint is not enabled" << dendl
;
3122 dout(10) << "tolerating ERANGE on replay" << dendl
;
3126 dout(10) << "tolerating ENOENT on replay" << dendl
;
3132 const char *msg
= "unexpected error code";
3134 if (r
== -ENOENT
&& (op
->op
== Transaction::OP_CLONERANGE
||
3135 op
->op
== Transaction::OP_CLONE
||
3136 op
->op
== Transaction::OP_CLONERANGE2
)) {
3137 msg
= "ENOENT on clone suggests osd bug";
3138 } else if (r
== -ENOSPC
) {
3139 // For now, if we hit _any_ ENOSPC, crash, before we do any damage
3140 // by partially applying transactions.
3141 msg
= "ENOSPC from disk filesystem, misconfigured cluster";
3142 } else if (r
== -ENOTEMPTY
) {
3143 msg
= "ENOTEMPTY suggests garbage data in osd data dir";
3144 } else if (r
== -EPERM
) {
3145 msg
= "EPERM suggests file(s) in osd data dir not owned by ceph user, or leveldb corruption";
3148 derr
<< " error " << cpp_strerror(r
) << " not handled on operation " << op
3149 << " (" << spos
<< ", or op " << spos
.op
<< ", counting from 0)" << dendl
;
3150 dout(0) << msg
<< dendl
;
3151 dout(0) << " transaction dump:\n";
3152 JSONFormatter
f(true);
3153 f
.open_object_section("transaction");
3163 assert(0 == "unexpected error");
3173 /*********************************************/
3177 // --------------------
3180 bool FileStore::exists(const coll_t
& _cid
, const ghobject_t
& oid
)
3182 tracepoint(objectstore
, exists_enter
, _cid
.c_str());
3183 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3185 bool retval
= stat(cid
, oid
, &st
) == 0;
3186 tracepoint(objectstore
, exists_exit
, retval
);
3190 int FileStore::stat(
3191 const coll_t
& _cid
, const ghobject_t
& oid
, struct stat
*st
, bool allow_eio
)
3193 tracepoint(objectstore
, stat_enter
, _cid
.c_str());
3194 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3195 int r
= lfn_stat(cid
, oid
, st
);
3196 assert(allow_eio
|| !m_filestore_fail_eio
|| r
!= -EIO
);
3198 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
3199 << " = " << r
<< dendl
;
3201 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
3203 << " (size " << st
->st_size
<< ")" << dendl
;
3205 if (cct
->_conf
->filestore_debug_inject_read_err
&&
3206 debug_mdata_eio(oid
)) {
3209 tracepoint(objectstore
, stat_exit
, r
);
3214 int FileStore::set_collection_opts(
3216 const pool_opts_t
& opts
)
3221 int FileStore::read(
3223 const ghobject_t
& oid
,
3230 tracepoint(objectstore
, read_enter
, _cid
.c_str(), offset
, len
);
3231 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3233 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3236 int r
= lfn_open(cid
, oid
, false, &fd
);
3238 dout(10) << __FUNC__
<< ": (" << cid
<< "/" << oid
<< ") open error: "
3239 << cpp_strerror(r
) << dendl
;
3243 if (offset
== 0 && len
== 0) {
3245 memset(&st
, 0, sizeof(struct stat
));
3246 int r
= ::fstat(**fd
, &st
);
3251 #ifdef HAVE_POSIX_FADVISE
3252 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_RANDOM
)
3253 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_RANDOM
);
3254 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
)
3255 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_SEQUENTIAL
);
3258 bufferptr
bptr(len
); // prealloc space for entire read
3259 got
= safe_pread(**fd
, bptr
.c_str(), len
, offset
);
3261 dout(10) << __FUNC__
<< ": (" << cid
<< "/" << oid
<< ") pread error: " << cpp_strerror(got
) << dendl
;
3265 bptr
.set_length(got
); // properly size the buffer
3267 bl
.push_back(std::move(bptr
)); // put it in the target bufferlist
3269 #ifdef HAVE_POSIX_FADVISE
3270 if (op_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
)
3271 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_DONTNEED
);
3272 if (op_flags
& (CEPH_OSD_OP_FLAG_FADVISE_RANDOM
| CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL
))
3273 posix_fadvise(**fd
, offset
, len
, POSIX_FADV_NORMAL
);
3276 if (m_filestore_sloppy_crc
&& (!replaying
|| backend
->can_checkpoint())) {
3278 int errors
= backend
->_crc_verify_read(**fd
, offset
, got
, bl
, &ss
);
3280 dout(0) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~"
3281 << got
<< " ... BAD CRC:\n" << ss
.str() << dendl
;
3282 assert(0 == "bad crc on read");
3288 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~"
3289 << got
<< "/" << len
<< dendl
;
3290 if (cct
->_conf
->filestore_debug_inject_read_err
&&
3291 debug_data_eio(oid
)) {
3293 } else if (cct
->_conf
->filestore_debug_random_read_err
&&
3294 (rand() % (int)(cct
->_conf
->filestore_debug_random_read_err
* 100.0)) == 0) {
3295 dout(0) << __func__
<< ": inject random EIO" << dendl
;
3298 tracepoint(objectstore
, read_exit
, got
);
3303 int FileStore::_do_fiemap(int fd
, uint64_t offset
, size_t len
,
3304 map
<uint64_t, uint64_t> *m
)
3307 struct fiemap_extent
*extent
= NULL
;
3308 struct fiemap
*fiemap
= NULL
;
3312 r
= backend
->do_fiemap(fd
, offset
, len
, &fiemap
);
3316 if (fiemap
->fm_mapped_extents
== 0) {
3321 extent
= &fiemap
->fm_extents
[0];
3323 /* start where we were asked to start */
3324 if (extent
->fe_logical
< offset
) {
3325 extent
->fe_length
-= offset
- extent
->fe_logical
;
3326 extent
->fe_logical
= offset
;
3331 struct fiemap_extent
*last
= nullptr;
3332 while (i
< fiemap
->fm_mapped_extents
) {
3333 struct fiemap_extent
*next
= extent
+ 1;
3335 dout(10) << __FUNC__
<< ": fm_mapped_extents=" << fiemap
->fm_mapped_extents
3336 << " fe_logical=" << extent
->fe_logical
<< " fe_length=" << extent
->fe_length
<< dendl
;
3338 /* try to merge extents */
3339 while ((i
< fiemap
->fm_mapped_extents
- 1) &&
3340 (extent
->fe_logical
+ extent
->fe_length
== next
->fe_logical
)) {
3341 next
->fe_length
+= extent
->fe_length
;
3342 next
->fe_logical
= extent
->fe_logical
;
3348 if (extent
->fe_logical
+ extent
->fe_length
> offset
+ len
)
3349 extent
->fe_length
= offset
+ len
- extent
->fe_logical
;
3350 (*m
)[extent
->fe_logical
] = extent
->fe_length
;
3354 uint64_t xoffset
= last
->fe_logical
+ last
->fe_length
- offset
;
3355 offset
= last
->fe_logical
+ last
->fe_length
;
3357 const bool is_last
= (last
->fe_flags
& FIEMAP_EXTENT_LAST
) || (len
== 0);
3366 int FileStore::_do_seek_hole_data(int fd
, uint64_t offset
, size_t len
,
3367 map
<uint64_t, uint64_t> *m
)
3369 #if defined(__linux__) && defined(SEEK_HOLE) && defined(SEEK_DATA)
3370 off_t hole_pos
, data_pos
;
3373 // If lseek fails with errno setting to be ENXIO, this means the current
3374 // file offset is beyond the end of the file.
3375 off_t start
= offset
;
3376 while(start
< (off_t
)(offset
+ len
)) {
3377 data_pos
= lseek(fd
, start
, SEEK_DATA
);
3383 dout(10) << "failed to lseek: " << cpp_strerror(r
) << dendl
;
3386 } else if (data_pos
> (off_t
)(offset
+ len
)) {
3390 hole_pos
= lseek(fd
, data_pos
, SEEK_HOLE
);
3392 if (errno
== ENXIO
) {
3396 dout(10) << "failed to lseek: " << cpp_strerror(r
) << dendl
;
3401 if (hole_pos
>= (off_t
)(offset
+ len
)) {
3402 (*m
)[data_pos
] = offset
+ len
- data_pos
;
3405 (*m
)[data_pos
] = hole_pos
- data_pos
;
3416 int FileStore::fiemap(const coll_t
& _cid
, const ghobject_t
& oid
,
3417 uint64_t offset
, size_t len
,
3420 map
<uint64_t, uint64_t> exomap
;
3421 int r
= fiemap(_cid
, oid
, offset
, len
, exomap
);
3423 ::encode(exomap
, bl
);
3428 int FileStore::fiemap(const coll_t
& _cid
, const ghobject_t
& oid
,
3429 uint64_t offset
, size_t len
,
3430 map
<uint64_t, uint64_t>& destmap
)
3432 tracepoint(objectstore
, fiemap_enter
, _cid
.c_str(), offset
, len
);
3433 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
3436 if ((!backend
->has_seek_data_hole() && !backend
->has_fiemap()) ||
3437 len
<= (size_t)m_filestore_fiemap_threshold
) {
3438 destmap
[offset
] = len
;
3442 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3446 int r
= lfn_open(cid
, oid
, false, &fd
);
3448 dout(10) << "read couldn't open " << cid
<< "/" << oid
<< ": " << cpp_strerror(r
) << dendl
;
3452 if (backend
->has_seek_data_hole()) {
3453 dout(15) << "seek_data/seek_hole " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3454 r
= _do_seek_hole_data(**fd
, offset
, len
, &destmap
);
3455 } else if (backend
->has_fiemap()) {
3456 dout(15) << "fiemap ioctl" << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3457 r
= _do_fiemap(**fd
, offset
, len
, &destmap
);
3464 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << r
<< " num_extents=" << destmap
.size() << " " << destmap
<< dendl
;
3465 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
3466 tracepoint(objectstore
, fiemap_exit
, r
);
3470 int FileStore::_remove(const coll_t
& cid
, const ghobject_t
& oid
,
3471 const SequencerPosition
&spos
)
3473 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
3474 int r
= lfn_unlink(cid
, oid
, spos
);
3475 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
3479 int FileStore::_truncate(const coll_t
& cid
, const ghobject_t
& oid
, uint64_t size
)
3481 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " size " << size
<< dendl
;
3482 int r
= lfn_truncate(cid
, oid
, size
);
3483 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " size " << size
<< " = " << r
<< dendl
;
3488 int FileStore::_touch(const coll_t
& cid
, const ghobject_t
& oid
)
3490 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
3493 int r
= lfn_open(cid
, oid
, true, &fd
);
3499 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
3503 int FileStore::_write(const coll_t
& cid
, const ghobject_t
& oid
,
3504 uint64_t offset
, size_t len
,
3505 const bufferlist
& bl
, uint32_t fadvise_flags
)
3507 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3511 r
= lfn_open(cid
, oid
, true, &fd
);
3513 dout(0) << __FUNC__
<< ": couldn't open " << cid
<< "/"
3515 << cpp_strerror(r
) << dendl
;
3520 r
= bl
.write_fd(**fd
, offset
);
3522 derr
<< __FUNC__
<< ": write_fd on " << cid
<< "/" << oid
3523 << " error: " << cpp_strerror(r
) << dendl
;
3529 if (r
>= 0 && m_filestore_sloppy_crc
) {
3530 int rc
= backend
->_crc_update_write(**fd
, offset
, len
, bl
);
3534 if (replaying
|| m_disable_wbthrottle
) {
3535 if (fadvise_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
) {
3536 #ifdef HAVE_POSIX_FADVISE
3537 posix_fadvise(**fd
, 0, 0, POSIX_FADV_DONTNEED
);
3541 wbthrottle
.queue_wb(fd
, oid
, offset
, len
,
3542 fadvise_flags
& CEPH_OSD_OP_FLAG_FADVISE_DONTNEED
);
3548 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << r
<< dendl
;
3552 int FileStore::_zero(const coll_t
& cid
, const ghobject_t
& oid
, uint64_t offset
, size_t len
)
3554 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< dendl
;
3557 if (cct
->_conf
->filestore_punch_hole
) {
3558 #ifdef CEPH_HAVE_FALLOCATE
3559 # if !defined(DARWIN) && !defined(__FreeBSD__)
3560 # ifdef FALLOC_FL_KEEP_SIZE
3561 // first try to punch a hole.
3563 ret
= lfn_open(cid
, oid
, false, &fd
);
3569 ret
= ::fstat(**fd
, &st
);
3576 // first try fallocate
3577 ret
= fallocate(**fd
, FALLOC_FL_KEEP_SIZE
| FALLOC_FL_PUNCH_HOLE
,
3582 // ensure we extent file size, if needed
3583 if (offset
+ len
> (uint64_t)st
.st_size
) {
3584 ret
= ::ftruncate(**fd
, offset
+ len
);
3594 if (ret
>= 0 && m_filestore_sloppy_crc
) {
3595 int rc
= backend
->_crc_update_zero(**fd
, offset
, len
);
3601 if (ret
!= -EOPNOTSUPP
)
3602 goto out
; // some other error
3608 // lame, kernel is old and doesn't support it.
3609 // write zeros.. yuck!
3610 dout(20) << __FUNC__
<< ": falling back to writing zeros" << dendl
;
3613 bl
.append_zero(len
);
3614 ret
= _write(cid
, oid
, offset
, len
, bl
);
3617 #ifdef CEPH_HAVE_FALLOCATE
3618 # if !defined(DARWIN) && !defined(__FreeBSD__)
3619 # ifdef FALLOC_FL_KEEP_SIZE
3624 dout(20) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " " << offset
<< "~" << len
<< " = " << ret
<< dendl
;
3628 int FileStore::_clone(const coll_t
& cid
, const ghobject_t
& oldoid
, const ghobject_t
& newoid
,
3629 const SequencerPosition
& spos
)
3631 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oldoid
<< " -> " << cid
<< "/" << newoid
<< dendl
;
3633 if (_check_replay_guard(cid
, newoid
, spos
) < 0)
3640 r
= lfn_open(cid
, oldoid
, false, &o
, &index
);
3644 assert(NULL
!= (index
.index
));
3645 RWLock::WLocker
l((index
.index
)->access_lock
);
3647 r
= lfn_open(cid
, newoid
, true, &n
, &index
);
3651 r
= ::ftruncate(**n
, 0);
3657 r
= ::fstat(**o
, &st
);
3663 r
= _do_clone_range(**o
, **n
, 0, st
.st_size
, 0);
3668 dout(20) << "objectmap clone" << dendl
;
3669 r
= object_map
->clone(oldoid
, newoid
, &spos
);
3670 if (r
< 0 && r
!= -ENOENT
)
3676 map
<string
, bufferptr
> aset
;
3677 r
= _fgetattrs(**o
, aset
);
3681 r
= chain_fgetxattr(**o
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
3682 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
3683 r
= chain_fsetxattr
<true, true>(**n
, XATTR_SPILL_OUT_NAME
, XATTR_NO_SPILL_OUT
,
3684 sizeof(XATTR_NO_SPILL_OUT
));
3686 r
= chain_fsetxattr
<true, true>(**n
, XATTR_SPILL_OUT_NAME
, XATTR_SPILL_OUT
,
3687 sizeof(XATTR_SPILL_OUT
));
3692 r
= _fsetattrs(**n
, aset
);
3697 // clone is non-idempotent; record our work.
3698 _set_replay_guard(**n
, spos
, &newoid
);
3705 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oldoid
<< " -> " << cid
<< "/" << newoid
<< " = " << r
<< dendl
;
3706 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
3710 int FileStore::_do_clone_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
)
3712 dout(20) << __FUNC__
<< ": copy " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3713 return backend
->clone_range(from
, to
, srcoff
, len
, dstoff
);
3716 int FileStore::_do_sparse_copy_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
)
3718 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3720 map
<uint64_t, uint64_t> exomap
;
3721 // fiemap doesn't allow zero length
3725 if (backend
->has_seek_data_hole()) {
3726 dout(15) << "seek_data/seek_hole " << from
<< " " << srcoff
<< "~" << len
<< dendl
;
3727 r
= _do_seek_hole_data(from
, srcoff
, len
, &exomap
);
3728 } else if (backend
->has_fiemap()) {
3729 dout(15) << "fiemap ioctl" << from
<< " " << srcoff
<< "~" << len
<< dendl
;
3730 r
= _do_fiemap(from
, srcoff
, len
, &exomap
);
3734 int64_t written
= 0;
3738 for (map
<uint64_t, uint64_t>::iterator miter
= exomap
.begin(); miter
!= exomap
.end(); ++miter
) {
3739 uint64_t it_off
= miter
->first
- srcoff
+ dstoff
;
3740 r
= _do_copy_range(from
, to
, miter
->first
, miter
->second
, it_off
, true);
3742 derr
<< __FUNC__
<< ": copy error at " << miter
->first
<< "~" << miter
->second
3743 << " to " << it_off
<< ", " << cpp_strerror(r
) << dendl
;
3746 written
+= miter
->second
;
3750 if (m_filestore_sloppy_crc
) {
3751 int rc
= backend
->_crc_update_clone_range(from
, to
, srcoff
, len
, dstoff
);
3755 r
= ::fstat(to
, &st
);
3758 derr
<< __FUNC__
<< ": fstat error at " << to
<< " " << cpp_strerror(r
) << dendl
;
3761 if (st
.st_size
< (int)(dstoff
+ len
)) {
3762 r
= ::ftruncate(to
, dstoff
+ len
);
3765 derr
<< __FUNC__
<< ": ftruncate error at " << dstoff
+len
<< " " << cpp_strerror(r
) << dendl
;
3773 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3777 int FileStore::_do_copy_range(int from
, int to
, uint64_t srcoff
, uint64_t len
, uint64_t dstoff
, bool skip_sloppycrc
)
3779 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3781 loff_t pos
= srcoff
;
3782 loff_t end
= srcoff
+ len
;
3783 int buflen
= 4096 * 16; //limit by pipe max size.see fcntl
3785 #ifdef CEPH_HAVE_SPLICE
3786 if (backend
->has_splice()) {
3788 if (pipe(pipefd
) < 0) {
3790 derr
<< " pipe " << " got " << cpp_strerror(r
) << dendl
;
3794 loff_t dstpos
= dstoff
;
3796 int l
= MIN(end
-pos
, buflen
);
3797 r
= safe_splice(from
, &pos
, pipefd
[1], NULL
, l
, SPLICE_F_NONBLOCK
);
3798 dout(10) << " safe_splice read from " << pos
<< "~" << l
<< " got " << r
<< dendl
;
3800 derr
<< __FUNC__
<< ": safe_splice read error at " << pos
<< "~" << len
3801 << ", " << cpp_strerror(r
) << dendl
;
3805 // hrm, bad source range, wtf.
3807 derr
<< __FUNC__
<< ": got short read result at " << pos
3808 << " of fd " << from
<< " len " << len
<< dendl
;
3812 r
= safe_splice(pipefd
[0], NULL
, to
, &dstpos
, r
, 0);
3813 dout(10) << " safe_splice write to " << to
<< " len " << r
3814 << " got " << r
<< dendl
;
3816 derr
<< __FUNC__
<< ": write error at " << pos
<< "~"
3817 << r
<< ", " << cpp_strerror(r
) << dendl
;
3828 actual
= ::lseek64(from
, srcoff
, SEEK_SET
);
3829 if (actual
!= (int64_t)srcoff
) {
3834 derr
<< "lseek64 to " << srcoff
<< " got " << cpp_strerror(r
) << dendl
;
3837 actual
= ::lseek64(to
, dstoff
, SEEK_SET
);
3838 if (actual
!= (int64_t)dstoff
) {
3843 derr
<< "lseek64 to " << dstoff
<< " got " << cpp_strerror(r
) << dendl
;
3849 int l
= MIN(end
-pos
, buflen
);
3850 r
= ::read(from
, buf
, l
);
3851 dout(25) << " read from " << pos
<< "~" << l
<< " got " << r
<< dendl
;
3853 if (errno
== EINTR
) {
3857 derr
<< __FUNC__
<< ": read error at " << pos
<< "~" << len
3858 << ", " << cpp_strerror(r
) << dendl
;
3863 // hrm, bad source range, wtf.
3865 derr
<< __FUNC__
<< ": got short read result at " << pos
3866 << " of fd " << from
<< " len " << len
<< dendl
;
3871 int r2
= safe_write(to
, buf
+op
, r
-op
);
3872 dout(25) << " write to " << to
<< " len " << (r
-op
)
3873 << " got " << r2
<< dendl
;
3876 derr
<< __FUNC__
<< ": write error at " << pos
<< "~"
3877 << r
-op
<< ", " << cpp_strerror(r
) << dendl
;
3889 if (r
< 0 && replaying
) {
3890 assert(r
== -ERANGE
);
3891 derr
<< __FUNC__
<< ": short source tolerated because we are replaying" << dendl
;
3894 assert(replaying
|| pos
== end
);
3895 if (r
>= 0 && !skip_sloppycrc
&& m_filestore_sloppy_crc
) {
3896 int rc
= backend
->_crc_update_clone_range(from
, to
, srcoff
, len
, dstoff
);
3899 dout(20) << __FUNC__
<< ": " << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3903 int FileStore::_clone_range(const coll_t
& oldcid
, const ghobject_t
& oldoid
, const coll_t
& newcid
, const ghobject_t
& newoid
,
3904 uint64_t srcoff
, uint64_t len
, uint64_t dstoff
,
3905 const SequencerPosition
& spos
)
3907 dout(15) << __FUNC__
<< ": " << oldcid
<< "/" << oldoid
<< " -> " << newcid
<< "/" << newoid
<< " " << srcoff
<< "~" << len
<< " to " << dstoff
<< dendl
;
3909 if (_check_replay_guard(newcid
, newoid
, spos
) < 0)
3914 r
= lfn_open(oldcid
, oldoid
, false, &o
);
3918 r
= lfn_open(newcid
, newoid
, true, &n
);
3922 r
= _do_clone_range(**o
, **n
, srcoff
, len
, dstoff
);
3927 // clone is non-idempotent; record our work.
3928 _set_replay_guard(**n
, spos
, &newoid
);
3935 dout(10) << __FUNC__
<< ": " << oldcid
<< "/" << oldoid
<< " -> " << newcid
<< "/" << newoid
<< " "
3936 << srcoff
<< "~" << len
<< " to " << dstoff
<< " = " << r
<< dendl
;
3940 class SyncEntryTimeout
: public Context
{
3943 explicit SyncEntryTimeout(CephContext
* cct
, int commit_timeo
)
3944 : cct(cct
), m_commit_timeo(commit_timeo
)
3948 void finish(int r
) override
{
3949 BackTrace
*bt
= new BackTrace(1);
3950 generic_dout(-1) << "FileStore: sync_entry timed out after "
3951 << m_commit_timeo
<< " seconds.\n";
3961 void FileStore::sync_entry()
3965 utime_t max_interval
;
3966 max_interval
.set_from_double(m_filestore_max_sync_interval
);
3967 utime_t min_interval
;
3968 min_interval
.set_from_double(m_filestore_min_sync_interval
);
3970 utime_t startwait
= ceph_clock_now();
3972 dout(20) << __FUNC__
<< ": waiting for max_interval " << max_interval
<< dendl
;
3973 sync_cond
.WaitInterval(lock
, max_interval
);
3975 dout(20) << __FUNC__
<< ": not waiting, force_sync set" << dendl
;
3979 dout(20) << __FUNC__
<< ": force_sync set" << dendl
;
3982 dout(20) << __FUNC__
<< ": stop set" << dendl
;
3985 // wait for at least the min interval
3986 utime_t woke
= ceph_clock_now();
3988 dout(20) << __FUNC__
<< ": woke after " << woke
<< dendl
;
3989 if (woke
< min_interval
) {
3990 utime_t t
= min_interval
;
3992 dout(20) << __FUNC__
<< ": waiting for another " << t
3993 << " to reach min interval " << min_interval
<< dendl
;
3994 sync_cond
.WaitInterval(lock
, t
);
4000 fin
.swap(sync_waiters
);
4004 if (apply_manager
.commit_start()) {
4005 utime_t start
= ceph_clock_now();
4006 uint64_t cp
= apply_manager
.get_committing_seq();
4008 sync_entry_timeo_lock
.Lock();
4009 SyncEntryTimeout
*sync_entry_timeo
=
4010 new SyncEntryTimeout(cct
, m_filestore_commit_timeout
);
4011 if (!timer
.add_event_after(m_filestore_commit_timeout
,
4012 sync_entry_timeo
)) {
4013 sync_entry_timeo
= nullptr;
4015 sync_entry_timeo_lock
.Unlock();
4017 logger
->set(l_filestore_committing
, 1);
4019 dout(15) << __FUNC__
<< ": committing " << cp
<< dendl
;
4020 stringstream errstream
;
4021 if (cct
->_conf
->filestore_debug_omap_check
&& !object_map
->check(errstream
)) {
4022 derr
<< errstream
.str() << dendl
;
4026 if (backend
->can_checkpoint()) {
4027 int err
= write_op_seq(op_fd
, cp
);
4029 derr
<< "Error during write_op_seq: " << cpp_strerror(err
) << dendl
;
4030 assert(0 == "error during write_op_seq");
4034 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)cp
);
4036 err
= backend
->create_checkpoint(s
, &cid
);
4039 derr
<< "snap create '" << s
<< "' got error " << err
<< dendl
;
4043 snaps
.push_back(cp
);
4044 apply_manager
.commit_started();
4048 dout(20) << " waiting for checkpoint " << cid
<< " to complete" << dendl
;
4049 err
= backend
->sync_checkpoint(cid
);
4051 derr
<< "ioctl WAIT_SYNC got " << cpp_strerror(err
) << dendl
;
4052 assert(0 == "wait_sync got error");
4054 dout(20) << " done waiting for checkpoint " << cid
<< " to complete" << dendl
;
4057 apply_manager
.commit_started();
4060 int err
= object_map
->sync();
4062 derr
<< "object_map sync got " << cpp_strerror(err
) << dendl
;
4063 assert(0 == "object_map sync returned error");
4066 err
= backend
->syncfs();
4068 derr
<< "syncfs got " << cpp_strerror(err
) << dendl
;
4069 assert(0 == "syncfs returned error");
4072 err
= write_op_seq(op_fd
, cp
);
4074 derr
<< "Error during write_op_seq: " << cpp_strerror(err
) << dendl
;
4075 assert(0 == "error during write_op_seq");
4077 err
= ::fsync(op_fd
);
4079 derr
<< "Error during fsync of op_seq: " << cpp_strerror(err
) << dendl
;
4080 assert(0 == "error during fsync of op_seq");
4084 utime_t done
= ceph_clock_now();
4085 utime_t lat
= done
- start
;
4086 utime_t dur
= done
- startwait
;
4087 dout(10) << __FUNC__
<< ": commit took " << lat
<< ", interval was " << dur
<< dendl
;
4088 utime_t max_pause_lat
= logger
->tget(l_filestore_sync_pause_max_lat
);
4089 if (max_pause_lat
< dur
- lat
) {
4090 logger
->tinc(l_filestore_sync_pause_max_lat
, dur
- lat
);
4093 logger
->inc(l_filestore_commitcycle
);
4094 logger
->tinc(l_filestore_commitcycle_latency
, lat
);
4095 logger
->tinc(l_filestore_commitcycle_interval
, dur
);
4097 apply_manager
.commit_finish();
4098 if (!m_disable_wbthrottle
) {
4102 logger
->set(l_filestore_committing
, 0);
4104 // remove old snaps?
4105 if (backend
->can_checkpoint()) {
4107 while (snaps
.size() > 2) {
4108 snprintf(s
, sizeof(s
), COMMIT_SNAP_ITEM
, (long long unsigned)snaps
.front());
4110 dout(10) << "removing snap '" << s
<< "'" << dendl
;
4111 int r
= backend
->destroy_checkpoint(s
);
4114 derr
<< "unable to destroy snap '" << s
<< "' got " << cpp_strerror(err
) << dendl
;
4119 dout(15) << __FUNC__
<< ": committed to op_seq " << cp
<< dendl
;
4121 if (sync_entry_timeo
) {
4122 Mutex::Locker
lock(sync_entry_timeo_lock
);
4123 timer
.cancel_event(sync_entry_timeo
);
4130 finish_contexts(cct
, fin
, 0);
4132 if (!sync_waiters
.empty()) {
4133 dout(10) << __FUNC__
<< ": more waiters, committing again" << dendl
;
4136 if (!stop
&& journal
&& journal
->should_commit_now()) {
4137 dout(10) << __FUNC__
<< ": journal says we should commit again (probably is/was full)" << dendl
;
4145 void FileStore::_start_sync()
4147 if (!journal
) { // don't do a big sync if the journal is on
4148 dout(10) << __FUNC__
<< dendl
;
4151 dout(10) << __FUNC__
<< ": - NOOP (journal is on)" << dendl
;
4155 void FileStore::do_force_sync()
4157 dout(10) << __FUNC__
<< dendl
;
4158 Mutex::Locker
l(lock
);
4163 void FileStore::start_sync(Context
*onsafe
)
4165 Mutex::Locker
l(lock
);
4166 sync_waiters
.push_back(onsafe
);
4169 dout(10) << __FUNC__
<< dendl
;
4172 void FileStore::sync()
4174 Mutex
l("FileStore::sync");
4177 C_SafeCond
*fin
= new C_SafeCond(&l
, &c
, &done
);
4183 dout(10) << "sync waiting" << dendl
;
4187 dout(10) << "sync done" << dendl
;
4190 void FileStore::_flush_op_queue()
4192 dout(10) << __FUNC__
<< ": draining op tp" << dendl
;
4194 dout(10) << __FUNC__
<< ": waiting for apply finisher" << dendl
;
4195 for (vector
<Finisher
*>::iterator it
= apply_finishers
.begin(); it
!= apply_finishers
.end(); ++it
) {
4196 (*it
)->wait_for_empty();
4201 * flush - make every queued write readable
4203 void FileStore::flush()
4205 dout(10) << __FUNC__
<< dendl
;
4207 if (cct
->_conf
->filestore_blackhole
) {
4209 Mutex
lock("FileStore::flush::lock");
4217 if (m_filestore_journal_writeahead
) {
4220 dout(10) << __FUNC__
<< ": draining ondisk finisher" << dendl
;
4221 for (vector
<Finisher
*>::iterator it
= ondisk_finishers
.begin(); it
!= ondisk_finishers
.end(); ++it
) {
4222 (*it
)->wait_for_empty();
4227 dout(10) << __FUNC__
<< ": complete" << dendl
;
4231 * sync_and_flush - make every queued write readable AND committed to disk
4233 void FileStore::sync_and_flush()
4235 dout(10) << __FUNC__
<< dendl
;
4237 if (m_filestore_journal_writeahead
) {
4242 // includes m_filestore_journal_parallel
4246 dout(10) << __FUNC__
<< ": done" << dendl
;
4249 int FileStore::flush_journal()
4251 dout(10) << __FUNC__
<< dendl
;
4257 int FileStore::snapshot(const string
& name
)
4259 dout(10) << __FUNC__
<< ": " << name
<< dendl
;
4262 if (!backend
->can_checkpoint()) {
4263 dout(0) << __FUNC__
<< ": " << name
<< " failed, not supported" << dendl
;
4268 snprintf(s
, sizeof(s
), CLUSTER_SNAP_ITEM
, name
.c_str());
4270 int r
= backend
->create_checkpoint(s
, NULL
);
4272 derr
<< __FUNC__
<< ": " << name
<< " failed: " << cpp_strerror(r
) << dendl
;
4278 // -------------------------------
4281 int FileStore::_fgetattr(int fd
, const char *name
, bufferptr
& bp
)
4283 char val
[CHAIN_XATTR_MAX_BLOCK_LEN
];
4284 int l
= chain_fgetxattr(fd
, name
, val
, sizeof(val
));
4286 bp
= buffer::create(l
);
4287 memcpy(bp
.c_str(), val
, l
);
4288 } else if (l
== -ERANGE
) {
4289 l
= chain_fgetxattr(fd
, name
, 0, 0);
4291 bp
= buffer::create(l
);
4292 l
= chain_fgetxattr(fd
, name
, bp
.c_str(), l
);
4295 assert(!m_filestore_fail_eio
|| l
!= -EIO
);
4299 int FileStore::_fgetattrs(int fd
, map
<string
,bufferptr
>& aset
)
4303 int len
= chain_flistxattr(fd
, names1
, sizeof(names1
)-1);
4306 if (len
== -ERANGE
) {
4307 len
= chain_flistxattr(fd
, 0, 0);
4309 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4312 dout(10) << " -ERANGE, len is " << len
<< dendl
;
4313 names2
= new char[len
+1];
4314 len
= chain_flistxattr(fd
, names2
, len
);
4315 dout(10) << " -ERANGE, got " << len
<< dendl
;
4317 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4322 } else if (len
< 0) {
4323 assert(!m_filestore_fail_eio
|| len
!= -EIO
);
4330 char *end
= name
+ len
;
4331 while (name
< end
) {
4332 char *attrname
= name
;
4333 if (parse_attrname(&name
)) {
4335 dout(20) << __FUNC__
<< ": " << fd
<< " getting '" << name
<< "'" << dendl
;
4336 int r
= _fgetattr(fd
, attrname
, aset
[name
]);
4343 name
+= strlen(name
) + 1;
4350 int FileStore::_fsetattrs(int fd
, map
<string
, bufferptr
> &aset
)
4352 for (map
<string
, bufferptr
>::iterator p
= aset
.begin();
4355 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4356 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4358 if (p
->second
.length())
4359 val
= p
->second
.c_str();
4362 // ??? Why do we skip setting all the other attrs if one fails?
4363 int r
= chain_fsetxattr(fd
, n
, val
, p
->second
.length());
4365 derr
<< __FUNC__
<< ": chain_setxattr returned " << r
<< dendl
;
4372 // debug EIO injection
4373 void FileStore::inject_data_error(const ghobject_t
&oid
) {
4374 Mutex::Locker
l(read_error_lock
);
4375 dout(10) << __FUNC__
<< ": init error on " << oid
<< dendl
;
4376 data_error_set
.insert(oid
);
4378 void FileStore::inject_mdata_error(const ghobject_t
&oid
) {
4379 Mutex::Locker
l(read_error_lock
);
4380 dout(10) << __FUNC__
<< ": init error on " << oid
<< dendl
;
4381 mdata_error_set
.insert(oid
);
4384 void FileStore::debug_obj_on_delete(const ghobject_t
&oid
) {
4385 Mutex::Locker
l(read_error_lock
);
4386 dout(10) << __FUNC__
<< ": clear error on " << oid
<< dendl
;
4387 data_error_set
.erase(oid
);
4388 mdata_error_set
.erase(oid
);
4390 bool FileStore::debug_data_eio(const ghobject_t
&oid
) {
4391 Mutex::Locker
l(read_error_lock
);
4392 if (data_error_set
.count(oid
)) {
4393 dout(10) << __FUNC__
<< ": inject error on " << oid
<< dendl
;
4399 bool FileStore::debug_mdata_eio(const ghobject_t
&oid
) {
4400 Mutex::Locker
l(read_error_lock
);
4401 if (mdata_error_set
.count(oid
)) {
4402 dout(10) << __FUNC__
<< ": inject error on " << oid
<< dendl
;
4412 int FileStore::getattr(const coll_t
& _cid
, const ghobject_t
& oid
, const char *name
, bufferptr
&bp
)
4414 tracepoint(objectstore
, getattr_enter
, _cid
.c_str());
4415 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
4416 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "'" << dendl
;
4418 int r
= lfn_open(cid
, oid
, false, &fd
);
4422 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4423 get_attrname(name
, n
, CHAIN_XATTR_MAX_NAME_LEN
);
4424 r
= _fgetattr(**fd
, n
, bp
);
4426 if (r
== -ENODATA
) {
4427 map
<string
, bufferlist
> got
;
4429 to_get
.insert(string(name
));
4431 r
= get_index(cid
, &index
);
4433 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4436 r
= object_map
->get_xattrs(oid
, to_get
, &got
);
4437 if (r
< 0 && r
!= -ENOENT
) {
4438 dout(10) << __FUNC__
<< ": get_xattrs err r =" << r
<< dendl
;
4442 dout(10) << __FUNC__
<< ": got.size() is 0" << dendl
;
4445 bp
= bufferptr(got
.begin()->second
.c_str(),
4446 got
.begin()->second
.length());
4450 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "' = " << r
<< dendl
;
4451 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4452 if (cct
->_conf
->filestore_debug_inject_read_err
&&
4453 debug_mdata_eio(oid
)) {
4456 tracepoint(objectstore
, getattr_exit
, r
);
4457 return r
< 0 ? r
: 0;
4461 int FileStore::getattrs(const coll_t
& _cid
, const ghobject_t
& oid
, map
<string
,bufferptr
>& aset
)
4463 tracepoint(objectstore
, getattrs_enter
, _cid
.c_str());
4464 const coll_t
& cid
= !_need_temp_object_collection(_cid
, oid
) ? _cid
: _cid
.get_temp();
4465 set
<string
> omap_attrs
;
4466 map
<string
, bufferlist
> omap_aset
;
4468 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
4470 bool spill_out
= true;
4473 int r
= lfn_open(cid
, oid
, false, &fd
);
4478 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4479 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
)))
4482 r
= _fgetattrs(**fd
, aset
);
4484 fd
= FDRef(); // defensive
4490 dout(10) << __FUNC__
<< ": no xattr exists in object_map r = " << r
<< dendl
;
4494 r
= get_index(cid
, &index
);
4496 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4500 r
= object_map
->get_all_xattrs(oid
, &omap_attrs
);
4501 if (r
< 0 && r
!= -ENOENT
) {
4502 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4506 r
= object_map
->get_xattrs(oid
, omap_attrs
, &omap_aset
);
4507 if (r
< 0 && r
!= -ENOENT
) {
4508 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4514 assert(omap_attrs
.size() == omap_aset
.size());
4515 for (map
<string
, bufferlist
>::iterator i
= omap_aset
.begin();
4516 i
!= omap_aset
.end();
4518 string
key(i
->first
);
4519 aset
.insert(make_pair(key
,
4520 bufferptr(i
->second
.c_str(), i
->second
.length())));
4523 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4524 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4526 if (cct
->_conf
->filestore_debug_inject_read_err
&&
4527 debug_mdata_eio(oid
)) {
4530 tracepoint(objectstore
, getattrs_exit
, r
);
4535 int FileStore::_setattrs(const coll_t
& cid
, const ghobject_t
& oid
, map
<string
,bufferptr
>& aset
,
4536 const SequencerPosition
&spos
)
4538 map
<string
, bufferlist
> omap_set
;
4539 set
<string
> omap_remove
;
4540 map
<string
, bufferptr
> inline_set
;
4541 map
<string
, bufferptr
> inline_to_set
;
4544 bool incomplete_inline
= false;
4546 int r
= lfn_open(cid
, oid
, false, &fd
);
4552 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4553 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
)))
4558 r
= _fgetattrs(**fd
, inline_set
);
4559 incomplete_inline
= (r
== -E2BIG
);
4560 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4561 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
4562 << (incomplete_inline
? " (incomplete_inline, forcing omap)" : "")
4565 for (map
<string
,bufferptr
>::iterator p
= aset
.begin();
4568 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4569 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4571 if (incomplete_inline
) {
4572 chain_fremovexattr(**fd
, n
); // ignore any error
4573 omap_set
[p
->first
].push_back(p
->second
);
4577 if (p
->second
.length() > m_filestore_max_inline_xattr_size
) {
4578 if (inline_set
.count(p
->first
)) {
4579 inline_set
.erase(p
->first
);
4580 r
= chain_fremovexattr(**fd
, n
);
4584 omap_set
[p
->first
].push_back(p
->second
);
4588 if (!inline_set
.count(p
->first
) &&
4589 inline_set
.size() >= m_filestore_max_inline_xattrs
) {
4590 omap_set
[p
->first
].push_back(p
->second
);
4593 omap_remove
.insert(p
->first
);
4594 inline_set
.insert(*p
);
4596 inline_to_set
.insert(*p
);
4599 if (spill_out
!= 1 && !omap_set
.empty()) {
4600 chain_fsetxattr(**fd
, XATTR_SPILL_OUT_NAME
, XATTR_SPILL_OUT
,
4601 sizeof(XATTR_SPILL_OUT
));
4604 r
= _fsetattrs(**fd
, inline_to_set
);
4608 if (spill_out
&& !omap_remove
.empty()) {
4609 r
= object_map
->remove_xattrs(oid
, omap_remove
, &spos
);
4610 if (r
< 0 && r
!= -ENOENT
) {
4611 dout(10) << __FUNC__
<< ": could not remove_xattrs r = " << r
<< dendl
;
4612 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4615 r
= 0; // don't confuse the debug output
4619 if (!omap_set
.empty()) {
4620 r
= object_map
->set_xattrs(oid
, omap_set
, &spos
);
4622 dout(10) << __FUNC__
<< ": could not set_xattrs r = " << r
<< dendl
;
4623 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4630 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4635 int FileStore::_rmattr(const coll_t
& cid
, const ghobject_t
& oid
, const char *name
,
4636 const SequencerPosition
&spos
)
4638 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "'" << dendl
;
4640 bool spill_out
= true;
4642 int r
= lfn_open(cid
, oid
, false, &fd
);
4648 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4649 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
4653 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4654 get_attrname(name
, n
, CHAIN_XATTR_MAX_NAME_LEN
);
4655 r
= chain_fremovexattr(**fd
, n
);
4656 if (r
== -ENODATA
&& spill_out
) {
4658 r
= get_index(cid
, &index
);
4660 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4663 set
<string
> to_remove
;
4664 to_remove
.insert(string(name
));
4665 r
= object_map
->remove_xattrs(oid
, to_remove
, &spos
);
4666 if (r
< 0 && r
!= -ENOENT
) {
4667 dout(10) << __FUNC__
<< ": could not remove_xattrs index r = " << r
<< dendl
;
4668 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4675 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " '" << name
<< "' = " << r
<< dendl
;
4679 int FileStore::_rmattrs(const coll_t
& cid
, const ghobject_t
& oid
,
4680 const SequencerPosition
&spos
)
4682 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< dendl
;
4684 map
<string
,bufferptr
> aset
;
4686 set
<string
> omap_attrs
;
4688 bool spill_out
= true;
4690 int r
= lfn_open(cid
, oid
, false, &fd
);
4696 r
= chain_fgetxattr(**fd
, XATTR_SPILL_OUT_NAME
, buf
, sizeof(buf
));
4697 if (r
>= 0 && !strncmp(buf
, XATTR_NO_SPILL_OUT
, sizeof(XATTR_NO_SPILL_OUT
))) {
4701 r
= _fgetattrs(**fd
, aset
);
4703 for (map
<string
,bufferptr
>::iterator p
= aset
.begin(); p
!= aset
.end(); ++p
) {
4704 char n
[CHAIN_XATTR_MAX_NAME_LEN
];
4705 get_attrname(p
->first
.c_str(), n
, CHAIN_XATTR_MAX_NAME_LEN
);
4706 r
= chain_fremovexattr(**fd
, n
);
4708 dout(10) << __FUNC__
<< ": could not remove xattr r = " << r
<< dendl
;
4715 dout(10) << __FUNC__
<< ": no xattr exists in object_map r = " << r
<< dendl
;
4719 r
= get_index(cid
, &index
);
4721 dout(10) << __FUNC__
<< ": could not get index r = " << r
<< dendl
;
4725 r
= object_map
->get_all_xattrs(oid
, &omap_attrs
);
4726 if (r
< 0 && r
!= -ENOENT
) {
4727 dout(10) << __FUNC__
<< ": could not get omap_attrs r = " << r
<< dendl
;
4728 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4731 r
= object_map
->remove_xattrs(oid
, omap_attrs
, &spos
);
4732 if (r
< 0 && r
!= -ENOENT
) {
4733 dout(10) << __FUNC__
<< ": could not remove omap_attrs r = " << r
<< dendl
;
4738 chain_fsetxattr(**fd
, XATTR_SPILL_OUT_NAME
, XATTR_NO_SPILL_OUT
,
4739 sizeof(XATTR_NO_SPILL_OUT
));
4745 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " = " << r
<< dendl
;
4752 int FileStore::_collection_remove_recursive(const coll_t
&cid
,
4753 const SequencerPosition
&spos
)
4756 int r
= collection_stat(cid
, &st
);
4763 vector
<ghobject_t
> objects
;
4765 while (!max
.is_max()) {
4766 r
= collection_list(cid
, max
, ghobject_t::get_max(),
4767 300, &objects
, &max
);
4770 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
4773 assert(_check_replay_guard(cid
, *i
, spos
));
4774 r
= _remove(cid
, *i
, spos
);
4780 return _destroy_collection(cid
);
4783 // --------------------------
4786 int FileStore::list_collections(vector
<coll_t
>& ls
)
4788 return list_collections(ls
, false);
4791 int FileStore::list_collections(vector
<coll_t
>& ls
, bool include_temp
)
4793 tracepoint(objectstore
, list_collections_enter
);
4794 dout(10) << __FUNC__
<< dendl
;
4797 snprintf(fn
, sizeof(fn
), "%s/current", basedir
.c_str());
4800 DIR *dir
= ::opendir(fn
);
4803 derr
<< "tried opening directory " << fn
<< ": " << cpp_strerror(-r
) << dendl
;
4804 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4808 struct dirent
*de
= nullptr;
4809 while ((de
= ::readdir(dir
))) {
4810 if (de
->d_type
== DT_UNKNOWN
) {
4811 // d_type not supported (non-ext[234], btrfs), must stat
4813 char filename
[PATH_MAX
];
4814 snprintf(filename
, sizeof(filename
), "%s/%s", fn
, de
->d_name
);
4816 r
= ::stat(filename
, &sb
);
4819 derr
<< "stat on " << filename
<< ": " << cpp_strerror(-r
) << dendl
;
4820 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4823 if (!S_ISDIR(sb
.st_mode
)) {
4826 } else if (de
->d_type
!= DT_DIR
) {
4829 if (strcmp(de
->d_name
, "omap") == 0) {
4832 if (de
->d_name
[0] == '.' &&
4833 (de
->d_name
[1] == '\0' ||
4834 (de
->d_name
[1] == '.' &&
4835 de
->d_name
[2] == '\0')))
4838 if (!cid
.parse(de
->d_name
)) {
4839 derr
<< "ignoring invalid collection '" << de
->d_name
<< "'" << dendl
;
4842 if (!cid
.is_temp() || include_temp
)
4847 derr
<< "trying readdir " << fn
<< ": " << cpp_strerror(r
) << dendl
;
4852 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4853 tracepoint(objectstore
, list_collections_exit
, r
);
4857 int FileStore::collection_stat(const coll_t
& c
, struct stat
*st
)
4859 tracepoint(objectstore
, collection_stat_enter
, c
.c_str());
4861 get_cdir(c
, fn
, sizeof(fn
));
4862 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
4863 int r
= ::stat(fn
, st
);
4866 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
4867 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4868 tracepoint(objectstore
, collection_stat_exit
, r
);
4872 bool FileStore::collection_exists(const coll_t
& c
)
4874 tracepoint(objectstore
, collection_exists_enter
, c
.c_str());
4876 bool ret
= collection_stat(c
, &st
) == 0;
4877 tracepoint(objectstore
, collection_exists_exit
, ret
);
4881 int FileStore::collection_empty(const coll_t
& c
, bool *empty
)
4883 tracepoint(objectstore
, collection_empty_enter
, c
.c_str());
4884 dout(15) << __FUNC__
<< ": " << c
<< dendl
;
4886 int r
= get_index(c
, &index
);
4888 derr
<< __FUNC__
<< ": get_index returned: " << cpp_strerror(r
)
4893 assert(NULL
!= index
.index
);
4894 RWLock::RLocker
l((index
.index
)->access_lock
);
4896 vector
<ghobject_t
> ls
;
4897 r
= index
->collection_list_partial(ghobject_t(), ghobject_t::get_max(),
4900 derr
<< __FUNC__
<< ": collection_list_partial returned: "
4901 << cpp_strerror(r
) << dendl
;
4902 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
4905 *empty
= ls
.empty();
4906 tracepoint(objectstore
, collection_empty_exit
, *empty
);
4910 int FileStore::_collection_set_bits(const coll_t
& c
, int bits
)
4913 get_cdir(c
, fn
, sizeof(fn
));
4914 dout(10) << __FUNC__
<< ": " << fn
<< " " << bits
<< dendl
;
4918 int fd
= ::open(fn
, O_RDONLY
);
4923 get_attrname("bits", n
, PATH_MAX
);
4924 r
= chain_fsetxattr(fd
, n
, (char*)&v
, sizeof(v
));
4925 VOID_TEMP_FAILURE_RETRY(::close(fd
));
4927 dout(10) << __FUNC__
<< ": " << fn
<< " " << bits
<< " = " << r
<< dendl
;
4931 int FileStore::collection_bits(const coll_t
& c
)
4934 get_cdir(c
, fn
, sizeof(fn
));
4935 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
4939 int fd
= ::open(fn
, O_RDONLY
);
4944 get_attrname("bits", n
, PATH_MAX
);
4945 r
= chain_fgetxattr(fd
, n
, (char*)&bits
, sizeof(bits
));
4946 VOID_TEMP_FAILURE_RETRY(::close(fd
));
4952 dout(10) << __FUNC__
<< ": " << fn
<< " = " << bits
<< dendl
;
4956 int FileStore::collection_list(const coll_t
& c
,
4957 const ghobject_t
& orig_start
,
4958 const ghobject_t
& end
,
4960 vector
<ghobject_t
> *ls
, ghobject_t
*next
)
4962 ghobject_t start
= orig_start
;
4966 ghobject_t temp_next
;
4969 // figure out the pool id. we need this in order to generate a
4970 // meaningful 'next' value.
4975 if (c
.is_temp(&pgid
)) {
4976 pool
= -2 - pgid
.pool();
4978 } else if (c
.is_pg(&pgid
)) {
4981 } else if (c
.is_meta()) {
4983 shard
= shard_id_t::NO_SHARD
;
4985 // hrm, the caller is test code! we should get kill it off. for now,
4988 shard
= shard_id_t::NO_SHARD
;
4990 dout(20) << __FUNC__
<< ": pool is " << pool
<< " shard is " << shard
4991 << " pgid " << pgid
<< dendl
;
4995 sep
.set_shard(shard
);
4996 if (!c
.is_temp() && !c
.is_meta()) {
4998 dout(10) << __FUNC__
<< ": first checking temp pool" << dendl
;
4999 coll_t temp
= c
.get_temp();
5000 int r
= collection_list(temp
, start
, end
, max
, ls
, next
);
5003 if (*next
!= ghobject_t::get_max())
5006 dout(10) << __FUNC__
<< ": fall through to non-temp collection, start "
5009 dout(10) << __FUNC__
<< ": start " << start
<< " >= sep " << sep
<< dendl
;
5014 int r
= get_index(c
, &index
);
5018 assert(NULL
!= index
.index
);
5019 RWLock::RLocker
l((index
.index
)->access_lock
);
5021 r
= index
->collection_list_partial(start
, end
, max
, ls
, next
);
5024 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5027 dout(20) << "objects: " << *ls
<< dendl
;
5029 // HashIndex doesn't know the pool when constructing a 'next' value
5030 if (next
&& !next
->is_max()) {
5031 next
->hobj
.pool
= pool
;
5032 next
->set_shard(shard
);
5033 dout(20) << " next " << *next
<< dendl
;
5039 int FileStore::omap_get(const coll_t
& _c
, const ghobject_t
&hoid
,
5041 map
<string
, bufferlist
> *out
)
5043 tracepoint(objectstore
, omap_get_enter
, _c
.c_str());
5044 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5045 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5047 int r
= get_index(c
, &index
);
5051 assert(NULL
!= index
.index
);
5052 RWLock::RLocker
l((index
.index
)->access_lock
);
5053 r
= lfn_find(hoid
, index
);
5057 r
= object_map
->get(hoid
, header
, out
);
5058 if (r
< 0 && r
!= -ENOENT
) {
5059 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5062 tracepoint(objectstore
, omap_get_exit
, 0);
5066 int FileStore::omap_get_header(
5068 const ghobject_t
&hoid
,
5072 tracepoint(objectstore
, omap_get_header_enter
, _c
.c_str());
5073 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5074 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5076 int r
= get_index(c
, &index
);
5080 assert(NULL
!= index
.index
);
5081 RWLock::RLocker
l((index
.index
)->access_lock
);
5082 r
= lfn_find(hoid
, index
);
5086 r
= object_map
->get_header(hoid
, bl
);
5087 if (r
< 0 && r
!= -ENOENT
) {
5088 assert(allow_eio
|| !m_filestore_fail_eio
|| r
!= -EIO
);
5091 tracepoint(objectstore
, omap_get_header_exit
, 0);
5095 int FileStore::omap_get_keys(const coll_t
& _c
, const ghobject_t
&hoid
, set
<string
> *keys
)
5097 tracepoint(objectstore
, omap_get_keys_enter
, _c
.c_str());
5098 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5099 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5101 int r
= get_index(c
, &index
);
5105 assert(NULL
!= index
.index
);
5106 RWLock::RLocker
l((index
.index
)->access_lock
);
5107 r
= lfn_find(hoid
, index
);
5111 r
= object_map
->get_keys(hoid
, keys
);
5112 if (r
< 0 && r
!= -ENOENT
) {
5113 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5116 tracepoint(objectstore
, omap_get_keys_exit
, 0);
5120 int FileStore::omap_get_values(const coll_t
& _c
, const ghobject_t
&hoid
,
5121 const set
<string
> &keys
,
5122 map
<string
, bufferlist
> *out
)
5124 tracepoint(objectstore
, omap_get_values_enter
, _c
.c_str());
5125 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5126 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5128 const char *where
= "()";
5129 int r
= get_index(c
, &index
);
5131 where
= " (get_index)";
5135 assert(NULL
!= index
.index
);
5136 RWLock::RLocker
l((index
.index
)->access_lock
);
5137 r
= lfn_find(hoid
, index
);
5139 where
= " (lfn_find)";
5143 r
= object_map
->get_values(hoid
, keys
, out
);
5144 if (r
< 0 && r
!= -ENOENT
) {
5145 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5146 where
= " (get_values)";
5151 tracepoint(objectstore
, omap_get_values_exit
, r
);
5152 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = " << r
5157 int FileStore::omap_check_keys(const coll_t
& _c
, const ghobject_t
&hoid
,
5158 const set
<string
> &keys
,
5161 tracepoint(objectstore
, omap_check_keys_enter
, _c
.c_str());
5162 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5163 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5166 int r
= get_index(c
, &index
);
5170 assert(NULL
!= index
.index
);
5171 RWLock::RLocker
l((index
.index
)->access_lock
);
5172 r
= lfn_find(hoid
, index
);
5176 r
= object_map
->check_keys(hoid
, keys
, out
);
5177 if (r
< 0 && r
!= -ENOENT
) {
5178 assert(!m_filestore_fail_eio
|| r
!= -EIO
);
5181 tracepoint(objectstore
, omap_check_keys_exit
, 0);
5185 ObjectMap::ObjectMapIterator
FileStore::get_omap_iterator(const coll_t
& _c
,
5186 const ghobject_t
&hoid
)
5188 tracepoint(objectstore
, get_omap_iterator
, _c
.c_str());
5189 const coll_t
& c
= !_need_temp_object_collection(_c
, hoid
) ? _c
: _c
.get_temp();
5190 dout(15) << __FUNC__
<< ": " << c
<< "/" << hoid
<< dendl
;
5192 int r
= get_index(c
, &index
);
5194 dout(10) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = 0 "
5195 << "(get_index failed with " << cpp_strerror(r
) << ")" << dendl
;
5196 return ObjectMap::ObjectMapIterator();
5199 assert(NULL
!= index
.index
);
5200 RWLock::RLocker
l((index
.index
)->access_lock
);
5201 r
= lfn_find(hoid
, index
);
5203 dout(10) << __FUNC__
<< ": " << c
<< "/" << hoid
<< " = 0 "
5204 << "(lfn_find failed with " << cpp_strerror(r
) << ")" << dendl
;
5205 return ObjectMap::ObjectMapIterator();
5208 return object_map
->get_iterator(hoid
);
5211 int FileStore::_collection_hint_expected_num_objs(const coll_t
& c
, uint32_t pg_num
,
5212 uint64_t expected_num_objs
,
5213 const SequencerPosition
&spos
)
5215 dout(15) << __FUNC__
<< ": collection: " << c
<< " pg number: "
5216 << pg_num
<< " expected number of objects: " << expected_num_objs
<< dendl
;
5219 int ret
= collection_empty(c
, &empty
);
5222 if (!empty
&& !replaying
) {
5223 dout(0) << "Failed to give an expected number of objects hint to collection : "
5224 << c
<< ", only empty collection can take such type of hint. " << dendl
;
5229 ret
= get_index(c
, &index
);
5232 // Pre-hash the collection
5233 ret
= index
->pre_hash_collection(pg_num
, expected_num_objs
);
5234 dout(10) << "pre_hash_collection " << c
<< " = " << ret
<< dendl
;
5237 _set_replay_guard(c
, spos
);
5242 int FileStore::_create_collection(
5245 const SequencerPosition
&spos
)
5248 get_cdir(c
, fn
, sizeof(fn
));
5249 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
5250 int r
= ::mkdir(fn
, 0755);
5253 if (r
== -EEXIST
&& replaying
)
5255 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
5262 r
= _collection_set_bits(c
, bits
);
5265 // create parallel temp collection, too
5266 if (!c
.is_meta() && !c
.is_temp()) {
5267 coll_t temp
= c
.get_temp();
5268 r
= _create_collection(temp
, 0, spos
);
5273 _set_replay_guard(c
, spos
);
5277 int FileStore::_destroy_collection(const coll_t
& c
)
5281 get_cdir(c
, fn
, sizeof(fn
));
5282 dout(15) << __FUNC__
<< ": " << fn
<< dendl
;
5285 r
= get_index(c
, &from
);
5288 assert(NULL
!= from
.index
);
5289 RWLock::WLocker
l((from
.index
)->access_lock
);
5291 r
= from
->prep_delete();
5302 // destroy parallel temp collection, too
5303 if (!c
.is_meta() && !c
.is_temp()) {
5304 coll_t temp
= c
.get_temp();
5305 int r2
= _destroy_collection(temp
);
5313 dout(10) << __FUNC__
<< ": " << fn
<< " = " << r
<< dendl
;
5318 int FileStore::_collection_add(const coll_t
& c
, const coll_t
& oldcid
, const ghobject_t
& o
,
5319 const SequencerPosition
& spos
)
5321 dout(15) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << o
<< dendl
;
5323 int dstcmp
= _check_replay_guard(c
, o
, spos
);
5327 // check the src name too; it might have a newer guard, and we don't
5328 // want to clobber it
5329 int srccmp
= _check_replay_guard(oldcid
, o
, spos
);
5333 // open guard on object so we don't any previous operations on the
5334 // new name that will modify the source inode.
5336 int r
= lfn_open(oldcid
, o
, 0, &fd
);
5338 // the source collection/object does not exist. If we are replaying, we
5339 // should be safe, so just return 0 and move on.
5341 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5342 << oldcid
<< "/" << o
<< " (dne, continue replay) " << dendl
;
5345 if (dstcmp
> 0) { // if dstcmp == 0 the guard already says "in-progress"
5346 _set_replay_guard(**fd
, spos
, &o
, true);
5349 r
= lfn_link(oldcid
, c
, o
, o
);
5350 if (replaying
&& !backend
->can_checkpoint() &&
5351 r
== -EEXIST
) // crashed between link() and set_replay_guard()
5356 // close guard on object so we don't do this again
5358 _close_replay_guard(**fd
, spos
);
5362 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << o
<< " = " << r
<< dendl
;
5366 int FileStore::_collection_move_rename(const coll_t
& oldcid
, const ghobject_t
& oldoid
,
5367 coll_t c
, const ghobject_t
& o
,
5368 const SequencerPosition
& spos
,
5371 dout(15) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
<< dendl
;
5376 /* If the destination collection doesn't exist during replay,
5377 * we need to delete the src object and continue on
5379 if (!collection_exists(c
))
5383 dstcmp
= _check_replay_guard(c
, o
, spos
);
5387 // check the src name too; it might have a newer guard, and we don't
5388 // want to clobber it
5389 srccmp
= _check_replay_guard(oldcid
, oldoid
, spos
);
5394 // open guard on object so we don't any previous operations on the
5395 // new name that will modify the source inode.
5397 r
= lfn_open(oldcid
, oldoid
, 0, &fd
);
5399 // the source collection/object does not exist. If we are replaying, we
5400 // should be safe, so just return 0 and move on.
5402 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5403 << oldcid
<< "/" << oldoid
<< " (dne, continue replay) " << dendl
;
5404 } else if (allow_enoent
) {
5405 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from "
5406 << oldcid
<< "/" << oldoid
<< " (dne, ignoring enoent)"
5409 assert(0 == "ERROR: source must exist");
5415 if (allow_enoent
&& dstcmp
> 0) { // if dstcmp == 0, try_rename was started.
5419 r
= 0; // don't know if object_map was cloned
5421 if (dstcmp
> 0) { // if dstcmp == 0 the guard already says "in-progress"
5422 _set_replay_guard(**fd
, spos
, &o
, true);
5425 r
= lfn_link(oldcid
, c
, oldoid
, o
);
5426 if (replaying
&& !backend
->can_checkpoint() &&
5427 r
== -EEXIST
) // crashed between link() and set_replay_guard()
5437 // the name changed; link the omap content
5438 r
= object_map
->rename(oldoid
, o
, &spos
);
5446 r
= lfn_unlink(oldcid
, oldoid
, spos
, true);
5449 r
= lfn_open(c
, o
, 0, &fd
);
5451 // close guard on object so we don't do this again
5453 _close_replay_guard(**fd
, spos
, &o
);
5458 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
5459 << " = " << r
<< dendl
;
5464 if (_check_replay_guard(oldcid
, oldoid
, spos
) > 0) {
5465 r
= lfn_unlink(oldcid
, oldoid
, spos
, true);
5468 dout(10) << __FUNC__
<< ": " << c
<< "/" << o
<< " from " << oldcid
<< "/" << oldoid
5469 << " = " << r
<< dendl
;
5473 void FileStore::_inject_failure()
5475 if (m_filestore_kill_at
) {
5476 int final
= --m_filestore_kill_at
;
5477 dout(5) << __FUNC__
<< ": " << (final
+1) << " -> " << final
<< dendl
;
5479 derr
<< __FUNC__
<< ": KILLING" << dendl
;
5486 int FileStore::_omap_clear(const coll_t
& cid
, const ghobject_t
&hoid
,
5487 const SequencerPosition
&spos
) {
5488 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5490 int r
= get_index(cid
, &index
);
5494 assert(NULL
!= index
.index
);
5495 RWLock::RLocker
l((index
.index
)->access_lock
);
5496 r
= lfn_find(hoid
, index
);
5500 r
= object_map
->clear_keys_header(hoid
, &spos
);
5501 if (r
< 0 && r
!= -ENOENT
)
5506 int FileStore::_omap_setkeys(const coll_t
& cid
, const ghobject_t
&hoid
,
5507 const map
<string
, bufferlist
> &aset
,
5508 const SequencerPosition
&spos
) {
5509 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5512 //treat pgmeta as a logical object, skip to check exist
5513 if (hoid
.is_pgmeta())
5516 r
= get_index(cid
, &index
);
5518 dout(20) << __FUNC__
<< ": get_index got " << cpp_strerror(r
) << dendl
;
5522 assert(NULL
!= index
.index
);
5523 RWLock::RLocker
l((index
.index
)->access_lock
);
5524 r
= lfn_find(hoid
, index
);
5526 dout(20) << __FUNC__
<< ": lfn_find got " << cpp_strerror(r
) << dendl
;
5531 if (g_conf
->subsys
.should_gather(ceph_subsys_filestore
, 20)) {
5532 for (auto& p
: aset
) {
5533 dout(20) << __FUNC__
<< ": set " << p
.first
<< dendl
;
5536 r
= object_map
->set_keys(hoid
, aset
, &spos
);
5537 dout(20) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< " = " << r
<< dendl
;
5541 int FileStore::_omap_rmkeys(const coll_t
& cid
, const ghobject_t
&hoid
,
5542 const set
<string
> &keys
,
5543 const SequencerPosition
&spos
) {
5544 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5547 //treat pgmeta as a logical object, skip to check exist
5548 if (hoid
.is_pgmeta())
5551 r
= get_index(cid
, &index
);
5555 assert(NULL
!= index
.index
);
5556 RWLock::RLocker
l((index
.index
)->access_lock
);
5557 r
= lfn_find(hoid
, index
);
5562 r
= object_map
->rm_keys(hoid
, keys
, &spos
);
5563 if (r
< 0 && r
!= -ENOENT
)
5568 int FileStore::_omap_rmkeyrange(const coll_t
& cid
, const ghobject_t
&hoid
,
5569 const string
& first
, const string
& last
,
5570 const SequencerPosition
&spos
) {
5571 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< " [" << first
<< "," << last
<< "]" << dendl
;
5574 ObjectMap::ObjectMapIterator iter
= get_omap_iterator(cid
, hoid
);
5577 for (iter
->lower_bound(first
); iter
->valid() && iter
->key() < last
;
5579 keys
.insert(iter
->key());
5582 return _omap_rmkeys(cid
, hoid
, keys
, spos
);
5585 int FileStore::_omap_setheader(const coll_t
& cid
, const ghobject_t
&hoid
,
5586 const bufferlist
&bl
,
5587 const SequencerPosition
&spos
)
5589 dout(15) << __FUNC__
<< ": " << cid
<< "/" << hoid
<< dendl
;
5591 int r
= get_index(cid
, &index
);
5595 assert(NULL
!= index
.index
);
5596 RWLock::RLocker
l((index
.index
)->access_lock
);
5597 r
= lfn_find(hoid
, index
);
5601 return object_map
->set_header(hoid
, bl
, &spos
);
5604 int FileStore::_split_collection(const coll_t
& cid
,
5608 const SequencerPosition
&spos
)
5612 dout(15) << __FUNC__
<< ": " << cid
<< " bits: " << bits
<< dendl
;
5613 if (!collection_exists(cid
)) {
5614 dout(2) << __FUNC__
<< ": " << cid
<< " DNE" << dendl
;
5618 if (!collection_exists(dest
)) {
5619 dout(2) << __FUNC__
<< ": " << dest
<< " DNE" << dendl
;
5624 int dstcmp
= _check_replay_guard(dest
, spos
);
5628 int srccmp
= _check_replay_guard(cid
, spos
);
5632 _set_global_replay_guard(cid
, spos
);
5633 _set_replay_guard(cid
, spos
, true);
5634 _set_replay_guard(dest
, spos
, true);
5637 r
= get_index(cid
, &from
);
5641 r
= get_index(dest
, &to
);
5644 assert(NULL
!= from
.index
);
5645 RWLock::WLocker
l1((from
.index
)->access_lock
);
5647 assert(NULL
!= to
.index
);
5648 RWLock::WLocker
l2((to
.index
)->access_lock
);
5650 r
= from
->split(rem
, bits
, to
.index
);
5653 _close_replay_guard(cid
, spos
);
5654 _close_replay_guard(dest
, spos
);
5656 _collection_set_bits(cid
, bits
);
5657 if (!r
&& cct
->_conf
->filestore_debug_verify_split
) {
5658 vector
<ghobject_t
> objects
;
5663 next
, ghobject_t::get_max(),
5664 get_ideal_list_max(),
5667 if (objects
.empty())
5669 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
5672 dout(20) << __FUNC__
<< ": " << *i
<< " still in source "
5674 assert(!i
->match(bits
, rem
));
5678 next
= ghobject_t();
5682 next
, ghobject_t::get_max(),
5683 get_ideal_list_max(),
5686 if (objects
.empty())
5688 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
5691 dout(20) << __FUNC__
<< ": " << *i
<< " now in dest "
5693 assert(i
->match(bits
, rem
));
5701 int FileStore::_set_alloc_hint(const coll_t
& cid
, const ghobject_t
& oid
,
5702 uint64_t expected_object_size
,
5703 uint64_t expected_write_size
)
5705 dout(15) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " object_size " << expected_object_size
<< " write_size " << expected_write_size
<< dendl
;
5710 if (expected_object_size
== 0 || expected_write_size
== 0)
5713 ret
= lfn_open(cid
, oid
, false, &fd
);
5718 // TODO: a more elaborate hint calculation
5719 uint64_t hint
= MIN(expected_write_size
, m_filestore_max_alloc_hint_size
);
5721 ret
= backend
->set_alloc_hint(**fd
, hint
);
5722 dout(20) << __FUNC__
<< ": hint " << hint
<< " ret " << ret
<< dendl
;
5727 dout(10) << __FUNC__
<< ": " << cid
<< "/" << oid
<< " object_size " << expected_object_size
<< " write_size " << expected_write_size
<< " = " << ret
<< dendl
;
5728 assert(!m_filestore_fail_eio
|| ret
!= -EIO
);
5732 const char** FileStore::get_tracked_conf_keys() const
5734 static const char* KEYS
[] = {
5735 "filestore_max_inline_xattr_size",
5736 "filestore_max_inline_xattr_size_xfs",
5737 "filestore_max_inline_xattr_size_btrfs",
5738 "filestore_max_inline_xattr_size_other",
5739 "filestore_max_inline_xattrs",
5740 "filestore_max_inline_xattrs_xfs",
5741 "filestore_max_inline_xattrs_btrfs",
5742 "filestore_max_inline_xattrs_other",
5743 "filestore_max_xattr_value_size",
5744 "filestore_max_xattr_value_size_xfs",
5745 "filestore_max_xattr_value_size_btrfs",
5746 "filestore_max_xattr_value_size_other",
5747 "filestore_min_sync_interval",
5748 "filestore_max_sync_interval",
5749 "filestore_queue_max_ops",
5750 "filestore_queue_max_bytes",
5751 "filestore_expected_throughput_bytes",
5752 "filestore_expected_throughput_ops",
5753 "filestore_queue_low_threshhold",
5754 "filestore_queue_high_threshhold",
5755 "filestore_queue_high_delay_multiple",
5756 "filestore_queue_max_delay_multiple",
5757 "filestore_commit_timeout",
5758 "filestore_dump_file",
5759 "filestore_kill_at",
5760 "filestore_fail_eio",
5761 "filestore_fadvise",
5762 "filestore_sloppy_crc",
5763 "filestore_sloppy_crc_block_size",
5764 "filestore_max_alloc_hint_size",
5770 void FileStore::handle_conf_change(const struct md_config_t
*conf
,
5771 const std::set
<std::string
> &changed
)
5773 if (changed
.count("filestore_max_inline_xattr_size") ||
5774 changed
.count("filestore_max_inline_xattr_size_xfs") ||
5775 changed
.count("filestore_max_inline_xattr_size_btrfs") ||
5776 changed
.count("filestore_max_inline_xattr_size_other") ||
5777 changed
.count("filestore_max_inline_xattrs") ||
5778 changed
.count("filestore_max_inline_xattrs_xfs") ||
5779 changed
.count("filestore_max_inline_xattrs_btrfs") ||
5780 changed
.count("filestore_max_inline_xattrs_other") ||
5781 changed
.count("filestore_max_xattr_value_size") ||
5782 changed
.count("filestore_max_xattr_value_size_xfs") ||
5783 changed
.count("filestore_max_xattr_value_size_btrfs") ||
5784 changed
.count("filestore_max_xattr_value_size_other")) {
5786 Mutex::Locker
l(lock
);
5787 set_xattr_limits_via_conf();
5791 if (changed
.count("filestore_queue_max_bytes") ||
5792 changed
.count("filestore_queue_max_ops") ||
5793 changed
.count("filestore_expected_throughput_bytes") ||
5794 changed
.count("filestore_expected_throughput_ops") ||
5795 changed
.count("filestore_queue_low_threshhold") ||
5796 changed
.count("filestore_queue_high_threshhold") ||
5797 changed
.count("filestore_queue_high_delay_multiple") ||
5798 changed
.count("filestore_queue_max_delay_multiple")) {
5799 Mutex::Locker
l(lock
);
5800 set_throttle_params();
5803 if (changed
.count("filestore_min_sync_interval") ||
5804 changed
.count("filestore_max_sync_interval") ||
5805 changed
.count("filestore_kill_at") ||
5806 changed
.count("filestore_fail_eio") ||
5807 changed
.count("filestore_sloppy_crc") ||
5808 changed
.count("filestore_sloppy_crc_block_size") ||
5809 changed
.count("filestore_max_alloc_hint_size") ||
5810 changed
.count("filestore_fadvise")) {
5811 Mutex::Locker
l(lock
);
5812 m_filestore_min_sync_interval
= conf
->filestore_min_sync_interval
;
5813 m_filestore_max_sync_interval
= conf
->filestore_max_sync_interval
;
5814 m_filestore_kill_at
= conf
->filestore_kill_at
;
5815 m_filestore_fail_eio
= conf
->filestore_fail_eio
;
5816 m_filestore_fadvise
= conf
->filestore_fadvise
;
5817 m_filestore_sloppy_crc
= conf
->filestore_sloppy_crc
;
5818 m_filestore_sloppy_crc_block_size
= conf
->filestore_sloppy_crc_block_size
;
5819 m_filestore_max_alloc_hint_size
= conf
->filestore_max_alloc_hint_size
;
5821 if (changed
.count("filestore_commit_timeout")) {
5822 Mutex::Locker
l(sync_entry_timeo_lock
);
5823 m_filestore_commit_timeout
= conf
->filestore_commit_timeout
;
5825 if (changed
.count("filestore_dump_file")) {
5826 if (conf
->filestore_dump_file
.length() &&
5827 conf
->filestore_dump_file
!= "-") {
5828 dump_start(conf
->filestore_dump_file
);
5835 int FileStore::set_throttle_params()
5838 bool valid
= throttle_bytes
.set_params(
5839 cct
->_conf
->filestore_queue_low_threshhold
,
5840 cct
->_conf
->filestore_queue_high_threshhold
,
5841 cct
->_conf
->filestore_expected_throughput_bytes
,
5842 cct
->_conf
->filestore_queue_high_delay_multiple
,
5843 cct
->_conf
->filestore_queue_max_delay_multiple
,
5844 cct
->_conf
->filestore_queue_max_bytes
,
5847 valid
&= throttle_ops
.set_params(
5848 cct
->_conf
->filestore_queue_low_threshhold
,
5849 cct
->_conf
->filestore_queue_high_threshhold
,
5850 cct
->_conf
->filestore_expected_throughput_ops
,
5851 cct
->_conf
->filestore_queue_high_delay_multiple
,
5852 cct
->_conf
->filestore_queue_max_delay_multiple
,
5853 cct
->_conf
->filestore_queue_max_ops
,
5856 logger
->set(l_filestore_op_queue_max_ops
, throttle_ops
.get_max());
5857 logger
->set(l_filestore_op_queue_max_bytes
, throttle_bytes
.get_max());
5860 derr
<< "tried to set invalid params: "
5864 return valid
? 0 : -EINVAL
;
5867 void FileStore::dump_start(const std::string
& file
)
5869 dout(10) << __FUNC__
<< ": " << file
<< dendl
;
5870 if (m_filestore_do_dump
) {
5873 m_filestore_dump_fmt
.reset();
5874 m_filestore_dump_fmt
.open_array_section("dump");
5875 m_filestore_dump
.open(file
.c_str());
5876 m_filestore_do_dump
= true;
5879 void FileStore::dump_stop()
5881 dout(10) << __FUNC__
<< dendl
;
5882 m_filestore_do_dump
= false;
5883 if (m_filestore_dump
.is_open()) {
5884 m_filestore_dump_fmt
.close_section();
5885 m_filestore_dump_fmt
.flush(m_filestore_dump
);
5886 m_filestore_dump
.flush();
5887 m_filestore_dump
.close();
5891 void FileStore::dump_transactions(vector
<ObjectStore::Transaction
>& ls
, uint64_t seq
, OpSequencer
*osr
)
5893 m_filestore_dump_fmt
.open_array_section("transactions");
5894 unsigned trans_num
= 0;
5895 for (vector
<ObjectStore::Transaction
>::iterator i
= ls
.begin(); i
!= ls
.end(); ++i
, ++trans_num
) {
5896 m_filestore_dump_fmt
.open_object_section("transaction");
5897 m_filestore_dump_fmt
.dump_string("osr", osr
->get_name());
5898 m_filestore_dump_fmt
.dump_unsigned("seq", seq
);
5899 m_filestore_dump_fmt
.dump_unsigned("trans_num", trans_num
);
5900 (*i
).dump(&m_filestore_dump_fmt
);
5901 m_filestore_dump_fmt
.close_section();
5903 m_filestore_dump_fmt
.close_section();
5904 m_filestore_dump_fmt
.flush(m_filestore_dump
);
5905 m_filestore_dump
.flush();
5908 void FileStore::set_xattr_limits_via_conf()
5910 uint32_t fs_xattr_size
;
5912 uint32_t fs_xattr_max_value_size
;
5914 switch (m_fs_type
) {
5915 #if defined(__linux__)
5916 case XFS_SUPER_MAGIC
:
5917 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_xfs
;
5918 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_xfs
;
5919 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_xfs
;
5921 case BTRFS_SUPER_MAGIC
:
5922 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_btrfs
;
5923 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_btrfs
;
5924 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_btrfs
;
5928 fs_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size_other
;
5929 fs_xattrs
= cct
->_conf
->filestore_max_inline_xattrs_other
;
5930 fs_xattr_max_value_size
= cct
->_conf
->filestore_max_xattr_value_size_other
;
5934 // Use override value if set
5935 if (cct
->_conf
->filestore_max_inline_xattr_size
)
5936 m_filestore_max_inline_xattr_size
= cct
->_conf
->filestore_max_inline_xattr_size
;
5938 m_filestore_max_inline_xattr_size
= fs_xattr_size
;
5940 // Use override value if set
5941 if (cct
->_conf
->filestore_max_inline_xattrs
)
5942 m_filestore_max_inline_xattrs
= cct
->_conf
->filestore_max_inline_xattrs
;
5944 m_filestore_max_inline_xattrs
= fs_xattrs
;
5946 // Use override value if set
5947 if (cct
->_conf
->filestore_max_xattr_value_size
)
5948 m_filestore_max_xattr_value_size
= cct
->_conf
->filestore_max_xattr_value_size
;
5950 m_filestore_max_xattr_value_size
= fs_xattr_max_value_size
;
5952 if (m_filestore_max_xattr_value_size
< cct
->_conf
->osd_max_object_name_len
) {
5953 derr
<< "WARNING: max attr value size ("
5954 << m_filestore_max_xattr_value_size
5955 << ") is smaller than osd_max_object_name_len ("
5956 << cct
->_conf
->osd_max_object_name_len
5957 << "). Your backend filesystem appears to not support attrs large "
5958 << "enough to handle the configured max rados name size. You may get "
5959 << "unexpected ENAMETOOLONG errors on rados operations or buggy "
5965 uint64_t FileStore::estimate_objects_overhead(uint64_t num_objects
)
5967 uint64_t res
= num_objects
* blk_size
/ 2; //assumes that each object uses ( in average ) additional 1/2 block due to FS allocation granularity.
5971 int FileStore::apply_layout_settings(const coll_t
&cid
)
5973 dout(20) << __FUNC__
<< ": " << cid
<< dendl
;
5975 int r
= get_index(cid
, &index
);
5977 dout(10) << "Error getting index for " << cid
<< ": " << cpp_strerror(r
)
5982 return index
->apply_layout_settings();
5986 // -- FSSuperblock --
5988 void FSSuperblock::encode(bufferlist
&bl
) const
5990 ENCODE_START(2, 1, bl
);
5991 compat_features
.encode(bl
);
5992 ::encode(omap_backend
, bl
);
5996 void FSSuperblock::decode(bufferlist::iterator
&bl
)
5998 DECODE_START(2, bl
);
5999 compat_features
.decode(bl
);
6001 ::decode(omap_backend
, bl
);
6003 omap_backend
= "leveldb";
6007 void FSSuperblock::dump(Formatter
*f
) const
6009 f
->open_object_section("compat");
6010 compat_features
.dump(f
);
6011 f
->dump_string("omap_backend", omap_backend
);
6015 void FSSuperblock::generate_test_instances(list
<FSSuperblock
*>& o
)
6018 o
.push_back(new FSSuperblock(z
));
6019 CompatSet::FeatureSet feature_compat
;
6020 CompatSet::FeatureSet feature_ro_compat
;
6021 CompatSet::FeatureSet feature_incompat
;
6022 feature_incompat
.insert(CEPH_FS_FEATURE_INCOMPAT_SHARDS
);
6023 z
.compat_features
= CompatSet(feature_compat
, feature_ro_compat
,
6025 o
.push_back(new FSSuperblock(z
));
6026 z
.omap_backend
= "rocksdb";
6027 o
.push_back(new FSSuperblock(z
));