// clean up
super = bluefs_super_t();
- delete log_writer;
+ _close_writer(log_writer);
log_writer = NULL;
block_all.clear();
_stop_alloc();
void BlueFS::umount()
{
dout(1) << __func__ << dendl;
+
sync_metadata();
- delete log_writer;
+ _close_writer(log_writer);
log_writer = NULL;
+ // manually clean up it's iocs
+ for (auto p : ioc_reap_queue) {
+ delete p;
+ }
+ ioc_reap_queue.clear();
+
block_all.clear();
_stop_alloc();
file_map.clear();
assert(r == 0);
}
- delete log_writer;
+ _close_writer(log_writer);
log_file->fnode.size = bl.length();
log_writer = new FileWriter(log_file, bdev.size());
}
dout(10) << __func__ << dendl;
utime_t start = ceph_clock_now(NULL);
+ vector<IOContext*> iocv;
+ iocv.swap(ioc_reap_queue);
for (auto p : alloc) {
p->commit_start();
}
for (auto p : alloc) {
p->commit_finish();
}
+ for (auto p : iocv) {
+ delete p;
+ }
utime_t end = ceph_clock_now(NULL);
utime_t dur = end - start;
dout(10) << __func__ << " done in " << dur << dendl;
return 0;
}
+void BlueFS::_close_writer(FileWriter *h)
+{
+ dout(10) << __func__ << " " << h << dendl;
+ for (auto i : h->iocv) {
+ if (i->has_aios()) {
+ ioc_reap_queue.push_back(i);
+ } else {
+ delete i;
+ }
+ }
+ h->iocv.clear();
+ delete h;
+}
+
int BlueFS::open_for_read(
const string& dirname,
const string& filename,
}
~FileWriter() {
file->num_writers.dec();
- for (auto p : iocv) {
- delete p;
- }
+ assert(iocv.empty()); // caller must call BlueFS::close_writer()
}
void append(const char *buf, size_t len) {
vector<interval_set<uint64_t> > block_all; ///< extents in bdev we own
vector<Allocator*> alloc; ///< allocators for bdevs
+ vector<IOContext*> ioc_reap_queue; ///< iocs from closed writers
+
void _init_alloc();
void _stop_alloc();
int _write_super();
int _replay(); ///< replay journal
+ void _close_writer(FileWriter *h);
+
// always put the super in the second 4k block. FIXME should this be
// block size independent?
unsigned get_super_offset() {
FileReader **h,
bool random = false);
+ void close_writer(FileWriter *h) {
+ Mutex::Locker l(lock);
+ _close_writer(h);
+ }
+
int rename(const string& old_dir, const string& old_file,
const string& new_dir, const string& new_file);
public:
BlueRocksWritableFile(BlueFS *fs, BlueFS::FileWriter *h) : fs(fs), h(h) {}
~BlueRocksWritableFile() {
- delete h;
+ fs->close_writer(h);
}
// Indicates if the class makes use of unbuffered I/O