Commit f10cf499 authored by Mike Hibler's avatar Mike Hibler

Changes for a standalone distribution:

	- add a BSD Makefile
	- add imagezip.tar target to GNUmakefile (to make dist tarball)
	- reorg of code in imageunzip so it can be compiled w/o pthreads
parent 96ce1770
......@@ -9,6 +9,10 @@ TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = os/imagezip
DISTFILES = TODO ext2_fs.h imagehdr.h linux_types.h queue.h \
imagedump.c imagedump.8 imagezip.c imagedump.8 \
imageunzip.c imageunzip.8
WITH_NTFS = @WINSUPPORT@
include $(OBJDIR)/Makeconf
......@@ -55,17 +59,22 @@ ntfs:
version.c: imagezip.c imageunzip.c imagedump.c
echo >$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
install: $(INSTALL_BINDIR)/imagezip $(INSTALL_BINDIR)/imageunzip
install: $(INSTALL_BINDIR)/imagezip $(INSTALL_BINDIR)/imageunzip $(INSTALL_BINDIR)/imagedump
client-install:
$(INSTALL) -m 755 -o root -g wheel -d $(DESTDIR)/usr/local/bin
$(INSTALL_PROGRAM) imagezip $(DESTDIR)/usr/local/bin/imagezip
$(INSTALL_PROGRAM) imageunzip $(DESTDIR)/usr/local/bin/imageunzip
$(INSTALL_PROGRAM) imagedump $(DESTDIR)/usr/local/bin/imagedump
clean:
@if [ -d ntfs ]; then \
$(MAKE) -C ntfs clean; \
fi;
/bin/rm -f *.o imagezip imageunzip version.c
/bin/rm -f *.o imagezip imageunzip imagedump version.c
imagezip.tar: Makefile.sa $(DISTFILES)
(cd $(SRCDIR); cp -p Makefile.sa Makefile; \
tar cf - Makefile $(DISTFILES); rm -f Makefile) > imagezip.tar
.PHONY: $(NTFSDIR)
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Makefile for the standalone version of imagezip/unzip.
# (Standalone meaning not part of the Netbed build environment.)
#
BINDIR= /usr/local/bin
.if defined(NOTHREADS)
PTHREADCFLAGS = -DNOTHREADS
PTHREADLIBS =
.else
PTHREADCFLAGS = -D_THREAD_SAFE \
-I/usr/local/include/pthread/linuxthreads
PTHREADLIBS = -L/usr/local/lib -llthread -llgcc_r
.endif
CFLAGS = -Wall -O2 -g -static
LIBS = -lz $(PTHREADLIBS)
UNZIPCFLAGS = $(CFLAGS) $(PTHREADCFLAGS) -Wall
UNZIPLIBS = $(LIBS) $(PTHREADLIBS)
all: imagezip imageunzip imagedump
imagezip: imagezip.o version.o
$(CC) $(CFLAGS) imagezip.o version.o $(LIBS) -o imagezip
imageunzip: imageunzip.o version.o
$(CC) $(CFLAGS) imageunzip.o version.o $(UNZIPLIBS) -o imageunzip
imageunzip.o: imageunzip.c
$(CC) -c $(UNZIPCFLAGS) -o imageunzip.o $<
imagedump: imagedump.o version.o
$(CC) $(CFLAGS) imagedump.o version.o $(LIBS) -o imagedump
version.c: imagezip.c imageunzip.c imagedump.c
echo >$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
install:
$(INSTALL) imagezip $(DESTDIR)$(BINDIR)/imagezip
$(INSTALL) imageunzip $(DESTDIR)$(BINDIR)/imageunzip
$(INSTALL) imagedump $(DESTDIR)$(BINDIR)/imagedump
clean:
rm -f *.o imagezip imageunzip imagedump version.c
.include <bsd.prog.mk>
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2002 University of Utah and the Flux Group.
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -24,9 +24,11 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/disklabel.h>
#include <pthread.h>
#include "imagehdr.h"
#include "queue.h"
#ifndef NOTHREADS
#include <pthread.h>
#endif
/*
* Define this if you want to test frisbee's random presentation of chunks
......@@ -71,7 +73,6 @@ static int debug = 0;
static int outfd;
static int dofill = 0;
static int nothreads = 0;
static pthread_t child_pid;
static int rdycount;
static int imageversion = 1;
#ifndef FRISBEE
......@@ -83,15 +84,11 @@ static int dotcol;
static char chunkbuf[SUBBLOCKSIZE];
static struct timeval stamp;
#endif
static void threadinit(void);
static void threadwait(void);
static void threadquit(void);
int readmbr(int slice);
int fixmbr(int slice, int dtype);
static int inflate_subblock(char *);
void writezeros(off_t offset, off_t zcount);
void writedata(off_t offset, size_t count, void *buf);
void *DiskWriter(void *arg);
static void getrelocinfo(blockhdr_t *hdr);
static void applyrelocs(off_t offset, size_t cc, void *buf);
......@@ -99,7 +96,6 @@ static void applyrelocs(off_t offset, size_t cc, void *buf);
static int seekable;
static off_t nextwriteoffset;
static int writeinprogress; /* XXX */
static int imagetoobigwarned;
#ifdef FAKEFRISBEE
......@@ -115,6 +111,21 @@ static int *chunklist, *nextchunk;
unsigned long decompidles;
unsigned long writeridles;
#ifdef NOTHREADS
#define threadinit()
#define threadwait()
#define threadquit()
#else
static void threadinit(void);
static void threadwait(void);
static void threadquit(void);
static void *DiskWriter(void *arg);
static int writeinprogress; /* XXX */
static pthread_t child_pid;
static pthread_mutex_t freelist_mutex, readyqueue_mutex;
static pthread_cond_t freelist_condvar, readyqueue_condvar;
/*
* A queue of ready to write data blocks.
*/
......@@ -132,14 +143,14 @@ typedef struct {
static queue_head_t readyqueue;
static readyblock_t *freelist;
#define READYQSIZE 256
static pthread_mutex_t freelist_mutex, readyqueue_mutex;
static pthread_cond_t freelist_condvar, readyqueue_condvar;
#endif
static void
dowrite_request(off_t offset, off_t size, void *buf)
{
#ifndef NOTHREADS
readyhdr_t *hdr;
#endif
/*
* Adjust for partition start and ensure data fits
......@@ -160,19 +171,31 @@ dowrite_request(off_t offset, off_t size, void *buf)
totaledata += size;
/*
* Null buf means its a request to zero.
* If we are not filling, just return.
*/
if (nothreads) {
/*
* Null buf means its a request to zero.
* If we are not filling, just return.
*/
if (buf == NULL) {
if (dofill)
writezeros(offset, size);
} else {
assert(size <= OUTSIZE+SECSIZE);
/*
* Handle any relocations
*/
applyrelocs(offset, (size_t)size, buf);
writedata(offset, (size_t)size, buf);
}
return;
}
#ifndef NOTHREADS
if (buf == NULL) {
if (!dofill)
return;
if (nothreads) {
writezeros(offset, size);
return;
}
if ((hdr = (readyhdr_t *)malloc(sizeof(readyhdr_t))) == NULL) {
fprintf(stderr, "Out of memory\n");
exit(1);
......@@ -193,11 +216,6 @@ dowrite_request(off_t offset, off_t size, void *buf)
*/
applyrelocs(offset, cc, buf);
if (nothreads) {
writedata(offset, cc, buf);
return;
}
/*
* Try to allocate a block. Wait if none available.
*/
......@@ -222,6 +240,7 @@ dowrite_request(off_t offset, off_t size, void *buf)
queue_enter(&readyqueue, hdr, readyhdr_t *, chain);
pthread_mutex_unlock(&readyqueue_mutex);
pthread_cond_signal(&readyqueue_condvar);
#endif
}
static inline int devread(int fd, void *buf, size_t size)
......@@ -256,6 +275,9 @@ main(int argc, char **argv)
extern char build_info[];
struct timeval estamp;
#ifdef NOTHREADS
nothreads = 1;
#endif
while ((ch = getopt(argc, argv, "vdhs:zp:onFD:")) != -1)
switch(ch) {
#ifdef FAKEFRISBEE
......@@ -326,7 +348,7 @@ main(int argc, char **argv)
else
infd = fileno(stdin);
if (argc == 2) {
if (argc == 2 && strcmp(argv[1], "-")) {
if ((outfd =
open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
perror("opening output file");
......@@ -558,6 +580,7 @@ ImageUnzipQuit(void)
}
#endif
#ifndef NOTHREADS
static void *readyqueuemem;
static void
......@@ -635,6 +658,51 @@ threadquit(void)
freelist = 0;
}
void *
DiskWriter(void *arg)
{
readyblock_t *rdyblk = 0;
while (1) {
pthread_testcancel();
pthread_mutex_lock(&readyqueue_mutex);
if (queue_empty(&readyqueue)) {
/* fprintf(stderr, "Writer idle\n"); */
writeridles++;
do {
pthread_cond_wait(&readyqueue_condvar,
&readyqueue_mutex);
pthread_testcancel();
} while (queue_empty(&readyqueue));
}
queue_remove_first(&readyqueue, rdyblk,
readyblock_t *, header.chain);
writeinprogress = 1; /* XXX */
pthread_mutex_unlock(&readyqueue_mutex);
if (rdyblk->header.zero) {
writezeros(rdyblk->header.offset, rdyblk->header.size);
free(rdyblk);
writeinprogress = 0; /* XXX, ok as unlocked access */
continue;
}
rdycount++;
assert(rdyblk->header.size <= OUTSIZE+SECSIZE);
writedata(rdyblk->header.offset, (size_t)rdyblk->header.size,
rdyblk->buf);
writeinprogress = 0; /* XXX, ok as unlocked access */
pthread_mutex_lock(&freelist_mutex);
rdyblk->header.chain.next = (void *) freelist;
freelist = rdyblk;
pthread_mutex_unlock(&freelist_mutex);
pthread_cond_signal(&freelist_condvar);
}
}
#endif
static int
inflate_subblock(char *chunkbufp)
{
......@@ -870,7 +938,8 @@ writezeros(off_t offset, off_t zcount)
}
nextwriteoffset = offset;
} else if (offset != nextwriteoffset) {
fprintf(stderr, "Attempted non-contiguous write\n");
fprintf(stderr, "Non-contiguous write @ %qu (should be %qu)\n",
offset, nextwriteoffset);
exit(1);
}
......@@ -904,7 +973,8 @@ writedata(off_t offset, size_t size, void *buf)
else if (offset == nextwriteoffset)
cc = write(outfd, buf, size);
else {
fprintf(stderr, "Attempted non-contiguous write\n");
fprintf(stderr, "Non-contiguous write @ %qu (should be %qu)\n",
offset, nextwriteoffset);
exit(1);
}
......@@ -1011,50 +1081,6 @@ fixmbr(int slice, int dtype)
return 0;
}
void *
DiskWriter(void *arg)
{
readyblock_t *rdyblk = 0;
while (1) {
pthread_testcancel();
pthread_mutex_lock(&readyqueue_mutex);
if (queue_empty(&readyqueue)) {
/* fprintf(stderr, "Writer idle\n"); */
writeridles++;
do {
pthread_cond_wait(&readyqueue_condvar,
&readyqueue_mutex);
pthread_testcancel();
} while (queue_empty(&readyqueue));
}
queue_remove_first(&readyqueue, rdyblk,
readyblock_t *, header.chain);
writeinprogress = 1; /* XXX */
pthread_mutex_unlock(&readyqueue_mutex);
if (rdyblk->header.zero) {
writezeros(rdyblk->header.offset, rdyblk->header.size);
free(rdyblk);
writeinprogress = 0; /* XXX, ok as unlocked access */
continue;
}
rdycount++;
assert(rdyblk->header.size <= OUTSIZE+SECSIZE);
writedata(rdyblk->header.offset, (size_t)rdyblk->header.size,
rdyblk->buf);
writeinprogress = 0; /* XXX, ok as unlocked access */
pthread_mutex_lock(&freelist_mutex);
rdyblk->header.chain.next = (void *) freelist;
freelist = rdyblk;
pthread_mutex_unlock(&freelist_mutex);
pthread_cond_signal(&freelist_condvar);
}
}
static struct blockreloc *reloctable;
static int numrelocs;
static void reloc_bsdlabel(struct disklabel *label);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment