From b84f473a163ef6a8367550366610c2c4039f3c5d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 14 Apr 2010 10:40:16 +0200 Subject: [PATCH] Cleanup restore_object packet --- bacula/src/cats/cats.h | 5 +---- bacula/src/cats/sql_create.c | 16 ++++++---------- bacula/src/dird/catreq.c | 6 +++--- bacula/src/dird/fd_cmds.c | 21 ++++++++++----------- bacula/src/filed/fd_plugins.h | 5 +++-- bacula/src/filed/job.c | 14 +++++--------- bacula/src/plugins/fd/test-plugin-fd.c | 6 +++--- 7 files changed, 31 insertions(+), 42 deletions(-) diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 423004ebd3..1dc05e8d98 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -940,10 +940,7 @@ struct ATTR_DBR { }; struct ROBJECT_DBR { - char *full_fname; - char *fname; - char *path; - char *plugin_name; + char *object_name; char *object; uint32_t object_len; uint32_t ObjectIndex; diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 10ff580840..44e016c465 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -1267,25 +1267,21 @@ bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ro) POOLMEM *esc_obj = get_pool_memory(PM_MESSAGE); db_lock(mdb); - Dmsg1(dbglevel, "Fname=%s\n", ro->fname); + Dmsg1(dbglevel, "Oname=%s\n", ro->object_name); Dmsg0(dbglevel, "put_object_into_catalog\n"); - split_path_and_file(jcr, mdb, ro->full_fname); - + mdb->fnl = strlen(ro->object_name); mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->fnl*2+1); - db_escape_string(jcr, mdb, mdb->esc_name, mdb->fname, mdb->fnl); + db_escape_string(jcr, mdb, mdb->esc_name, ro->object_name, mdb->fnl); - mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1); - db_escape_string(jcr, mdb, mdb->esc_path, mdb->path, mdb->pnl); - esc_obj = check_pool_memory_size(esc_obj, ro->object_len*2+1); db_escape_string(jcr, mdb, esc_obj, ro->object, ro->object_len); Mmsg(mdb->cmd, - "INSERT INTO RestoreObject (Fname,Path,PluginName,RestoreObject," + "INSERT INTO RestoreObject (Fname,RestoreObject," "ObjectLength,ObjectIndex,ObjectType,FileIndex,JobId) VALUES" - "('%s','%s','%s','%s',%d,%d,%d,%d,%u)", - mdb->esc_name, mdb->esc_path, mdb->esc_path, esc_obj, ro->object_len, + "('%s','%s',%d,%d,%d,%d,%u)", + mdb->esc_name, esc_obj, ro->object_len, ro->ObjectIndex, FT_RESTORE_FIRST, ro->FileIndex, ro->JobId); ro->RestoreObjectId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("RestoreObject")); diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 1f765da18b..5627db5942 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -456,7 +456,7 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) POOLMEM *attrEx = get_pool_memory(PM_MESSAGE); char *p; memset(&ro, 0, sizeof(ro)); - ro.full_fname = fname; + ro.object_name = fname; ro.Stream = Stream; ro.FileType = ar->FileType; ro.FileIndex = FileIndex; @@ -474,8 +474,8 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) /* Add a EOS for those who attempt to print the object */ p = attrEx + ro.object_len; *p = 0; - Dmsg7(000, "fname=%s stream=%d FT=%d FI=%d JobId=%d, obj_len=%d\nobj=\"%s\"\n", - ro.full_fname, ro.Stream, ro.FileType, ro.FileIndex, ro.JobId, + Dmsg7(000, "oname=%s stream=%d FT=%d FI=%d JobId=%d, obj_len=%d\nobj=\"%s\"\n", + ro.object_name, ro.Stream, ro.FileType, ro.FileIndex, ro.JobId, ro.object_len, attrEx); /* Send it */ if (!db_create_restore_object_record(jcr, jcr->db, &ro)) { diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index a500840644..94b58dd220 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -679,17 +679,16 @@ static int restore_object_handler(void *ctx, int num_fields, char **row) return 1; } fd->fsend("restoreobject JobId=%s ObjLen=%s ObjInx=%s ObjType=%s FI=%s\n", - row[0], row[3], row[6], row[7], row[8]); + row[0], row[1], row[2], row[3], row[4]); - fd->fsend("%s", row[1]); /* send Fname */ -// Dmsg1(000, "Send obj: %s\n", fd->msg); - - fd->fsend("%s", row[2]); /* send Path */ + msg_save = fd->msg; + fd->msg = row[5] ? row[5] : (char *)""; + fd->msglen = strlen(fd->msg); + fd->send(); /* send Object name */ // Dmsg1(000, "Send obj: %s\n", fd->msg); - msg_save = fd->msg; - fd->msg = row[4]; /* object */ - fd->msglen = str_to_uint64(row[3]); /* object length */ + fd->msg = row[6] ? row[6] : (char *)""; /* object */ + fd->msglen = str_to_uint64(row[1]); /* object length */ fd->send(); /* send object */ // Dmsg1(000, "Send obj: %s\n", fd->msg); fd->msg = msg_save; @@ -706,9 +705,9 @@ bool send_restore_objects(JCR *jcr) if (!jcr->JobIds || !jcr->JobIds[0]) { return true; } - Mmsg(query, "SELECT JobId,Fname,Path,ObjectLength,RestoreObject," - "PluginName,ObjectIndex,ObjectType,FileIndex " - "FROM RestoreObject WHERE JobId IN (%s)", jcr->JobIds); + Mmsg(query, "SELECT JobId,ObjectLength,ObjectIndex,ObjectType," + "FileIndex,Fname,RestoreObject FROM RestoreObject " + "WHERE JobId IN (%s) ORDER BY ObjectIndex ASC", jcr->JobIds); /* restore_object_handler is called for each file found */ db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)jcr); diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 7c37eaffcf..963451b4b4 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -77,11 +77,12 @@ */ struct restore_object_pkt { int32_t pkt_size; /* size of this packet */ - char *fname; /* Full path and filename */ - int32_t object_type; /* FT_xx for this file */ + char *object_name; /* Object name */ char *object; /* restore object data to save */ + int32_t object_type; /* FT_xx for this file */ int32_t object_len; /* restore object length */ int32_t object_index; /* restore object index */ + int32_t stream; /* attribute stream id */ uint32_t JobId; /* JobId object came from */ int32_t pkt_end; /* end packet sentinel */ }; diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 66bf6c9735..b11466128a 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -647,17 +647,13 @@ static int restore_object_cmd(JCR *jcr) // Dmsg5(000, "Recv object: JobId=%u objlen=%d objinx=%d objtype=%d FI=%d\n", // JobId, object_len, object_index, object_type, FileIndex); - /* Read Fname */ + /* Read Object name */ if (dir->recv() < 0) { goto bail_out; } -// Dmsg2(000, "Recv Fname object: len=%d Fname=%s\n", dir->msglen, dir->msg); - rop.fname = bstrdup(dir->msg); +// Dmsg2(000, "Recv Fname object: len=%d Oname=%s\n", dir->msglen, dir->msg); + rop.object_name = bstrdup(dir->msg); - /* Read Path */ - if (dir->recv() < 0) { - goto bail_out; - } // Dmsg2(000, "Recv Path object: len=%d Path=%s\n", dir->msglen, dir->msg); /* Read Object */ @@ -670,8 +666,8 @@ static int restore_object_cmd(JCR *jcr) /* pass to plugin */ generate_plugin_event(jcr, bEventRestoreObject, (void *)&rop); - if (rop.fname) { - free(rop.fname); + if (rop.object_name) { + free(rop.object_name); } if (!rop.object) { dir->msg = get_pool_memory(PM_MESSAGE); diff --git a/bacula/src/plugins/fd/test-plugin-fd.c b/bacula/src/plugins/fd/test-plugin-fd.c index 8165499f1e..8a239e8b95 100644 --- a/bacula/src/plugins/fd/test-plugin-fd.c +++ b/bacula/src/plugins/fd/test-plugin-fd.c @@ -238,8 +238,8 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) break; } rop = (restore_object_pkt *)value; - bfuncs->DebugMessage(ctx, fi, li, dbglvl, "test-plugin-fd: len=%d JobId=%d fname=%s\n", - rop->object_len, rop->JobId, rop->fname); + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "test-plugin-fd: len=%d JobId=%d oname=%s\n", + rop->object_len, rop->JobId, rop->object_name); break; /* Plugin command e.g. plugin = ::read command:write command */ case bEventRestoreCommand: @@ -290,7 +290,7 @@ static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp) return bRC_Error; } time_t now = time(NULL); - sp->fname = p_ctx->fname; + sp->fname = (char *)"james.xml"; sp->object = (char *)"This is test data for the restore object."; sp->object_len = strlen(sp->object); sp->index = 2; -- 2.39.5