static void syn_removed(struct tcmu_device *dev) { syn_dev_t *s = tcmu_get_dev_private(dev); tcmu_dbg("removed %s\n", tcmu_get_dev_cfgstring(dev)); g_source_remove(s->watcher_id); g_io_channel_unref(s->gio); g_free(s); }
static int syn_added(struct tcmu_device *dev) { syn_dev_t *s = g_new0(syn_dev_t, 1); tcmu_dbg("added %s\n", tcmu_get_dev_cfgstring(dev)); tcmu_set_dev_private(dev, s); s->gio = g_io_channel_unix_new(tcmu_get_dev_fd(dev)); s->watcher_id = g_io_add_watch(s->gio, G_IO_IN, syn_dev_callback, dev); return 0; }
static int file_open(struct tcmu_device *dev) { struct file_state *state; int64_t size; char *config; state = calloc(1, sizeof(*state)); if (!state) return -ENOMEM; tcmu_set_dev_private(dev, state); state->block_size = tcmu_get_attribute(dev, "hw_block_size"); if (state->block_size == -1) { errp("Could not get device block size\n"); goto err; } size = tcmu_get_device_size(dev); if (size == -1) { errp("Could not get device size\n"); goto err; } state->num_lbas = size / state->block_size; config = strchr(tcmu_get_dev_cfgstring(dev), '/'); if (!config) { errp("no configuration found in cfgstring\n"); goto err; } config += 1; /* get past '/' */ state->fd = open(config, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (state->fd == -1) { errp("could not open %s: %m\n", config); goto err; } return 0; err: free(state); return -EINVAL; }
static int tcmu_glfs_open(struct tcmu_device *dev) { struct glfs_state *gfsp; int ret = 0; char *config; struct stat st; int attribute; gfsp = calloc(1, sizeof(*gfsp)); if (!gfsp) return -ENOMEM; tcmu_set_dev_private(dev, gfsp); attribute = tcmu_get_attribute(dev, "hw_block_size"); if (attribute == -1) { errp("Could not get hw_block_size setting\n"); goto fail; } gfsp->block_size = attribute; config = strchr(tcmu_get_dev_cfgstring(dev), '/'); if (!config) { errp("no configuration found in cfgstring\n"); goto fail; } config += 1; /* get past '/' */ if (parse_imagepath(config, &gfsp->servername, &gfsp->volname, &gfsp->pathname) == -1) { errp("servername, volname, or pathname not set\n"); goto fail; } gfsp->fs = glfs_new(gfsp->volname); if (!gfsp->fs) { errp("glfs_new failed\n"); goto fail; } ret = glfs_set_volfile_server(gfsp->fs, "tcp", gfsp->servername, GLUSTER_PORT); if (ret) { errp("glfs_set_volfile_server failed: %m\n"); goto fail; } ret = glfs_init(gfsp->fs); if (ret) { errp("glfs_init failed: %m\n"); goto fail; } gfsp->gfd = glfs_open(gfsp->fs, gfsp->pathname, ALLOWED_BSOFLAGS); if (!gfsp->gfd) { errp("glfs_open failed: %m\n"); goto fail; } ret = glfs_lstat(gfsp->fs, gfsp->pathname, &st); if (ret) { errp("glfs_lstat failed: %m\n"); goto fail; } if (st.st_size != tcmu_get_device_size(dev)) { errp("device size and backing size disagree: " "device %lld backing %lld\n", tcmu_get_device_size(dev), (long long) st.st_size); goto fail; } return 0; fail: if (gfsp->gfd) glfs_close(gfsp->gfd); if (gfsp->fs) glfs_fini(gfsp->fs); free(gfsp->volname); free(gfsp->pathname); free(gfsp->servername); free(gfsp); return -EIO; }