Beispiel #1
0
/*
 * Take the deviceID property from the object path and get the raw devpath
 * of the drive that corresponds to the given device ID.
 */
static dm_descriptor_t *
get_partition_descs(CCIMObjectPath *op)
{
	CCIMPropertyList	*prop_list = NULL;
	CCIMProperty		*prop = NULL;
	int			error;
	dm_descriptor_t		dp;
	dm_descriptor_t		*da;
	dm_descriptor_t		*dpa;

	if (op != NULL) {
	    prop_list = op->mKeyProperties;
	}

	for (; prop_list; prop_list = prop_list->mNext) {

	    if (((prop = prop_list->mDataObject) != NULL &&
		prop->mName != NULL &&
		strcasecmp(prop->mName, "deviceid")) == 0) {
		break;
	    }
	}

	if (prop == NULL || prop->mValue == NULL) {
	    return (NULL);
	}

	dp = dm_get_descriptor_by_name(DM_DRIVE, prop->mValue, &error);
	if (error != 0) {
	    return (NULL);
	}

	da = dm_get_associated_descriptors(dp, DM_MEDIA, &error);
	dm_free_descriptor(dp);
	if (error != 0 || da == NULL) {
	    return (NULL);
	}

	if (da[0] == NULL) {
	    dm_free_descriptors(da);
	    return (NULL);
	}

	dpa = dm_get_associated_descriptors(da[0], DM_PARTITION, &error);
	dm_free_descriptors(da);
	if (error != 0 || dpa == NULL) {
	    return (NULL);
	}

	if (dpa[0] == NULL) {
	    dm_free_descriptors(dpa);
	    return (NULL);
	}

	return (dpa);
}
Beispiel #2
0
/*
 * Return: 1 if fails, 0 if ok.  geometry array contains:
 *     0. SectorsPerCylinder
 *     1. HeadsPerCylinder
 *     2. BytesPerCylinder
 *     3. PhysicalCylinders
 *     4. DataCylinders
 *     5. AlternateCylinders
 *     6. ActualCylinders
 */
static int
disk_geometry(char *media_name, ulong_t *geometry)
{
	int		error;
	dm_descriptor_t d;
	nvlist_t	*attrs;
	uint32_t	val32;

	d = dm_get_descriptor_by_name(DM_MEDIA, media_name, &error);
	if (error != 0) {
	    return (1);
	}

	attrs = dm_get_attributes(d, &error);
	dm_free_descriptor(d);
	if (error != 0) {
	    return (1);
	}

	/*
	 * If nsect is not in the attr list then we have media that does
	 * not have geometry info on it (e.g. EFI label).  So return a failure
	 * in this case.  Otherwise, just get the attrs we can and return
	 * their values.
	 */
	if (nvlist_lookup_uint32(attrs, DM_NSECTORS, &val32) != 0) {
	    nvlist_free(attrs);
	    return (1);
	}
	geometry[0] = val32;
	val32 = 0;

	nvlist_lookup_uint32(attrs, DM_NHEADS, &val32);
	geometry[1] = val32;
	val32 = 0;
	nvlist_lookup_uint32(attrs, DM_BLOCKSIZE, &val32);
	geometry[2] = (geometry[1] * geometry[0]) * val32;
	val32 = 0;
	nvlist_lookup_uint32(attrs, DM_NPHYSCYLINDERS, &val32);
	geometry[3] = val32;
	val32 = 0;
	nvlist_lookup_uint32(attrs, DM_NCYLINDERS, &val32);
	geometry[4] = val32;
	val32 = 0;
	nvlist_lookup_uint32(attrs, DM_NALTCYLINDERS, &val32);
	geometry[5] = val32;
	val32 = 0;
	/* This one is probably there only in x86 machines. */
	nvlist_lookup_uint32(attrs, DM_NACTUALCYLINDERS, &val32);
	geometry[6] = val32;

	nvlist_free(attrs);

	return (0);
}
Beispiel #3
0
/*ARGSUSED*/
static int
disk_temp_reading(topo_mod_t *mod, tnode_t *node, topo_version_t vers,
    nvlist_t *in, nvlist_t **out)
{
	char *devid;
	uint32_t temp;
	dm_descriptor_t drive_descr = NULL;
	nvlist_t *drive_stats, *pargs, *nvl;
	int err;

	if (vers > TOPO_METH_DISK_TEMP_VERSION)
		return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW));

	if (nvlist_lookup_nvlist(in, TOPO_PROP_ARGS, &pargs) != 0 ||
	    nvlist_lookup_string(pargs, TOPO_IO_DEVID, &devid) != 0) {
		topo_mod_dprintf(mod, "Failed to lookup %s arg",
		    TOPO_IO_DEVID);
		return (topo_mod_seterrno(mod, EMOD_NVL_INVAL));
	}

	if ((drive_descr = dm_get_descriptor_by_name(DM_DRIVE, devid,
	    &err)) == NULL) {
		topo_mod_dprintf(mod, "failed to get drive decriptor for %s",
		    devid);
		return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
	}

	if ((drive_stats = dm_get_stats(drive_descr, DM_DRV_STAT_TEMPERATURE,
	    &err)) == NULL ||
	    nvlist_lookup_uint32(drive_stats, DM_TEMPERATURE, &temp) != 0) {
		topo_mod_dprintf(mod, "failed to read disk temp for %s",
		    devid);
		dm_free_descriptor(drive_descr);
		return (topo_mod_seterrno(mod, EMOD_UNKNOWN));
	}
	dm_free_descriptor(drive_descr);

	if (topo_mod_nvalloc(mod, &nvl, NV_UNIQUE_NAME) != 0 ||
	    nvlist_add_string(nvl, TOPO_PROP_VAL_NAME,
	    TOPO_SENSOR_READING) != 0 ||
	    nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, TOPO_TYPE_DOUBLE) !=
	    0 || nvlist_add_double(nvl, TOPO_PROP_VAL_VAL, (double)temp) != 0) {
		topo_mod_dprintf(mod, "Failed to allocate 'out' nvlist\n");
		nvlist_free(nvl);
		return (topo_mod_seterrno(mod, EMOD_NOMEM));
	}
	*out = nvl;

	return (0);
}
/*
 * Validate a device.
 */
int
check_device(const char *path, boolean_t force, boolean_t isspare)
{
	dm_descriptor_t desc;
	int err;
	char *dev;

	/*
	 * For whole disks, libdiskmgt does not include the leading dev path.
	 */
	dev = strrchr(path, '/');
	assert(dev != NULL);
	dev++;
	if ((desc = dm_get_descriptor_by_name(DM_ALIAS, dev, &err)) != NULL) {
		err = check_disk(path, desc, force, isspare);
		dm_free_descriptor(desc);
		return (err);
	}

	return (check_slice(path, force, B_FALSE, isspare));
}
Beispiel #5
0
/*
 * Convenience function to get slice stats
 */
void
dm_get_slice_stats(char *slice, nvlist_t **dev_stats, int *errp)
{
	dm_descriptor_t	devp;

	*dev_stats = NULL;
	*errp = 0;

	if (slice == NULL) {
		return;
	}

	/*
	 * Errors must be handled by the caller. The dm_descriptor_t *
	 * values will be NULL if an error occured in these calls.
	 */
	devp = dm_get_descriptor_by_name(DM_SLICE, slice, errp);
	if (devp != NULL) {
		*dev_stats = dm_get_stats(devp, DM_SLICE_STAT_USE,
		    errp);
		dm_free_descriptor(devp);
	}
}
Beispiel #6
0
/*
 * Returns, via slices paramater, a dm_descriptor_t list of
 * slices for the named disk drive.
 */
void
dm_get_slices(char *drive, dm_descriptor_t **slices, int *errp)
{
	dm_descriptor_t alias;
	dm_descriptor_t	*media;
	dm_descriptor_t *disk;

	*slices = NULL;
	*errp = 0;

	if (drive == NULL) {
		return;
	}

	alias = dm_get_descriptor_by_name(DM_ALIAS, drive, errp);

	/*
	 * Errors must be handled by the caller. The dm_descriptor_t *
	 * values will be NULL if an error occured in these calls.
	 */

	if (alias != NULL) {
		disk = dm_get_associated_descriptors(alias, DM_DRIVE, errp);
		dm_free_descriptor(alias);
		if (disk != NULL) {
			media = dm_get_associated_descriptors(*disk,
			    DM_MEDIA, errp);
			dm_free_descriptors(disk);
			if (media != NULL) {
				*slices = dm_get_associated_descriptors(*media,
				    DM_SLICE, errp);
				dm_free_descriptors(media);
			}
		}
	}
}
Beispiel #7
0
/*
 * Take the deviceID property from the object path and get the raw devpath
 * of the drive that corresponds to the given device ID.
 */
static CIMBool
get_devpath(CCIMObjectPath *op, char *devpath, int len)
{
	CCIMPropertyList	*prop_list = NULL;
	CCIMProperty		*prop = NULL;
	int			error;
	dm_descriptor_t		dp;
	dm_descriptor_t		*da;
	nvlist_t		*attrs;
	char			*opath;
	char			*keyprop;
	int			type = 0;
	char			*p;

	if (strcasecmp(op->mName, "Solaris_Disk") == 0) {
	    keyprop = "Tag";
	    type = 1;
	} else if (strcasecmp(op->mName, "Solaris_DiskDrive") == 0) {
	    keyprop = "deviceid";
	    type = 2;
	} else if (strcasecmp(op->mName, "Solaris_DiskPartition") == 0) {
	    keyprop = "deviceid";
	    type = 3;
	} else {
	    return (cim_false);
	}

	if (op != NULL) {
	    prop_list = op->mKeyProperties;
	}

	for (; prop_list; prop_list = prop_list->mNext) {

	    if (((prop = prop_list->mDataObject) != NULL &&
		prop->mName != NULL && strcasecmp(prop->mName, keyprop)) == 0) {
		break;
	    }
	}

	if (prop == NULL || prop->mValue == NULL) {
	    return (cim_false);
	}

	switch (type) {
	case 1:
	    dp = dm_get_descriptor_by_name(DM_MEDIA, prop->mValue, &error);
	    if (error != 0) {
		return (cim_false);
	    }

	    da = dm_get_associated_descriptors(dp, DM_DRIVE, &error);
	    dm_free_descriptor(dp);
	    if (error != 0 || da == NULL) {
		return (cim_false);
	    }

	    if (da[0] == NULL) {
		dm_free_descriptors(da);
		return (cim_false);
	    }

	    attrs = dm_get_attributes(da[0], &error);
	    dm_free_descriptors(da);
	    if (error != 0) {
		return (cim_false);
	    }

	    if (nvlist_lookup_string(attrs, DM_OPATH, &opath) != 0) {
		nvlist_free(attrs);
		return (cim_false);
	    }
	    (void) strlcpy(devpath, opath, len);
	    nvlist_free(attrs);
	    break;

	case 2:
	    dp = dm_get_descriptor_by_name(DM_DRIVE, prop->mValue, &error);
	    if (error != 0) {
		return (cim_false);
	    }

	    attrs = dm_get_attributes(dp, &error);
	    dm_free_descriptor(dp);
	    if (error != 0) {
		return (cim_false);
	    }

	    if (nvlist_lookup_string(attrs, DM_OPATH, &opath) != 0) {
		nvlist_free(attrs);
		return (cim_false);
	    }
	    (void) strlcpy(devpath, opath, len);
	    nvlist_free(attrs);
	    break;

	case 3:
	    /* Convert the Solaris_DiskPartition value to rdsk. */
	    p = strstr(prop->mValue, "/dsk/");
	    if (p == NULL || (strlen(prop->mValue) + 2) > len) {
		(void) strlcpy(devpath, prop->mValue, len);
	    } else {
		p++;
		*p = 0;
		(void) strcpy(devpath, prop->mValue);	/* copy up to dsk/ */
		*p = 'd';
		(void) strcat(devpath, "r");		/* prefix 'r' to dsk/ */
		(void) strcat(devpath, p);		/* append the rest */
	    }
	    break;
	}

	return (cim_true);
}
Beispiel #8
0
/*
 * Set the properties of the disk node, from dev_di_node_t data.
 * Properties include:
 *	group: protocol	 properties: resource, asru, label, fru
 *	group: authority properties: product-id, chasis-id, server-id
 *	group: io	 properties: devfs-path, devid
 *	group: storage	 properties:
 *		- logical-disk, disk-model, disk-manufacturer, serial-number
 *		- firmware-revision, capacity-in-bytes
 *
 * NOTE: the io and storage groups won't be present if the dnode passed in is
 * NULL. This happens when a disk is found through ses, but is not enumerated
 * in the devinfo tree.
 */
static int
disk_set_props(topo_mod_t *mod, tnode_t *parent,
    tnode_t *dtn, dev_di_node_t *dnode)
{
	nvlist_t	*asru = NULL, *drive_attrs;
	char		*label = NULL;
	nvlist_t	*fmri = NULL;
	dm_descriptor_t drive_descr = NULL;
	uint32_t	rpm;
	int		err;

	/* pull the label property down from our parent 'bay' node */
	if (topo_node_label(parent, &label, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "label error %s\n", topo_strerror(err));
		goto error;
	}
	if (topo_node_label_set(dtn, label, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "label_set error %s\n", topo_strerror(err));
		goto error;
	}

	/* get the resource fmri, and use it as the fru */
	if (topo_node_resource(dtn, &fmri, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "resource error: %s\n", topo_strerror(err));
		goto error;
	}
	if (topo_node_fru_set(dtn, fmri, 0, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "fru_set error: %s\n", topo_strerror(err));
		goto error;
	}

	/* create/set the authority group */
	if ((topo_pgroup_create(dtn, &disk_auth_pgroup, &err) != 0) &&
	    (err != ETOPO_PROP_DEFD)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "create disk_auth error %s\n", topo_strerror(err));
		goto error;
	}

	/* create the storage group */
	if (topo_pgroup_create(dtn, &storage_pgroup, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "create storage error %s\n", topo_strerror(err));
		goto error;
	}

	/* no dnode was found for this disk - skip the io and storage groups */
	if (dnode == NULL) {
		err = 0;
		goto out;
	}

	/* form and set the asru */
	if ((asru = topo_mod_devfmri(mod, FM_DEV_SCHEME_VERSION,
	    dnode->ddn_dpath, dnode->ddn_devid)) == NULL) {
		err = ETOPO_FMRI_UNKNOWN;
		topo_mod_dprintf(mod, "disk_set_props: "
		    "asru error %s\n", topo_strerror(err));
		goto error;
	}
	if (topo_node_asru_set(dtn, asru, 0, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "asru_set error %s\n", topo_strerror(err));
		goto error;
	}

	/* create/set the devfs-path and devid in the io group */
	if (topo_pgroup_create(dtn, &io_pgroup, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "create io error %s\n", topo_strerror(err));
		goto error;
	}

	if (topo_prop_set_string(dtn, TOPO_PGROUP_IO, TOPO_IO_DEV_PATH,
	    TOPO_PROP_IMMUTABLE, dnode->ddn_dpath, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set dev error %s\n", topo_strerror(err));
		goto error;
	}

	if (dnode->ddn_devid && topo_prop_set_string(dtn, TOPO_PGROUP_IO,
	    TOPO_IO_DEVID, TOPO_PROP_IMMUTABLE, dnode->ddn_devid, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set devid error %s\n", topo_strerror(err));
		goto error;
	}

	if (dnode->ddn_ppath_count != 0 &&
	    topo_prop_set_string_array(dtn, TOPO_PGROUP_IO, TOPO_IO_PHYS_PATH,
	    TOPO_PROP_IMMUTABLE, (const char **)dnode->ddn_ppath,
	    dnode->ddn_ppath_count, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set phys-path error %s\n", topo_strerror(err));
		goto error;
	}

	/* set the storage group public /dev name */
	if (dnode->ddn_lpath != NULL &&
	    topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_LOGICAL_DISK_NAME, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_lpath, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set disk_name error %s\n", topo_strerror(err));
		goto error;
	}

	/* populate other misc storage group properties */
	if (dnode->ddn_mfg && (topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_MANUFACTURER, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_mfg, &err) != 0)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set mfg error %s\n", topo_strerror(err));
		goto error;
	}
	if (dnode->ddn_model && (topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_MODEL, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_model, &err) != 0)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set model error %s\n", topo_strerror(err));
		goto error;
	}
	if (dnode->ddn_serial && (topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_SERIAL_NUM, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_serial, &err) != 0)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set serial error %s\n", topo_strerror(err));
		goto error;
	}
	if (dnode->ddn_firm && (topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_FIRMWARE_REV, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_firm, &err) != 0)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set firm error %s\n", topo_strerror(err));
		goto error;
	}
	if (dnode->ddn_cap && (topo_prop_set_string(dtn, TOPO_PGROUP_STORAGE,
	    TOPO_STORAGE_CAPACITY, TOPO_PROP_IMMUTABLE,
	    dnode->ddn_cap, &err) != 0)) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set cap error %s\n", topo_strerror(err));
		goto error;
	}

	if (dnode->ddn_devid == NULL ||
	    (drive_descr = dm_get_descriptor_by_name(DM_DRIVE,
	    dnode->ddn_devid, &err)) == NULL ||
	    (drive_attrs = dm_get_attributes(drive_descr, &err)) == NULL)
		goto out;

	if (nvlist_lookup_boolean(drive_attrs, DM_SOLIDSTATE) == 0 ||
	    nvlist_lookup_uint32(drive_attrs, DM_RPM, &rpm) != 0)
		goto out;

	if (topo_prop_set_uint32(dtn, TOPO_PGROUP_STORAGE, TOPO_STORAGE_RPM,
	    TOPO_PROP_IMMUTABLE, rpm, &err) != 0) {
		topo_mod_dprintf(mod, "disk_set_props: "
		    "set rpm error %s\n", topo_strerror(err));
		dm_free_descriptor(drive_descr);
		goto error;
	}
	err = 0;

out:
	if (drive_descr != NULL)
		dm_free_descriptor(drive_descr);
	nvlist_free(fmri);
	if (label)
		topo_mod_strfree(mod, label);
	nvlist_free(asru);
	return (err);

error:	err = topo_mod_seterrno(mod, err);
	goto out;
}
Beispiel #9
0
/*
 * Checks for overlapping slices.   If the given device is a slice, and it
 * overlaps with any non-backup slice on the disk, return true with a detailed
 * description similar to dm_inuse().
 */
int
dm_isoverlapping(char *slicename, char **overlaps_with, int *errp)
{
	dm_descriptor_t slice = NULL;
	dm_descriptor_t *media = NULL;
	dm_descriptor_t *slices = NULL;
	int 		i = 0;
	uint32_t	in_snum;
	uint64_t 	start_block = 0;
	uint64_t 	end_block = 0;
	uint64_t 	media_size = 0;
	uint64_t 	size = 0;
	nvlist_t 	*media_attrs = NULL;
	nvlist_t 	*slice_attrs = NULL;
	int		ret = 0;

	slice = dm_get_descriptor_by_name(DM_SLICE, slicename, errp);
	if (slice == NULL)
		goto out;

	/*
	 * Get the list of slices be fetching the associated media, and then all
	 * associated slices.
	 */
	media = dm_get_associated_descriptors(slice, DM_MEDIA, errp);
	if (media == NULL || *media == NULL || *errp != 0)
		goto out;

	slices = dm_get_associated_descriptors(*media, DM_SLICE, errp);
	if (slices == NULL || *slices == NULL || *errp != 0)
		goto out;

	media_attrs = dm_get_attributes(*media, errp);
	if (media_attrs == NULL || *errp)
		goto out;

	*errp = nvlist_lookup_uint64(media_attrs, DM_NACCESSIBLE, &media_size);
	if (*errp != 0)
		goto out;

	slice_attrs = dm_get_attributes(slice, errp);
	if (slice_attrs == NULL || *errp != 0)
		goto out;

	*errp = nvlist_lookup_uint64(slice_attrs, DM_START, &start_block);
	if (*errp != 0)
		goto out;

	*errp = nvlist_lookup_uint64(slice_attrs, DM_SIZE, &size);
	if (*errp != 0)
		goto out;

	*errp = nvlist_lookup_uint32(slice_attrs, DM_INDEX, &in_snum);
	if (*errp != 0)
		goto out;

	end_block = (start_block + size) - 1;

	for (i = 0; slices[i]; i ++) {
		uint64_t other_start;
		uint64_t other_end;
		uint64_t other_size;
		uint32_t snum;

		nvlist_t *other_attrs = dm_get_attributes(slices[i], errp);

		if (other_attrs == NULL)
			continue;

		if (*errp != 0)
			goto out;

		*errp = nvlist_lookup_uint64(other_attrs, DM_START,
		    &other_start);
		if (*errp) {
			nvlist_free(other_attrs);
			goto out;
		}

		*errp = nvlist_lookup_uint64(other_attrs, DM_SIZE,
		    &other_size);

		if (*errp) {
			nvlist_free(other_attrs);
			ret = -1;
			goto out;
		}

		other_end = (other_size + other_start) - 1;

		*errp = nvlist_lookup_uint32(other_attrs, DM_INDEX,
		    &snum);

		if (*errp) {
			nvlist_free(other_attrs);
			ret = -1;
			goto out;
		}

		/*
		 * Check to see if there are > 2 overlapping regions
		 * on this media in the same region as this slice.
		 * This is done by assuming the following:
		 *   	Slice 2 is the backup slice if it is the size
		 *	of the whole disk
		 * If slice 2 is the overlap and slice 2 is the size of
		 * the whole disk, continue. If another slice is found
		 * that overlaps with our slice, return it.
		 * There is the potential that there is more than one slice
		 * that our slice overlaps with, however, we only return
		 * the first overlapping slice we find.
		 *
		 */
		if (start_block >= other_start && start_block <= other_end) {
			if ((snum == 2 && (other_size == media_size)) ||
			    snum == in_snum) {
				continue;
			} else {
				char *str = dm_get_name(slices[i], errp);
				if (*errp != 0) {
					nvlist_free(other_attrs);
					ret = -1;
					goto out;
				}
				*overlaps_with = strdup(str);
				dm_free_name(str);
				nvlist_free(other_attrs);
				ret = 1;
				goto out;
			}
		} else if (other_start >= start_block &&
		    other_start <= end_block) {
			if ((snum == 2 && (other_size == media_size)) ||
			    snum == in_snum) {
				continue;
			} else {
				char *str = dm_get_name(slices[i], errp);
				if (*errp != 0) {
					nvlist_free(other_attrs);
					ret = -1;
					goto out;
				}
				*overlaps_with = strdup(str);
				dm_free_name(str);
				nvlist_free(other_attrs);
				ret = 1;
				goto out;
			}
		}
		nvlist_free(other_attrs);
	}

out:
	if (media_attrs)
		nvlist_free(media_attrs);
	if (slice_attrs)
		nvlist_free(slice_attrs);

	if (slices)
		dm_free_descriptors(slices);
	if (media)
		dm_free_descriptors(media);
	if (slice)
		dm_free_descriptor(slice);

	return (ret);
}
Beispiel #10
0
/* ARGSUSED */
CCIMInstance*
cp_getInstance_Solaris_IDEInterface(CCIMObjectPath* pOP)
{
	CCIMInstance* 		inst = NULL;
	CCIMPropertyList* 	pCurPropList;
	dm_descriptor_t		d_descriptor;
	dm_descriptor_t		c_descriptor;
	CCIMObjectPath		*antOp = NULL;
	CCIMObjectPath		*depOp = NULL;
	int			error;
	char			*name;

	if (pOP == NULL) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	if ((pCurPropList = pOP->mKeyProperties) == NULL) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	antOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
	    ANTECEDENT, &error);

	if (error == 0) {
	    depOp = (CCIMObjectPath *)util_getKeyValue(pCurPropList, reference,
		DEPENDENT, &error);
	}

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
		NULL, NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	/*
	 * Now, get the name of the antecedent from the object path.
	 */

	if ((pCurPropList = antOp->mKeyProperties) == NULL) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
	    &error);

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
		NULL, NULL, &error);
	}

	/*
	 * The only reason it is needed to get the descriptor for these
	 * two devices is to verify that they still exist and are valid.
	 * If they are not found, then getting the instance for this
	 * association as passed in by the client is not possible.
	 */
	c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
	    &error);
	/*
	 * Not found. Return a null instance.
	 */

	if (c_descriptor == NULL || error == ENODEV) {
	    return ((CCIMInstance *)NULL);
	}

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
	    return ((CCIMInstance*)NULL);
	}
	dm_free_descriptor(c_descriptor);

	/*
	 * Now, get the name of the dependent from the object path.
	 */

	if ((pCurPropList = depOp->mKeyProperties) == NULL) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
	    &error);

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_INVALID_PARAMETER,
		NULL, NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	d_descriptor = dm_get_descriptor_by_name(DM_DRIVE, name,
	    &error);
	/*
	 * Not found. Return a null instance.
	 */

	if (d_descriptor == NULL || error == ENODEV) {
	    d_descriptor = dm_get_descriptor_by_name(DM_ALIAS, name,
		&error);
	    if (d_descriptor == NULL || error == ENODEV) {
		util_handleError(IDE_GETINSTANCE, CIM_ERR_NOT_FOUND,
		    NULL, NULL, &error);
		return ((CCIMInstance *)NULL);
	    }
	}

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	dm_free_descriptor(d_descriptor);

	/*
	 * At this point I have verified I have the two devices that
	 * are part of this association. Use the object paths I got
	 * earlier to create the ideinterface instance.
	 */
	inst = ideIntAssocToInst(antOp, ANTECEDENT, depOp, DEPENDENT, &error);

	if (error != 0) {
	    util_handleError(IDE_GETINSTANCE, CIM_ERR_FAILED,
		IDEINT_ASSOC_TO_INSTANCE_FAILURE, NULL, &error);
	    return ((CCIMInstance *)NULL);
	}

	return (inst);
}
Beispiel #11
0
/* ARGSUSED */
CCIMInstanceList *
cp_associators_Solaris_IDEInterface(CCIMObjectPath *pAssocName,
    CCIMObjectPath *pObjectName, cimchar *pResultClass, cimchar *pRole,
	cimchar *pResultRole)
{
	CCIMPropertyList	*pCurPropList;
	CCIMInstanceList	*instList = NULL;
	dm_descriptor_t		*assoc_descriptors = NULL;
	dm_descriptor_t		*tmpList = NULL;
	dm_descriptor_t		obj_desc = NULL;
	char			*name;
	int			error = 0;
	int			isAntecedent = 0;
	int			isAlias = 0;

	if ((pObjectName == NULL ||
	    (pCurPropList = pObjectName->mKeyProperties) == NULL)) {
	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstanceList *)NULL);
	}

	if (strcasecmp(pObjectName->mName, IDE_CONTROLLER) == 0) {
	    isAntecedent = 1;
	}

	if (pRole != NULL) {
	    if (strcasecmp(pRole, ANTECEDENT) == 0) {
		if (isAntecedent != 1) {
		    util_handleError(IDE_ASSOCIATORS,
			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
		    return ((CCIMInstanceList *)NULL);
		}
	    } else if (strcasecmp(pRole, DEPENDENT) == 0) {
		if (isAntecedent == 1) {
		    util_handleError(IDE_ASSOCIATORS,
			CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
		    return ((CCIMInstanceList *)NULL);
		}
	    }
	}

	/*
	 * Both ide controller and disk drive have deviceid as the
	 * key.
	 */

	name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
	    &error);
	if (error != 0) {
	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
		NULL, &error);
	    return ((CCIMInstanceList *)NULL);
	}

	if (isAntecedent) {
	    obj_desc = dm_get_descriptor_by_name(DM_CONTROLLER, name,
		&error);
	} else {
	    obj_desc = dm_get_descriptor_by_name(DM_DRIVE, name,
		&error);
	    if (obj_desc == NULL || error == ENODEV) {
		isAlias = 1;
		obj_desc = dm_get_descriptor_by_name(DM_ALIAS, name, &error);
	    }
	}

	if (obj_desc == NULL) {
	    return ((CCIMInstanceList *)NULL);
	}

	if (error != 0) {
	    util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
		DM_GET_DESC_BYNAME_FAILURE, NULL, &error);
	    return ((CCIMInstanceList *)NULL);
	}

	if (isAlias) {
	    tmpList = dm_get_associated_descriptors(obj_desc, DM_DRIVE,
		&error);
	    if (tmpList == NULL) {
		return ((CCIMInstanceList *)NULL);
	    }

	    if (tmpList[0] == NULL) {
		dm_free_descriptors(tmpList);
		return ((CCIMInstanceList *)NULL);
	    }
	}


	if (isAntecedent) {
		/*
		 * Get associated descriptors.
		 */

	    assoc_descriptors = dm_get_associated_descriptors(obj_desc,
		DM_DRIVE, &error);
	    dm_free_descriptor(obj_desc);

	    if (assoc_descriptors == NULL) {
		return (instList);
	    }

	    if (assoc_descriptors[0] == NULL) {
		dm_free_descriptors(assoc_descriptors);
		return (instList);
	    }

	    if (error != 0) {
		util_handleError(IDE_ASSOCIATORS,  CIM_ERR_FAILED,
		    DM_GET_ASSOC_FAILURE, NULL, &error);
		return ((CCIMInstanceList *)NULL);
	    }

		/*
		 * Generate the inst list of the associated disk drives.
		 */

	    instList = drive_descriptors_toCCIMObjPathInstList(DISK_DRIVE,
		assoc_descriptors, &error);
	    dm_free_descriptors(assoc_descriptors);

	    if (error != 0) {
		util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
		return ((CCIMInstanceList *)NULL);
	    }
	} else {
		/*
		 * This is the disk drive calling this function. Return the
		 * controllers that are associated with this disk.
		 */

	    if (tmpList == NULL && obj_desc == NULL) {
		return ((CCIMInstanceList *)NULL);
	    }

	    if (tmpList != NULL) {
		assoc_descriptors = dm_get_associated_descriptors(tmpList[0],
		    DM_CONTROLLER, &error);
		dm_free_descriptors(tmpList);
	    } else {
		assoc_descriptors = dm_get_associated_descriptors(obj_desc,
		    DM_CONTROLLER, &error);
		dm_free_descriptor(obj_desc);
	    }

	    if (assoc_descriptors == NULL) {
		return ((CCIMInstanceList *)NULL);
	    }

	    if (assoc_descriptors[0] == NULL) {
		dm_free_descriptors(assoc_descriptors);
		return ((CCIMInstanceList *)NULL);
	    }

	    if (error != 0) {
		util_handleError(IDE_ASSOCIATORS,  CIM_ERR_FAILED,
		    DM_GET_ASSOC_FAILURE, NULL, &error);
		return ((CCIMInstanceList *)NULL);
	    }

	    instList = ctrl_descriptors_toCCIMInstanceList(IDE_CONTROLLER,
		assoc_descriptors, &error, 2, "ata", "pcata");
	    dm_free_descriptors(assoc_descriptors);

	    if (error != 0) {
		util_handleError(IDE_ASSOCIATORS, CIM_ERR_FAILED,
		    IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
		return ((CCIMInstanceList *)NULL);
	    }
	}

	return (instList);
}
Beispiel #12
0
/* ARGSUSED */
CCIMInstanceList*
cp_enumInstances_Solaris_IDEInterface(CCIMObjectPath* pOP)
{
	CCIMInstanceList	*instList = NULL;
	CCIMObjectPathList	*cObjList = NULL;
	CCIMObjectPathList	*tmpObjList;
	CCIMObjectPath		*objPath;
	CCIMInstance		*inst;
	CCIMException		*ex;
	dm_descriptor_t		*d_descriptorp = NULL;
	int			error = 0;

	/*
	 * Get the list of IDE Controllers. Then get the associated drives
	 * via the device api.
	 */

	objPath = cim_createEmptyObjectPath(IDE_CONTROLLER);
	if (objPath == NULL) {
	    ex = cim_getLastError();
	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		CREATE_OBJECT_PATH, ex, &error);
	    return ((CCIMInstanceList *)NULL);
	}

	cObjList = cimom_enumerateInstanceNames(objPath, cim_false);
	cim_freeObjectPath(objPath);

	/*
	 * NULL means error.
	 */
	if (cObjList == NULL) {
	    ex = cim_getLastError();
	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		ENUM_INSTANCENAMES_FAILURE, ex, &error);
	    return ((CCIMInstanceList *)NULL);
	}

	if (cObjList->mDataObject == NULL) {
	    return ((CCIMInstanceList *)NULL);
	}

	instList = cim_createInstanceList();
	if (instList == NULL) {
	    ex = cim_getLastError();
	    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		CREATE_INSTANCE_LIST_FAILURE, ex, &error);
	    return ((CCIMInstanceList *)NULL);
	}
	/*
	 * Loop through all of these controller objects and get the associated
	 * disks.
	 */

	for (tmpObjList = cObjList;
	    tmpObjList != NULL && tmpObjList->mDataObject != NULL;
		tmpObjList = tmpObjList->mNext) {

	    char 		*name = NULL;
	    CCIMObjectPath 	*cOp;
	    CCIMInstanceList	*tmpList = NULL;
	    CCIMInstanceList	*tmpList1;
	    CCIMPropertyList	*pCurPropList;
	    CCIMObjectPathList	*dObjList;
	    CCIMInstanceList	*tL;
	    dm_descriptor_t	c_descriptor = NULL;
	    error = 0;

	    cOp = tmpObjList->mDataObject;
	    if ((pCurPropList = cOp->mKeyProperties) == NULL) {
		util_handleError(IDE_ENUMINSTANCES,
		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
		cim_freeObjectPathList(cObjList);
		cim_freeInstanceList(instList);
		return ((CCIMInstanceList *)NULL);
	    }

	    name = (cimchar *)util_getKeyValue(pCurPropList, string, DEVICEID,
		&error);

	    if (error != 0) {
		util_handleError(IDE_ENUMINSTANCES,
		    CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
		cim_freeObjectPathList(cObjList);
		cim_freeInstanceList(instList);
		return ((CCIMInstanceList *)NULL);
	    }

	    c_descriptor = dm_get_descriptor_by_name(DM_CONTROLLER, name,
		&error);
	    if (c_descriptor == NULL || error == ENODEV) {
		continue;
	    }
	    if (error != 0) {
		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		    DM_GET_DESC_BYNAME_FAILURE, NULL,
			&error);
		cim_freeObjectPathList(cObjList);
		cim_freeInstanceList(instList);
		return ((CCIMInstanceList *)NULL);
	    }

	    d_descriptorp = dm_get_associated_descriptors(c_descriptor,
		DM_DRIVE, &error);
	    dm_free_descriptor(c_descriptor);

		/*
		 * If there are no drives associated with this controller,
		 * continue on to the next controller.
		 */

	    if (d_descriptorp == NULL) {
		continue;
	    }

	    if (d_descriptorp[0] == NULL) {
		dm_free_descriptors(d_descriptorp);
		continue;
	    }

	    if (error == ENODEV) {
		continue;
	    }

	    if (error != 0) {
		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		    DM_GET_ASSOC_FAILURE, NULL, &error);
		cim_freeInstanceList(instList);
		cim_freeObjectPathList(cObjList);
		return ((CCIMInstanceList *)NULL);
	    }

	    tmpList = drive_descriptors_toCCIMObjPathInstList(
		DISK_DRIVE, d_descriptorp, &error);
	    dm_free_descriptors(d_descriptorp);
	    d_descriptorp = NULL;

	    if (error != 0) {
		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
		cim_freeInstanceList(instList);
		cim_freeObjectPathList(cObjList);
		return ((CCIMInstanceList *)NULL);
	    }

		/*
		 * It is possible that the controller does not have a drive
		 * associated with it. If this is true, the list will be
		 * NULL.
		 */

	    if (tmpList == NULL) {
		continue;
	    }

	    dObjList = cim_createObjectPathList(tmpList);
	    cim_freeInstanceList(tmpList);

	    if (dObjList == NULL) {
		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		    DRIVE_DESC_TO_INSTANCE_FAILURE, NULL, &error);
		cim_freeInstanceList(instList);
		cim_freeObjectPathList(cObjList);
		return ((CCIMInstanceList *)NULL);
	    }
	    tmpList1 = ideIntAssocToInstList(
		cOp, ANTECEDENT, dObjList, DEPENDENT, &error);
	    cim_freeObjectPathList(dObjList);

	    if (error != 0) {
		util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
		    IDECTRL_DESC_TO_INSTANCE_FAILURE, NULL, &error);
		cim_freeInstanceList(instList);
		cim_freeObjectPathList(cObjList);
		return ((CCIMInstanceList *)NULL);
	    }

	    tL = tmpList1;
	    do {
		inst = cim_copyInstance(tL->mDataObject);
		instList = cim_addInstance(instList, inst);
		if (instList == NULL) {
		    util_handleError(IDE_ENUMINSTANCES, CIM_ERR_FAILED,
			ADD_INSTANCE_FAILURE, NULL, &error);
		    cim_freeObjectPathList(cObjList);
		    cim_freeObjectPathList(tmpList1);
		    return ((CCIMInstanceList *)NULL);
		}
		tL = tL->mNext;
	    } while (tL && tL->mDataObject != NULL);

	    cim_freeInstanceList(tmpList1);
	} /* end for */

	cim_freeObjectPathList(cObjList);
	/*
	 * It is possible I will have an empty instance list at
	 * this point. So, I must check and NULL this out if
	 * there are no entries.
	 */
	if (instList->mDataObject == NULL) {
	    cim_freeInstanceList(instList);
	    instList = NULL;
	}
	return (instList);
}