~registry/lvm2/master

« back to all changes in this revision

Viewing changes to daemons/lvmetad/lvmetad-core.c

  • Committer: Zdenek Kabelac
  • Date: 2012-12-15 16:23:28 UTC
  • Revision ID: git-v1:ed23da95b63308e11f8d680b189686a5d2d380d0
lvmetad: simplify pvid memory allocation.

Since pvid_dup and cft config appears to be tightly
binded together - reuse it's memory pool for string.
Simplifies release of hashes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        dm_hash_destroy(s->vgid_to_metadata);
68
68
        dm_hash_destroy(s->vgid_to_vgname);
69
69
        dm_hash_destroy(s->vgname_to_vgid);
70
 
 
71
 
        n = dm_hash_get_first(s->device_to_pvid);
72
 
        while (n) {
73
 
                dm_free(dm_hash_get_data(s->device_to_pvid, n));
74
 
                n = dm_hash_get_next(s->device_to_pvid, n);
75
 
        }
76
 
 
77
70
        dm_hash_destroy(s->device_to_pvid);
78
71
        dm_hash_destroy(s->pvid_to_vgid);
79
72
}
768
761
        const char *pvid = daemon_request_str(r, "uuid", NULL);
769
762
        int64_t device = daemon_request_int(r, "device", 0);
770
763
        struct dm_config_tree *pvmeta;
771
 
        char *pvid_old;
772
764
 
773
765
        DEBUGLOG(s, "pv_gone: %s / %" PRIu64, pvid, device);
774
766
 
783
775
        DEBUGLOG(s, "pv_gone (updated): %s / %" PRIu64, pvid, device);
784
776
 
785
777
        pvmeta = dm_hash_lookup(s->pvid_to_pvmeta, pvid);
786
 
        pvid_old = dm_hash_lookup_binary(s->device_to_pvid, &device, sizeof(device));
787
778
        dm_hash_remove_binary(s->device_to_pvid, &device, sizeof(device));
788
779
        dm_hash_remove(s->pvid_to_pvmeta, pvid);
789
780
        vg_remove_if_missing(s, dm_hash_lookup(s->pvid_to_vgid, pvid));
790
781
        unlock_pvid_to_pvmeta(s);
791
782
 
792
 
        if (pvid_old)
793
 
                dm_free(pvid_old);
794
 
 
795
783
        if (pvmeta) {
796
784
                dm_config_destroy(pvmeta);
797
785
                return daemon_reply_simple("OK", NULL);
826
814
        struct dm_config_node *pvmeta = dm_config_find_node(r.cft->root, "pvmeta");
827
815
        uint64_t device;
828
816
        struct dm_config_tree *cft, *pvmeta_old_dev = NULL, *pvmeta_old_pvid = NULL;
829
 
        char *old;
830
 
        char *pvid_dup;
 
817
        const char *old;
 
818
        const char *pvid_dup;
831
819
        int complete = 0, orphan = 0;
832
820
        int64_t seqno = -1, seqno_old = -1;
833
821
 
849
837
 
850
838
        DEBUGLOG(s, "pv_found %s, vgid = %s, device = %" PRIu64 ", old = %s", pvid, vgid, device, old);
851
839
 
852
 
        dm_free(old);
853
 
 
854
840
        if (!(cft = dm_config_create()) ||
855
841
            !(cft->root = dm_config_clone_node(cft, pvmeta, 0))) {
856
842
                unlock_pvid_to_pvmeta(s);
859
845
                return reply_fail("out of memory");
860
846
        }
861
847
 
862
 
        if (!(pvid_dup = dm_strdup(pvid))) {
 
848
        if (!(pvid_dup = dm_pool_strdup(dm_config_memory(cft), pvid))) {
863
849
                unlock_pvid_to_pvmeta(s);
864
850
                dm_config_destroy(cft);
865
851
                return reply_fail("out of memory");
870
856
                unlock_pvid_to_pvmeta(s);
871
857
                dm_hash_remove(s->pvid_to_pvmeta, pvid);
872
858
                dm_config_destroy(cft);
873
 
                dm_free(pvid_dup);
874
859
                return reply_fail("out of memory");
875
860
        }
876
861
        if (pvmeta_old_pvid)