]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: cleanup names, don't copy probing results
authorKarel Zak <kzak@redhat.com>
Mon, 23 Feb 2015 14:45:41 +0000 (15:45 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Feb 2015 09:24:15 +0000 (10:24 +0100)
* cleanup function and variable names (s/vals/values/)
* in "safe probe" mode libblkid copies probing result from the first
  attempt, this is unnecessary, with values list we can just move
  values to another list rather than copy all.
* add new debug messages

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/blkidP.h
libblkid/src/partitions/partitions.c
libblkid/src/probe.c
libblkid/src/superblocks/superblocks.c
libblkid/src/topology/topology.c

index 4d440800e61d26931cde2a012af063d9f65a3e14..8060bcc45bb64e1a1cdc882de154a3ed7b5be633 100644 (file)
@@ -198,7 +198,7 @@ struct blkid_struct_probe
        struct blkid_chain      chains[BLKID_NCHAINS];  /* array of chains */
        struct blkid_chain      *cur_chain;             /* current chain */
 
-       struct list_head        vals;           /* results */
+       struct list_head        values;         /* results */
 
        struct blkid_struct_probe *parent;      /* for clones */
        struct blkid_struct_probe *disk_probe;  /* whole-disk probing */
@@ -417,9 +417,9 @@ extern int blkid_probe_is_covered_by_pt(blkid_probe pr,
                                        blkid_loff_t offset, blkid_loff_t size)
                        __attribute__((warn_unused_result));
 
-extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn)
+extern void blkid_probe_chain_reset_values(blkid_probe pr, struct blkid_chain *chn)
                        __attribute__((nonnull));
-extern int blkid_probe_chain_copy_vals(blkid_probe pr,
+extern int blkid_probe_chain_save_values(blkid_probe pr,
                                       struct blkid_chain *chn,
                                       struct list_head *vals)
                        __attribute__((nonnull));
@@ -429,13 +429,15 @@ extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr,
                        __attribute__((nonnull))
                        __attribute__((warn_unused_result));
 
-extern void blkid_probe_free_val(struct blkid_prval *v);
+extern void blkid_probe_free_value(struct blkid_prval *v);
 
 
-extern void blkid_probe_append_vals(blkid_probe pr,
+extern void blkid_probe_append_values_list(blkid_probe pr,
                                    struct list_head *vals)
                        __attribute__((nonnull));
 
+extern void blkid_probe_free_values_list(struct list_head *vals);
+
 extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr)
                        __attribute__((nonnull))
                        __attribute__((warn_unused_result));
index b28dfbd57a5cd47609bdf5cf114206be95124baf..6e55a8f3ee4f3df4fbc0c536dada0806ed784c0a 100644 (file)
@@ -556,7 +556,7 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
                        /* reset after error */
                        reset_partlist(blkid_probe_get_partlist(pr));
                        if (chn && !chn->binary)
-                               blkid_probe_chain_reset_vals(pr, chn);
+                               blkid_probe_chain_reset_values(pr, chn);
                        DBG(LOWPROBE, ul_debug("%s probefunc failed, rc %d",
                                                  id->name, rc));
                }
@@ -584,7 +584,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
        if (!pr || chn->idx < -1)
                return -EINVAL;
 
-       blkid_probe_chain_reset_vals(pr, chn);
+       blkid_probe_chain_reset_values(pr, chn);
 
        if (pr->flags & BLKID_FL_NOSCAN_DEV)
                return BLKID_PROBE_NONE;
@@ -1108,7 +1108,7 @@ int blkid_partitions_set_ptuuid(blkid_probe pr, unsigned char *uuid)
                return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return -ENOMEM;
 }
 
index 2f4e7c90e3360c6d14725ba14cb22bcae1c78969..fa06459073320f491e3b5d5769ef3880527a5905 100644 (file)
@@ -130,7 +130,7 @@ static const struct blkid_chaindrv *chains_drvs[] = {
 };
 
 static struct blkid_prval *blkid_probe_new_value(void);
-static void blkid_probe_reset_vals(blkid_probe pr);
+static void blkid_probe_reset_values(blkid_probe pr);
 static void blkid_probe_reset_buffer(blkid_probe pr);
 
 /**
@@ -157,7 +157,7 @@ blkid_probe blkid_new_probe(void)
                pr->chains[i].enabled = chains_drvs[i]->dflt_enabled;
        }
        INIT_LIST_HEAD(&pr->buffers);
-       INIT_LIST_HEAD(&pr->vals);
+       INIT_LIST_HEAD(&pr->values);
        return pr;
 }
 
@@ -262,39 +262,44 @@ void blkid_free_probe(blkid_probe pr)
        if ((pr->flags & BLKID_FL_PRIVATE_FD) && pr->fd >= 0)
                close(pr->fd);
        blkid_probe_reset_buffer(pr);
+       blkid_probe_reset_values(pr);
        blkid_free_probe(pr->disk_probe);
 
        DBG(LOWPROBE, ul_debug("free probe %p", pr));
        free(pr);
 }
 
-void blkid_probe_free_val(struct blkid_prval *v)
+void blkid_probe_free_value(struct blkid_prval *v)
 {
        if (!v)
                return;
 
        list_del(&v->prvals);
        free(v->data);
+
+       DBG(LOWPROBE, ul_debug(" free value %s", v->name));
        free(v);
 }
 
 /*
  * Removes chain values from probing result.
  */
-void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn)
+void blkid_probe_chain_reset_values(blkid_probe pr, struct blkid_chain *chn)
 {
 
        struct list_head *p, *pnext;
 
-       if (!pr || list_empty(&pr->vals))
+       if (!pr || list_empty(&pr->values))
                return;
 
-       list_for_each_safe(p, pnext, &pr->vals) {
+       DBG(LOWPROBE, ul_debug("reseting %s values", chn->driver->name));
+
+       list_for_each_safe(p, pnext, &pr->values) {
                struct blkid_prval *v = list_entry(p,
                                                struct blkid_prval, prvals);
 
                if (v->chain == chn)
-                       blkid_probe_free_val(v);
+                       blkid_probe_free_value(v);
        }
 }
 
@@ -304,9 +309,14 @@ static void blkid_probe_chain_reset_position(struct blkid_chain *chn)
                chn->idx = -1;
 }
 
-static struct blkid_prval *blkid_probe_deep_copy_val(struct blkid_prval *dest,
-                                               struct blkid_prval *src)
+/*
+static struct blkid_prval *blkid_probe_copy_value(struct blkid_prval *src)
 {
+       struct blkid_prval *dest = blkid_probe_new_value();
+
+       if (!dest)
+               return NULL;
+
        memcpy(dest, src, sizeof(struct blkid_prval));
 
        dest->data = malloc(src->len);
@@ -316,34 +326,31 @@ static struct blkid_prval *blkid_probe_deep_copy_val(struct blkid_prval *dest,
        memcpy(dest->data, src->data, src->len);
 
        INIT_LIST_HEAD(&dest->prvals);
-
        return dest;
 }
+*/
 
 /*
- * Copies chain values from probing result to @vals.
+ * Move chain values from probing result to @vals
  */
-int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
-               struct list_head *vals)
+int blkid_probe_chain_save_values(blkid_probe pr, struct blkid_chain *chn,
+                               struct list_head *vals)
 {
-       struct list_head *p;
-       struct blkid_prval *new_v, *v;
-
-       list_for_each(p, &pr->vals) {
+       struct list_head *p, *pnext;
+       struct blkid_prval *v;
 
-               v = list_entry(p, struct blkid_prval, prvals);
+       DBG(LOWPROBE, ul_debug("saving %s values", chn->driver->name));
 
-               new_v = blkid_probe_new_value();
-               if (!new_v)
-                       break;
+       list_for_each_safe(p, pnext, &pr->values) {
 
+               v = list_entry(p, struct blkid_prval, prvals);
                if (v->chain != chn)
                        continue;
 
-               if (!blkid_probe_deep_copy_val(new_v, v))
-                       break;
+               list_del(&v->prvals);
+               INIT_LIST_HEAD(&v->prvals);
 
-               list_add_tail(&new_v->prvals, vals);
+               list_add_tail(&v->prvals, vals);
        }
        return 0;
 }
@@ -351,9 +358,26 @@ int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
 /*
  * Appends values from @vals to the probing result
  */
-void blkid_probe_append_vals(blkid_probe pr, struct list_head *vals)
+void blkid_probe_append_values_list(blkid_probe pr, struct list_head *vals)
+{
+       DBG(LOWPROBE, ul_debug("appending values"));
+
+       list_splice(vals, &pr->values);
+       INIT_LIST_HEAD(vals);
+}
+
+
+void blkid_probe_free_values_list(struct list_head *vals)
 {
-       list_splice(vals, &pr->vals);
+       if (!vals)
+               return;
+
+       DBG(LOWPROBE, ul_debug("freeing values list"));
+
+       while (!list_empty(vals)) {
+               struct blkid_prval *v = list_entry(vals->next, struct blkid_prval, prvals);
+               blkid_probe_free_value(v);
+       }
 }
 
 struct blkid_chain *blkid_probe_get_chain(blkid_probe pr)
@@ -423,7 +447,7 @@ void blkid_reset_probe(blkid_probe pr)
        if (!pr)
                return;
 
-       blkid_probe_reset_vals(pr);
+       blkid_probe_reset_values(pr);
        blkid_probe_set_wiper(pr, 0, 0);
 
        pr->cur_chain = NULL;
@@ -662,20 +686,20 @@ static void blkid_probe_reset_buffer(blkid_probe pr)
        INIT_LIST_HEAD(&pr->buffers);
 }
 
-static void blkid_probe_reset_vals(blkid_probe pr)
+static void blkid_probe_reset_values(blkid_probe pr)
 {
-       if (!pr || list_empty(&pr->vals))
+       if (!pr || list_empty(&pr->values))
                return;
 
        DBG(LOWPROBE, ul_debug("resetting results pr=%p", pr));
 
-       while (!list_empty(&pr->vals)) {
-               struct blkid_prval *v = list_entry(pr->vals.next,
+       while (!list_empty(&pr->values)) {
+               struct blkid_prval *v = list_entry(pr->values.next,
                                                struct blkid_prval, prvals);
-               blkid_probe_free_val(v);
+               blkid_probe_free_value(v);
        }
 
-       INIT_LIST_HEAD(&pr->vals);
+       INIT_LIST_HEAD(&pr->values);
 }
 
 /*
@@ -1319,7 +1343,7 @@ struct blkid_prval *blkid_probe_assign_value(
 
        v->name = name;
        v->chain = pr->cur_chain;
-       list_add_tail(&v->prvals, &pr->vals);
+       list_add_tail(&v->prvals, &pr->values);
 
        DBG(LOWPROBE, ul_debug("assigning %s [%s]", name, v->chain->driver->name));
        return v;
@@ -1378,7 +1402,7 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
        len = vasprintf((char **) &v->data, fmt, ap);
 
        if (len <= 0) {
-               blkid_probe_free_val(v);
+               blkid_probe_free_value(v);
                return len == 0 ? -EINVAL : -ENOMEM;
        }
        v->len = len + 1;
@@ -1633,7 +1657,7 @@ int blkid_probe_numof_values(blkid_probe pr)
        if (!pr)
                return -1;
 
-       list_for_each(p, &pr->vals)
+       list_for_each(p, &pr->values)
                ++i;
        return i;
 }
@@ -1711,10 +1735,10 @@ int blkid_probe_has_value(blkid_probe pr, const char *name)
 
 struct blkid_prval *blkid_probe_last_value(blkid_probe pr)
 {
-       if (!pr || list_empty(&pr->vals))
+       if (!pr || list_empty(&pr->values))
                return NULL;
 
-       return list_last_entry(&pr->vals, struct blkid_prval, prvals);
+       return list_last_entry(&pr->values, struct blkid_prval, prvals);
 }
 
 
@@ -1726,7 +1750,7 @@ struct blkid_prval *__blkid_probe_get_value(blkid_probe pr, int num)
        if (!pr || num < 0)
                return NULL;
 
-       list_for_each(p, &pr->vals) {
+       list_for_each(p, &pr->values) {
                if (i++ != num)
                        continue;
                return list_entry(p, struct blkid_prval, prvals);
@@ -1738,10 +1762,10 @@ struct blkid_prval *__blkid_probe_lookup_value(blkid_probe pr, const char *name)
 {
        struct list_head *p;
 
-       if (!pr || list_empty(&pr->vals) || !name)
+       if (!pr || list_empty(&pr->values) || !name)
                return NULL;
 
-       list_for_each(p, &pr->vals) {
+       list_for_each(p, &pr->values) {
                struct blkid_prval *v = list_entry(p, struct blkid_prval,
                                                prvals);
 
@@ -1893,6 +1917,6 @@ void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size)
                DBG(LOWPROBE, ul_debug("previously wiped area modified "
                                       " -- ignore previous results"));
                blkid_probe_set_wiper(pr, 0, 0);
-               blkid_probe_chain_reset_vals(pr, chn);
+               blkid_probe_chain_reset_values(pr, chn);
        }
 }
index 8d381599e0aa0706220a837e851b0a2cffba5f08..334d67304823997d3f2e9ab8602f00444af801b7 100644 (file)
@@ -341,7 +341,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
        if (!pr || chn->idx < -1)
                return -EINVAL;
 
-       blkid_probe_chain_reset_vals(pr, chn);
+       blkid_probe_chain_reset_values(pr, chn);
 
        if (pr->flags & BLKID_FL_NOSCAN_DEV)
                return BLKID_PROBE_NONE;
@@ -402,7 +402,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                        DBG(LOWPROBE, ul_debug("\tcall probefunc()"));
                        rc = id->probefunc(pr, mag);
                        if (rc != BLKID_PROBE_OK) {
-                               blkid_probe_chain_reset_vals(pr, chn);
+                               blkid_probe_chain_reset_values(pr, chn);
                                if (rc < 0)
                                        break;
                                continue;
@@ -422,7 +422,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                        rc = blkid_probe_set_magic(pr, off, mag->len,
                                        (unsigned char *) mag->magic);
                if (rc) {
-                       blkid_probe_chain_reset_vals(pr, chn);
+                       blkid_probe_chain_reset_values(pr, chn);
                        DBG(LOWPROBE, ul_debug("failed to set result -- ignore"));
                        continue;
                }
@@ -479,27 +479,30 @@ static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn)
 
                if (count == 1) {
                        /* save the first result */
-                       blkid_probe_chain_copy_vals(pr, chn, &vals);
+                       blkid_probe_chain_save_values(pr, chn, &vals);
                        idx = chn->idx;
                }
        }
 
        if (rc < 0)
-               return rc;              /* error */
+               goto done;              /* error */
 
        if (count > 1 && intol) {
                DBG(LOWPROBE, ul_debug("ERROR: superblocks chain: "
                               "ambivalent result detected (%d filesystems)!",
                               count));
-               return -2;              /* error, ambivalent result (more FS) */
+               rc = -2;                /* error, ambivalent result (more FS) */
+               goto done;
+       }
+       if (!count) {
+               rc = BLKID_PROBE_NONE;
+               goto done;
        }
-       if (!count)
-               return BLKID_PROBE_NONE;
 
        if (idx != -1) {
                /* restore the first result */
-               blkid_probe_chain_reset_vals(pr, chn);
-               blkid_probe_append_vals(pr, &vals);
+               blkid_probe_chain_reset_values(pr, chn);
+               blkid_probe_append_values_list(pr, &vals);
                chn->idx = idx;
        }
 
@@ -511,7 +514,10 @@ static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn)
        if (chn->idx >= 0 && idinfos[chn->idx]->usage & BLKID_USAGE_RAID)
                pr->prob_flags |= BLKID_PROBE_FL_IGNORE_PT;
 
-       return BLKID_PROBE_OK;
+       rc = BLKID_PROBE_OK;
+done:
+       blkid_probe_free_values_list(&vals);
+       return rc;
 }
 
 int blkid_probe_set_version(blkid_probe pr, const char *version)
@@ -586,7 +592,7 @@ int blkid_probe_set_id_label(blkid_probe pr, const char *name,
                        return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 
 }
@@ -618,7 +624,7 @@ int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
                        return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 }
 
@@ -646,7 +652,7 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
                        return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 }
 
@@ -678,7 +684,7 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
                        return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 }
 
@@ -737,7 +743,7 @@ int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
                        return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 }
 
@@ -776,7 +782,7 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam
                return 0;
        }
 
-       blkid_probe_free_val(v);
+       blkid_probe_free_value(v);
        return rc;
 }
 
index 93fa3802e5efc37b717f428c27a8b69aa14218da..88747241497e53997dcd77ba94d02e4d17f90002 100644 (file)
@@ -167,7 +167,7 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn)
                }
        }
 
-       blkid_probe_chain_reset_vals(pr, chn);
+       blkid_probe_chain_reset_values(pr, chn);
 
        DBG(LOWPROBE, ul_debug("--> starting probing loop [TOPOLOGY idx=%d]",
                chn->idx));