static int cluster_format(int argc, char **argv) { int fd, ret; struct sd_so_req hdr; struct sd_so_rsp *rsp = (struct sd_so_rsp *)&hdr; unsigned rlen, wlen; struct timeval tv; char store_name[STORE_LEN]; fd = connect_to(sdhost, sdport); if (fd < 0) return EXIT_SYSFAIL; gettimeofday(&tv, NULL); memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_MAKE_FS; hdr.copies = cluster_cmd_data.copies; if (cluster_cmd_data.nohalt) set_nohalt(&hdr.flags); hdr.epoch = node_list_version; hdr.ctime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000; if (strlen(cluster_cmd_data.name)) strncpy(store_name, cluster_cmd_data.name, STORE_LEN); else strcpy(store_name, DEFAULT_STORE); hdr.data_length = wlen = strlen(store_name) + 1; hdr.flags |= SD_FLAG_CMD_WRITE; printf("using backend %s store\n", store_name); ret = exec_req(fd, (struct sd_req *)&hdr, store_name, &wlen, &rlen); close(fd); if (ret) { fprintf(stderr, "Failed to connect\n"); return EXIT_SYSFAIL; } if (rsp->result != SD_RES_SUCCESS) { fprintf(stderr, "Format failed: %s\n", sd_strerror(rsp->result)); return list_store(); } return EXIT_SUCCESS; }
static int cluster_format(int argc, char **argv) { int fd, ret; struct sd_so_req hdr; struct sd_so_rsp *rsp = (struct sd_so_rsp *)&hdr; unsigned rlen, wlen; struct timeval tv; fd = connect_to(sdhost, sdport); if (fd < 0) return EXIT_SYSFAIL; gettimeofday(&tv, NULL); memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_MAKE_FS; hdr.copies = cluster_cmd_data.copies; if (cluster_cmd_data.nohalt) set_nohalt(&hdr.flags); hdr.epoch = node_list_version; hdr.ctime = (uint64_t) tv.tv_sec << 32 | tv.tv_usec * 1000; rlen = 0; wlen = 0; ret = exec_req(fd, (struct sd_req *)&hdr, NULL, &wlen, &rlen); close(fd); if (ret) { fprintf(stderr, "failed to connect\n"); return EXIT_SYSFAIL; } if (rsp->result != SD_RES_SUCCESS) { fprintf(stderr, "%s\n", sd_strerror(rsp->result)); return EXIT_FAILURE; } return EXIT_SUCCESS; }