From 1b73c971fbd3d0a6fbcb3a280c4322668411325e Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 12 Aug 2009 12:09:53 +0200 Subject: [PATCH] Add .lsfiles, .lsdirs, .update command to interface user with bvfs object --- bacula/src/cats/bvfs.c | 1 + bacula/src/dird/ua_dotcmds.c | 158 +++++++++++++++++++++++++++++++++++ bacula/technotes | 2 + 3 files changed, 161 insertions(+) diff --git a/bacula/src/cats/bvfs.c b/bacula/src/cats/bvfs.c index 570e074acc..c27ab50fce 100644 --- a/bacula/src/cats/bvfs.c +++ b/bacula/src/cats/bvfs.c @@ -438,6 +438,7 @@ void bvfs_update_cache(JCR *jcr, B_DB *mdb) Dmsg1(dbglevel, "Affected row(s) = %d\n", nb); db_end_transaction(jcr, mdb); + free_pool_memory(jobids); } /* diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 462d8ed27a..7f5f4cb591 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -40,6 +40,8 @@ #include "bacula.h" #include "dird.h" +#include "cats/bvfs.h" +#include "findlib/find.h" /* Imported variables */ @@ -64,6 +66,10 @@ static bool backupscmd(UAContext *ua, const char *cmd); static bool levelscmd(UAContext *ua, const char *cmd); static bool getmsgscmd(UAContext *ua, const char *cmd); +static bool dot_lsdirs(UAContext *ua, const char *cmd); +static bool dot_lsfiles(UAContext *ua, const char *cmd); +static bool dot_update(UAContext *ua, const char *cmd); + static bool api_cmd(UAContext *ua, const char *cmd); static bool sql_cmd(UAContext *ua, const char *cmd); static bool dot_quit_cmd(UAContext *ua, const char *cmd); @@ -88,6 +94,9 @@ static struct cmdstruct commands[] = { /* help */ /* can be used in runscript * { NT_(".sql"), sql_cmd, NULL, false}, { NT_(".status"), dot_status_cmd, NULL, false}, { NT_(".storage"), storagecmd, NULL, true}, + { NT_(".lsdirs"), dot_lsdirs, NULL, true}, + { NT_(".lsfiles"), dot_lsfiles, NULL, true}, + { NT_(".update"), dot_update, NULL, true}, { NT_(".types"), typescmd, NULL, false} }; #define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct))) @@ -145,6 +154,155 @@ bool do_a_dot_command(UAContext *ua) return ok; } +static bool dot_update(UAContext *ua, const char *cmd) +{ + if (!open_client_db(ua)) { + return 1; + } + + int pos = find_arg_with_value(ua, "jobid"); + if (pos != -1) { /* find jobid arg */ + if (is_a_number_list(ua->argv[pos])) { + bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, ua->argv[pos]); + } + } else { + /* update cache for all jobids */ + bvfs_update_cache(ua->jcr, ua->db); + } + return true; +} + +static int bvfs_result_handler(void *ctx, int fields, char **row) +{ + UAContext *ua = (UAContext *)ctx; + struct stat statp; + int32_t LinkFI; + char empty[] = "A A A A A A A A A A A A A A"; + + memset(&statp, 0, sizeof(struct stat)); + decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty, + &statp, &LinkFI); + + if (fields == BVFS_DIR_RECORD) { + char *path = bvfs_basename_dir(row[BVFS_Name]); + ua->send_msg("%s\t%s\t\%s\n", row[BVFS_Id], row[BVFS_JobId], path); + } else if (fields == BVFS_FILE_RECORD) { + ua->send_msg("%s\t%s\t\%s\n", row[BVFS_Id], row[BVFS_JobId], row[BVFS_Name]); + } + + return 0; +} + +static bool bvfs_parse_arg(UAContext *ua, + DBId_t *pathid, char **path, char **jobid, + int *limit, int *offset) +{ + *pathid=0; + *limit=2000; + *offset=0; + *path=NULL; + *jobid=NULL; + + for (int i=1; iargc; i++) { + if (strcasecmp(ua->argk[i], NT_("pathid")) == 0) { + if (is_a_number(ua->argv[i])) { + *pathid = str_to_int64(ua->argv[i]); + } + } + if (strcasecmp(ua->argk[i], NT_("path")) == 0) { + *path = ua->argv[i]; + } + + if (strcasecmp(ua->argk[i], NT_("jobid")) == 0) { + if (is_a_number_list(ua->argv[i])) { + *jobid = ua->argv[i]; + } + } + + if (strcasecmp(ua->argk[i], NT_("limit")) == 0) { + if (is_a_number(ua->argv[i])) { + *limit = str_to_int64(ua->argv[i]); + } + } + + if (strcasecmp(ua->argk[i], NT_("offset")) == 0) { + if (is_a_number(ua->argv[i])) { + *offset = str_to_int64(ua->argv[i]); + } + } + } + + if (!((pathid || path) && jobid)) { + return false; + } + + if (!open_client_db(ua)) { + return 1; + } + + return true; +} + +static bool dot_lsfiles(UAContext *ua, const char *cmd) +{ + DBId_t pathid=0; + int limit=2000, offset=0; + char *path=NULL, *jobid=NULL; + + if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, + &limit, &offset)) + { + ua->error_msg("Can't find jobid, pathid or path argument\n"); + return true; /* not enough param */ + } + + Bvfs fs(ua->jcr, ua->db); + fs.set_jobids(jobid); + fs.set_limit(limit); + fs.set_offset(offset); + fs.set_handler(bvfs_result_handler, ua); + + if (pathid) { + fs.ch_dir(pathid); + } else { + fs.ch_dir(path); + } + + fs.ls_files(); + + return true; +} + +static bool dot_lsdirs(UAContext *ua, const char *cmd) +{ + DBId_t pathid=0; + int limit=2000, offset=0; + char *path=NULL, *jobid=NULL; + + if (!bvfs_parse_arg(ua, &pathid, &path, &jobid, + &limit, &offset)) + { + ua->error_msg("Can't find jobid, pathid or path argument\n"); + return true; /* not enough param */ + } + + Bvfs fs(ua->jcr, ua->db); + fs.set_jobids(jobid); + fs.set_limit(limit); + fs.set_offset(offset); + fs.set_handler(bvfs_result_handler, ua); + + if (pathid) { + fs.ch_dir(pathid); + } else { + fs.ch_dir(path); + } + + fs.ls_dirs(); + + return true; +} + static bool dot_quit_cmd(UAContext *ua, const char *cmd) { quit_cmd(ua, cmd); diff --git a/bacula/technotes b/bacula/technotes index a2f7bf3403..83c8c00211 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +12Aug09 +ebl Add .lsfiles, .lsdirs, .update command to interface user with bvfs object 10Aug09 kes Pull Philipp Storz' bacula.spec changes for OpenSuSE build service kes Implement MaximumConcurrentJobs for SD devices. -- 2.39.5