#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include "include/stringify.h"
+#include "include/scope_guard.h"
#include "common/errno.h"
#include <gtest/gtest.h>
void write_data(BlueFS &fs, uint64_t rationed_bytes)
{
- BlueFS::FileWriter *h;
int j=0, r=0;
uint64_t written_bytes = 0;
rationed_bytes -= ALLOC_SIZE;
while (1) {
string file = "file.";
file.append(to_string(j));
+ BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
+ ASSERT_NE(nullptr, h);
+ auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
bufferlist bl;
char *buf = gen_buffer(ALLOC_SIZE);
bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf);
h->append(bl.c_str(), bl.length());
r = fs.fsync(h);
if (r < 0) {
- fs.close_writer(h);
break;
}
written_bytes += g_conf->bluefs_alloc_size;
- fs.close_writer(h);
j++;
if ((rationed_bytes - written_bytes) <= g_conf->bluefs_alloc_size) {
break;
void write_single_file(BlueFS &fs, uint64_t rationed_bytes)
{
- BlueFS::FileWriter *h;
stringstream ss;
- string dir = "dir.test";
- string file = "testfile";
- int r=0;
+ const string dir = "dir.test";
+ const string file = "testfile";
uint64_t written_bytes = 0;
rationed_bytes -= ALLOC_SIZE;
while (1) {
+ BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
+ ASSERT_NE(nullptr, h);
+ auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
bufferlist bl;
char *buf = gen_buffer(ALLOC_SIZE);
bufferptr bp = buffer::claim_char(ALLOC_SIZE, buf);
bl.push_back(bp);
h->append(bl.c_str(), bl.length());
- r = fs.fsync(h);
+ int r = fs.fsync(h);
if (r < 0) {
- fs.close_writer(h);
break;
}
written_bytes += g_conf->bluefs_alloc_size;
- fs.close_writer(h);
if ((rationed_bytes - written_bytes) <= g_conf->bluefs_alloc_size) {
break;
}
ASSERT_EQ(0, fs.mkfs(fsid));
ASSERT_EQ(0, fs.mount());
{
- BlueFS::FileWriter *h;
for (int i=0; i<10; i++) {
string dir = "dir.";
dir.append(to_string(i));
for (int j=0; j<10; j++) {
string file = "file.";
file.append(to_string(j));
+ BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
+ ASSERT_NE(nullptr, h);
+ auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
bufferlist bl;
char *buf = gen_buffer(4096);
bufferptr bp = buffer::claim_char(4096, buf);
bl.push_back(bp);
h->append(bl.c_str(), bl.length());
fs.fsync(h);
- fs.close_writer(h);
}
}
}
ASSERT_EQ(0, fs.mkfs(fsid));
ASSERT_EQ(0, fs.mount());
{
- BlueFS::FileWriter *h;
for (int i=0; i<10; i++) {
string dir = "dir.";
dir.append(to_string(i));
for (int j=0; j<10; j++) {
string file = "file.";
file.append(to_string(j));
+ BlueFS::FileWriter *h;
ASSERT_EQ(0, fs.open_for_write(dir, file, &h, false));
+ ASSERT_NE(nullptr, h);
+ auto sg = make_scope_guard([&fs, h] { fs.close_writer(h); });
bufferlist bl;
char *buf = gen_buffer(4096);
bufferptr bp = buffer::claim_char(4096, buf);
bl.push_back(bp);
h->append(bl.c_str(), bl.length());
fs.fsync(h);
- fs.close_writer(h);
}
}
}