Do a bit of cleanup and add a bit of debugging to the checkpoint module.
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 20 Oct 2003 06:50:51 +0000 (06:50 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 20 Oct 2003 06:50:51 +0000 (06:50 +0000)
Fix a bug in the offset calculations in the ELF checkpoint file descriptor
writeout code... one loop was skipping descriptors 0,1,2, another loop
was not.  This bug had prevented 'primes' from being properly checkpointed.

sys/checkpt/checkpt.c
sys/kern/imgact_elf.c

index 5d5e512..ccdbcda 100644 (file)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $DragonFly: src/sys/checkpt/Attic/checkpt.c,v 1.1 2003/10/20 04:48:42 dillon Exp $
+ * $DragonFly: src/sys/checkpt/Attic/checkpt.c,v 1.2 2003/10/20 06:50:49 dillon Exp $
  */
 
 #include <sys/types.h>
@@ -222,7 +222,7 @@ ckpt_thaw_proc(struct proc *p, struct file *fp)
 
        if ((error = elf_gethdr(fp, ehdr)) != 0)
                goto done;
-       nbyte = sizeof(Elf_Phdr)*ehdr->e_phnum; 
+       nbyte = sizeof(Elf_Phdr) * ehdr->e_phnum; 
        phdr = malloc(nbyte, M_TEMP, M_WAITOK); 
 
        /* fetch description of program writable mappings */
@@ -393,6 +393,7 @@ mmap_phdr(struct file *fp, Elf_Phdr *phdr)
        if ((error = fp_mmap(addr, len, prot, flags, fp, pos, &addr)) != 0) {
                PRINTF(("mmap failed: %d\n", error);       );
        }
+       PRINTF(("map @%08x-%08x fileoff %08x-%08x\n", (int)addr, (int)((char *)addr + len), (int)pos, (int)(pos + len)));
        TRACE_EXIT;
        return error;
 }
@@ -515,8 +516,6 @@ elf_gettextvp(struct proc *p, struct file *fp)
            vminfo.cvm_daddr >= (caddr_t)VM_MAXUSER_ADDRESS ||
            vminfo.cvm_taddr >= (caddr_t)VM_MAXUSER_ADDRESS
        ) {
-           printf("failed %08x\n", vminfo.cvm_dsize);
-           printf("failed %08x\n", vminfo.cvm_tsize);
            error = ERANGE;
            goto done;
        }
@@ -567,8 +566,8 @@ elf_getfiles(struct proc *p, struct file *fp)
        for (i = 0; i < filecount; i++) {
                struct ckpt_fileinfo *cfi= &cfi_base[i];
                if (cfi->cfi_index < 0 || cfi->cfi_index >=  p->p_fd->fd_nfiles) {
-                       PRINTF(("can't currently restore fd: %d\n");
-                              cfi->cfi_index);
+                       PRINTF(("can't currently restore fd: %d\n",
+                              cfi->cfi_index));
                        goto done;
                }
                if ((error = ckpt_fhtovp(&cfi->cfi_fh, &vp)) != 0)
index c4164d3..00f970c 100644 (file)
@@ -27,7 +27,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/kern/imgact_elf.c,v 1.73.2.13 2002/12/28 19:49:41 dillon Exp $
- * $DragonFly: src/sys/kern/imgact_elf.c,v 1.11 2003/10/20 04:47:32 dillon Exp $
+ * $DragonFly: src/sys/kern/imgact_elf.c,v 1.12 2003/10/20 06:50:51 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -869,12 +869,12 @@ generic_elf_coredump(struct proc *p, struct file *fp, off_t limit)
        if (error == 0) {
                Elf_Phdr *php;
                int i;
+               int nbytes;
 
                php = (Elf_Phdr *)((char *)hdr + sizeof(Elf_Ehdr)) + 1;
                for (i = 0;  i < seginfo.count;  i++) {
-                       int nbytes;
-                       error = fp_write(fp, (caddr_t)php->p_vaddr, php->p_filesz, 
-                                        &nbytes);
+                       error = fp_write(fp, (caddr_t)php->p_vaddr,
+                                       php->p_filesz, &nbytes);
                        if (error != 0)
                                break;
                        php++;
@@ -1224,7 +1224,7 @@ static void
 elf_putfiles(struct proc *p, void *dst, int *off)
 {
        int i, error;
-       struct ckpt_filehdr *cfh;
+       struct ckpt_filehdr *cfh = NULL;
        struct ckpt_fileinfo *cfi;
        struct file *fp;        
        struct vnode *vp;
@@ -1234,33 +1234,30 @@ elf_putfiles(struct proc *p, void *dst, int *off)
         */
        if (dst) {
                cfh = (struct ckpt_filehdr *)((char *)dst + *off);
-               *off += sizeof(struct ckpt_filehdr); 
                cfh->cfh_nfiles = 0;            
-               /*
-                * ignore STDIN/STDERR/STDOUT
-                */
-               for (i = 3; i < p->p_fd->fd_nfiles; i++) {
-                       if ((fp = p->p_fd->fd_ofiles[i]) != NULL && fp->f_type == DTYPE_VNODE) {        
-                               cfh->cfh_nfiles++;
-                               printf("saving fd: %d\n", i);
-                               cfi = (struct ckpt_fileinfo *)((char *)dst + *off);
-                               cfi->cfi_index = i;
-                               cfi->cfi_flags = fp->f_flag;
-                               cfi->cfi_offset = fp->f_offset;
-                               vp = (struct vnode *)fp->f_data;
-                               cfi->cfi_fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
-                               error = VFS_VPTOFH(vp, &cfi->cfi_fh.fh_fid);
-
-                               *off += sizeof(struct ckpt_fileinfo);
-                       }
+       }
+       *off += sizeof(struct ckpt_filehdr); 
+
+       /*
+        * ignore STDIN/STDERR/STDOUT
+        */
+       for (i = 3; i < p->p_fd->fd_nfiles; i++) {
+               if ((fp = p->p_fd->fd_ofiles[i]) == NULL)
+                       continue;
+               if (fp->f_type != DTYPE_VNODE)
+                       continue;
+               if (dst) {
+                       cfh->cfh_nfiles++;
+                       cfi = (struct ckpt_fileinfo *)((char *)dst + *off);
+                       cfi->cfi_index = i;
+                       cfi->cfi_flags = fp->f_flag;
+                       cfi->cfi_offset = fp->f_offset;
+                       vp = (struct vnode *)fp->f_data;
+                       cfi->cfi_fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
+                       error = VFS_VPTOFH(vp, &cfi->cfi_fh.fh_fid);
                }
-       } else {
-               *off += sizeof(struct ckpt_filehdr); 
-               for (i = 0; i < p->p_fd->fd_nfiles; i++) 
-                       if ((fp = p->p_fd->fd_ofiles[i]) != NULL  && fp->f_type == DTYPE_VNODE)         
-                               *off += sizeof(struct ckpt_fileinfo);
+               *off += sizeof(struct ckpt_fileinfo);
        }
-       
 }
 
 static void