" --image-format <format-number> format to use when creating an image\n"
" format 1 is the original format (default)\n"
" format 2 supports cloning\n"
-" --id <username> rados user (without 'client.' prefix) to authenticate as\n"
+" --id <username> rados user (without 'client.'prefix) to\n"
+" authenticate as\n"
" --keyfile <path> file containing secret key for use with cephx\n"
" --shared <tag> take a shared (rather than exclusive) lock\n"
" --format <output-format> output format (default: plain, json, xml)\n";
cout << "\r" << operation << ": 100% complete...done." << std::endl;
}
void fail() {
- cout << "\r" << operation << ": " << last_pc << "% complete...failed." << std::endl;
+ cout << "\r" << operation << ": " << last_pc << "% complete...failed."
+ << std::endl;
}
};
return 0;
}
-static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool lflag, const char *output_format)
+static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool lflag,
+ const char *output_format)
{
std::vector<string> names;
int r = rbd.list(io_ctx, names);
// weird striping not allowed with format 1!
if ((stripe_unit || stripe_count) &&
(stripe_unit != (1ull << *order) && stripe_count != 1)) {
- cerr << "non-default striping not allowed with format 1; use --format 2" << std::endl;
+ cerr << "non-default striping not allowed with format 1; use --format 2"
+ << std::endl;
return -EINVAL;
}
r = rbd.create(io_ctx, imgname, size, order);
}
if (stripe_unit != (1ull << *order) && stripe_count != 1)
features |= RBD_FEATURE_STRIPINGV2;
- r = rbd.create3(io_ctx, imgname, size, features, order, stripe_unit, stripe_count);
+ r = rbd.create3(io_ctx, imgname, size, features, order,
+ stripe_unit, stripe_count);
}
if (r < 0)
return r;
f->dump_string("stripe_unit", stringify(prettybyte_t(image.get_stripe_unit())));
f->dump_string("stripe_count", stringify(image.get_stripe_count()));
} else {
- cout << "\tstripe unit: " << prettybyte_t(image.get_stripe_unit()) << std::endl
+ cout << "\tstripe unit: " << prettybyte_t(image.get_stripe_unit())
+ << std::endl
<< "\tstripe count: " << image.get_stripe_count() << std::endl;
}
}
return 0;
}
-static int do_delete(librbd::RBD &rbd, librados::IoCtx& io_ctx, const char *imgname)
+static int do_delete(librbd::RBD &rbd, librados::IoCtx& io_ctx,
+ const char *imgname)
{
MyProgressContext pc("Removing image");
int r = rbd.remove_with_progress(io_ctx, imgname, pc);
if (r < 0)
return r;
- r = image.snap_list(snaps);
+ r = image.snap_list(snaps);
if (r < 0 || snaps.empty())
return r;
if (in_flight >= max)
return false;
in_flight++;
- librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion((void *)this, rbd_bencher_completion);
+ librbd::RBD::AioCompletion *c =
+ new librbd::RBD::AioCompletion((void *)this, rbd_bencher_completion);
image->aio_write(off, len, bl, c);
//cout << "start " << c << " at " << off << "~" << len << std::endl;
return true;
c->release();
}
-static int do_bench_write(librbd::Image& image, uint64_t io_size, uint64_t io_threads, uint64_t io_bytes)
+static int do_bench_write(librbd::Image& image, uint64_t io_size,
+ uint64_t io_threads, uint64_t io_bytes)
{
rbd_bencher b(&image);
utime_t now = ceph_clock_now(NULL);
utime_t elapsed = now - start;
if (elapsed.sec() != last.sec()) {
- printf("%5d %8d %8.2lf %8.2lf\n", (int)elapsed, (int)(ios - io_threads),
+ printf("%5d %8d %8.2lf %8.2lf\n",
+ (int)elapsed,
+ (int)(ios - io_threads),
(double)(ios - io_threads) / elapsed,
(double)(off - io_threads * io_size) / elapsed);
last = elapsed;
utime_t now = ceph_clock_now(NULL);
double elapsed = now - start;
- printf("elapsed: %5d ops: %8d ops/sec: %8.2lf bytes/sec: %8.2lf\n", (int)elapsed, ios,
- (double)ios / elapsed,
- (double)off / elapsed);
+ printf("elapsed: %5d ops: %8d ops/sec: %8.2lf bytes/sec: %8.2lf\n",
+ (int)elapsed, ios, (double)ios / elapsed, (double)off / elapsed);
return 0;
}
uint64_t totalsize;
MyProgressContext pc;
- ExportContext(int f, uint64_t t) : fd(f), totalsize(t), pc("Exporting image") {}
+ ExportContext(int f, uint64_t t) : fd(f), totalsize(t), pc("Exporting image")
+ {}
};
static int export_read_cb(uint64_t ofs, size_t len, const char *buf, void *arg)
if (!bl.is_zero()) {
r = image.write(image_pos, blklen, bl);
if (r < 0) {
- cerr << "rbd: error writing to image block" << cpp_strerror(r) << std::endl;
+ cerr << "rbd: error writing to image block" << cpp_strerror(r)
+ << std::endl;
return r;
}
}
return r;
}
- fsync(fd); /* flush it first, otherwise extents information might not have been flushed yet */
+ // flush it first, otherwise extents may not be allocated or readable
+ fsync(fd);
fiemap = read_fiemap(fd);
if (fiemap && !fiemap->fm_mapped_extents) {
cerr << "rbd: empty fiemap!" << std::endl;
fiemap = NULL;
}
if (!fiemap) {
- fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) + sizeof(struct fiemap_extent));
+ size_t fiemap_size = sizeof(struct fiemap) + sizeof(struct fiemap_extent);
+ fiemap = (struct fiemap *)malloc(fiemap_size);
if (!fiemap) {
cerr << "rbd: failed to allocate fiemap, not enough memory." << std::endl;
close(fd);
size_t extent_len = 0;
size_t read_len = 1ULL << *order;
- file_pos = fiemap->fm_extents[extent].fe_logical; /* position within the file we're reading */
+ /* position within the file we're reading */
+ file_pos = fiemap->fm_extents[extent].fe_logical;
do { /* try to merge consecutive extents */
#define LARGE_ENOUGH_EXTENT (32 * 1024 * 1024)
extent_len + fiemap->fm_extents[extent].fe_length > LARGE_ENOUGH_EXTENT)
break; /* don't try to merge if we're big enough */
- extent_len += fiemap->fm_extents[extent].fe_length; /* length of current extent */
+ /* length of current extent */
+ extent_len += fiemap->fm_extents[extent].fe_length;
end_ofs = MIN((off_t)size, file_pos + (off_t)extent_len);
extent++;
}
bufferlist bl;
bl.append(p);
- librbd::RBD::AioCompletion *completion = new librbd::RBD::AioCompletion(NULL, NULL);
+ librbd::RBD::AioCompletion *completion =
+ new librbd::RBD::AioCompletion(NULL, NULL);
if (!completion) {
r = -ENOMEM;
goto done;
RbdWatchCtx(const char *imgname) : name(imgname) {}
virtual ~RbdWatchCtx() {}
virtual void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) {
- cout << name << " got notification opcode=" << (int)opcode << " ver=" << ver << " bl.length=" << bl.length() << std::endl;
+ cout << name << " got notification opcode=" << (int)opcode << " ver="
+ << ver << " bl.length=" << bl.length() << std::endl;
}
};
return 0;
}
-static int do_kernel_add(const char *poolname, const char *imgname, const char *snapname)
+static int do_kernel_add(const char *poolname, const char *imgname,
+ const char *snapname)
{
MonMap monmap;
int r = monmap.build_initial(g_ceph_context, cerr);
r = -errno;
if (r == -ENOENT) {
cerr << "rbd: /sys/bus/rbd/add does not exist!" << std::endl
- << "Did you run 'modprobe rbd' or is your rbd module too old?" << std::endl;
+ << "Did you run 'modprobe rbd' or is your rbd module too old?"
+ << std::endl;
}
return r;
}
if (err.empty()) {
format = ret;
format_specified = true;
- cerr << "rbd: using --format for specifying the rbd image format is deprecated,"
- << " use --image-format instead"
+ cerr << "rbd: using --format for specifying the rbd image format is"
+ << " deprecated, use --image-format instead"
<< std::endl;
} else {
output_format = strdup(val.c_str());
return EXIT_FAILURE;
}
- if (output_format_specified && opt_cmd != OPT_SHOWMAPPED && opt_cmd != OPT_INFO &&
- opt_cmd != OPT_LIST && opt_cmd != OPT_SNAP_LIST && opt_cmd != OPT_LOCK_LIST &&
- opt_cmd != OPT_CHILDREN) {
+ if (output_format_specified && opt_cmd != OPT_SHOWMAPPED &&
+ opt_cmd != OPT_INFO && opt_cmd != OPT_LIST && opt_cmd != OPT_SNAP_LIST &&
+ opt_cmd != OPT_LOCK_LIST && opt_cmd != OPT_CHILDREN) {
cerr << "rbd: command doesn't use output formatting"
<< std::endl;
return EXIT_FAILURE;
return EXIT_FAILURE;
}
- if (opt_cmd != OPT_LIST && opt_cmd != OPT_IMPORT && opt_cmd != OPT_UNMAP && opt_cmd != OPT_SHOWMAPPED &&
- !imgname) {
+ if (opt_cmd != OPT_LIST && opt_cmd != OPT_IMPORT && opt_cmd != OPT_UNMAP &&
+ opt_cmd != OPT_SHOWMAPPED && !imgname) {
cerr << "rbd: image name was not specified" << std::endl;
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
- set_pool_image_name(dest_poolname, destname, (char **)&dest_poolname, (char **)&destname, (char **)&dest_snapname);
+ set_pool_image_name(dest_poolname, destname, (char **)&dest_poolname,
+ (char **)&destname, (char **)&dest_snapname);
if (opt_cmd == OPT_IMPORT) {
if (poolname && dest_poolname) {
return EXIT_FAILURE;
}
if ((stripe_unit && !stripe_count) || (!stripe_unit && stripe_count)) {
- cerr << "must specify both (or neither) of stripe-unit and stripe-count" << std::endl;
+ cerr << "must specify both (or neither) of stripe-unit and stripe-count"
+ << std::endl;
usage();
return EXIT_FAILURE;
}
- r = do_create(rbd, io_ctx, imgname, size, &order, format, features, stripe_unit, stripe_count);
+ r = do_create(rbd, io_ctx, imgname, size, &order, format, features,
+ stripe_unit, stripe_count);
if (r < 0) {
cerr << "rbd: create error: " << cpp_strerror(-r) << std::endl;
return EXIT_FAILURE;