Skip to content

Commit

Permalink
merged storage from dmitrii/eee-dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii committed Mar 9, 2011
1 parent 5d7e876 commit 8ea7085
Show file tree
Hide file tree
Showing 31 changed files with 6,531 additions and 3,444 deletions.
13 changes: 9 additions & 4 deletions storage/Makefile
Expand Up @@ -4,13 +4,15 @@

include ../Makedefs

STORAGE_LIBS = ${LIBS} -lcurl -lssl -lcrypto
IMAGER_LIBS = ../util/euca_auth.o ../util/misc.o ../util/ipc.o cache.o walrus.o cmd_download.o cmd_create.o cmd_inject.o cmd_convert.o cmd_upload.o cmd_bundle.o cmd_fsck.o map.o vmdk.o http.o img.o diskfile.o helpers.o
VDDK_FLAGS = $(LIBS) -lvixDiskLib -lvixMntapi -std=gnu99 -UDYNAMIC_LOADING
STORAGE_LIBS = -lcurl -lssl -lcrypto
IMAGER_LIBS = ../util/euca_auth.o ../util/misc.o ../util/ipc.o cache.o walrus.o cmd_download.o cmd_create.o cmd_inject.o cmd_convert.o cmd_upload.o cmd_bundle.o cmd_fsck.o map.o vmdk.o http.o img.o diskfile.o diskutil.o
VDDK_FLAGS = -L${VDDK_HOME}/lib -lvixDiskLib -lvixMntapi -std=gnu99 -UDYNAMIC_LOADING
IMAGER_WRAPPER=euca_imager
IMAGER=_euca_imager
#EFENCE=-lefence

all: storage.o storage-windows.o walrus.o Wclient $(IMAGER)
all: storage.o storage-windows.o walrus.o Wclient $(IMAGER) test_blobstore
#all: storage.o storage-windows.o walrus.o test_blobstore

build: all

Expand All @@ -26,6 +28,9 @@ walrus.o: walrus.c walrus.h
test: test.c storage.h storage.o storage-windows.o ../util/misc.o ../util/data.o ../util/ipc.o ../util/euca_auth.o walrus.o
$(CC) $(CFLAGS) $(INCLUDES) test.c storage.o storage-windows.o ../util/misc.o ../util/data.o ../util/ipc.o ../util/euca_auth.o walrus.o $(STORAGE_LIBS) -o test

test_blobstore: blobstore.o blobstore.c blobstore.h map.o diskutil.o ../util/misc.o
$(CC) -g -rdynamic -std=gnu99 $(CFLAGS) $(INCLUDES) -D_UNIT_TEST blobstore.c -o test_blobstore map.o diskutil.o ../util/misc.o -lpthread $(EFENCE)

test_url: http.c
$(CC) -D_UNIT_TEST -o test_url http.c

Expand Down
263 changes: 133 additions & 130 deletions storage/Wclient.c
@@ -1,40 +1,43 @@
// -*- mode: C; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
// vim: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:

/*
Copyright (c) 2009 Eucalyptus Systems, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, only version 3 of the License.
This file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
Please contact Eucalyptus Systems, Inc., 130 Castilian
Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/>
if you need additional information or have any questions.
This file may incorporate work covered under the following copyright and
permission notice:
Copyright (c) 2009 Eucalyptus Systems, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, only version 3 of the License.
This file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
Please contact Eucalyptus Systems, Inc., 130 Castilian
Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/>
if you need additional information or have any questions.
This file may incorporate work covered under the following copyright and
permission notice:
Software License Agreement (BSD License)
Copyright (c) 2008, Regents of the University of California
Redistribution and use of this software in source and binary forms, with
or without modification, are permitted provided that the following
conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
Expand Down Expand Up @@ -80,118 +83,118 @@ char debug = 1;

int main (int argc, char * argv[])
{
char * command = DEFAULT_COMMAND;
char * hostport = NULL;
char * manifest = NULL;
char * file_name = NULL;
char * url = NULL;
char * login = NULL;
char * password = NULL;
char * command = DEFAULT_COMMAND;
char * hostport = NULL;
char * manifest = NULL;
char * file_name = NULL;
char * url = NULL;
char * login = NULL;
char * password = NULL;
int do_compress = 0;
int ch;

while ((ch = getopt(argc, argv, "dh:m:f:zu:l:p:")) != -1) {
switch (ch) {
case 'h':
hostport = optarg;
break;
case 'm':
manifest = optarg;
break;
case 'd':
debug = 1;
break;
case 'f':
file_name = optarg;
break;
case 'u':
url = optarg;
break;
case 'l':
login = optarg;
break;
case 'p':
password = optarg;
break;
case 'z':
do_compress = 1;
break;
case '?':
default:
USAGE;
}
}
argc -= optind;
argv += optind;

if (argc>0) {
command = argv[0];
}

int do_get;
if ( strcmp (command, "GetDecryptedImage")==0
int ch;

while ((ch = getopt(argc, argv, "dh:m:f:zu:l:p:")) != -1) {
switch (ch) {
case 'h':
hostport = optarg;
break;
case 'm':
manifest = optarg;
break;
case 'd':
debug = 1;
break;
case 'f':
file_name = optarg;
break;
case 'u':
url = optarg;
break;
case 'l':
login = optarg;
break;
case 'p':
password = optarg;
break;
case 'z':
do_compress = 1;
break;
case '?':
default:
USAGE;
}
}
argc -= optind;
argv += optind;

if (argc>0) {
command = argv[0];
}

int do_get;
if ( strcmp (command, "GetDecryptedImage")==0
|| strcmp (command, "GetObject")==0 ) {
if (manifest==NULL) {
fprintf (stderr, "Error: manifest must be specified\n");
USAGE;
}
do_get = 1;
} else if ( strcmp (command, "HttpPut")==0) {
if (url==NULL || file_name==NULL) {
fprintf (stderr, "Error: URL and input file must be specified\n");
USAGE;
}
do_get = 0;
} else {
fprintf (stderr, "Error: unknown command [%s]\n", command);
USAGE;
}

if (do_get) {
/* use a temporary file for network data */
char * tmp_name = strdup ("walrus-download-XXXXXX");
int tmp_fd = mkstemp (tmp_name);
if (tmp_fd<0) {
fprintf (stderr, "Error: failed to create a temporary file\n");
if (manifest==NULL) {
fprintf (stderr, "Error: manifest must be specified\n");
USAGE;
}
do_get = 1;
} else if ( strcmp (command, "HttpPut")==0) {
if (url==NULL || file_name==NULL) {
fprintf (stderr, "Error: URL and input file must be specified\n");
USAGE;
}
do_get = 0;
} else {
fprintf (stderr, "Error: unknown command [%s]\n", command);
USAGE;
}
close (tmp_fd);

int result;
char request [STRSIZE];
if (hostport) {
snprintf (request, STRSIZE, "http://%s%s/%s", hostport, WALRUS_ENDPOINT, manifest);
if ( strcmp(command, "GetObject")==0 ) {
result = walrus_object_by_url (request, tmp_name, do_compress);
} else {
result = walrus_image_by_manifest_url (request, tmp_name, do_compress);

if (do_get) {
/* use a temporary file for network data */
char * tmp_name = strdup ("walrus-download-XXXXXX");
int tmp_fd = mkstemp (tmp_name);
if (tmp_fd<0) {
fprintf (stderr, "Error: failed to create a temporary file\n");
USAGE;
}
} else {
strncpy (request, manifest, STRSIZE);
if ( strcmp(command, "GetObject")==0 ) {
result = walrus_object_by_path (request, tmp_name, do_compress);
close (tmp_fd);

int result;
char request [STRSIZE];
if (hostport) {
snprintf (request, STRSIZE, "http://%s%s/%s", hostport, WALRUS_ENDPOINT, manifest);
if ( strcmp(command, "GetObject")==0 ) {
result = walrus_object_by_url (request, tmp_name, do_compress);
} else {
result = walrus_image_by_manifest_url (request, tmp_name, do_compress);
}
} else {
result = walrus_image_by_manifest_path (request, tmp_name, do_compress);
strncpy (request, manifest, STRSIZE);
if ( strcmp(command, "GetObject")==0 ) {
result = walrus_object_by_path (request, tmp_name, do_compress);
} else {
result = walrus_image_by_manifest_path (request, tmp_name, do_compress);
}
}
}

if (result) {
/* error has occured */
cat (tmp_name);
fprintf (stderr, "\n"); /* in case error doesn't end with a newline */
remove (tmp_name);
} else {
/* all's well */
if (file_name) {
rename (tmp_name, file_name);

if (result) {
/* error has occured */
cat (tmp_name);
fprintf (stderr, "\n"); /* in case error doesn't end with a newline */
remove (tmp_name);
} else {
fprintf (stderr, "Saved output in %s\n", tmp_name);
/* all's well */
if (file_name) {
rename (tmp_name, file_name);
} else {
fprintf (stderr, "Saved output in %s\n", tmp_name);
}
}

free (tmp_name);
} else { // HttpPut
int result = http_put (file_name, url, login, password);
}

free (tmp_name);
} else { // HttpPut
int result = http_put (file_name, url, login, password);
}
return 0;
return 0;
}

0 comments on commit 8ea7085

Please sign in to comment.