Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make btape use a BTAPE_DCR instead of a DCR
After the changes introduced with commit
8a90b58
( Implement the DCR (Device Control Record)
  as an inherited class of SMARTALLOC)
, btape used the wrong type of DCR.

Now we use a BTAPE_DCR.

Fixes #400: btape fill test fails
  • Loading branch information
pstorz authored and Marco van Wieringen committed Feb 17, 2015
1 parent a226e41 commit 2487305
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 25 deletions.
13 changes: 11 additions & 2 deletions src/stored/bcopy.c
Expand Up @@ -83,6 +83,7 @@ int main (int argc, char *argv[])
char *DirectorName = NULL;
DIRRES *director = NULL;
bool ignore_label_errors = false;
DCR *in_dcr, *out_dcr;

setlocale(LC_ALL, "");
bindtextdomain("bareos", LOCALEDIR);
Expand Down Expand Up @@ -191,11 +192,15 @@ int main (int argc, char *argv[])
* Setup and acquire input device for reading
*/
Dmsg0(100, "About to setup input jcr\n");
in_jcr = setup_jcr("bcopy", argv[0], bsr, director, iVolumeName, true); /* read device */

in_dcr = New(DCR);
in_jcr = setup_jcr("bcopy", argv[0], bsr, director, in_dcr, iVolumeName, true); /* read device */
if (!in_jcr) {
exit(1);
}

in_jcr->ignore_label_errors = ignore_label_errors;

in_dev = in_jcr->dcr->dev;
if (!in_dev) {
exit(1);
Expand All @@ -205,14 +210,18 @@ int main (int argc, char *argv[])
* Setup output device for writing
*/
Dmsg0(100, "About to setup output jcr\n");
out_jcr = setup_jcr("bcopy", argv[1], bsr, director, oVolumeName, false); /* write device */

out_dcr = New(DCR);
out_jcr = setup_jcr("bcopy", argv[1], bsr, director, out_dcr, oVolumeName, false); /* write device */
if (!out_jcr) {
exit(1);
}

out_dev = out_jcr->dcr->dev;
if (!out_dev) {
exit(1);
}

Dmsg0(100, "About to acquire device for writing\n");

/*
Expand Down
3 changes: 2 additions & 1 deletion src/stored/bextract.c
Expand Up @@ -384,7 +384,8 @@ static void do_extract(char *devname)

enable_backup_privileges(NULL, 1);

jcr = setup_jcr("bextract", devname, bsr, director, VolumeName, true); /* read device */
dcr = New(DCR);
jcr = setup_jcr("bextract", devname, bsr, director, dcr, VolumeName, true); /* read device */
if (!jcr) {
exit(1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/stored/bls.c
Expand Up @@ -239,7 +239,8 @@ int main (int argc, char *argv[])
if (bsrName) {
bsr = parse_bsr(NULL, bsrName);
}
jcr = setup_jcr("bls", argv[i], bsr, director, VolumeName, true); /* read device */
dcr = New(DCR);
jcr = setup_jcr("bls", argv[i], bsr, director, dcr, VolumeName, true); /* read device */
if (!jcr) {
exit(1);
}
Expand Down
9 changes: 6 additions & 3 deletions src/stored/bscan.c
Expand Up @@ -135,6 +135,7 @@ int main (int argc, char *argv[])
char *VolumeName = NULL;
char *DirectorName = NULL;
DIRRES *director = NULL;
DCR *dcr;
#if defined(HAVE_DYNAMIC_CATS_BACKENDS)
alist *backend_directories = NULL;
#endif
Expand Down Expand Up @@ -292,18 +293,20 @@ int main (int argc, char *argv[])
/* Check that working directory is good */
if (stat(working_directory, &stat_buf) != 0) {
Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"),
working_directory);
working_directory);
}
if (!S_ISDIR(stat_buf.st_mode)) {
Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"),
working_directory);
working_directory);
}

bjcr = setup_jcr("bscan", argv[0], bsr, director, VolumeName, true); /* read device */
dcr = New(DCR);
bjcr = setup_jcr("bscan", argv[0], bsr, director, dcr, VolumeName, true);
if (!bjcr) {
exit(1);
}
dev = bjcr->read_dcr->dev;

if (showProgress) {
char ed1[50];
struct stat sb;
Expand Down
7 changes: 5 additions & 2 deletions src/stored/btape.c
Expand Up @@ -290,20 +290,23 @@ int main(int margc, char *margv[])
exit(1);
}

jcr = setup_jcr("btape", margv[0], bsr, director, NULL, false); /* write device */
dcr = New(BTAPE_DCR);
jcr = setup_jcr("btape", margv[0], bsr, director, dcr, NULL, false); /* write device */
if (!jcr) {
exit(1);
}

dev = jcr->dcr->dev;
if (!dev) {
exit(1);
}

if (!dev->is_tape()) {
Pmsg0(000, _("btape only works with tape storage.\n"));
usage();
exit(1);
}
dcr = jcr->dcr;

if (!open_the_device()) {
exit(1);
}
Expand Down
31 changes: 16 additions & 15 deletions src/stored/butil.c
Expand Up @@ -35,7 +35,8 @@
#include "stored.h"

/* Forward referenced functions */
static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeName, bool readonly);
static bool setup_to_access_device(DCR *dcr, JCR *jcr, char *dev_name,
const char *VolumeName, bool readonly);
static DEVRES *find_device_res(char *device_name, bool readonly);
static void my_free_jcr(JCR *jcr);

Expand Down Expand Up @@ -76,11 +77,11 @@ char *rec_state_bits_to_str(DEV_RECORD *rec)
* tools (e.g. bls, bextract, bscan, ...)
*/
JCR *setup_jcr(const char *name, char *dev_name,
BSR *bsr, DIRRES *director,
BSR *bsr, DIRRES *director, DCR *dcr,
const char *VolumeName, bool readonly)
{
DCR *dcr;
JCR *jcr = new_jcr(sizeof(JCR), my_free_jcr);

jcr->bsr = bsr;
jcr->director = director;
jcr->VolSessionId = 1;
Expand All @@ -107,15 +108,17 @@ JCR *setup_jcr(const char *name, char *dev_name,
init_autochangers();
create_volume_lists();

dcr = setup_to_access_device(jcr, dev_name, VolumeName, readonly);
if (!dcr) {
if (!setup_to_access_device(dcr, jcr, dev_name, VolumeName, readonly)) {
return NULL;
}

if (!bsr && VolumeName) {
bstrncpy(dcr->VolumeName, VolumeName, sizeof(dcr->VolumeName));
}

bstrncpy(dcr->pool_name, "Default", sizeof(dcr->pool_name));
bstrncpy(dcr->pool_type, "Backup", sizeof(dcr->pool_type));

return jcr;
}

Expand All @@ -124,12 +127,12 @@ JCR *setup_jcr(const char *name, char *dev_name,
* If the caller wants read access, acquire the device, otherwise,
* the caller will do it.
*/
static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeName, bool readonly)
static bool setup_to_access_device(DCR *dcr, JCR *jcr, char *dev_name,
const char *VolumeName, bool readonly)
{
DEVICE *dev;
char *p;
DEVRES *device;
DCR *dcr;
char VolName[MAX_NAME_LENGTH];

init_reservations_lock();
Expand Down Expand Up @@ -162,17 +165,16 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeN

if ((device = find_device_res(dev_name, readonly)) == NULL) {
Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"),
dev_name, configfile);
return NULL;
dev_name, configfile);
return false;
}

dev = init_dev(jcr, device);
if (!dev) {
Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name);
return NULL;
return false;
}
device->dev = dev;
dcr = New(DCR);
jcr->dcr = dcr;
setup_new_dcr_device(jcr, dcr, dev, NULL);
if (!readonly) {
Expand All @@ -189,20 +191,19 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, const char *VolumeN
if (readonly) { /* read only access? */
Dmsg0(100, "Acquire device for read\n");
if (!acquire_device_for_read(dcr)) {
return NULL;
return false;
}
jcr->read_dcr = dcr;
} else {
if (!first_open_device(dcr)) {
Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), dev->print_name());
return NULL;
return false;
}
}

return dcr;
return true;
}


/*
* Called here when freeing JCR so that we can get rid
* of "daemon" specific memory allocated.
Expand Down
2 changes: 1 addition & 1 deletion src/stored/protos.h
Expand Up @@ -68,7 +68,7 @@ void ser_block_header(DEV_BLOCK *block);
/* butil.c -- utilities for SD tool programs */
void print_ls_output(const char *fname, const char *link, int type, struct stat *statp);
JCR *setup_jcr(const char *name, char *dev_name,
BSR *bsr, DIRRES *director,
BSR *bsr, DIRRES *director, DCR* dcr,
const char *VolumeName, bool readonly);
void display_tape_error_status(JCR *jcr, DEVICE *dev);

Expand Down

0 comments on commit 2487305

Please sign in to comment.