Skip to content

Commit

Permalink
Print object ID in '"%016" PRIx64'
Browse files Browse the repository at this point in the history
This commit lets Sheepdog print object ID in 16-digit zero-padded
hexadecimal, that is, '"%016" PRIx64'.

I think this is operator-friendly because s/he can tell whether
that object is a data object (00...), an inode object (80...), a
ledger object (08...) and so on, simply by looking at the printed.

Fix #340

Signed-off-by: Takashi Menjo <menjo.takashi@lab.ntt.co.jp>
(cherry picked from commit e882d76)

Conflicts:
	dog/benchmark.c
	sheep/gateway.c
	sheep/group.c
	sheep/recovery.c
	sheep/request.c
	sheep/vdi.c
  • Loading branch information
tmenjo committed Jan 24, 2017
1 parent bdb9f11 commit 4693ab4
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 181 deletions.
8 changes: 4 additions & 4 deletions dog/common.c
Expand Up @@ -72,12 +72,12 @@ int dog_read_object(uint64_t oid, void *data, unsigned int datalen,

ret = dog_exec_req(&sd_nid, &hdr, data);
if (ret < 0) {
sd_err("Failed to read object %" PRIx64, oid);
sd_err("Failed to read object %016" PRIx64, oid);
return SD_RES_EIO;
}

if (rsp->result != SD_RES_SUCCESS) {
sd_err("Failed to read object %" PRIx64 " %s", oid,
sd_err("Failed to read object %016" PRIx64 " %s", oid,
sd_strerror(rsp->result));
return rsp->result;
}
Expand Down Expand Up @@ -114,11 +114,11 @@ int dog_write_object(uint64_t oid, uint64_t cow_oid, void *data,

ret = dog_exec_req(&sd_nid, &hdr, data);
if (ret < 0) {
sd_err("Failed to write object %" PRIx64, oid);
sd_err("Failed to write object %016" PRIx64, oid);
return SD_RES_EIO;
}
if (rsp->result != SD_RES_SUCCESS) {
sd_err("Failed to write object %" PRIx64 ": %s", oid,
sd_err("Failed to write object %016" PRIx64 ": %s", oid,
sd_strerror(rsp->result));
return rsp->result;
}
Expand Down
6 changes: 3 additions & 3 deletions dog/farm/farm.c
Expand Up @@ -274,7 +274,7 @@ static void do_save_object(struct work *work)
return;
error:
free(buf);
sd_err("Fail to save object, oid %"PRIx64, sw->entry.oid);
sd_err("Fail to save object, oid %016"PRIx64, sw->entry.oid);
uatomic_set_true(&work_error);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ static void do_load_object(struct work *work)
return;
error:
free(buffer);
sd_err("Fail to load object, oid %"PRIx64, sw->entry.oid);
sd_err("Fail to load object, oid %016"PRIx64, sw->entry.oid);
uatomic_set_true(&work_error);
}

Expand Down Expand Up @@ -480,7 +480,7 @@ static int visit_vdi_obj_entry(struct trunk_entry *entry, void *data)

inode = slice_read(entry->sha1, &size);
if (!inode) {
sd_err("Fail to load vdi object, oid %"PRIx64, entry->oid);
sd_err("Fail to load vdi object, oid %016"PRIx64, entry->oid);
goto out;
}

Expand Down
2 changes: 1 addition & 1 deletion dog/farm/object_tree.c
Expand Up @@ -69,7 +69,7 @@ void object_tree_print(void)
printf("nr_objs: %d\n", tree.nr_objs);

rb_for_each_entry(entry, &tree.root, node)
printf("Obj id: %"PRIx64"\n", entry->oid);
printf("Obj id: %016"PRIx64"\n", entry->oid);
}

void object_tree_free(void)
Expand Down
30 changes: 15 additions & 15 deletions dog/vdi.c
Expand Up @@ -872,7 +872,7 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
ret = dog_read_object(vid_to_vdi_oid(vid), inode, sizeof(*inode),
0, false);
if (ret) {
sd_err("failed to read inode object: %"PRIx64,
sd_err("failed to read inode object: %016"PRIx64,
vid_to_vdi_oid(vid));
ret = EXIT_FAILURE;
goto out;
Expand Down Expand Up @@ -905,7 +905,7 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
false, true);
if (ret) {
sd_err("failed to update inode for discarding objects:"
" %"PRIx64, vid_to_vdi_oid(vid));
" %016"PRIx64, vid_to_vdi_oid(vid));
ret = EXIT_FAILURE;
goto out;
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ static int vdi_object_location(int argc, char **argv)
vdi_id = sd_inode_get_vid(inode, idx);
oid = vid_to_data_oid(vdi_id, idx);
if (vdi_id) {
printf("Looking for the object 0x%" PRIx64
printf("Looking for the object %016" PRIx64
" (vid 0x%" PRIx32 " idx %"PRIu64
", %u copies) with %d nodes\n\n",
oid, vid, idx, inode->nr_copies, sd_nodes_nr);
Expand Down Expand Up @@ -1239,7 +1239,7 @@ static int do_track_object(uint64_t oid, uint8_t nr_copies)
struct rb_root nroot = RB_ROOT;

log = (struct epoch_log *)next_log;
printf("\nobj %"PRIx64" locations at epoch %d, copies = %d\n",
printf("\nobj %016"PRIx64" locations at epoch %d, copies = %d\n",
oid, log->epoch, nr_copies);
printf("---------------------------------------------------\n");

Expand Down Expand Up @@ -1315,11 +1315,11 @@ static int vdi_track(int argc, char **argv)
vdi_id = sd_inode_get_vid(inode, idx);
oid = vid_to_data_oid(vdi_id, idx);

printf("Tracking the object 0x%" PRIx64
printf("Tracking the object %016" PRIx64
" (the inode vid 0x%" PRIx32 " idx %u)"
" with %d nodes\n", oid, vid, idx, sd_nodes_nr);
} else
printf("Tracking the object 0x%" PRIx64
printf("Tracking the object %016" PRIx64
" (the inode vid 0x%" PRIx32 ")"
" with %d nodes\n", oid, vid, sd_nodes_nr);

Expand Down Expand Up @@ -1683,7 +1683,7 @@ static void write_object_to(const struct sd_vnode *vnode, uint64_t oid,
exit(EXIT_SYSFAIL);

if (rsp->result != SD_RES_SUCCESS) {
sd_err("FATAL: failed to write %"PRIx64", %s", oid,
sd_err("FATAL: failed to write %016"PRIx64", %s", oid,
sd_strerror(rsp->result));
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -1762,9 +1762,9 @@ static void vdi_repair_main(struct work *work)
struct vdi_check_info *info = vcw->info;

if (vcw->object_found)
fprintf(stdout, "fixed replica %"PRIx64"\n", info->oid);
fprintf(stdout, "fixed replica %016"PRIx64"\n", info->oid);
else
fprintf(stdout, "fixed missing %"PRIx64"\n", info->oid);
fprintf(stdout, "fixed missing %016"PRIx64"\n", info->oid);

info->refcnt--;
if (info->refcnt == 0)
Expand Down Expand Up @@ -1806,7 +1806,7 @@ static void vdi_check_object_work(struct work *work)
vcw->object_found = false;
break;
default:
sd_err("failed to read %" PRIx64 " from %s, %s", info->oid,
sd_err("failed to read %016" PRIx64 " from %s, %s", info->oid,
addr_to_str(vcw->vnode->node->nid.addr,
vcw->vnode->node->nid.port),
sd_strerror(rsp->result));
Expand All @@ -1819,10 +1819,10 @@ static void check_replicatoin_object(struct vdi_check_info *info)
if (info->majority == NULL) {
switch (info->result) {
case VDI_CHECK_NO_OBJ_FOUND:
sd_err("no node has %" PRIx64, info->oid);
sd_err("no node has %016" PRIx64, info->oid);
break;
case VDI_CHECK_NO_MAJORITY_FOUND:
sd_err("no majority of %" PRIx64, info->oid);
sd_err("no majority of %016" PRIx64, info->oid);
break;
default:
sd_err("unknown result of vdi check: %d", info->result);
Expand Down Expand Up @@ -1885,12 +1885,12 @@ static void check_erasure_object(struct vdi_check_info *info)
ec_decode_buffer(ctx, ds, idx, obj, d + k);
if (memcmp(obj, info->vcw[d + k].buf, len) != 0) {
/* TODO repair the inconsistency */
sd_err("object %"PRIx64" is inconsistent", oid);
sd_err("object %016"PRIx64" is inconsistent", oid);
goto out;
}
}
} else if (j > p) {
sd_err("failed to rebuild object %"PRIx64". %d copies get "
sd_err("failed to rebuild object %016"PRIx64". %d copies get "
"lost, more than %d", oid, j, p);
goto out;
} else {
Expand All @@ -1903,7 +1903,7 @@ static void check_erasure_object(struct vdi_check_info *info)
ec_decode_buffer(ctx, ds, input_idx, obj, m);
write_object_to(info->vcw[m].vnode, oid, obj,
len, true, info->vcw[m].ec_index);
fprintf(stdout, "fixed missing %"PRIx64", "
fprintf(stdout, "fixed missing %016"PRIx64", "
"copy index %d\n", info->oid, m);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/sd_inode.c
Expand Up @@ -166,7 +166,7 @@ static void traverse_btree(const struct sd_inode *inode, btree_cb_fn fn,
ret = inode_actor.reader(iter_idx->oid, &tmp,
SD_INODE_DATA_INDEX_SIZE, 0);
if (ret != SD_RES_SUCCESS) {
sd_err("failed to read %"PRIx64, iter_idx->oid);
sd_err("failed to read %016"PRIx64, iter_idx->oid);
iter_idx++;
continue;
}
Expand Down Expand Up @@ -516,7 +516,7 @@ static int search_whole_btree(read_node_fn reader, const struct sd_inode *inode,
idx);
path->p_index_header = leaf_node;
} else {
sd_debug("last ext-node is full (oid: %"
sd_debug("last ext-node is full (oid: %016"
PRIx64")", oid);
free(leaf_node);
}
Expand Down
26 changes: 13 additions & 13 deletions sheep/gateway.c
Expand Up @@ -35,7 +35,7 @@ static struct req_iter *prepare_replication_requests(struct request *req,
uint64_t off = req->rq.obj.offset;
struct req_iter *reqs = xzalloc(sizeof(*reqs) * nr_copies);

sd_debug("%"PRIx64, req->rq.obj.oid);
sd_debug("%016"PRIx64, req->rq.obj.oid);

*nr = nr_copies;
for (int i = 0; i < nr_copies; i++) {
Expand Down Expand Up @@ -150,7 +150,7 @@ static struct req_iter *prepare_erasure_requests(struct request *req, int *nr)

p = buf = init_erasure_buffer(req, SD_EC_DATA_STRIPE_SIZE * nr_stripe);
if (!buf) {
sd_err("failed to init erasure buffer %"PRIx64,
sd_err("failed to init erasure buffer %016"PRIx64,
req->rq.obj.oid);
free(reqs);
reqs = NULL;
Expand Down Expand Up @@ -267,7 +267,7 @@ static int gateway_replication_read(struct request *req)
if (ret == SD_RES_SUCCESS)
goto out;

sd_err("local read %"PRIx64" failed, %s", oid,
sd_err("local read %016"PRIx64" failed, %s", oid,
sd_strerror(ret));
break;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ static int wait_forward_request(struct forward_info *fi, struct request *req)
}
ret = rsp->result;
if (ret != SD_RES_SUCCESS) {
sd_err("fail %"PRIx64", %s", req->rq.obj.oid,
sd_err("fail %016"PRIx64", %s", req->rq.obj.oid,
sd_strerror(ret));
err_ret = ret;
}
Expand Down Expand Up @@ -478,7 +478,7 @@ static int gateway_forward_request(struct request *req)
int nr_copies = get_req_copy_number(req), nr_reqs, nr_to_send = 0;
struct req_iter *reqs = NULL;

sd_debug("%"PRIx64, oid);
sd_debug("%016"PRIx64, oid);

gateway_init_fwd_hdr(&hdr, &req->rq);
oid_to_nodes(oid, &req->vinfo->vroot, nr_copies, target_nodes);
Expand Down Expand Up @@ -563,15 +563,15 @@ static int prepare_obj_refcnt(const struct sd_req *hdr, uint32_t *vids,
nr_vids * sizeof(vids[0]),
offsetof(struct sd_inode, data_vdi_id[start]));
if (ret != SD_RES_SUCCESS) {
sd_err("failed to read vdi, %" PRIx64, hdr->obj.oid);
sd_err("failed to read vdi, %016" PRIx64, hdr->obj.oid);
return ret;
}

ret = sd_read_object(hdr->obj.oid, (char *)refs,
nr_vids * sizeof(refs[0]),
offsetof(struct sd_inode, gref[start]));
if (ret != SD_RES_SUCCESS) {
sd_err("failed to read vdi, %" PRIx64, hdr->obj.oid);
sd_err("failed to read vdi, %016" PRIx64, hdr->obj.oid);
return ret;
}

Expand Down Expand Up @@ -625,7 +625,7 @@ int gateway_read_obj(struct request *req)
if ((req->rq.flags & SD_FLAG_CMD_TGT) &&
!is_inode_refresh_req(req) &&
is_refresh_required(oid_to_vid(oid))) {
sd_debug("refresh is required: %"PRIx64, oid);
sd_debug("refresh is required: %016"PRIx64, oid);
return SD_RES_INODE_INVALIDATED;
}

Expand Down Expand Up @@ -695,7 +695,7 @@ int gateway_write_obj(struct request *req)

if ((req->rq.flags & SD_FLAG_CMD_TGT) &&
is_refresh_required(oid_to_vid(oid))) {
sd_debug("refresh is required: %"PRIx64, oid);
sd_debug("refresh is required: %016"PRIx64, oid);
return SD_RES_INODE_INVALIDATED;
}

Expand Down Expand Up @@ -730,21 +730,21 @@ int gateway_write_obj(struct request *req)
- offsetof(struct sd_inode, data_vdi_id);
start = offset / sizeof(*vids);

sd_debug("update reference counts, %" PRIx64, hdr->obj.oid);
sd_debug("update reference counts, %016" PRIx64, hdr->obj.oid);

ret = sd_write_object(hdr->obj.oid, (char *)zeroed_refs,
nr_vids * sizeof(*zeroed_refs),
offsetof(struct sd_inode, gref)
+ start * sizeof(*zeroed_refs), false);
if (ret != SD_RES_SUCCESS) {
sd_err("updating reference count of inode object %"
sd_err("updating reference count of inode object %016"
PRIx64 " failed: %s", hdr->obj.oid,
sd_strerror(ret));

goto out;
}

sd_debug("update ledger objects of %"PRIx64, hdr->obj.oid);
sd_debug("update ledger objects of %016"PRIx64, hdr->obj.oid);
refcnt_work = xzalloc(sizeof(*refcnt_work));

refcnt_work->vids = vids;
Expand Down Expand Up @@ -807,7 +807,7 @@ int gateway_create_and_write_obj(struct request *req)

if ((req->rq.flags & SD_FLAG_CMD_TGT) &&
is_refresh_required(oid_to_vid(oid))) {
sd_debug("refresh is required: %"PRIx64, oid);
sd_debug("refresh is required: %016"PRIx64, oid);
return SD_RES_INODE_INVALIDATED;
}

Expand Down
18 changes: 9 additions & 9 deletions sheep/http/kv.c
Expand Up @@ -132,7 +132,7 @@ static void bucket_iterater(struct sd_index *idx, void *arg, int ignore)
oid = vid_to_data_oid(idx->vdi_id, idx->idx);
ret = sd_read_object(oid, (char *)&bnode, sizeof(bnode), 0);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to read data object %"PRIx64, oid);
sd_err("Failed to read data object %016"PRIx64, oid);
return;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ static int read_account_meta(const char *account, uint64_t *bucket_count,
inode = xmalloc(sizeof(*inode));
ret = sd_read_object(oid, (char *)inode, sizeof(struct sd_inode), 0);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to read inode header %"PRIx64, oid);
sd_err("Failed to read inode header %016"PRIx64, oid);
goto out;
}

Expand Down Expand Up @@ -256,7 +256,7 @@ static int bnode_do_create(struct kv_bnode *bnode, struct sd_inode *inode,
bnode->oid = oid;
ret = sd_write_object(oid, (char *)bnode, sizeof(*bnode), 0, create);
if (ret != SD_RES_SUCCESS) {
sd_err("failed to create object, %" PRIx64, oid);
sd_err("failed to create object, %016" PRIx64, oid);
goto out;
}
if (!create)
Expand All @@ -265,7 +265,7 @@ static int bnode_do_create(struct kv_bnode *bnode, struct sd_inode *inode,
sd_inode_set_vid(inode, idx, vid);
ret = sd_inode_write_vid(inode, idx, vid, vid, 0, false, false);
if (ret != SD_RES_SUCCESS) {
sd_err("failed to update inode, %" PRIx64,
sd_err("failed to update inode, %016" PRIx64,
vid_to_vdi_oid(vid));
goto out;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ static void object_iterater(struct sd_index *idx, void *arg, int ignore)
oid = vid_to_data_oid(idx->vdi_id, idx->idx);
ret = sd_read_object(oid, (char *)onode, read_size, 0);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to read data object %"PRIx64, oid);
sd_err("Failed to read data object %016"PRIx64, oid);
goto out;
}

Expand Down Expand Up @@ -696,7 +696,7 @@ static int vdi_read_write(uint32_t vid, char *data, size_t length,

ret = exec_local_req_async(&hdr, data, iocb);
if (ret != SD_RES_SUCCESS)
sd_err("failed to write object %" PRIx64 ", %s",
sd_err("failed to write object %016" PRIx64 ", %s",
hdr.obj.oid, sd_strerror(ret));

offset += len;
Expand Down Expand Up @@ -895,7 +895,7 @@ static int onode_do_update(struct kv_onode *onode)
ret = sd_write_object(onode->oid, (char *)onode, ONODE_HDR_SIZE + len,
0, false);
if (ret != SD_RES_SUCCESS)
sd_err("Failed to update object, %" PRIx64, onode->oid);
sd_err("Failed to update object, %016" PRIx64, onode->oid);
return ret;
}

Expand Down Expand Up @@ -970,7 +970,7 @@ static int onode_do_create(struct kv_onode *onode, struct sd_inode *inode,
ret = sd_write_object(oid, (char *)onode, ONODE_HDR_SIZE + len,
0, create);
if (ret != SD_RES_SUCCESS) {
sd_err("failed to create object, %" PRIx64, oid);
sd_err("failed to create object, %016" PRIx64, oid);
goto out;
}
if (!create)
Expand All @@ -979,7 +979,7 @@ static int onode_do_create(struct kv_onode *onode, struct sd_inode *inode,
sd_inode_set_vid(inode, idx, vid);
ret = sd_inode_write_vid(inode, idx, vid, vid, 0, false, false);
if (ret != SD_RES_SUCCESS) {
sd_err("failed to update inode, %" PRIx64,
sd_err("failed to update inode, %016" PRIx64,
vid_to_vdi_oid(vid));
goto out;
}
Expand Down

0 comments on commit 4693ab4

Please sign in to comment.