]> sourceware.org Git - lvm2.git/commitdiff
archiver: inital change toward proper logging
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 3 Dec 2015 16:32:47 +0000 (17:32 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Thu, 3 Dec 2015 17:01:45 +0000 (18:01 +0100)
We have to modes of  'archive()' usage -
1. compulsory - fail stops command and user may try '-An' option
to do a command.

2. non-compulsory - some fails in archiving are ignorable (i.e.
read-only filesystem where archive dir is located).

Those 2 cases needs to be properly handle - i.e. the non-compulsory
logging should not be tampering  error logging message production.

So more work here is needed

lib/format_text/archiver.c

index e3d3d570c2086dd0c6e74f43018fbfc2e457706b..4f5ea256f4afe9be77366f888a2a0df33ffc0397 100644 (file)
@@ -98,20 +98,10 @@ static char *_build_desc(struct dm_pool *mem, const char *line, int before)
        return buffer;
 }
 
-static int __archive(struct volume_group *vg)
+static int _archive(struct volume_group *vg, int compulsory)
 {
        char *desc;
 
-       if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 1)))
-               return_0;
-
-       return archive_vg(vg, vg->cmd->archive_params->dir, desc,
-                         vg->cmd->archive_params->keep_days,
-                         vg->cmd->archive_params->keep_number);
-}
-
-int archive(struct volume_group *vg)
-{
        /* Don't archive orphan VGs. */
        if (is_orphan_vg(vg->name))
                return 1;
@@ -130,27 +120,43 @@ int archive(struct volume_group *vg)
                return 1;
        }
 
-       if (!dm_create_dir(vg->cmd->archive_params->dir))
-               return 0;
+       if (!dm_create_dir(vg->cmd->archive_params->dir)) {
+               /* FIXME: !compulsory logs error here */
+               log_error("Cannot create archiving directory %s.",
+                         vg->cmd->archive_params->dir);
+               return compulsory ? 0 : 1;
+       }
 
        /* Trap a read-only file system */
        if ((access(vg->cmd->archive_params->dir, R_OK | W_OK | X_OK) == -1) &&
-            (errno == EROFS))
-               return 0;
+           (errno == EROFS)) {
+               /* FIXME: !compulsory logs error here */
+               log_error("Cannot archive volume group metadata for %s to read-only filesystem.",
+                         vg->name);
+               return compulsory ? 0 : 1;
+       }
 
        log_verbose("Archiving volume group \"%s\" metadata (seqno %u).", vg->name,
                    vg->seqno);
-       if (!__archive(vg)) {
-               log_error("Volume group \"%s\" metadata archive failed.",
-                         vg->name);
-               return 0;
-       }
+
+       if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 1)))
+               return_0;
+
+       if (!archive_vg(vg, vg->cmd->archive_params->dir, desc,
+                       vg->cmd->archive_params->keep_days,
+                       vg->cmd->archive_params->keep_number))
+               return_0;
 
        vg->status |= ARCHIVED_VG;
 
        return 1;
 }
 
+int archive(struct volume_group *vg)
+{
+       return _archive(vg, 1);
+}
+
 int archive_display(struct cmd_context *cmd, const char *vg_name)
 {
        int r1, r2;
@@ -207,7 +213,7 @@ void backup_enable(struct cmd_context *cmd, int flag)
        cmd->backup_params->enabled = flag;
 }
 
-static int __backup(struct volume_group *vg)
+static int _backup(struct volume_group *vg)
 {
        char name[PATH_MAX];
        char *desc;
@@ -242,10 +248,13 @@ int backup_locally(struct volume_group *vg)
 
        /* Trap a read-only file system */
        if ((access(vg->cmd->backup_params->dir, R_OK | W_OK | X_OK) == -1) &&
-           (errno == EROFS))
+           (errno == EROFS)) {
+               log_warn("WARNING: Cannot backup of volume group %s metadata to read-only fs.",
+                         vg->name);
                return 0;
+       }
 
-       if (!__backup(vg)) {
+       if (!_backup(vg)) {
                log_error("Backup of volume group %s metadata failed.",
                          vg->name);
                return 0;
@@ -500,8 +509,9 @@ void check_current_backup(struct volume_group *vg)
                return;
 
        if (dm_snprintf(path, sizeof(path), "%s/%s",
-                        vg->cmd->backup_params->dir, vg->name) < 0) {
-               log_debug("Failed to generate backup filename.");
+                       vg->cmd->backup_params->dir, vg->name) < 0) {
+               log_warn("WARNING: Failed to generate backup pathname %s/%s.",
+                        vg->cmd->backup_params->dir, vg->name);
                return;
        }
 
@@ -517,11 +527,11 @@ void check_current_backup(struct volume_group *vg)
        log_suppress(old_suppress);
 
        if (vg_backup) {
-               if (!archive(vg_backup))
+               if (!_archive(vg_backup, 0))
                        stack;
                release_vg(vg_backup);
        }
-       if (!archive(vg))
+       if (!_archive(vg, 0))
                stack;
        if (!backup_locally(vg))
                stack;
This page took 0.047085 seconds and 5 git commands to generate.