29 #include <sys/types.h> 33 #include <editline/readline.h> 39 static const char RCFILE[] =
".hsm/config";
92 fprintf(stderr,
"m0_client_init() failed: %d\n",
rc);
100 fprintf(stderr,
"m0_container_init() failed: %d\n",
rc);
132 #define IO_SIZE (1024 * 1024) 141 fd = open(path, O_RDONLY);
143 fprintf(stderr,
"open '%s' failed: %s\n", path,
151 fprintf(stderr,
"failed to allocate IO buffer\n");
167 while ((read_nr = read(
fd, io_buff,
IO_SIZE)) > 0) {
170 fprintf(stderr,
"error on writting at %zu to " 181 fprintf(stderr,
"error after reading %zu bytes from '%s': %s\n",
182 (
size_t)off, path, strerror(errno));
197 fprintf(stderr,
"%s environment variable is not set\n", env);
218 printf(
"Usage: m0hsm <action> <fid> [...]\n");
219 printf(
" actions:\n");
220 printf(
" create <fid> <tier>\n");
221 printf(
" show <fid>\n");
222 printf(
" dump <fid>\n");
223 printf(
" write <fid> <offset> <len> <seed>\n");
224 printf(
" write_file <fid> <path>\n");
225 printf(
" read <fid> <offset> <len>\n");
226 printf(
" copy <fid> <offset> <len> <src_tier> " 227 "<tgt_tier> [options: mv,keep_prev,w2dest]\n");
228 printf(
" move <fid> <offset> <len> <src_tier> " 229 "<tgt_tier> [options: keep_prev,w2dest]\n");
230 printf(
" stage <fid> <offset> <len> <tgt_tier> " 231 "[options: mv,w2dest]\n");
232 printf(
" archive <fid> <offset> <len> <tgt_tier> " 233 "[options: mv,keep_prev,w2dest]\n");
234 printf(
" release <fid> <offset> <len> <tier> " 235 "[options: keep_latest]\n");
236 printf(
" multi_release <fid> <offset> <len> <max_tier> " 237 "[options: keep_latest]\n");
238 printf(
" set_write_tier <fid> <tier>\n\n");
239 printf(
" <fid> parameter format is [hi:]lo. " 240 "(hi == 0 if not specified.)\n");
241 printf(
" The numbers are read in decimal, hexadecimal " 242 "(when prefixed with `0x')\n" 243 " or octal (when prefixed with `0') formats.\n");
253 if (sscanf(
s,
"%lli", &ll) != 1)
268 res = sscanf(
s,
"%lli:%lli", &
hi, &lo);
272 }
else if (
res == 2) {
284 OPT_KEEP_PREV_VERS = 1,
285 OPT_WRITE_TO_DEST = 2,
289 [OPT_KEEP_PREV_VERS] =
"keep_prev",
290 [OPT_WRITE_TO_DEST] =
"w2dest",
293 char *subopts = opts;
296 while (*subopts !=
'\0') {
302 case OPT_KEEP_PREV_VERS:
306 case OPT_WRITE_TO_DEST:
310 fprintf(stderr,
"Unexpected option: %s\n",
value);
323 [OPT_KEEP_LATEST] =
"keep_latest",
326 char *subopts = opts;
329 while (*subopts !=
'\0') {
331 case OPT_KEEP_LATEST:
336 fprintf(stderr,
"Unexpected option: %s\n",
value);
344 {
"quiet", no_argument,
NULL,
'q'},
345 {
"verbose", required_argument,
NULL,
'v'},
347 #define SHORT_OPT "qv" 351 int c, option_index = 0;
354 &option_index)) != -1) {
413 tier = atoi(argv[
optind]);
485 src_tier = atoi(argv[
optind]);
487 tgt_tier = atoi(argv[
optind]);
518 tgt_tier = atoi(argv[
optind]);
545 tgt_tier = atoi(argv[
optind]);
572 tier = atoi(argv[
optind]);
595 tier = atoi(argv[
optind]);
608 #define SH_TOK_BUFSIZE 64 609 #define SH_TOK_DELIM " \t\r\n\a" 613 char **tokens = malloc(bufsize *
sizeof(
char*)), **tt;
617 fprintf(stderr,
"m0hsm: allocation error\n");
627 tokens[position] =
token;
630 if (position >= bufsize) {
632 tt = realloc(tokens, bufsize *
sizeof(
char*));
634 fprintf(stderr,
"m0hsm: allocation error\n");
642 tokens[position] =
NULL;
661 line = readline(
"m0hsm> ");
664 if (strlen(line) > 0)
680 int main(
int argc,
char **argv)
687 rcfile = fopen(rcpath,
"r");
688 if (rcfile ==
NULL) {
689 fprintf(stderr,
"m0hsm: error on opening %s file: %s\n",
690 rcpath, strerror(errno));
709 fprintf(stderr,
"m0hsm: error: client_init() failed!\n");
718 fprintf(stderr,
"m0hsm: error: m0hsm_init() failed!\n");
int m0hsm_archive(struct m0_uint128 id, uint8_t tgt_tier, off_t offset, size_t length, enum hsm_cp_flags flags)
void m0_entity_fini(struct m0_entity *entity)
int const char const void size_t int flags
int m0hsm_stage(struct m0_uint128 id, uint8_t tgt_tier, off_t offset, size_t length, enum hsm_cp_flags flags)
void m0_op_fini(struct m0_op *op)
static struct m0_client * instance
struct m0hsm_options options
int m0hsm_multi_release(struct m0_uint128 id, uint8_t max_tier, off_t offset, size_t length, enum hsm_rls_flags flags)
enum hsm_log_level trace_level
static struct m0_realm uber_realm
void m0_client_fini(struct m0_client *m0c, bool fini_m0)
int const char const void * value
uint64_t m0_client_layout_id(const struct m0_client *instance)
int m0_client_init(struct m0_client **m0c, struct m0_config *conf, bool init_m0)
const struct m0_uint128 M0_UBER_REALM
static void client_fini(void)
static const struct option option_tab[]
const struct m0_uint128 M0_ID_APP
int32_t m0_op_wait(struct m0_op *op, uint64_t bits, m0_time_t to)
int m0hsm_dump(FILE *stream, struct m0_uint128 id, bool details)
static int run_cmd(int argc, char **argv)
static int load_client_env()
struct m0_entity re_entity
int64_t read_arg64(const char *s)
char ** sh_split_line(char *line, int *argc)
static struct m0_addb2_callback c
static int client_init(void)
void m0_op_launch(struct m0_op **op, uint32_t nr)
int m0hsm_pwrite(struct m0_obj *obj, void *buffer, size_t length, off_t offset)
int m0hsm_test_write(struct m0_uint128 id, off_t offset, size_t len, int seed)
static int open_entity(struct m0_entity *entity)
static int parse_cmd_options(int argc, char **argv)
static struct m0_idx_dix_config dix_conf
static int load_env(char **tgt, const char *env)
static const char RCFILE[]
struct m0hsm_options hsm_options
int m0hsm_copy(struct m0_uint128 id, uint8_t src_tier, uint8_t tgt_tier, off_t offset, size_t len, enum hsm_cp_flags flags)
static void token(struct ff2c_context *ctx, struct ff2c_term *term, struct ff2c_token *tok)
int read_fid(const char *s, struct m0_uint128 *fid)
static m0_bindex_t offset
struct m0_pdclust_tgt_addr tgt
static struct m0_container container
static int parse_copy_subopt(char *opts, enum hsm_cp_flags *flags)
int main(int argc, char **argv)
int m0hsm_init(struct m0_client *instance, struct m0_realm *uber_realm, const struct m0hsm_options *in_options)
m0_time_t m0_time_from_now(uint64_t secs, long ns)
int m0hsm_create(struct m0_uint128 id, struct m0_obj *obj, uint8_t tier_idx, bool keep_open)
static int parse_release_subopt(char *opts, enum hsm_rls_flags *flags)
int m0hsm_release(struct m0_uint128 id, uint8_t tier, off_t offset, size_t len, enum hsm_rls_flags flags)
void m0_obj_init(struct m0_obj *obj, struct m0_realm *parent, const struct m0_uint128 *id, uint64_t layout_id)
struct m0t1fs_filedata * fd
int m0hsm_set_write_tier(struct m0_uint128 id, uint8_t tier_idx)
int fini(struct workload *w)
int m0hsm_test_read(struct m0_uint128 id, off_t offset, size_t len)
static int m0hsm_write_file(struct m0_uint128 id, const char *path)
void m0_container_init(struct m0_container *con, struct m0_realm *parent, const struct m0_uint128 *id, struct m0_client *instance)
void m0_op_free(struct m0_op *op)
int m0_entity_open(struct m0_entity *entity, struct m0_op **op)
static struct m0_addb2_source * s