本文整理汇总了C++中sd_init_req函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_init_req函数的具体用法?C++ sd_init_req怎么用?C++ sd_init_req使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_init_req函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}