本文整理汇总了C++中sd_init_req函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_init_req函数的具体用法?C++ sd_init_req怎么用?C++ sd_init_req使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_init_req函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: do_plug_unplug
static int do_plug_unplug(char *disks, bool plug)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int ret;
if (!strlen(disks)) {
sd_err("Empty path isn't allowed");
return EXIT_FAILURE;
}
if (plug)
sd_init_req(&hdr, SD_OP_MD_PLUG);
else
sd_init_req(&hdr, SD_OP_MD_UNPLUG);
hdr.flags = SD_FLAG_CMD_WRITE;
hdr.data_length = strlen(disks) + 1;
ret = dog_exec_req(sdhost, sdport, &hdr, disks);
if (ret < 0)
return EXIT_SYSFAIL;
if (rsp->result != SD_RES_SUCCESS) {
sd_err("Failed to execute request, look for sheep.log"
" for more information");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
开发者ID:SongWuCloud,项目名称:ACStor,代码行数:30,代码来源:node.c
示例2: round_down
/*
* Make sure we don't overwrite the existing data for misaligned write
*
* If either offset or length of request isn't aligned to
* SD_EC_DATA_STRIPE_SIZE, we have to read the unaligned blocks before write.
* This kind of write amplification indeed slow down the write operation with
* extra read overhead.
*/
static void *init_erasure_buffer(struct request *req, int buf_len)
{
char *buf;
uint32_t len = req->rq.data_length;
uint64_t off = req->rq.obj.offset;
uint64_t oid = req->rq.obj.oid;
int opcode = req->rq.opcode;
struct sd_req hdr;
uint64_t head = round_down(off, SD_EC_DATA_STRIPE_SIZE);
uint64_t tail = round_down(off + len, SD_EC_DATA_STRIPE_SIZE);
int ret;
buf = valloc(buf_len);
if(unlikely(!buf))
return NULL;
memset(buf, 0, buf_len);
if (opcode != SD_OP_WRITE_OBJ)
goto out;
if (off % SD_EC_DATA_STRIPE_SIZE) {
/* Read head */
sd_init_req(&hdr, SD_OP_READ_OBJ);
hdr.obj.oid = oid;
hdr.data_length = SD_EC_DATA_STRIPE_SIZE;
hdr.obj.offset = head;
ret = exec_local_req(&hdr, buf);
if (ret != SD_RES_SUCCESS) {
free(buf);
return NULL;
}
}
if ((len + off) % SD_EC_DATA_STRIPE_SIZE && tail - head > 0) {
/* Read tail */
sd_init_req(&hdr, SD_OP_READ_OBJ);
hdr.obj.oid = oid;
hdr.data_length = SD_EC_DATA_STRIPE_SIZE;
hdr.obj.offset = tail;
ret = exec_local_req(&hdr, buf + tail - head);
if (ret != SD_RES_SUCCESS) {
free(buf);
return NULL;
}
}
out:
memcpy(buf + off % SD_EC_DATA_STRIPE_SIZE, req->data, len);
return buf;
}
开发者ID:kentwei,项目名称:sheepdog,代码行数:57,代码来源:gateway.c
示例3: do_loglevel_set
int do_loglevel_set(const struct node_id *nid, const char *loglevel_str)
{
int32_t loglevel = -1;
int ret;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
for (int i = 0; i < ARRAY_SIZE(loglevel_table); i++) {
if (!strcmp(loglevel_table[i], loglevel_str)) {
loglevel = i;
break;
}
}
if (loglevel == -1)
return EXIT_USAGE;
sd_init_req(&hdr, SD_OP_SET_LOGLEVEL);
hdr.flags = SD_FLAG_CMD_WRITE;
hdr.data_length = sizeof(loglevel);
ret = dog_exec_req(nid, &hdr, &loglevel);
if (ret < 0)
return EXIT_SYSFAIL;
if (rsp->result != SD_RES_SUCCESS)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
开发者ID:hadrienk,项目名称:sheepdog,代码行数:30,代码来源:common.c
示例4: node_kill
static int node_kill(int argc, char **argv)
{
char host[128];
int node_id, ret;
struct sd_node_req req;
const char *p = argv[optind++];
if (!is_numeric(p)) {
fprintf(stderr, "Invalid node id '%s', "
"please specify a numeric value\n", p);
exit(EXIT_USAGE);
}
node_id = strtol(p, NULL, 10);
if (node_id < 0 || node_id >= sd_nodes_nr) {
fprintf(stderr, "Invalid node id '%d'\n", node_id);
exit(EXIT_USAGE);
}
addr_to_str(host, sizeof(host), sd_nodes[node_id].nid.addr, 0);
sd_init_req((struct sd_req *)&req, SD_OP_KILL_NODE);
ret = send_light_req((struct sd_req *)&req, host,
sd_nodes[node_id].nid.port);
if (ret) {
fprintf(stderr, "Failed to execute request\n");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
开发者ID:ChrisChung,项目名称:sheepdog,代码行数:32,代码来源:node.c
示例5: node_md_info
static int node_md_info(struct node_id *nid)
{
struct sd_md_info info = {};
char size_str[UINT64_DECIMAL_SIZE], used_str[UINT64_DECIMAL_SIZE],
avail_str[UINT64_DECIMAL_SIZE];
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int ret, i;
sd_init_req(&hdr, SD_OP_MD_INFO);
hdr.data_length = sizeof(info);
ret = dog_exec_req(nid->addr, nid->port, &hdr, &info);
if (ret < 0)
return EXIT_SYSFAIL;
if (rsp->result != SD_RES_SUCCESS) {
sd_err("failed to get multi-disk infomation: %s",
sd_strerror(rsp->result));
return EXIT_FAILURE;
}
for (i = 0; i < info.nr; i++) {
uint64_t size = info.disk[i].free + info.disk[i].used;
int ratio = (int)(((double)info.disk[i].used / size) * 100);
size_to_str(size, size_str, sizeof(size_str));
size_to_str(info.disk[i].used, used_str, sizeof(used_str));
size_to_str(info.disk[i].free, avail_str, sizeof(avail_str));
fprintf(stdout, "%2d\t%s\t%s\t%s\t%3d%%\t%s\n",
info.disk[i].idx, size_str, used_str, avail_str, ratio,
info.disk[i].path);
}
return EXIT_SUCCESS;
}
开发者ID:SongWuCloud,项目名称:ACStor,代码行数:35,代码来源:node.c
示例6: get_vdis_from
static int get_vdis_from(struct sd_node *node)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
struct vdi_copy *vc = NULL;
int i, ret = SD_RES_SUCCESS;
unsigned int rlen;
int count;
if (node_is_local(node))
goto out;
rlen = SD_DATA_OBJ_SIZE; /* FIXME */
vc = zalloc(rlen);
if (!vc) {
sd_printf(SDOG_ERR, "unable to allocate memory\n");
ret = SD_RES_NO_MEM;
goto out;
}
sd_init_req(&hdr, SD_OP_GET_VDI_COPIES);
hdr.data_length = rlen;
ret = sheep_exec_req(&node->nid, &hdr, (char *)vc);
if (ret != SD_RES_SUCCESS)
goto out;
count = rsp->data_length / sizeof(*vc);
for (i = 0; i < count; i++) {
set_bit(vc[i].vid, sys->vdi_inuse);
add_vdi_copy_number(vc[i].vid, vc[i].nr_copies);
}
out:
free(vc);
return ret;
}
开发者ID:kongjian,项目名称:sheepdog,代码行数:35,代码来源:group.c
示例7: trace_disable
static int trace_disable(int argc, char **argv)
{
const char *tracer = argv[optind];
int ret;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
sd_init_req(&hdr, SD_OP_TRACE_DISABLE);
hdr.flags = SD_FLAG_CMD_WRITE;
hdr.data_length = strlen(tracer) + 1;
ret = dog_exec_req(&sd_nid, &hdr, (void *)tracer);
if (ret < 0)
return EXIT_SYSFAIL;
switch (rsp->result) {
case SD_RES_SUCCESS:
break;
case SD_RES_NO_SUPPORT:
sd_err("no such tracer %s", tracer);
return EXIT_FAILURE;
case SD_RES_INVALID_PARMS:
sd_err("tracer %s is not enabled", tracer);
return EXIT_FAILURE;
default:
sd_err("unknown error (%s)", sd_strerror(rsp->result));
return EXIT_SYSFAIL;
}
return trace_read_buffer();
}
开发者ID:gHcAgree,项目名称:sheepdog-ng,代码行数:31,代码来源:trace.c
示例8: node_kill
static int node_kill(int argc, char **argv)
{
int node_id, ret;
struct sd_req req;
const char *p = argv[optind++];
if (!is_numeric(p)) {
sd_err("Invalid node id '%s', please specify a numeric value",
p);
exit(EXIT_USAGE);
}
node_id = strtol(p, NULL, 10);
if (node_id < 0 || node_id >= sd_nodes_nr) {
sd_err("Invalid node id '%d'", node_id);
exit(EXIT_USAGE);
}
sd_init_req(&req, SD_OP_KILL_NODE);
ret = send_light_req(&req, sd_nodes[node_id].nid.addr,
sd_nodes[node_id].nid.port);
if (ret) {
sd_err("Failed to execute request");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
开发者ID:SongWuCloud,项目名称:ACStor,代码行数:29,代码来源:node.c
示例9: node_recovery
static int node_recovery(int argc, char **argv)
{
int i, ret;
if (!raw_output) {
printf("Nodes In Recovery:\n");
printf(" Id Host:Port V-Nodes Zone\n");
}
for (i = 0; i < sd_nodes_nr; i++) {
char host[128];
struct sd_node_req req;
addr_to_str(host, sizeof(host), sd_nodes[i].nid.addr, 0);
sd_init_req((struct sd_req *)&req, SD_OP_STAT_RECOVERY);
ret = send_light_req_get_response((struct sd_req *)&req, host,
sd_nodes[i].nid.port);
if (ret == SD_RES_NODE_IN_RECOVERY) {
addr_to_str(host, sizeof(host),
sd_nodes[i].nid.addr, sd_nodes[i].nid.port);
printf(raw_output ? "%d %s %d %d\n" : "%4d %-20s%5d%11d\n",
i, host, sd_nodes[i].nr_vnodes,
sd_nodes[i].zone);
}
}
return EXIT_SUCCESS;
}
开发者ID:ChrisChung,项目名称:sheepdog,代码行数:30,代码来源:node.c
示例10: sd_read_object
int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
uint64_t offset, bool direct)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int ret;
sd_init_req(&hdr, SD_OP_READ_OBJ);
hdr.data_length = datalen;
hdr.obj.oid = oid;
hdr.obj.offset = offset;
if (direct)
hdr.flags |= SD_FLAG_CMD_DIRECT;
ret = collie_exec_req(sdhost, sdport, &hdr, data);
if (ret < 0) {
fprintf(stderr, "Failed to read object %" PRIx64 "\n", oid);
return SD_RES_EIO;
}
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Failed to read object %" PRIx64 " %s\n", oid,
sd_strerror(rsp->result));
return rsp->result;
}
untrim_zero_sectors(data, rsp->obj.offset, rsp->data_length, datalen);
return SD_RES_SUCCESS;
}
开发者ID:wangfan188,项目名称:sheepdog,代码行数:31,代码来源:common.c
示例11: sd_read_object
int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
uint64_t offset, bool direct)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int ret;
sd_init_req(&hdr, SD_OP_READ_OBJ);
hdr.data_length = datalen;
hdr.obj.oid = oid;
hdr.obj.offset = offset;
if (direct)
hdr.flags |= SD_FLAG_CMD_DIRECT;
ret = dog_exec_req(&sd_nid, &hdr, data);
if (ret < 0) {
sd_err("Failed to read object %" PRIx64, oid);
return SD_RES_EIO;
}
if (rsp->result != SD_RES_SUCCESS) {
sd_err("Failed to read object %" PRIx64 " %s", oid,
sd_strerror(rsp->result));
return rsp->result;
}
return SD_RES_SUCCESS;
}
开发者ID:hadrienk,项目名称:sheepdog,代码行数:29,代码来源:common.c
示例12: list_store
static int list_store(void)
{
int fd, ret;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
char buf[512] = { 0 };
fd = connect_to(sdhost, sdport);
if (fd < 0)
return EXIT_SYSFAIL;
sd_init_req(&hdr, SD_OP_GET_STORE_LIST);
hdr.data_length = 512;
ret = exec_req(fd, &hdr, buf);
close(fd);
if (ret) {
fprintf(stderr, "Failed to connect\n");
return EXIT_SYSFAIL;
}
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Restore failed: %s\n",
sd_strerror(rsp->result));
return EXIT_FAILURE;
}
printf("Available stores:\n");
printf("---------------------------------------\n");
printf("%s\n", buf);
return EXIT_SYSFAIL;
}
开发者ID:cloudcache,项目名称:sheepdog,代码行数:33,代码来源:cluster.c
示例13: sd_write_object
int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
unsigned int datalen, uint64_t offset, uint32_t flags,
int copies, bool create, bool direct)
{
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
int fd, ret;
fd = connect_to(sdhost, sdport);
if (fd < 0) {
fprintf(stderr, "Failed to connect\n");
return SD_RES_EIO;
}
if (create)
sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
else
sd_init_req(&hdr, SD_OP_WRITE_OBJ);
hdr.data_length = datalen;
hdr.flags = flags | SD_FLAG_CMD_WRITE;
if (cow_oid)
hdr.flags |= SD_FLAG_CMD_COW;
if (direct)
hdr.flags |= SD_FLAG_CMD_DIRECT;
hdr.obj.copies = copies;
hdr.obj.oid = oid;
hdr.obj.cow_oid = cow_oid;
hdr.obj.offset = offset;
ret = collie_exec_req(fd, &hdr, data);
close(fd);
if (ret) {
fprintf(stderr, "Failed to write object %" PRIx64 "\n", oid);
return SD_RES_EIO;
}
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Failed to write object %" PRIx64 ": %s\n", oid,
sd_strerror(rsp->result));
return rsp->result;
}
return SD_RES_SUCCESS;
}
开发者ID:changguanghua,项目名称:sheepdog,代码行数:46,代码来源:common.c
示例14: update_node_list
int update_node_list(int max_nodes, uint32_t epoch)
{
int fd, ret;
unsigned int size;
char *buf = NULL;
struct sd_node *ent;
struct sd_node_req hdr;
struct sd_node_rsp *rsp = (struct sd_node_rsp *)&hdr;
fd = connect_to(sdhost, sdport);
if (fd < 0)
return -1;
size = sizeof(*ent) * max_nodes;
buf = xzalloc(size);
sd_init_req((struct sd_req *)&hdr, SD_OP_GET_NODE_LIST);
hdr.request_ver = epoch;
hdr.data_length = size;
ret = collie_exec_req(fd, (struct sd_req *)&hdr, buf);
if (ret) {
ret = -1;
goto out;
}
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Failed to update node list: %s\n",
sd_strerror(rsp->result));
ret = -1;
goto out;
}
size = rsp->data_length;
sd_nodes_nr = size / sizeof(*ent);
if (sd_nodes_nr == 0) {
fprintf(stderr, "There are no active sheep daemons\n");
exit(EXIT_FAILURE);
}
/* FIXME */
if (sd_nodes_nr > max_nodes) {
ret = -1;
goto out;
}
memcpy(sd_nodes, buf, size);
sd_vnodes_nr = nodes_to_vnodes(sd_nodes, sd_nodes_nr, sd_vnodes);
sd_epoch = hdr.epoch;
master_idx = rsp->master_idx;
out:
if (buf)
free(buf);
if (fd >= 0)
close(fd);
return ret;
}
开发者ID:Vinchal,项目名称:sheepdog,代码行数:58,代码来源:collie.c
示例15: node_info
static int node_info(int argc, char **argv)
{
int i, ret, success = 0;
uint64_t total_size = 0, total_avail = 0, total_vdi_size = 0;
char total_str[UINT64_DECIMAL_SIZE], avail_str[UINT64_DECIMAL_SIZE], vdi_size_str[UINT64_DECIMAL_SIZE];
if (!raw_output)
printf("Id\tSize\tUsed\tUse%%\n");
for (i = 0; i < sd_nodes_nr; i++) {
char host[128];
struct sd_node_req req;
struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
char store_str[UINT64_DECIMAL_SIZE], free_str[UINT64_DECIMAL_SIZE];
addr_to_str(host, sizeof(host), sd_nodes[i].nid.addr, 0);
sd_init_req((struct sd_req *)&req, SD_OP_STAT_SHEEP);
req.epoch = sd_epoch;
ret = send_light_req((struct sd_req *)&req, host,
sd_nodes[i].nid.port);
size_to_str(rsp->store_size, store_str, sizeof(store_str));
size_to_str(rsp->store_size - rsp->store_free, free_str,
sizeof(free_str));
if (!ret) {
printf(raw_output ? "%d %s %s %d%%\n" : "%2d\t%s\t%s\t%3d%%\n",
i, store_str, free_str,
rsp->store_size == 0 ? 0 :
(int)(((double)(rsp->store_size - rsp->store_free) / rsp->store_size) * 100));
success++;
}
total_size += rsp->store_size;
total_avail += rsp->store_free;
}
if (success == 0) {
fprintf(stderr, "Cannot get information from any nodes\n");
return EXIT_SYSFAIL;
}
if (parse_vdi(cal_total_vdi_size, SD_INODE_HEADER_SIZE,
&total_vdi_size) < 0)
return EXIT_SYSFAIL;
size_to_str(total_size, total_str, sizeof(total_str));
size_to_str(total_size - total_avail, avail_str, sizeof(avail_str));
size_to_str(total_vdi_size, vdi_size_str, sizeof(vdi_size_str));
printf(raw_output ? "Total %s %s %d%% %s\n"
: "Total\t%s\t%s\t%3d%%\n\nTotal virtual image size\t%s\n",
total_str, avail_str,
(int)(((double)(total_size - total_avail) / total_size) * 100),
vdi_size_str);
return EXIT_SUCCESS;
}
开发者ID:shenyibin,项目名称:sheepdog,代码行数:58,代码来源:node.c
示例16: find_vdi_name
static int find_vdi_name(char *vdiname, uint32_t snapid, const char *tag,
uint32_t *vid, int for_snapshot)
{
int ret, fd;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
unsigned int wlen, rlen = 0;
char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
fd = connect_to(sdhost, sdport);
if (fd < 0)
return -1;
memset(buf, 0, sizeof(buf));
strncpy(buf, vdiname, SD_MAX_VDI_LEN);
strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN);
if (for_snapshot)
sd_init_req(&hdr, SD_OP_GET_VDI_INFO);
else
sd_init_req(&hdr, SD_OP_LOCK_VDI);
wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;
hdr.data_length = wlen;
hdr.flags = SD_FLAG_CMD_WRITE;
hdr.vdi.snapid = snapid;
ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
if (ret) {
ret = -1;
goto out;
}
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Cannot get VDI info for %s %d %s: %s\n",
vdiname, snapid, tag, sd_strerror(rsp->result));
ret = -1;
goto out;
}
*vid = rsp->vdi.vdi_id;
ret = 0;
out:
close(fd);
return ret;
}
开发者ID:unakatsuo,项目名称:sheepdog,代码行数:45,代码来源:vdi.c
示例17: cluster_info
static int cluster_info(int argc, char **argv)
{
int i, ret;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
struct epoch_log *logs;
int nr_logs, log_length;
time_t ti, ct;
struct tm tm;
char time_str[128];
log_length = sd_epoch * sizeof(struct epoch_log);
logs = xmalloc(log_length);
sd_init_req(&hdr, SD_OP_STAT_CLUSTER);
hdr.data_length = log_length;
ret = dog_exec_req(&sd_nid, &hdr, logs);
if (ret < 0)
goto error;
/* show cluster status */
if (!raw_output)
printf("Cluster status: ");
if (rsp->result == SD_RES_SUCCESS)
printf("running, auto-recovery %s\n", logs->disable_recovery ?
"disabled" : "enabled");
else
printf("%s\n", sd_strerror(rsp->result));
/* show cluster backend store */
if (cluster_cmd_data.show_store) {
if (!raw_output)
printf("Cluster store: ");
if (rsp->result == SD_RES_SUCCESS) {
char copy[10];
int data, parity;
if (!logs->copy_policy)
snprintf(copy, sizeof(copy), "%d",
logs->nr_copies);
else {
ec_policy_to_dp(logs->copy_policy,
&data, &parity);
snprintf(copy, sizeof(copy), "%d:%d",
data, parity);
}
printf("%s with %s redundancy policy\n",
logs->drv_name, copy);
} else
printf("%s\n", sd_strerror(rsp->result));
}
if (!raw_output && rsp->data_length > 0) {
ct = logs[0].ctime >> 32;
printf("\nCluster created at %s\n", ctime(&ct));
printf("Epoch Time Version\n");
}
开发者ID:xtlx2000,项目名称:sheepdog,代码行数:57,代码来源:cluster.c
示例18: vdi_read_write
static int vdi_read_write(uint32_t vid, char *data, size_t length,
off_t offset, bool is_read)
{
struct sd_req hdr;
uint32_t idx = offset / SD_DATA_OBJ_SIZE;
uint64_t done = 0;
struct request_iocb *iocb;
int ret;
iocb = local_req_init();
if (!iocb)
return SD_RES_SYSTEM_ERROR;
offset %= SD_DATA_OBJ_SIZE;
while (done < length) {
size_t len = min(length - done, SD_DATA_OBJ_SIZE - offset);
if (is_read) {
sd_init_req(&hdr, SD_OP_READ_OBJ);
} else {
sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
hdr.flags = SD_FLAG_CMD_WRITE;
}
hdr.data_length = len;
hdr.obj.oid = vid_to_data_oid(vid, idx);
hdr.obj.offset = offset;
ret = exec_local_req_async(&hdr, data, iocb);
if (ret != SD_RES_SUCCESS)
sd_err("failed to write object %" PRIx64 ", %s",
hdr.obj.oid, sd_strerror(ret));
offset += len;
if (offset == SD_DATA_OBJ_SIZE) {
offset = 0;
idx++;
}
done += len;
data += len;
}
return local_req_wait(iocb);
}
开发者ID:skuanr,项目名称:sheepdog,代码行数:43,代码来源:kv.c
示例19: parse_vdi
int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
{
int ret;
unsigned long nr;
static struct sd_inode i;
struct sd_req req;
struct sd_rsp *rsp = (struct sd_rsp *)&req;
static DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
unsigned int rlen = sizeof(vdi_inuse);
sd_init_req(&req, SD_OP_READ_VDIS);
req.data_length = sizeof(vdi_inuse);
ret = dog_exec_req(sdhost, sdport, &req, &vdi_inuse);
if (ret < 0)
goto out;
if (rsp->result != SD_RES_SUCCESS) {
sd_err("%s", sd_strerror(rsp->result));
goto out;
}
FOR_EACH_VDI(nr, vdi_inuse) {
uint64_t oid;
uint32_t snapid;
oid = vid_to_vdi_oid(nr);
memset(&i, 0, sizeof(i));
ret = sd_read_object(oid, &i, SD_INODE_HEADER_SIZE, 0, true);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to read inode header");
continue;
}
if (i.name[0] == '\0') /* this VDI has been deleted */
continue;
if (size > SD_INODE_HEADER_SIZE) {
rlen = DIV_ROUND_UP(i.vdi_size, SD_DATA_OBJ_SIZE) *
sizeof(i.data_vdi_id[0]);
if (rlen > size - SD_INODE_HEADER_SIZE)
rlen = size - SD_INODE_HEADER_SIZE;
ret = sd_read_object(oid, ((char *)&i) + SD_INODE_HEADER_SIZE,
rlen, SD_INODE_HEADER_SIZE, true);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to read inode");
continue;
}
}
snapid = vdi_is_snapshot(&i) ? i.snap_id : 0;
func(i.vdi_id, i.name, i.tag, snapid, 0, &i, data);
}
开发者ID:sglwlb,项目名称:sheepdog,代码行数:55,代码来源:common.c
示例20: trace_read_buffer
static int trace_read_buffer(void)
{
int fd, ret, tfd;
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
unsigned rlen, wlen;
#define TRACE_BUF_LEN (1024 * 1024 * 20)
char *buf = xzalloc(TRACE_BUF_LEN);
tfd = open(tracefile, O_CREAT | O_RDWR | O_APPEND | O_TRUNC, 0644);
if (tfd < 0) {
fprintf(stderr, "can't create tracefile\n");
return EXIT_SYSFAIL;
}
fd = connect_to(sdhost, sdport);
if (fd < 0)
return EXIT_SYSFAIL;
read_buffer:
sd_init_req(&hdr, SD_OP_TRACE_READ_BUF);
hdr.data_length = rlen = TRACE_BUF_LEN;
hdr.epoch = sd_epoch;
wlen = 0;
ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
if (ret) {
fprintf(stderr, "Failed to connect\n");
close(fd);
return EXIT_SYSFAIL;
}
if (rsp->result == SD_RES_AGAIN)
goto read_buffer;
if (rsp->result != SD_RES_SUCCESS) {
fprintf(stderr, "Trace failed: %s\n",
sd_strerror(rsp->result));
close(fd);
return EXIT_FAILURE;
}
xwrite(tfd, buf, rlen);
if (rlen == TRACE_BUF_LEN) {
memset(buf, 0, TRACE_BUF_LEN);
goto read_buffer;
}
close(fd);
free(buf);
return EXIT_SUCCESS;
}
开发者ID:shenyibin,项目名称:sheepdog,代码行数:53,代码来源:debug.c
注:本文中的sd_init_req函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论