#include <libudev.h>
#include "checkers.h"
-#include "memory.h"
#include "vector.h"
#include "util.h"
#include "structs.h"
#include "prio.h"
#include "prioritizers/alua_spc3.h"
#include "dm-generic.h"
+#include "devmapper.h"
struct adapter_group *
alloc_adaptergroup(void)
{
struct adapter_group *agp;
- agp = (struct adapter_group *)MALLOC(sizeof(struct adapter_group));
+ agp = (struct adapter_group *)calloc(1, sizeof(struct adapter_group));
if (!agp)
return NULL;
agp->host_groups = vector_alloc();
if (!agp->host_groups) {
- FREE(agp);
+ free(agp);
agp = NULL;
}
return agp;
vector_foreach_slot(adapters, agp, i) {
free_hostgroup(agp->host_groups);
- FREE(agp);
+ free(agp);
}
vector_free(adapters);
}
vector_foreach_slot(hostgroups, hgp, i) {
vector_free(hgp->paths);
- FREE(hgp);
+ free(hgp);
}
vector_free(hostgroups);
}
{
struct host_group *hgp;
- hgp = (struct host_group *)MALLOC(sizeof(struct host_group));
+ hgp = (struct host_group *)calloc(1, sizeof(struct host_group));
if (!hgp)
return NULL;
hgp->paths = vector_alloc();
if (!hgp->paths) {
- FREE(hgp);
+ free(hgp);
hgp = NULL;
}
return hgp;
{
struct path * pp;
- pp = (struct path *)MALLOC(sizeof(struct path));
+ pp = (struct path *)calloc(1, sizeof(struct path));
if (pp) {
pp->initialized = INIT_NEW;
vector_free(pp->hwe);
- FREE(pp);
+ free(pp);
}
void
{
struct pathgroup * pgp;
- pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));
+ pgp = (struct pathgroup *)calloc(1, sizeof(struct pathgroup));
if (!pgp)
return NULL;
pgp->paths = vector_alloc();
if (!pgp->paths) {
- FREE(pgp);
+ free(pgp);
return NULL;
}
return;
free_pathvec(pgp->paths, free_paths);
- FREE(pgp);
+ free(pgp);
}
void
{
struct multipath * mpp;
- mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
+ mpp = (struct multipath *)calloc(1, sizeof(struct multipath));
if (mpp) {
mpp->bestpg = 1;
return;
if (mpp->selector) {
- FREE(mpp->selector);
+ free(mpp->selector);
mpp->selector = NULL;
}
if (mpp->features) {
- FREE(mpp->features);
+ free(mpp->features);
mpp->features = NULL;
}
if (mpp->hwhandler) {
- FREE(mpp->hwhandler);
+ free(mpp->hwhandler);
mpp->hwhandler = NULL;
}
}
free_multipath_attributes(mpp);
if (mpp->alias) {
- FREE(mpp->alias);
+ free(mpp->alias);
mpp->alias = NULL;
}
- if (mpp->dmi) {
- FREE(mpp->dmi);
- mpp->dmi = NULL;
- }
-
if (!free_paths && mpp->pg) {
struct pathgroup *pgp;
struct path *pp;
vector_free(mpp->hwe);
mpp->hwe = NULL;
}
- FREE_PTR(mpp->mpcontext);
- FREE(mpp);
+ free(mpp->mpcontext);
+ free(mpp);
}
void
return NULL;
vector_foreach_slot (mpvec, mpp, i) {
- if (!mpp->dmi)
+ if (!has_dm_info(mpp))
continue;
- if (mpp->dmi->minor == minor)
+ if (mpp->dmi.minor == minor)
return mpp;
}
return NULL;
for (d = c; d >= 10; d /= 10)
l++;
- t = MALLOC(l + 1);
+ t = calloc(1, l + 1);
if (!t)
return 1;
snprintf(t, l + 1, "%0d%s %s", c, e, n);
- FREE(*f);
+ free(*f);
*f = t;
return 0;
/* Quick exit if all features have been removed */
if (c == 0) {
- n = MALLOC(2);
+ n = malloc(2);
if (!n)
return 1;
strcpy(n, "0");
/* Update feature count space */
l = strlen(*f) - d;
- n = MALLOC(l + 1);
+ n = malloc(l + 1);
if (!n)
return 1;
p = strchr(*f, ' ');
if (!p) {
/* Internal error, feature string inconsistent */
- FREE(n);
+ free(n);
return 1;
}
while (*p == ' ')
}
out:
- FREE(*f);
+ free(*f);
*f = n;
return 0;
}
+
+unsigned int bus_protocol_id(const struct path *pp) {
+ if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
+ return SYSFS_BUS_UNDEF;
+ if (pp->bus != SYSFS_BUS_SCSI)
+ return pp->bus;
+ if ((int)pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+ return SYSFS_BUS_UNDEF;
+ return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
+}