Skip to content

Commit

Permalink
Implement synchronization with blobstore.
Browse files Browse the repository at this point in the history
  • Loading branch information
gelinasc committed May 19, 2012
1 parent a909892 commit e8e6eea
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
60 changes: 57 additions & 3 deletions storage/blobstore.c
Expand Up @@ -288,8 +288,10 @@ static void close_filelock (blobstore_filelock * l)
// closing any one removes the lock for all descriptors
// held by a process)
for (int i=0; i<l->next_fd; i++) {
if(l->fd [i] > -1)
if(l->fd [i] > -1) {
close (l->fd [i]);
l->fd [i] = -1;
}
}
l->next_fd = 0; // knock the open fd counter back to 0
}
Expand Down Expand Up @@ -1113,19 +1115,37 @@ static int read_blockblob_metadata_path (blockblob_path_t path_t, const blobstor
// writes strings from 'array' or size 'array_size' (which can be 0) line-by-line
// into a specific metadata file (based on 'path_t') of blob 'bb_id'
// returns 0 for success and -1 for error
//#define CHUCK
static int write_array_blockblob_metadata_path (blockblob_path_t path_t, const blobstore * bs, const char * bb_id, char ** array, int array_size)
{
int ret = 0;
char path [MAX_PATH];
set_blockblob_metadata_path (path_t, bs, bb_id, path, sizeof (path));

#ifndef CHUCK
mode_t old_umask = umask (~BLOBSTORE_FILE_PERM);
FILE * fp = fopen (path, "w");
umask (old_umask);
if (fp == NULL) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
return -1;
}
#else /* CHUCK */
int fd = 0;
int ret_close = 0;
FILE *fp = NULL;
if ((fd = open_and_lock (path, (BLOBSTORE_FLAG_CREAT | BLOBSTORE_FLAG_RDWR), BLOBSTORE_METADATA_TIMEOUT_USEC, BLOBSTORE_FILE_PERM)) == -1) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
return(-1);
}

if ((fp = fopen(path, "w+")) == NULL) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
if((ret_close = close_and_unlock(fd)) != 0)
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
return(-1);
}
#endif /* CHUCK */

for (int i=0; i<array_size; i++) {
if (fprintf (fp, "%s\n", array [i]) < 0) {
Expand All @@ -1134,10 +1154,18 @@ static int write_array_blockblob_metadata_path (blockblob_path_t path_t, const b
break;
}
}

if (fclose (fp) == -1) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
ret = -1;
}

#ifdef CHUCK
if ((ret_close = close_and_unlock(fd)) != 0) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
ret = -1;
}
#endif /* CHUCK */
return ret;
}

Expand All @@ -1152,12 +1180,34 @@ static int read_array_blockblob_metadata_path (blockblob_path_t path_t, const bl
char path [MAX_PATH];
set_blockblob_metadata_path (path_t, bs, bb_id, path, sizeof (path));

#ifndef CHUCK
FILE * fp = fopen (path, "r");
if (fp == NULL) {
* array = NULL;
* array_size = 0;
return 0;
}
#else /* CHUCK */
int fd = 0;
int ret_close = 0;
FILE *fp = NULL;
if ((fd = open_and_lock (path, BLOBSTORE_FLAG_RDONLY, BLOBSTORE_METADATA_TIMEOUT_USEC, BLOBSTORE_FILE_PERM)) == -1) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
* array = NULL;
* array_size = 0;
return 0;
}

if ((fp = fopen(path, "r")) == NULL) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
if((ret_close = close_and_unlock(fd)) != 0)
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);

* array = NULL;
* array_size = 0;
return 0;
}
#endif /* CHUCK */

int i;
size_t n;
Expand Down Expand Up @@ -1190,6 +1240,12 @@ static int read_array_blockblob_metadata_path (blockblob_path_t path_t, const bl
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
ret = -1;
}
#ifdef CHUCK
if ((ret_close = close_and_unlock(fd)) != 0) {
PROPAGATE_ERR (BLOBSTORE_ERROR_UNKNOWN);
ret = -1;
}
#endif /* CHUCK */
if (ret == -1) {
if (lines!=NULL) {
for (int j=0; j<i; j++) {
Expand Down Expand Up @@ -1411,7 +1467,6 @@ static void set_device_path (blockblob * bb)

static blockblob ** walk_bs (blobstore * bs, const char * dir_path, blockblob ** tail_bb, const blockblob * bb_to_avoid)
{
int ret = 0;
DIR * dir;
if ((dir=opendir(dir_path))==NULL) {
return tail_bb; // ignore access errors in blobstore directory
Expand Down Expand Up @@ -1452,7 +1507,6 @@ static blockblob ** walk_bs (blobstore * bs, const char * dir_path, blockblob **

blockblob * bb = calloc (1, sizeof (blockblob));
if (bb==NULL) {
ret = 1;
goto free;
}
* tail_bb = bb; // add to LL
Expand Down
3 changes: 2 additions & 1 deletion storage/diskutil.c
Expand Up @@ -152,9 +152,10 @@ int diskutil_init (int require_grub) // 0 = not required, 1 = required
else
missing_handlers--;

if (helpers_path [GRUB_SETUP]) // don't need it, but grub-setup only exists on v2
if (helpers_path [GRUB_SETUP]) {// don't need it, but grub-setup only exists on v2
if (grub_version != 1)
grub_version = 2; // prefer 1 until 2 is implemented
}
else
missing_handlers--;

Expand Down
6 changes: 5 additions & 1 deletion storage/walrus.c
Expand Up @@ -347,9 +347,13 @@ static int walrus_request_timeout (const char * walrus_op, const char * verb, co
return code;
}

static int walrus_request (const char * walrus_op, const char * verb, const char * requested_url, const char * outfile, const int do_compress) {
#if 0
/* Unused function */
static int walrus_request (const char * walrus_op, const char * verb, const char * requested_url, const char * outfile, const int do_compress)
{
return (walrus_request_timeout(walrus_op, verb, requested_url, outfile, do_compress, 0, 0));
}
#endif /* 0 */

/* downloads a Walrus object from the URL, saves it to outfile */
int walrus_object_by_url (const char * url, const char * outfile, const int do_compress)
Expand Down

0 comments on commit e8e6eea

Please sign in to comment.