char *image_name;
struct rbd_image *next;
};
-struct rbd_image *rbd_images;
+struct rbd_image_data {
+ struct rbd_image *images;
+ void *buf;
+};
+struct rbd_image_data rbd_image_data;
struct rbd_openimage {
char *image_name;
/* prototypes */
int connect_to_cluster(rados_t *pcluster);
-void enumerate_images(struct rbd_image **head);
+void enumerate_images(struct rbd_image_data *data);
int open_rbd_image(const char *image_name);
int find_openrbd(const char *path);
void simple_err(const char *msg, int err);
void
-enumerate_images(struct rbd_image **head)
+enumerate_images(struct rbd_image_data *data)
{
+ struct rbd_image **head = &data->images;
char *ibuf = NULL;
size_t ibuf_len = 0;
struct rbd_image *im, *next;
im = next;
}
*head = NULL;
+ free(data->buf);
+ data->buf = NULL;
}
ret = rbd_list(ioctx, ibuf, &ibuf_len);
}
}
fprintf(stderr, "\n");
+ data->buf = ibuf;
}
int
if (image_name == (char *)NULL)
return -1;
- // relies on caller to keep rbd_images up to date
- for (im = rbd_images; im != NULL; im = im->next) {
+ // relies on caller to keep rbd_image_data up to date
+ for (im = rbd_image_data.images; im != NULL; im = im->next) {
if (strcmp(im->image_name, image_name) == 0) {
break;
}
pthread_mutex_lock(&readdir_lock);
- for (im = rbd_images; im != NULL; im = im->next)
+ for (im = rbd_image_data.images; im != NULL; im = im->next)
iter(cookie, im->image_name);
pthread_mutex_unlock(&readdir_lock);
}
unsigned int count = 0;
pthread_mutex_lock(&readdir_lock);
- enumerate_images(&rbd_images);
+ enumerate_images(&rbd_image_data);
pthread_mutex_unlock(&readdir_lock);
iter_images(&count, count_images_cb);
if (!in_opendir) {
pthread_mutex_lock(&readdir_lock);
- enumerate_images(&rbd_images);
+ enumerate_images(&rbd_image_data);
pthread_mutex_unlock(&readdir_lock);
}
fd = open_rbd_image(path + 1);
return -ENOENT;
pthread_mutex_lock(&readdir_lock);
- enumerate_images(&rbd_images);
+ enumerate_images(&rbd_image_data);
pthread_mutex_unlock(&readdir_lock);
fd = open_rbd_image(path + 1);
if (fd < 0)
num[0] = 1;
num[1] = 0;
pthread_mutex_lock(&readdir_lock);
- enumerate_images(&rbd_images);
+ enumerate_images(&rbd_image_data);
pthread_mutex_unlock(&readdir_lock);
iter_images(num, rbdfs_statfs_image_cb);
// only one directory, so global "in_opendir" flag should be fine
pthread_mutex_lock(&readdir_lock);
in_opendir++;
- enumerate_images(&rbd_images);
+ enumerate_images(&rbd_image_data);
pthread_mutex_unlock(&readdir_lock);
return 0;
}