rbdtool: add, use prettybyte_t type

This commit is contained in:
Sage Weil 2010-04-21 14:56:35 -07:00
parent 0cf079ac77
commit 2caf513594
2 changed files with 25 additions and 3 deletions

View File

@ -398,6 +398,28 @@ inline ostream& operator<<(ostream& out, const ceph_fsid& f) {
return out << b;
}
struct prettybyte_t {
uint64_t v;
prettybyte_t(uint64_t _v) : v(_v) {}
};
inline ostream& operator<<(ostream& out, const prettybyte_t& b)
{
__u64 bump_after = 100;
if (b.v > bump_after << 60)
return out << (b.v >> 60) << " EB";
if (b.v > bump_after << 50)
return out << (b.v >> 50) << " PB";
if (b.v > bump_after << 40)
return out << (b.v >> 40) << " TB";
if (b.v > bump_after << 30)
return out << (b.v >> 30) << " GB";
if (b.v > bump_after << 20)
return out << (b.v >> 20) << " MB";
if (b.v > bump_after << 10)
return out << (b.v >> 10) << " KB";
return out << b.v << " bytes";
}
struct kb_t {
uint64_t v;

View File

@ -70,9 +70,9 @@ static void init_rbd_header(struct rbd_obj_header_ondisk& ondisk,
void print_header(char *imgname, rbd_obj_header_ondisk *header)
{
cout << "rbd image '" << imgname << "':\n"
<< "\tsize " << kb_t(header->image_size >> 10) << " in "
<< "\tsize " << prettybyte_t(header->image_size) << " in "
<< (header->image_size >> header->obj_order) << " objects\n"
<< "\torder " << (int)header->obj_order << " (" << kb_t(1 << (header->obj_order-10)) << " objects)"
<< "\torder " << (int)header->obj_order << " (" << prettybyte_t(1 << (header->obj_order)) << " objects)"
<< std::endl;
}
@ -82,7 +82,7 @@ void trim_image(const char *imgname, rbd_obj_header_ondisk *header, __u64 newsiz
__u64 numseg = size >> header->obj_order;
__u64 start = newsize >> header->obj_order;
cout << "trimming device data from " << numseg << " to " << start << " objects..." << std::endl;
cout << "trimming image data from " << numseg << " to " << start << " objects..." << std::endl;
for (__u64 i=start; i<numseg; i++) {
char o[RBD_MAX_SEG_NAME_SIZE];
sprintf(o, "%s.%012llx", imgname, (unsigned long long)i);