Revision: 14504
Author: adrian.chadd
Date: Sun Mar 28 00:33:28 2010
Log: Migrate the swap metadata pack/unpack functions into
libsqstore/store_meta.c .
http://code.google.com/p/lusca-cache/source/detail?r=14504
Added:
/branches/LUSCA_HEAD/libsqstore/store_meta.c
Modified:
/branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c
/branches/LUSCA_HEAD/libsqstore/Makefile.am
/branches/LUSCA_HEAD/libsqstore/store_meta.h
/branches/LUSCA_HEAD/src/protos.h
/branches/LUSCA_HEAD/src/store_swapmeta.c
=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/libsqstore/store_meta.c Sun Mar 28 00:33:28 2010
@@ -0,0 +1,93 @@
+#include "../include/config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "../libcore/varargs.h"
+#include "../libcore/tools.h"
+#include "../libcore/kb.h" /* for squid_off_t */
+#include "../libcore/debug.h"
+
+#include "../libsqtlv/tlv.h"
+
+#include "libsqstore/store_mgr.h"
+#include "libsqstore/store_meta.h"
+
+
+char *
+storeSwapMetaPack(tlv * tlv_list, int *length)
+{
+ int buflen = 0;
+ tlv *t;
+ int j = 0;
+ char *buf;
+ assert(length != NULL);
+ buflen++; /* STORE_META_OK */
+ buflen += sizeof(int); /* size of header to follow */
+ for (t = tlv_list; t; t = t->next)
+ buflen += sizeof(char) + sizeof(int) + t->length;
+ buf = xmalloc(buflen);
+ buf[j++] = (char) STORE_META_OK;
+ xmemcpy(&buf[j], &buflen, sizeof(int));
+ j += sizeof(int);
+ for (t = tlv_list; t; t = t->next) {
+ buf[j++] = (char) t->type;
+ xmemcpy(&buf[j], &t->length, sizeof(int));
+ j += sizeof(int);
+ xmemcpy(&buf[j], t->value, t->length);
+ j += t->length;
+ }
+ assert((int) j == buflen);
+ *length = buflen;
+ return buf;
+}
+
+tlv *
+storeSwapMetaUnpack(const char *buf, int *hdr_len)
+{
+ tlv *TLV = NULL; /* we'll return this */
+ tlv **T = &TLV;
+ char type;
+ int length;
+ int buflen;
+ int j = 0;
+ assert(buf != NULL);
+ assert(hdr_len != NULL);
+ if (buf[j++] != (char) STORE_META_OK)
+ return NULL;
+ xmemcpy(&buflen, &buf[j], sizeof(int));
+ j += sizeof(int);
+ /*
+ * sanity check on 'buflen' value. It should be at least big
+ * enough to hold one type and one length.
+ */
+ if (buflen <= (sizeof(char) + sizeof(int)))
+ return NULL;
+ while (buflen - j >= (sizeof(char) + sizeof(int))) {
+ type = buf[j++];
+ /* VOID is reserved, but allow some slack for new types.. */
+ if (type <= STORE_META_VOID || type > STORE_META_END + 10) {
+ debug(20, 0) ("storeSwapMetaUnpack: bad type (%d)!\n", type);
+ break;
+ }
+ xmemcpy(&length, &buf[j], sizeof(int));
+ if (length < 0 || length > (1 << 16)) {
+ debug(20, 0) ("storeSwapMetaUnpack: insane length (%d)!\n",
length);
+ break;
+ }
+ j += sizeof(int);
+ if (j + length > buflen) {
+ debug(20, 0) ("storeSwapMetaUnpack: overflow!\n");
+ debug(20, 0) ("\ttype=%d, length=%d, buflen=%d, offset=%d\n",
+ type, length, buflen, (int) j);
+ break;
+ }
+ T = tlv_add(type, &buf[j], (size_t) length, T);
+ j += length;
+ }
+ *hdr_len = buflen;
+ return TLV;
+}
=======================================
--- /branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c Wed Mar 24
07:48:15 2010
+++ /branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c Sun Mar 28
00:33:28 2010
@@ -51,6 +51,8 @@
#include "libsqdebug/debug.h"
+#include "libsqtlv/tlv.h"
+
#include "libsqstore/store_mgr.h"
#include "libsqstore/store_meta.h"
#include "libsqstore/store_log.h"
=======================================
--- /branches/LUSCA_HEAD/libsqstore/Makefile.am Wed Jul 22 07:37:20 2009
+++ /branches/LUSCA_HEAD/libsqstore/Makefile.am Sun Mar 28 00:33:28 2010
@@ -5,7 +5,8 @@
libsqstore_a_SOURCES = \
store_log.c \
store_file_ufs.c \
- rebuild_entry.c
+ rebuild_entry.c \
+ store_meta.c
noinst_LIBRARIES = \
libsqstore.a
=======================================
--- /branches/LUSCA_HEAD/libsqstore/store_meta.h Tue Apr 21 17:52:36 2009
+++ /branches/LUSCA_HEAD/libsqstore/store_meta.h Sun Mar 28 00:33:28 2010
@@ -48,4 +48,7 @@
};
typedef struct _storeMetaIndexNew storeMetaIndexNew;
+extern tlv * storeSwapMetaUnpack(const char *buf, int *hdr_len);
+extern char * storeSwapMetaPack(tlv * tlv_list, int *length);
+
#endif
=======================================
--- /branches/LUSCA_HEAD/src/protos.h Sat Feb 13 23:34:59 2010
+++ /branches/LUSCA_HEAD/src/protos.h Sun Mar 28 00:33:28 2010
@@ -725,9 +725,7 @@
/*
* store_swapmeta.c
*/
-extern char *storeSwapMetaPack(tlv * tlv_list, int *length);
extern tlv *storeSwapMetaBuild(StoreEntry * e);
-extern tlv *storeSwapMetaUnpack(const char *buf, int *hdrlen);
extern char * storeSwapMetaAssemble(StoreEntry *e, int *length);
/*
=======================================
--- /branches/LUSCA_HEAD/src/store_swapmeta.c Tue Apr 21 01:37:50 2009
+++ /branches/LUSCA_HEAD/src/store_swapmeta.c Sun Mar 28 00:33:28 2010
@@ -146,78 +146,3 @@
assert(*length < buflen);
return buf;
}
-
-char *
-storeSwapMetaPack(tlv * tlv_list, int *length)
-{
- int buflen = 0;
- tlv *t;
- int j = 0;
- char *buf;
- assert(length != NULL);
- buflen++; /* STORE_META_OK */
- buflen += sizeof(int); /* size of header to follow */
- for (t = tlv_list; t; t = t->next)
- buflen += sizeof(char) + sizeof(int) + t->length;
- buf = xmalloc(buflen);
- buf[j++] = (char) STORE_META_OK;
- xmemcpy(&buf[j], &buflen, sizeof(int));
- j += sizeof(int);
- for (t = tlv_list; t; t = t->next) {
- buf[j++] = (char) t->type;
- xmemcpy(&buf[j], &t->length, sizeof(int));
- j += sizeof(int);
- xmemcpy(&buf[j], t->value, t->length);
- j += t->length;
- }
- assert((int) j == buflen);
- *length = buflen;
- return buf;
-}
-
-tlv *
-storeSwapMetaUnpack(const char *buf, int *hdr_len)
-{
- tlv *TLV = NULL; /* we'll return this */
- tlv **T = &TLV;
- char type;
- int length;
- int buflen;
- int j = 0;
- assert(buf != NULL);
- assert(hdr_len != NULL);
- if (buf[j++] != (char) STORE_META_OK)
- return NULL;
- xmemcpy(&buflen, &buf[j], sizeof(int));
- j += sizeof(int);
- /*
- * sanity check on 'buflen' value. It should be at least big
- * enough to hold one type and one length.
- */
- if (buflen <= (sizeof(char) + sizeof(int)))
- return NULL;
- while (buflen - j >= (sizeof(char) + sizeof(int))) {
- type = buf[j++];
- /* VOID is reserved, but allow some slack for new types.. */
- if (type <= STORE_META_VOID || type > STORE_META_END + 10) {
- debug(20, 0) ("storeSwapMetaUnpack: bad type (%d)!\n", type);
- break;
- }
- xmemcpy(&length, &buf[j], sizeof(int));
- if (length < 0 || length > (1 << 16)) {
- debug(20, 0) ("storeSwapMetaUnpack: insane length (%d)!\n", length);
- break;
- }
- j += sizeof(int);
- if (j + length > buflen) {
- debug(20, 0) ("storeSwapMetaUnpack: overflow!\n");
- debug(20, 0) ("\ttype=%d, length=%d, buflen=%d, offset=%d\n",
- type, length, buflen, (int) j);
- break;
- }
- T = tlv_add(type, &buf[j], (size_t) length, T);
- j += length;
- }
- *hdr_len = buflen;
- return TLV;
-}
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.