コード例 #1
0
ファイル: methods.c プロジェクト: andreiw/polaris
/*
 * 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);
}
コード例 #2
0
/*
 * Iterates through each available disk on the system.  For each free
 * dmgt_disk_t *, runs the given function with the dmgt_disk_t * as
 * the first arg and the given void * as the second arg.
 */
int
dmgt_avail_disk_iter(dmgt_disk_iter_f func, void *data)
{
    int error = 0;
    int filter[] = { DM_DT_FIXED, -1 };

    /* Search for fixed disks */
    dm_descriptor_t *disks = dm_get_descriptors(DM_DRIVE, filter, &error);

    if (error) {
        handle_error("unable to communicate with libdiskmgt");
    } else {
        int i;

        /* For each disk... */
        for (i = 0; disks != NULL && disks[i] != NULL; i++) {
            dm_descriptor_t disk = (dm_descriptor_t)disks[i];
            int online;

            /* Reset error flag for each disk */
            error = 0;

            /* Is this disk online? */
            online = get_disk_online(disk, &error);
            if (!error && online) {

                /* Get a dmgt_disk_t for this dm_descriptor_t */
                dmgt_disk_t *dp = get_disk(disk, &error);
                if (!error) {

                    /*
                     * If this disk or any of its
                     * slices is usable...
                     */
                    if (!dp->in_use ||
                            zjni_count_elements(
                                (void **)dp->slices) != 0) {

                        /* Run the given function */
                        if (func(dp, data)) {
                            error = -1;
                        }
                        dmgt_free_disk(dp);
#ifdef DEBUG
                    } else {
                        (void) fprintf(stderr, "disk "
                                       "has no available slices: "
                                       "%s\n", dp->name);
#endif
                    }

                }
            }
        }
        dm_free_descriptors(disks);
    }
    return (error);
}
コード例 #3
0
ファイル: entry.c プロジェクト: apprisi/illumos-gate
/*
 * 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);
			}
		}
	}
}
コード例 #4
0
ファイル: diskinfo.c プロジェクト: cornet/smartos-live
int
main(int argc, char *argv[])
{
	di_opts_t opts = { B_FALSE, B_FALSE };
	char c;

	dm_descriptor_t *media;
	int error, ii;
	int filter[] = { DM_DT_FIXED, -1 };

	while ((c = getopt(argc, argv, "Hp")) != EOF) {
		switch (c) {
		case 'H':
			opts.di_scripted = B_TRUE;
			break;
		case 'p':
			opts.di_parseable = B_TRUE;
			break;
		default:
			return (1);
		}
	}

	error = 0;
	if ((media = dm_get_descriptors(DM_MEDIA, filter, &error)) == NULL) {
		fprintf(stderr, "Error from dm_get_descriptors: %d\n", error);
		return (1);
	}

	if (!opts.di_scripted) {
		printf("TYPE    DISK      VID         PID"
		    "                SIZE            REMV\n");
	}

	for (ii = 0; media != NULL && media[ii] != NULL; ii++)
		print_disks(media[ii], &opts);
	dm_free_descriptors(media);

	return (0);
}
コード例 #5
0
/*
 * Gets a dmgt_disk_t for the given disk dm_descriptor_t.
 *
 * Results:
 *
 *  1. Success: error is set to 0 and a dmgt_disk_t is returned
 *
 *  2. Failure: error is set to -1 and NULL is returned
 */
static dmgt_disk_t *
get_disk(dm_descriptor_t disk, int *error)
{
    dmgt_disk_t *dp;
    *error = 0;

    dp = (dmgt_disk_t *)calloc(1, sizeof (dmgt_disk_t));
    if (dp == NULL) {
        handle_error("out of memory");
        *error = -1;
    } else {

        /* Get name */
        dp->name = get_device_name(disk, error);
        if (!*error) {

            /* Get aliases */
            dp->aliases = get_disk_aliases(disk, dp->name, error);
            if (!*error) {

                /* Get media */
                dm_descriptor_t *media =
                    dm_get_associated_descriptors(disk,
                                                  DM_MEDIA, error);
                if (*error != 0 || media == NULL ||
                        *media == NULL) {
                    handle_error(
                        "could not get media from disk %s",
                        dp->name);
                    *error = -1;
                } else {
                    /* Get size */
                    get_disk_size(media[0], dp->name,
                                  &(dp->size), &(dp->blocksize),
                                  error);
                    if (!*error) {
                        /* Get free slices */
                        dp->slices =
                            get_disk_usable_slices(
                                media[0], dp->name,
                                dp->blocksize,
                                &(dp->in_use), error);
                    }
                    dm_free_descriptors(media);
                }
            }
        }
    }

    if (*error) {
        /* Normalize error */
        *error = -1;

        if (dp != NULL) {
            dmgt_free_disk(dp);
            dp = NULL;
        }
    }

    return (dp);
}
コード例 #6
0
ファイル: methods.c プロジェクト: andreiw/polaris
/*
 * 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);
}
コード例 #7
0
ファイル: methods.c プロジェクト: andreiw/polaris
/*
 * Function:	getFdisk
 *
 * Parameters:	outParams - CCIMPropertyList pointer.  The output from
 *		the fdisk command is placed in this list.
 *		op - CCIMObjectPath pointer.  The object path contains
 *		deviceID of the device to fdisk.
 *
 * Returns:	Returns a CCIMProperty pointer.  The CCIMProperty referenced
 *		by the pointer will contain an mValue of cim_true for
 *		success or cim_false on failure.
 *
 * Notes:	The calling program is responsible for releasing the memory
 *		used by the returned CCIMProperty and the CCIMPropertyList
 *		pointed to by outParams.  I don't know why we return only
 *		four of the possible values from fdisk.  That is the way
 *		the Java provider worked and this provider was written to
 *		mimic the Java provider.
 */
CCIMProperty *
getFdisk(CCIMPropertyList *outParams, CCIMObjectPath *op)
{
	dm_descriptor_t		*da;
	int			i;
	int			cnt;
	ulong_t			*ret_array;
	int			error;
	char			*array_str;
	CCIMProperty		*prop;

	if (cim_checkRights(DISK_DRIVE, DISK_READ_RIGHT, (void *) NULL) ==
	    cim_false || op == NULL) {
		return (create_result_out(PROPFALSE, outParams));
	}

	if ((da = get_partition_descs(op)) == NULL) {
	    return (create_result_out(PROPFALSE, outParams));
	}

	/* Count the number of fdisk partitions. */
	for (cnt = 0; da[cnt]; cnt++);

	/* We return 4 values for each partition. */
	cnt = cnt * 4;

	ret_array = (ulong_t *)calloc(cnt, sizeof (ulong_t));
	if (ret_array == NULL) {
	    dm_free_descriptors(da);
	    util_handleError(DISK_DRIVE, CIM_ERR_FAILED, CIM_ERR_FAILED, NULL,
		&error);
	    return (create_result_out(PROPFALSE, outParams));
	}

	for (i = 0; da[i]; i++) {
	    if (!add_fdisk_props(ret_array, i, da[i])) {
		dm_free_descriptors(da);
		free(ret_array);
		return (create_result_out(PROPFALSE, outParams));
	    }
	}

	dm_free_descriptors(da);

	array_str = cim_encodeUint32Array(ret_array, cnt);

	free(ret_array);

	if (array_str == NULL) {
	    util_handleError(DISK_DRIVE, CIM_ERR_FAILED, CIM_ERR_FAILED, NULL,
		&error);
	    return (create_result_out(PROPFALSE, outParams));
	}

	if ((prop = cim_createProperty("FDiskPartitions", sint32_array,
	    array_str, NULL, cim_false)) == NULL) {
	    free(array_str);
	    return (create_result_out(PROPFALSE, outParams));
	}

	if ((cim_addPropertyToPropertyList(outParams, prop)) == NULL) {
	    cim_freeProperty(prop);
	    return (create_result_out(PROPFALSE, outParams));
	}

	return (create_result_out(PROPTRUE, outParams));
}
コード例 #8
0
ファイル: entry.c プロジェクト: apprisi/illumos-gate
/*
 * 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);
}
コード例 #9
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);
}
コード例 #10
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);
}
コード例 #11
0
ファイル: diskinfo.c プロジェクト: cornet/smartos-live
static void
print_disks(dm_descriptor_t media, di_opts_t *opts)
{
	dm_descriptor_t *disk, *controller;
	nvlist_t *mattrs, *dattrs, *cattrs;
	int error;

	uint64_t size, total;
	uint32_t blocksize;
	double total_in_GiB;
	char sizestr[32];

	char *vid, *pid, *opath, *c, *ctype;
	boolean_t removable;
	char device[MAXPATHLEN];
	size_t len;

	mattrs = dm_get_attributes(media, &error);
	assert(nvlist_lookup_uint64(mattrs, DM_SIZE, &size) == 0);
	assert(nvlist_lookup_uint32(mattrs, DM_BLOCKSIZE, &blocksize) == 0);
	nvlist_free(mattrs);

	if ((disk = dm_get_associated_descriptors(media,
	    DM_DRIVE, &error)) != NULL) {
		dattrs = dm_get_attributes(disk[0], &error);

		nvlist_query_string(dattrs, DM_VENDOR_ID, &vid);
		nvlist_query_string(dattrs, DM_PRODUCT_ID, &pid);
		nvlist_query_string(dattrs, DM_OPATH, &opath);

		removable = B_FALSE;
		(void) nvlist_lookup_boolean_value(dattrs,
		    DM_REMOVABLE, &removable);

		if ((controller = dm_get_associated_descriptors(disk[0],
		    DM_CONTROLLER, &error)) != NULL) {
			cattrs = dm_get_attributes(controller[0], &error);
			nvlist_query_string(cattrs, DM_CTYPE, &ctype);
			for (c = ctype; *c != '\0'; c++)
				*c = toupper(*c);
		}

		/*
		 * Parse full device path to only show the device name, i.e.
		 * c0t1d0.  Many paths will reference a particular slice
		 * (c0t1d0s0), so remove the slice if present.
		 */
		if ((c = strrchr(opath, '/')) != NULL)
			(void) strlcpy(device, c + 1, sizeof (device));
		else
			(void) strlcpy(device, opath, sizeof (device));
		len = strlen(device);
		if (device[len - 2] == 's' &&
		    (device[len - 1] >= '0' && device[len - 1] <= '9'))
			device[len - 2] = '\0';

		/*
		 * The size is given in blocks, so multiply the number of blocks
		 * by the block size to get the total size, then convert to GiB.
		 */
		total = size * blocksize;

		if (opts->di_parseable) {
			(void) snprintf(sizestr, sizeof (sizestr),
			    "%llu", total);
		} else {
			total_in_GiB = (double)total/ 1024.0 / 1024.0 / 1024.0;
			(void) snprintf(sizestr, sizeof (sizestr),
			    "%.2f GiB", total_in_GiB);
		}

		if (opts->di_scripted) {
			printf("%s\t%s\t%s\t%s\t%s\t%s\n",
			    ctype, device, vid, pid, sizestr,
			    removable ? "yes" : "no");
		} else {
			printf("%-4s    %-6s    %-8s    %-16s   "
			    "%-12s    %-4s\n", ctype, device,
			    vid, pid, sizestr, removable ? "yes" : "no");
		}

		nvlist_free(cattrs);
		nvlist_free(dattrs);
		dm_free_descriptors(controller);
	}

	dm_free_descriptors(disk);
}
コード例 #12
0
/* ARGSUSED */
int
check_disk(const char *name, dm_descriptor_t disk, int force, int isspare)
{
	dm_descriptor_t *drive, *media, *slice;
	int err = 0;
	int i;
	int ret;

	/*
	 * Get the drive associated with this disk.  This should never fail,
	 * because we already have an alias handle open for the device.
	 */
	if ((drive = dm_get_associated_descriptors(disk, DM_DRIVE,
	    &err)) == NULL || *drive == NULL) {
		if (err)
			libdiskmgt_error(err);
		return (0);
	}

	if ((media = dm_get_associated_descriptors(*drive, DM_MEDIA,
	    &err)) == NULL) {
		dm_free_descriptors(drive);
		if (err)
			libdiskmgt_error(err);
		return (0);
	}

	dm_free_descriptors(drive);

	/*
	 * It is possible that the user has specified a removable media drive,
	 * and the media is not present.
	 */
	if (*media == NULL) {
		dm_free_descriptors(media);
		vdev_error(gettext("'%s' has no media in drive\n"), name);
		return (-1);
	}

	if ((slice = dm_get_associated_descriptors(*media, DM_SLICE,
	    &err)) == NULL) {
		dm_free_descriptors(media);
		if (err)
			libdiskmgt_error(err);
		return (0);
	}

	dm_free_descriptors(media);

	ret = 0;

	/*
	 * Iterate over all slices and report any errors.  We don't care about
	 * overlapping slices because we are using the whole disk.
	 */
	for (i = 0; slice[i] != NULL; i++) {
		char *name = dm_get_name(slice[i], &err);

		if (check_slice(name, force, B_TRUE, isspare) != 0)
			ret = -1;

		dm_free_name(name);
	}

	dm_free_descriptors(slice);
	return (ret);
}