示例#1
0
func (s *Server) updateNameVolumeMap() error {
	volumeUUIDs := util.ListConfigIDs(s.Root, VOLUME_CFG_PREFIX, CFG_POSTFIX)
	for _, uuid := range volumeUUIDs {
		volume := s.loadVolume(uuid)
		if volume == nil {
			return fmt.Errorf("Volume list changed for volume %v, something is wrong", uuid)
		}
		if volume.Name != "" {
			if oldUUID, exists := s.NameVolumeMap[volume.Name]; exists && oldUUID != uuid {
				return fmt.Errorf("Duplicate volume name detected! %v used by both %v and %v",
					oldUUID, uuid)
			}
			s.NameVolumeMap[volume.Name] = uuid
		}
	}
	log.Debugf("Current volume name list: %v", s.NameVolumeMap)

	return nil
}
func (s *Server) ListVolume(volumeUUID, snapshotUUID string) ([]byte, error) {
	resp := api.VolumesResponse{
		Volumes: make(map[string]api.VolumeResponse),
	}

	var volumeUUIDs []string

	if volumeUUID != "" {
		volumeUUIDs = append(volumeUUIDs, volumeUUID)
	} else {
		volumeUUIDs = util.ListConfigIDs(s.Root, VOLUME_CFG_PREFIX, CFG_POSTFIX)
	}

	for _, uuid := range volumeUUIDs {
		volume := s.loadVolume(uuid)
		if volume == nil {
			return nil, fmt.Errorf("Volume list changed for volume %v", uuid)
		}
		resp.Volumes[uuid] = *getVolumeInfo(volume, snapshotUUID)
	}

	return api.ResponseOutput(resp)
}
func (device *Device) listVolumeIDs() []string {
	return util.ListConfigIDs(device.Root, DEVMAPPER_CFG_PREFIX+VOLUME_CFG_PREFIX, CFG_POSTFIX)
}