Esempio n. 1
0
//!
//! Zeroes out the volume's slot in the instance struct (no longer used)
//!
//! @param[in] pInstance a pointer to the instance to free a volume from
//! @param[in] sVolumeId the volume identifier string (vol-XXXXXXXX)
//!
//! @return a pointer to the volume structure if found otherwise NULL is returned
//!
//! @pre \li Both the \p pInstance and \p sVolumeId fields must not be NULL.
//!      \li The volume specified by \p sVolumeId must exists
//!
//! @post On success, the volume entry is erased from the instance volume list
//!
ncVolume *free_volume(ncInstance * pInstance, const char *sVolumeId)
{
    int slotsLeft = 0;
    ncVolume *pVol = NULL;
    ncVolume *pLastVol = NULL;

    // Make sure our given parameters are valid
    if ((pInstance == NULL) || (sVolumeId == NULL))
        return (NULL);

    // Check if this volume exists in our volume list
    if ((pVol = find_volume(pInstance, sVolumeId)) == NULL) {
        return (NULL);
    }
    // Make sure this is the volume we're looking for
    if (strncmp(pVol->volumeId, sVolumeId, CHAR_BUFFER_SIZE)) {
        return (NULL);
    }

    pLastVol = pInstance->volumes + (EUCA_MAX_VOLUMES - 1);
    slotsLeft = pLastVol - pVol;

    /* shift the remaining entries up, empty or not */
    if (slotsLeft)
        memmove(pVol, (pVol + 1), (slotsLeft * sizeof(ncVolume)));

    /* empty the last one */
    bzero(pLastVol, sizeof(ncVolume));
    return (pVol);
}
Esempio n. 2
0
//!
//! Records volume's information in the instance struct, updating the non-NULL values if the record
//! already exists
//!
//! @param[in] pInstance a pointer to our instance containing the volume information to save
//! @param[in] sVolumeId the volume identifier string (vol-XXXXXXXX)
//! @param[in] sVolumeAttachmentToken the attachment token associated with this volume and attachment
//! @param[in] sConnectionString the connection string info specific to this host's volume attachment
//! @param[in] sDevName the device name
//! @param[in] sStateName the current volume state name
//! @param[in] sXml the current volume xml
//!
//! @return a pointer to the volume if found. Otherwise NULL is returned.
//!
//! @pre \li Both \p pInstance and \p sVolumeId fields must not be NULL
//!      \li A volume with \p sVolumeId for \p pInstance should exists
//!      \li If such volume does not exists, we must have an empty slot in the volume list
//!
//! @post \li If any of \p pInstance or \p sVolumeId is NULL, the application will throw a SIGABRT signal
//!       \li If the volume is found or if we have an empty slot, the volume information will be saved
//!       \li If the volume is not found and if we do not have empty slot, NULL is returned and nothing is saved
//!
ncVolume *save_volume(ncInstance * pInstance, const char *sVolumeId, const char *sVolumeAttachmentToken, const char *sConnectionString, const char *sDevName,
                      const char *sStateName, const char *sXml)
{
    ncVolume *pVol = NULL;

    // Make sure pInstance and sVolumeId aren't NULL
    assert(pInstance != NULL);
    assert(sVolumeId != NULL);

    // Lookup for our device
    if ((pVol = find_volume(pInstance, sVolumeId)) != NULL) {
        //
        // Save our volume information
        //
        euca_strncpy(pVol->volumeId, sVolumeId, CHAR_BUFFER_SIZE);

        if (sVolumeAttachmentToken)
            euca_strncpy(pVol->attachmentToken, sVolumeAttachmentToken, CHAR_BUFFER_SIZE);

        if (sConnectionString)
            euca_strncpy(pVol->connectionString, sConnectionString, VERY_BIG_CHAR_BUFFER_SIZE);

        if (sDevName)
            euca_strncpy(pVol->devName, sDevName, CHAR_BUFFER_SIZE);

        if (sStateName)
            euca_strncpy(pVol->stateName, sStateName, CHAR_BUFFER_SIZE);

        if (sXml)
            euca_strncpy(pVol->volLibvirtXml, sXml, VERY_BIG_CHAR_BUFFER_SIZE);
    }

    return (pVol);
}
Esempio n. 3
0
static void
query_info_cb (GObject      *source_object,
               GAsyncResult *res,
               gpointer      user_data)
{
  GVfsBackendAfpBrowse *afp_backend = G_VFS_BACKEND_AFP_BROWSE (source_object);
  GVfsJobQueryInfo *job = G_VFS_JOB_QUERY_INFO (user_data);

  GError *err = NULL;
  GVfsAfpVolumeData *vol_data;

  if (!update_cache_finish (afp_backend, res, &err))
  {
    g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
    g_error_free (err);
    return;
  }

  vol_data = find_volume (afp_backend, job->filename);
  if (!vol_data)
  {
    g_vfs_job_failed_literal (G_VFS_JOB (job),  G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                              _("File doesn't exist"));
    return;
  }

  fill_info (job->file_info, vol_data, afp_backend);
  g_vfs_job_succeeded (G_VFS_JOB (job));
}
Esempio n. 4
0
static void add_volume(GUDisksVolumeMonitor* mon, GUDisksDevice* dev, gboolean emit_signal)
{
    if(!find_volume(mon, dev))
    {
        GUDisksVolume* vol = g_udisks_volume_new(mon, dev);
        mon->volumes = g_list_prepend(mon->volumes, vol);
        if(emit_signal)
            g_signal_emit(mon, sig_volume_added, 0, vol);
    }
}
Esempio n. 5
0
static void g_udisks_device_changed(GUDisksDevice* dev, GUDisksVolumeMonitor* mon)
{
    GUDisksDrive* drv = find_drive(mon, dev);
    GUDisksVolume* vol = find_volume(mon, dev);
    /*
    gboolean is_drive = dev->is_drive;
    char* usage = g_strdup(dev->usage);
    */
    g_debug("g_udisks_device_changed");
    if(drv)
    {
        g_signal_emit(mon, sig_drive_changed, 0, drv);
        g_udisks_drive_changed(drv);
        /* it's no longer a drive */
        if(!dev->is_drive)
            remove_drive(mon, dev);
    }
    else
    {
        if(dev->is_drive)
            add_drive(mon, dev, TRUE);
    }

    if(vol)
    {
        update_volume_drive(vol, mon);
        g_signal_emit(mon, sig_volume_changed, 0, vol);
        g_udisks_volume_changed(vol);

        /* it's no longer a volume */
        if(!g_udisks_device_is_volume(dev))
            remove_volume(mon, dev);
    }
    else
    {
        /* we got a usable volume now */
        if(g_udisks_device_is_volume(dev))
            add_volume(mon, dev, TRUE);
    }
}
Esempio n. 6
0
static void
mount_mountable_cb (GObject      *source_object,        
                    GAsyncResult *res,
                    gpointer      user_data)
{
  GVfsBackendAfpBrowse *afp_backend = G_VFS_BACKEND_AFP_BROWSE (source_object);
  GVfsJobMountMountable *job = G_VFS_JOB_MOUNT_MOUNTABLE (user_data);

  GError *err;
  GVfsAfpVolumeData *vol_data;
  GMountSpec *mount_spec;

  if (!update_cache_finish (afp_backend, res, &err))
  {
    g_vfs_job_failed_from_error (G_VFS_JOB (job), err);
    g_error_free (err);
    return;
  }

  vol_data = find_volume (afp_backend, job->filename);
  if (!vol_data)
  {
    g_vfs_job_failed (G_VFS_JOB (job),  G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                      _("File doesn't exist"));
    return;
  }

  mount_spec = g_mount_spec_new ("afp-volume");
  g_mount_spec_set (mount_spec, "host",
                    g_network_address_get_hostname (G_NETWORK_ADDRESS (afp_backend->addr)));
  g_mount_spec_set (mount_spec, "volume", vol_data->name);
  g_mount_spec_set (mount_spec, "user", afp_backend->logged_in_user);

  g_vfs_job_mount_mountable_set_target (job, mount_spec, "/", TRUE);
  g_mount_spec_unref (mount_spec);

  g_vfs_job_succeeded (G_VFS_JOB (job));
}
Esempio n. 7
0
void
renameobject(struct vinum_rename_msg *msg)
{
    struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
    struct drive *drive;
    struct sd *sd;
    struct plex *plex;
    struct volume *vol;

    switch (msg->type) {
    case drive_object:					    /* you can't attach a drive to anything */
	if (find_drive(msg->newname, 0) >= 0) {		    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	drive = validdrive(msg->index, reply);
	if (drive) {
	    bcopy(msg->newname, drive->label.name, MAXDRIVENAME);
	    save_config();
	    reply->error = 0;
	}
	return;

    case sd_object:					    /* you can't attach a subdisk to anything */
	if (find_subdisk(msg->newname, 0) >= 0) {	    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	sd = validsd(msg->index, reply);
	if (sd) {
	    bcopy(msg->newname, sd->name, MAXSDNAME);
	    update_sd_config(sd->sdno, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case plex_object:					    /* you can't attach a plex to anything */
	if (find_plex(msg->newname, 0) >= 0) {		    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	plex = validplex(msg->index, reply);
	if (plex) {
	    bcopy(msg->newname, plex->name, MAXPLEXNAME);
	    update_plex_config(plex->plexno, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case volume_object:					    /* you can't attach a volume to anything */
	if (find_volume(msg->newname, 0) >= 0) {	    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	vol = validvol(msg->index, reply);
	if (vol) {
	    bcopy(msg->newname, vol->name, MAXVOLNAME);
	    update_volume_config(msg->index, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case invalid_object:
	reply->error = EINVAL;
	reply->msg[0] = '\0';
    }
}