dump: Allow directly outputting raw kdump format
The flattened format (currently output by QEMU) is used by makedumpfile
only when it is outputting a vmcore to a file which is not seekable. The
flattened format functions essentially as a set of instructions of the
form "seek to the given offset, then write the given bytes out".
The flattened format can be reconstructed using makedumpfile -R, or
makedumpfile-R.pl, but it is a slow process because it requires copying
the entire vmcore. The flattened format can also be directly read by
crash, but still, it requires a lengthy reassembly phase.
To sum up, the flattened format is not an ideal one: it should only be
used on files which are actually not seekable. This is the exact
strategy which makedumpfile uses, as seen in the implementation of
"write_buffer()" in makedumpfile [1]. However, QEMU has always used the
flattened format. For compatibility it is best not to change the default
output format without warning. So, add a flag to DumpState which changes
the output to use the normal (i.e. raw) format. This flag will be added
to the QMP and HMP commands in the next change.
[1]: f23bb94356/makedumpfile.c (L5008-L5040)
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[ Marc-André: replace loff_t with off_t ]
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20230918233233.1431858-3-stephen.s.brennan@oracle.com>
			
			
This commit is contained in:
		
							parent
							
								
									4d7dd4ed4f
								
							
						
					
					
						commit
						d43a01db28
					
				
							
								
								
									
										22
									
								
								dump/dump.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								dump/dump.c
									
									
									
									
									
								
							@ -814,6 +814,10 @@ static int write_start_flat_header(DumpState *s)
 | 
			
		||||
    MakedumpfileHeader *mh;
 | 
			
		||||
    int ret = 0;
 | 
			
		||||
 | 
			
		||||
    if (s->kdump_raw) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QEMU_BUILD_BUG_ON(sizeof *mh > MAX_SIZE_MDF_HEADER);
 | 
			
		||||
    mh = g_malloc0(MAX_SIZE_MDF_HEADER);
 | 
			
		||||
 | 
			
		||||
@ -837,6 +841,10 @@ static int write_end_flat_header(DumpState *s)
 | 
			
		||||
{
 | 
			
		||||
    MakedumpfileDataHeader mdh;
 | 
			
		||||
 | 
			
		||||
    if (s->kdump_raw) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mdh.offset = END_FLAG_FLAT_HEADER;
 | 
			
		||||
    mdh.buf_size = END_FLAG_FLAT_HEADER;
 | 
			
		||||
 | 
			
		||||
@ -853,7 +861,14 @@ static int write_buffer(DumpState *s, off_t offset, const void *buf, size_t size
 | 
			
		||||
{
 | 
			
		||||
    size_t written_size;
 | 
			
		||||
    MakedumpfileDataHeader mdh;
 | 
			
		||||
    off_t seek_loc;
 | 
			
		||||
 | 
			
		||||
    if (s->kdump_raw) {
 | 
			
		||||
        seek_loc = lseek(s->fd, offset, SEEK_SET);
 | 
			
		||||
        if (seek_loc == (off_t) -1) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        mdh.offset = cpu_to_be64(offset);
 | 
			
		||||
        mdh.buf_size = cpu_to_be64(size);
 | 
			
		||||
 | 
			
		||||
@ -861,6 +876,7 @@ static int write_buffer(DumpState *s, off_t offset, const void *buf, size_t size
 | 
			
		||||
        if (written_size != sizeof(mdh)) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    written_size = qemu_write_full(s->fd, buf, size);
 | 
			
		||||
    if (written_size != size) {
 | 
			
		||||
@ -1775,7 +1791,8 @@ static void vmcoreinfo_update_phys_base(DumpState *s)
 | 
			
		||||
 | 
			
		||||
static void dump_init(DumpState *s, int fd, bool has_format,
 | 
			
		||||
                      DumpGuestMemoryFormat format, bool paging, bool has_filter,
 | 
			
		||||
                      int64_t begin, int64_t length, Error **errp)
 | 
			
		||||
                      int64_t begin, int64_t length, bool kdump_raw,
 | 
			
		||||
                      Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    ERRP_GUARD();
 | 
			
		||||
    VMCoreInfoState *vmci = vmcoreinfo_find();
 | 
			
		||||
@ -1786,6 +1803,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,
 | 
			
		||||
    s->has_format = has_format;
 | 
			
		||||
    s->format = format;
 | 
			
		||||
    s->written_size = 0;
 | 
			
		||||
    s->kdump_raw = kdump_raw;
 | 
			
		||||
 | 
			
		||||
    /* kdump-compressed is conflict with paging and filter */
 | 
			
		||||
    if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
 | 
			
		||||
@ -2168,7 +2186,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,
 | 
			
		||||
    dump_state_prepare(s);
 | 
			
		||||
 | 
			
		||||
    dump_init(s, fd, has_format, format, paging, has_begin,
 | 
			
		||||
              begin, length, errp);
 | 
			
		||||
              begin, length, false, errp);
 | 
			
		||||
    if (*errp) {
 | 
			
		||||
        qatomic_set(&s->status, DUMP_STATUS_FAILED);
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
@ -157,6 +157,7 @@ typedef struct DumpState {
 | 
			
		||||
    MemoryMappingList list;
 | 
			
		||||
    bool resume;
 | 
			
		||||
    bool detached;
 | 
			
		||||
    bool kdump_raw;
 | 
			
		||||
    hwaddr memory_offset;
 | 
			
		||||
    int fd;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user