Revision: 14245
Author: adrian.chadd
Date: Fri Jul 24 20:20:55 2009
Log: Fix issue 46 - truncated COSS objects

swap_file_sz is the whole file size - swap metadata reply status, headers,  
body.
rebuild_entry re->file_size is the reply status, headers, body w/out swap  
metadata
rebuild_entry re->hdr_size is the swap metadata

* Change the rebuild entry code to know this!
* Change the UFS rebuild helper to correctly set re->file_size based on the  
stat()
   size -minus- the already established swap header size


http://code.google.com/p/lusca-cache/source/detail?r=14245

Modified:
  /branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c
  /branches/LUSCA_HEAD/libsqstore/rebuild_entry.c
  /branches/LUSCA_HEAD/tools/ufs_log_dump.c

=======================================
--- /branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c        Wed Jul 22  
07:37:20 2009
+++ /branches/LUSCA_HEAD/app/ufs_rebuild/ufs_build_dir.c        Fri Jul 24  
20:20:55 2009
@@ -82,7 +82,13 @@
                close(fd);
                return 0;
        }
-       re->file_size = sb.st_size;
+       if (re->hdr_size < 0) {
+               close(fd);
+               return 0;
+       }
+       /* The total UFS file size is inclusive of swap metadata, reply  
status+headers and body */
+       /* re->file_size is exclusive of swap metadata. Make sure that is set  
correctly */
+       re->file_size = sb.st_size - re->hdr_size;
        close(fd);
        return 1;
  }
=======================================
--- /branches/LUSCA_HEAD/libsqstore/rebuild_entry.c     Wed Jul 22 07:37:20 2009
+++ /branches/LUSCA_HEAD/libsqstore/rebuild_entry.c     Fri Jul 24 20:20:55 2009
@@ -97,6 +97,10 @@
                memcpy(&re->mi, t->value, sizeof(re->mi));
                parsed++;
                break;
+
+           /* Undocumented mess! */
+           /* STORE_META_OBJSIZE is the objectLen(). It includes the reply  
headers but not the swap metadata */
+           /* swap_file_sz in the rebuild entry data is the objectLen() +  
swap_hdr_size */
            case STORE_META_OBJSIZE:
                debug(47, 5) ("  STORE_META_OBJSIZE\n");
                /* XXX is this typecast'ed to the right "size" on all platforms 
? */
@@ -123,7 +127,15 @@
        sd.lastref = re->mi.lastref;
        sd.expires = re->mi.expires;
        sd.lastmod = re->mi.lastmod;
-       sd.swap_file_sz = re->file_size;
+       /*
+        * If we get here - either file_size must be set by the parser above
+        * or by some other method (eg UFS dir rebuild will use stat()
+        * and then substract the swap header length.
+        */
+       if (re->file_size < 0 || re->hdr_size < 0)
+               return -1;
+
+       sd.swap_file_sz = re->hdr_size + re->file_size;
        sd.refcount = re->mi.refcount;
        sd.flags = re->mi.flags;

=======================================
--- /branches/LUSCA_HEAD/tools/ufs_log_dump.c   Sun May  3 00:29:11 2009
+++ /branches/LUSCA_HEAD/tools/ufs_log_dump.c   Fri Jul 24 20:20:55 2009
@@ -86,18 +86,19 @@
  void
  read_file(const char *path)
  {
-       int fd;
-       char buf[BUFSIZE];
-       int len;
+       FILE *fp;
+#if 0
        storeSwapLogHeader *hdr;
-       storeSwapLogData *se;
-
-       fd = open(path, O_RDONLY);
-       if (fd < 0) {
-               perror("open");
+#endif
+       storeSwapLogData se;
+
+       fp = fopen(path, "rb");
+       if (! fp) {
+               perror("fopen");
                return;
        }

+#if 0
        /* read the header */
        len = read(fd, buf, sizeof(storeSwapLogData));
        if (len < 0) {
@@ -118,14 +119,14 @@

        printf("swaplog header version: %d; record size: %d\n", hdr->version,  
hdr->record_size);
        printf("size of current swaplog entry: %d\n", sizeof(storeSwapLogData));
+#endif

        /* Start reading entries */
-       while ((len = read(fd, buf, sizeof(storeSwapLogData))) > 0) {
-               se = (storeSwapLogData *) buf;
-               printf(  "Entry: %s\n", storeMetaText(se));
+       while (fread(&se, sizeof(se), 1, fp) == 1) {
+               printf(  "Entry: %s\n", storeMetaText(&se));
        }

-       close(fd);
+       fclose(fp);
  }

  int

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to