ustd: use commit_seq to get buffers from crashed process
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 7 Apr 2009 01:00:50 +0000 (21:00 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 7 Apr 2009 01:00:50 +0000 (21:00 -0400)
it works!

ustd/lowlevel.c

index f386089e21b54f9c1a0b98cc351d26084deed454..7c5dc3d99cdd47a1189009a9a35b7b624345e8ef 100644 (file)
@@ -1,3 +1,5 @@
+#include <assert.h>
+
 #include "tracer.h"
 #include "ustd.h"
 #include "localerr.h"
@@ -18,8 +20,8 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf)
        DBG("consumed offset is %ld", consumed_offset);
        DBG("write offset is %ld", write_offset);
 
-       long first_subbuf = write_offset / buf->subbuf_size;
-       long last_subbuf = consumed_offset / buf->subbuf_size;
+       long first_subbuf = consumed_offset / buf->subbuf_size;
+       long last_subbuf = write_offset / buf->subbuf_size;
 
        if(last_subbuf - first_subbuf > buf->n_subbufs) {
                DBG("an overflow has occurred, nothing can be recovered");
@@ -27,21 +29,38 @@ void finish_consuming_dead_subbuffer(struct buffer_info *buf)
        }
 
        for(i_subbuf=first_subbuf; ; i_subbuf++, i_subbuf %= buf->n_subbufs) {
-               long commit_count = local_read(&ltt_buf->commit_count[i_subbuf]);
+               void *tmp;
+               long commit_seq = local_read(&ltt_buf->commit_seq[i_subbuf]);
 
                unsigned long valid_length = buf->subbuf_size;
                long n_subbufs_order = get_count_order(buf->n_subbufs);
-               long commit_count_mask = (~0UL >> n_subbufs_order);
+               long commit_seq_mask = (~0UL >> n_subbufs_order);
+
+               if((commit_seq & commit_seq_mask) == 0)
+                       break;
 
                /* check if subbuf was fully written */
-               if (((commit_count - buf->subbuf_size) & commit_count_mask)
+               if (!((commit_seq - buf->subbuf_size) & commit_seq_mask)
                    - (USTD_BUFFER_TRUNC(consumed_offset, buf) >> n_subbufs_order)
                    != 0) {
                        struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size;
-                       valid_length = buf->subbuf_size - header->lost_size;
+                       valid_length = (unsigned long)buf->subbuf_size - header->lost_size;
                }
+               else {
+                       struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size;
+
+                       valid_length = commit_seq;
+                       header->lost_size = buf->subbuf_size-valid_length;
+                       assert(i_subbuf == last_subbuf);
+               }
+
+               patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, valid_length);
 
-               patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, buf->subbuf_size);
+               /* pad with empty bytes */
+               tmp = malloc(buf->subbuf_size-valid_length);
+               memset(tmp, 0, buf->subbuf_size-valid_length);
+               patient_write(buf->file_fd, tmp, buf->subbuf_size-valid_length);
+               free(tmp);
 
                if(i_subbuf == last_subbuf)
                        break;
This page took 0.026162 seconds and 4 git commands to generate.