Skip to content

Commit

Permalink
Cleanup Media Record Enbled handling.
Browse files Browse the repository at this point in the history
- Use enum with the values it can have that mean something when reading
  the code.
- Removed whole argument parsing in update_volume() as update_volenabled()
  is called which calls get_enabled() which already does the whole parsing.
  • Loading branch information
Marco van Wieringen committed Nov 16, 2015
1 parent ac8379b commit ca3f777
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/dird/autoprune.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void prune_volumes(JCR *jcr, bool InChanger,
}
Dmsg1(100, "Examine vol=%s\n", lmr.VolumeName);
/* Don't prune archived volumes */
if (lmr.Enabled == 2) {
if (lmr.Enabled == VOL_ARCHIVED) {
Dmsg1(100, "Vol=%s disabled\n", lmr.VolumeName);
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/dird/catreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ void catalog_request(JCR *jcr, BSOCK *bs)
check_if_volume_valid_or_recyclable(jcr, &mr, &reason);
}
}
if (!reason && mr.Enabled != 1) {

if (!reason && mr.Enabled != VOL_ENABLED) {
reason = _("is not Enabled");
}
if (reason == NULL) {
Expand Down
6 changes: 6 additions & 0 deletions src/dird/dird.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ enum {
fnv_no_prune = false
};

enum e_enabled_val {
VOL_NOT_ENABLED = 0,
VOL_ENABLED = 1,
VOL_ARCHIVED = 2
};

enum e_prtmsg {
DISPLAY_ERROR,
NO_DISPLAY
Expand Down
2 changes: 1 addition & 1 deletion src/dird/newvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool newVolume(JCR *jcr, MEDIA_DBR *mr, STORERES *store)
goto bail_out;
}
pr.NumVols++;
mr->Enabled = 1;
mr->Enabled = VOL_ENABLED;
set_storageid_in_mr(store, mr);
if (db_create_media_record(jcr, jcr->db, mr) &&
db_update_pool_record(jcr, jcr->db, &pr)) {
Expand Down
4 changes: 2 additions & 2 deletions src/dird/ua_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
mr->LabelType = pr->LabelType;
mr->MinBlocksize = pr->MinBlocksize;
mr->MaxBlocksize = pr->MaxBlocksize;
mr->Enabled = 1;
mr->Enabled = VOL_ENABLED;
}


Expand Down Expand Up @@ -465,7 +465,7 @@ static int add_cmd(UAContext *ua, const char *cmd)
bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i);
mr.Slot = Slot++;
mr.InChanger = InChanger;
mr.Enabled = 1;
mr.Enabled = VOL_ENABLED;
set_storageid_in_mr(store, &mr);
Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
Expand Down
20 changes: 11 additions & 9 deletions src/dird/ua_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ bool is_yesno(char *val, int *ret)

/*
* Gets a yes or no response
* Returns: false if failure
* true if success => ua->pint32_val == 1 for yes
* ua->pint32_val == 0 for no
* Returns: false if failure
* true if success => ua->pint32_val == 1 for yes
* ua->pint32_val == 0 for no
*/
bool get_yesno(UAContext *ua, const char *prompt)
{
Expand All @@ -161,27 +161,29 @@ bool get_yesno(UAContext *ua, const char *prompt)
}

/*
* Gets an Enabled value => 0, 1, 2, yes, no, archived
* Returns: 0, 1, 2 if OK
* -1 on error
* Gets an Enabled value => 0, 1, 2, yes, no, archived
* Returns: 0, 1, 2 if OK
* -1 on error
*/
int get_enabled(UAContext *ua, const char *val)
{
int Enabled = -1;

if (bstrcasecmp(val, "yes") || bstrcasecmp(val, "true")) {
Enabled = 1;
Enabled = VOL_ENABLED;
} else if (bstrcasecmp(val, "no") || bstrcasecmp(val, "false")) {
Enabled = 0;
Enabled = VOL_NOT_ENABLED;
} else if (bstrcasecmp(val, "archived")) {
Enabled = 2;
Enabled = VOL_ARCHIVED;
} else {
Enabled = atoi(val);
}

if (Enabled < 0 || Enabled > 2) {
ua->error_msg(_("Invalid Enabled value, it must be yes, no, archived, 0, 1, or 2\n"));
return -1;
}

return Enabled;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
set_pool_dbr_defaults_in_media_dbr(mr, pr);
mr->VolBytes = VolBytes;
mr->InChanger = mr->Slot > 0; /* if slot give assume in changer */
mr->Enabled = 1;
mr->Enabled = VOL_ENABLED;
set_storageid_in_mr(ua->jcr->res.wstore, mr);
if (db_create_media_record(ua->jcr, ua->db, mr)) {
ua->info_msg(_("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
Expand Down
9 changes: 4 additions & 5 deletions src/dird/ua_prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ int prune_cmd(UAContext *ua, const char *cmd)
return false;
}

if (mr.Enabled == 2) {
ua->error_msg(_("Cannot prune Volume \"%s\" because it is archived.\n"),
mr.VolumeName);
if (mr.Enabled == VOL_ARCHIVED) {
ua->error_msg(_("Cannot prune Volume \"%s\" because it is archived.\n"), mr.VolumeName);
return false;
}

Expand Down Expand Up @@ -851,7 +850,7 @@ bool prune_volume(UAContext *ua, MEDIA_DBR *mr)
bool ok = false;
int count;

if (mr->Enabled == 2) {
if (mr->Enabled == VOL_ARCHIVED) {
return false; /* Cannot prune archived volumes */
}

Expand Down Expand Up @@ -890,7 +889,7 @@ int get_prune_list_for_volume(UAContext *ua, MEDIA_DBR *mr, del_ctx *del)
utime_t now, period;
char ed1[50], ed2[50];

if (mr->Enabled == 2) {
if (mr->Enabled == VOL_ARCHIVED) {
return 0; /* cannot prune Archived volumes */
}

Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_purge.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ static int action_on_purge_cmd(UAContext *ua, const char *cmd)
* Look for all Purged volumes that can be recycled, are enabled and have more the 10,000 bytes.
*/
mr.Recycle = 1;
mr.Enabled = 1;
mr.Enabled = VOL_ENABLED;
mr.VolBytes = 10000;
set_storageid_in_mr(store, &mr);
bstrncpy(mr.VolStatus, "Purged", sizeof(mr.VolStatus));
Expand Down
15 changes: 3 additions & 12 deletions src/dird/ua_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ static void update_volenabled(UAContext *ua, char *val, MEDIA_DBR *mr)
}
set_storageid_in_mr(NULL, mr);
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
ua->error_msg(_("Error updating media record Enabled: ERR=%s"),
db_strerror(ua->db));
ua->error_msg(_("Error updating media record Enabled: ERR=%s"), db_strerror(ua->db));
} else {
ua->info_msg(_("New Enabled is: %d\n"), mr->Enabled);
}
Expand Down Expand Up @@ -805,15 +804,7 @@ static int update_volume(UAContext *ua)
if (!get_cmd(ua, _("Enter new Enabled: "))) {
return 0;
}
if (bstrcasecmp(ua->cmd, "yes") || bstrcasecmp(ua->cmd, "true")) {
mr.Enabled = 1;
} else if (bstrcasecmp(ua->cmd, "no") || bstrcasecmp(ua->cmd, "false")) {
mr.Enabled = 0;
} else if (bstrcasecmp(ua->cmd, "archived")) {
mr.Enabled = 2;
} else {
mr.Enabled = atoi(ua->cmd);
}

update_volenabled(ua, ua->cmd, &mr);
break;

Expand Down Expand Up @@ -1010,7 +1001,7 @@ static void update_slots(UAContext *ua)
bool scan;
int max_slots;
int drive = -1;
int Enabled = 1;
int Enabled = VOL_ENABLED;
bool have_enabled;
int i;

Expand Down

0 comments on commit ca3f777

Please sign in to comment.