+static int client_loglevel = LL_ERROR;
+DEFINE_STDERR_LOGGER(stderr_log, client_loglevel);
+__printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log;
+
+#ifdef HAVE_READLINE
+#include "interactive.h"
+#include "server_completion.h"
+#include "afs_completion.h"
+
+struct exec_task {
+ struct task task;
+ struct btr_node *btrn;
+ char *result_buf;
+ size_t result_size;
+};
+
+static void exec_pre_select(struct sched *s, struct task *t)
+{
+ struct exec_task *et = container_of(t, struct exec_task, task);
+ int ret = btr_node_status(et->btrn, 0, BTR_NT_LEAF);
+
+ if (ret != 0)
+ sched_min_delay(s);
+}
+
+static int exec_post_select(__a_unused struct sched *s, struct task *t)
+{
+ struct exec_task *et = container_of(t, struct exec_task, task);
+ struct btr_node *btrn = et->btrn;
+ char *buf;
+ size_t sz;
+ int ret;
+
+ ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
+ if (ret <= 0)
+ return ret;
+ sz = btr_next_buffer(btrn, &buf);
+ if (sz <= 1)
+ goto out;
+ et->result_buf = para_realloc(et->result_buf, et->result_size + sz - 1);
+ memcpy(et->result_buf + et->result_size - 1, buf, sz - 1);
+ et->result_size += sz - 1;
+ et->result_buf[et->result_size - 1] = '\0';
+out:
+ btr_consume(btrn, sz);
+ return 0;
+}
+
+static int make_client_argv(const char *line)
+{
+ int ret;
+
+ free_argv(ct->conf.inputs);
+ ret = create_argv(line, " ", &ct->conf.inputs);
+ if (ret >= 0)
+ ct->conf.inputs_num = ret;
+ return ret;
+}
+
+static int execute_client_command(const char *cmd, char **result)
+{
+ int ret;
+ struct sched command_sched = {.default_timeout = {.tv_sec = 1}};
+ struct exec_task exec_task = {
+ .task = {
+ .pre_select = exec_pre_select,
+ .post_select = exec_post_select,
+ .status = "client exec task",
+ },
+ .result_buf = para_strdup(""),
+ .result_size = 1,
+ };
+ *result = NULL;
+ ret = make_client_argv(cmd);
+ if (ret < 0)
+ goto out;
+ exec_task.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "exec_collect"));
+ register_task(&command_sched, &exec_task.task);
+ ret = client_connect(ct, &command_sched, NULL, exec_task.btrn);
+ if (ret < 0)
+ goto out;
+ schedule(&command_sched);
+ *result = exec_task.result_buf;
+ btr_remove_node(&exec_task.btrn);
+ ret = 1;
+out:
+ btr_remove_node(&exec_task.btrn);
+ if (ret < 0)
+ free(exec_task.result_buf);
+ return ret;
+}
+
+static int extract_matches_from_command(const char *word, char *cmd,
+ char ***matches)
+{
+ char *buf, **sl;
+ int ret;
+
+ ret = execute_client_command(cmd, &buf);
+ if (ret < 0)
+ return ret;
+ ret = create_argv(buf, "\n", &sl);
+ free(buf);
+ if (ret < 0)
+ return ret;
+ ret = i9e_extract_completions(word, sl, matches);
+ free_argv(sl);
+ return ret;
+}
+
+static int complete_attributes(const char *word, char ***matches)
+{
+ return extract_matches_from_command(word, "lsatt", matches);
+}
+
+static void complete_addblob(__a_unused const char *blob_type,
+ __a_unused struct i9e_completion_info *ci,
+ __a_unused struct i9e_completion_result *cr)
+{
+ cr->filename_completion_desired = true;
+}
+
+static void generic_blob_complete(const char *blob_type,
+ struct i9e_completion_info *ci,
+ struct i9e_completion_result *cr)
+{
+ char cmd[20];
+ sprintf(cmd, "ls%s", blob_type);
+ extract_matches_from_command(ci->word, cmd, &cr->matches);
+}
+
+static void complete_catblob(const char *blob_type,
+ struct i9e_completion_info *ci,
+ struct i9e_completion_result *cr)
+{
+ generic_blob_complete(blob_type, ci, cr);
+}
+
+static void complete_lsblob(const char *blob_type,
+ struct i9e_completion_info *ci,
+ struct i9e_completion_result *cr)
+{
+ char *opts[] = {"-i", "-l", "-r", NULL};
+
+ if (ci->word[0] == '-')
+ return i9e_complete_option(opts, ci, cr);
+ generic_blob_complete(blob_type, ci, cr);
+}
+
+static void complete_rmblob(const char *blob_type,
+ struct i9e_completion_info *ci,
+ struct i9e_completion_result *cr)