Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package makedumpfile for openSUSE:Factory checked in at 2021-11-20 22:47:57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/makedumpfile (Old) and /work/SRC/openSUSE:Factory/.makedumpfile.new.1895 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "makedumpfile" Sat Nov 20 22:47:57 2021 rev:82 rq:932486 version:1.7.0 Changes: -------- --- /work/SRC/openSUSE:Factory/makedumpfile/makedumpfile.changes 2021-07-22 22:43:22.207199048 +0200 +++ /work/SRC/openSUSE:Factory/.makedumpfile.new.1895/makedumpfile.changes 2021-11-20 22:48:18.535806819 +0100 @@ -1,0 +2,13 @@ +Fri Nov 19 10:54:59 UTC 2021 - Petr Tesa????k <[email protected]> + +- Turn on zstd. + +------------------------------------------------------------------- +Thu Nov 18 16:14:20 UTC 2021 - Petr Tesa????k <[email protected]> + +- Update to 1.7.0 + * Zstandard (zstd) compression support + * New -L option to limit output file size + * Support of kernels up to v5.15 (x86_64) + +------------------------------------------------------------------- Old: ---- makedumpfile-1.6.9.tar.gz New: ---- makedumpfile-1.7.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ makedumpfile.spec ++++++ --- /var/tmp/diff_new_pack.hnrWTd/_old 2021-11-20 22:48:19.099804950 +0100 +++ /var/tmp/diff_new_pack.hnrWTd/_new 2021-11-20 22:48:19.099804950 +0100 @@ -24,6 +24,14 @@ %endif %endif +%if 0%{!?have_zstd:1} +%if 0%{?sle_version} >= 150200 +%define have_zstd 1 +%else +%define have_zstd 0 +%endif +%endif + # Compatibility cruft # there is no separate -ltinfo until openSUSE 13.1 / SLE 12 %if 0%{?suse_version} < 1310 && 0%{?sles_version} < 12 @@ -32,7 +40,7 @@ # End of compatibility cruft Name: makedumpfile -Version: 1.6.9 +Version: 1.7.0 Release: 0 Summary: Partial kernel dump License: GPL-2.0-only @@ -43,6 +51,7 @@ Patch0: %{name}-override-libtinfo.patch Patch1: %{name}-ppc64-VA-range-SUSE.patch Patch2: %{name}-PN_XNUM.patch +BuildRequires: libbz2-devel BuildRequires: libdw-devel BuildRequires: libelf-devel BuildRequires: libeppic-devel @@ -52,14 +61,12 @@ BuildRequires: zlib-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build ExclusiveArch: %{ix86} x86_64 ia64 ppc ppc64 ppc64le s390x %{arm} aarch64 -%if 0%{?suse_version} >= 1140 || 0%{?sles_version} >= 11 -BuildRequires: libbz2-devel -%else -BuildRequires: bzip2 -%endif %if %{have_snappy} BuildRequires: snappy-devel %endif +%if %{have_zstd} +BuildRequires: libzstd-devel +%endif %description makedumpfile is a dump program to shorten the size of dump file. It @@ -78,6 +85,9 @@ %if %{have_snappy} export USESNAPPY=on %endif +%if %{have_zstd} +export USEZSTD=on +%endif export USELZO=on export LINKTYPE=dynamic make %{?_smp_mflags} LDFLAGS="-Wl,-rpath,%{_libdir}/%{name}-%{version}" ++++++ makedumpfile-1.6.9.tar.gz -> makedumpfile-1.7.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/Makefile new/makedumpfile-1.7.0/Makefile --- old/makedumpfile-1.6.9/Makefile 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/Makefile 2021-11-08 01:36:15.000000000 +0100 @@ -1,7 +1,7 @@ # makedumpfile -VERSION=1.6.9 -DATE=13 May 2021 +VERSION=1.7.0 +DATE=8 Nov 2021 # Honour the environment variable CC ifeq ($(strip $CC),) @@ -68,6 +68,20 @@ CFLAGS += -DUSESNAPPY endif +ifeq ($(USEZSTD), on) +LIBS := -lzstd $(LIBS) +CFLAGS += -DUSEZSTD +endif + +ifeq ($(DEBUG), on) +# Requires libasan +CFLAGS += -fsanitize=address +# Requires libubsan +CFLAGS += -fsanitize=undefined +# Warning: extremely slow +#CFLAGS += -fanalyzer +endif + LIBS := $(LIBS) -lpthread try-run = $(shell set -e; \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/README new/makedumpfile-1.7.0/README --- old/makedumpfile-1.6.9/README 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/README 2021-11-08 01:36:15.000000000 +0100 @@ -49,7 +49,10 @@ 7.Build with snappy support: # make USESNAPPY=on ; make install The user has to prepare snappy library. - 8.Build the extension module for --eppic option. + 8.Build with zstd support: + # make USEZSTD=on ; make install + The user has to prepare zstd library. + 9.Build the extension module for --eppic option. # make eppic_makedumpfile.so The user has to prepare eppic library from the following site: http://code.google.com/p/eppic/ @@ -142,6 +145,9 @@ 5.10 | | ** | | | | ** | | -- | | OK | | | 5.11 | | ** | | | | ** | | -- | | OK | | | 5.12 | | ** | | | | ** | | -- | | OK | | | + 5.13 | | ** | | | | ** | | -- | | OK | | | + 5.14 | | ** | | | | ** | | -- | | OK | | | + 5.15 | | ** | | | | ** | | -- | | OK | | | OK : Support. -- : Not support. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/arch/arm.c new/makedumpfile-1.7.0/arch/arm.c --- old/makedumpfile-1.6.9/arch/arm.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/arch/arm.c 2021-11-08 01:36:15.000000000 +0100 @@ -80,7 +80,7 @@ int get_machdep_info_arm(void) { - info->page_offset = SYMBOL(_stext) & 0xffff0000UL; + info->page_offset = SYMBOL(_stext) & 0xffc00000UL; /* Check if we can get MAX_PHYSMEM_BITS from vmcoreinfo */ if (NUMBER(MAX_PHYSMEM_BITS) != NOT_FOUND_NUMBER) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/diskdump_mod.h new/makedumpfile-1.7.0/diskdump_mod.h --- old/makedumpfile-1.6.9/diskdump_mod.h 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/diskdump_mod.h 2021-11-08 01:36:15.000000000 +0100 @@ -98,6 +98,7 @@ #define DUMP_DH_COMPRESSED_INCOMPLETE 0x8 /* indicate an incomplete dumpfile */ #define DUMP_DH_EXCLUDED_VMEMMAP 0x10 /* unused vmemmap pages are excluded */ +#define DUMP_DH_COMPRESSED_ZSTD 0x20 /* page is compressed with zstd */ /* descriptor of each page for vmcore */ typedef struct page_desc { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/elf_info.c new/makedumpfile-1.7.0/elf_info.c --- old/makedumpfile-1.6.9/elf_info.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/elf_info.c 2021-11-08 01:36:15.000000000 +0100 @@ -628,7 +628,7 @@ for (i = 0; i < num_pt_loads; i++) { pls = &pt_loads[i]; - if (max_paddr < pls->phys_end) + if (pls->phys_start != NOT_PADDR && max_paddr < pls->phys_end) max_paddr = pls->phys_end; } return max_paddr; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/erase_info.c new/makedumpfile-1.7.0/erase_info.c --- old/makedumpfile-1.6.9/erase_info.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/erase_info.c 2021-11-08 01:36:15.000000000 +0100 @@ -280,10 +280,8 @@ } module_name = (char *)(module_struct_mem + OFFSET(module.name)); - if (strlen(module_name) < MOD_NAME_LEN) - strcpy(modules->name, module_name); - else - strncpy(modules->name, module_name, MOD_NAME_LEN-1); + strncpy(modules->name, module_name, MOD_NAME_LEN - 1); + modules->name[MOD_NAME_LEN - 1] = '\0'; mod_init = ULONG(module_struct_mem + OFFSET(module.module_init)); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/makedumpfile.8 new/makedumpfile-1.7.0/makedumpfile.8 --- old/makedumpfile-1.6.9/makedumpfile.8 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/makedumpfile.8 2021-11-08 01:36:15.000000000 +0100 @@ -1,4 +1,4 @@ -.TH MAKEDUMPFILE 8 "13 May 2021" "makedumpfile v1.6.9" "Linux System Administrator's Manual" +.TH MAKEDUMPFILE 8 "8 Nov 2021" "makedumpfile v1.7.0" "Linux System Administrator's Manual" .SH NAME makedumpfile \- make a small dumpfile of kdump .SH SYNOPSIS @@ -132,10 +132,19 @@ .SH OPTIONS .TP -\fB\-c,\-l,\-p\fR -Compress dump data by each page using zlib for -c option, lzo for -l -option or snappy for -p option. -(-l option needs USELZO=on and -p option needs USESNAPPY=on when building) +\fB\-c,\-l,\-p,\-z\fR +Compress dump data by the page using the following compression library respectively: +.br + \fB-c\fR : zlib +.br + \fB-l\fR : lzo +.br + \fB-p\fR : snappy +.br + \fB-z\fR : zstd +.br +(-l, -p and -z option need USELZO=on, USESNAPPY=on and USEZSTD=on respectively +when building makedumpfile) .br A user cannot specify this option with \-E option, because the ELF format does not support compressed data. @@ -157,9 +166,10 @@ Then the pages are excluded only from domain-0. .br If specifying multiple dump_levels with the delimiter ',', makedumpfile retries -to create a \fIDUMPFILE\fR by other dump_level when "No space on device" error -happens. For example, if dump_level is "11,31" and makedumpfile fails -by dump_level 11, makedumpfile retries it by dump_level 31. +to create \fIDUMPFILE\fR using the next dump_level when the size of a dumpfile +exceeds the limit specified with '-L' or when a "No space on device" error +happens. For example, if dump_level is "11,31" and makedumpfile fails with +dump_level 11, makedumpfile retries with dump_level 31. .br .B Example: .br @@ -221,6 +231,11 @@ 30 | | X | X | X | X 31 | X | X | X | X | X +.TP +\fB\-L\fR \fISIZE\fR +Limit the size of the output file to \fISIZE\fR bytes. An incomplete +\fIDUMPFILE\fR or \fILOGFILE\fR is written if the size would otherwise exceed +\fISIZE\fR. .TP \fB\-E\fR diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/makedumpfile.c new/makedumpfile-1.7.0/makedumpfile.c --- old/makedumpfile-1.6.9/makedumpfile.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/makedumpfile.c 2021-11-08 01:36:15.000000000 +0100 @@ -296,26 +296,20 @@ static inline unsigned long calculate_len_buf_out(long page_size) { - unsigned long len_buf_out_zlib, len_buf_out_lzo, len_buf_out_snappy; - unsigned long len_buf_out; - - len_buf_out_zlib = len_buf_out_lzo = len_buf_out_snappy = 0; + unsigned long zlib, lzo, snappy, zstd; + zlib = lzo = snappy = zstd = 0; + zlib = compressBound(page_size); #ifdef USELZO - len_buf_out_lzo = page_size + page_size / 16 + 64 + 3; + lzo = page_size + page_size / 16 + 64 + 3; #endif - #ifdef USESNAPPY - len_buf_out_snappy = snappy_max_compressed_length(page_size); + snappy = snappy_max_compressed_length(page_size); #endif - - len_buf_out_zlib = compressBound(page_size); - - len_buf_out = MAX(len_buf_out_zlib, - MAX(len_buf_out_lzo, - len_buf_out_snappy)); - - return len_buf_out; +#ifdef USEZSTD + zstd = ZSTD_compressBound(page_size); +#endif + return MAX(zlib, MAX(lzo, MAX(snappy, zstd))); } #define BITMAP_SECT_LEN 4096 @@ -838,7 +832,7 @@ * Read page data */ rdbuf = pd.flags & (DUMP_DH_COMPRESSED_ZLIB | DUMP_DH_COMPRESSED_LZO | - DUMP_DH_COMPRESSED_SNAPPY) ? buf : bufptr; + DUMP_DH_COMPRESSED_SNAPPY | DUMP_DH_COMPRESSED_ZSTD) ? buf : bufptr; if (read(info->fd_memory, rdbuf, pd.size) != pd.size) { ERRMSG("Can't read %s. %s\n", info->name_memory, strerror(errno)); @@ -880,6 +874,14 @@ return FALSE; } #endif +#ifdef USEZSTD + } else if ((pd.flags & DUMP_DH_COMPRESSED_ZSTD)) { + ret = ZSTD_decompress(bufptr, info->page_size, buf, pd.size); + if (ZSTD_isError(ret) || (ret != info->page_size)) { + ERRMSG("Uncompress failed: %d\n", ret); + return FALSE; + } +#endif } return TRUE; @@ -917,7 +919,7 @@ * Read page data */ rdbuf = pd.flags & (DUMP_DH_COMPRESSED_ZLIB | DUMP_DH_COMPRESSED_LZO | - DUMP_DH_COMPRESSED_SNAPPY) ? buf : bufptr; + DUMP_DH_COMPRESSED_SNAPPY | DUMP_DH_COMPRESSED_ZSTD) ? buf : bufptr; if (read(fd_memory, rdbuf, pd.size) != pd.size) { ERRMSG("Can't read %s. %s\n", info->name_memory, strerror(errno)); @@ -959,6 +961,14 @@ return FALSE; } #endif +#ifdef USEZSTD + } else if ((pd.flags & DUMP_DH_COMPRESSED_ZSTD)) { + ret = ZSTD_decompress(bufptr, info->page_size, buf, pd.size); + if (ZSTD_isError(ret) || (ret != info->page_size)) { + ERRMSG("Uncompress failed: %d\n", ret); + return FALSE; + } +#endif } return TRUE; @@ -1407,8 +1417,9 @@ int open_dump_bitmap(void) { - int i, fd; char *tmpname; + size_t len; + int i, fd; /* Unnecessary to open */ if (!info->working_dir && !info->flag_reassemble && !info->flag_refiltering @@ -1421,15 +1432,15 @@ else if (!tmpname) tmpname = "/tmp"; - if ((info->name_bitmap = (char *)malloc(sizeof(FILENAME_BITMAP) + - strlen(tmpname) + 1)) == NULL) { + /* +2 for '/' and terminating '\0' */ + len = strlen(FILENAME_BITMAP) + strlen(tmpname) + 2; + info->name_bitmap = malloc(len); + if (!info->name_bitmap) { ERRMSG("Can't allocate memory for the filename. %s\n", strerror(errno)); return FALSE; } - strcpy(info->name_bitmap, tmpname); - strcat(info->name_bitmap, "/"); - strcat(info->name_bitmap, FILENAME_BITMAP); + snprintf(info->name_bitmap, len, "%s/%s", tmpname, FILENAME_BITMAP); if ((fd = mkstemp(info->name_bitmap)) < 0) { ERRMSG("Can't open the bitmap file(%s). %s\n", info->name_bitmap, strerror(errno)); @@ -1563,6 +1574,7 @@ SYMBOL_INIT(pgdat_list, "pgdat_list"); SYMBOL_INIT(contig_page_data, "contig_page_data"); SYMBOL_INIT(prb, "prb"); + SYMBOL_INIT(clear_seq, "clear_seq"); SYMBOL_INIT(log_buf, "log_buf"); SYMBOL_INIT(log_buf_len, "log_buf_len"); SYMBOL_INIT(log_end, "log_end"); @@ -2008,6 +2020,9 @@ OFFSET_INIT(printk_info.text_len, "printk_info", "text_len"); OFFSET_INIT(atomic_long_t.counter, "atomic_long_t", "counter"); + + SIZE_INIT(latched_seq, "latched_seq"); + OFFSET_INIT(latched_seq.val, "latched_seq", "val"); } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { /* * In kernel 3.11-rc4 the log structure name was renamed @@ -2239,6 +2254,7 @@ WRITE_SYMBOL("pgdat_list", pgdat_list); WRITE_SYMBOL("contig_page_data", contig_page_data); WRITE_SYMBOL("prb", prb); + WRITE_SYMBOL("clear_seq", clear_seq); WRITE_SYMBOL("log_buf", log_buf); WRITE_SYMBOL("log_buf_len", log_buf_len); WRITE_SYMBOL("log_end", log_end); @@ -2274,6 +2290,7 @@ WRITE_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer); WRITE_STRUCTURE_SIZE("prb_desc", prb_desc); WRITE_STRUCTURE_SIZE("printk_info", printk_info); + WRITE_STRUCTURE_SIZE("latched_seq", latched_seq); } else if (info->flag_use_printk_log) WRITE_STRUCTURE_SIZE("printk_log", printk_log); else @@ -2343,6 +2360,8 @@ WRITE_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len); WRITE_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter); + + WRITE_MEMBER_OFFSET("latched_seq.val", latched_seq.val); } else if (info->flag_use_printk_log) { WRITE_MEMBER_OFFSET("printk_log.ts_nsec", printk_log.ts_nsec); WRITE_MEMBER_OFFSET("printk_log.len", printk_log.len); @@ -2484,7 +2503,9 @@ /* if the release have been stored, skip this time. */ if (strlen(info->release)) continue; - strcpy(info->release, buf + strlen(STR_OSRELEASE)); + memcpy(info->release, buf + strlen(STR_OSRELEASE), + STRLEN_OSRELEASE-1); + info->release[STRLEN_OSRELEASE-1] = '\0'; } if (strncmp(buf, STR_PAGESIZE, strlen(STR_PAGESIZE)) == 0) { page_size = strtol(buf+strlen(STR_PAGESIZE),&endp,10); @@ -2684,6 +2705,7 @@ READ_SYMBOL("pgdat_list", pgdat_list); READ_SYMBOL("contig_page_data", contig_page_data); READ_SYMBOL("prb", prb); + READ_SYMBOL("clear_seq", clear_seq); READ_SYMBOL("log_buf", log_buf); READ_SYMBOL("log_buf_len", log_buf_len); READ_SYMBOL("log_end", log_end); @@ -2792,6 +2814,9 @@ READ_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len); READ_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter); + + READ_STRUCTURE_SIZE("latched_seq", latched_seq); + READ_MEMBER_OFFSET("latched_seq.val", latched_seq.val); } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { info->flag_use_printk_ringbuffer = FALSE; info->flag_use_printk_log = TRUE; @@ -2855,39 +2880,50 @@ int copy_vmcoreinfo(off_t offset, unsigned long size) { - int fd; - char buf[VMCOREINFO_BYTES]; const off_t failed = (off_t)-1; + int ret = FALSE; + char *buf; + int fd; if (!offset || !size) return FALSE; + buf = malloc(size); + if (!buf) { + ERRMSG("Can't allocate buffer for vmcoreinfo. %s\n", + strerror(errno)); + return FALSE; + } + if ((fd = mkstemp(info->name_vmcoreinfo)) < 0) { ERRMSG("Can't open the vmcoreinfo file(%s). %s\n", info->name_vmcoreinfo, strerror(errno)); - return FALSE; + goto out; } if (lseek(info->fd_memory, offset, SEEK_SET) == failed) { ERRMSG("Can't seek the dump memory(%s). %s\n", info->name_memory, strerror(errno)); - return FALSE; + goto out; } - if (read(info->fd_memory, &buf, size) != size) { + if (read(info->fd_memory, buf, size) != size) { ERRMSG("Can't read the dump memory(%s). %s\n", info->name_memory, strerror(errno)); - return FALSE; + goto out; } - if (write(fd, &buf, size) != size) { + if (write(fd, buf, size) != size) { ERRMSG("Can't write the vmcoreinfo file(%s). %s\n", info->name_vmcoreinfo, strerror(errno)); - return FALSE; + goto out; } if (close(fd) < 0) { ERRMSG("Can't close the vmcoreinfo file(%s). %s\n", info->name_vmcoreinfo, strerror(errno)); - return FALSE; + goto out; } - return TRUE; + ret = TRUE; +out: + free(buf); + return ret; } int @@ -3887,6 +3923,12 @@ return FALSE; } #endif +#ifdef USEZSTD + if ((ZSTD_CCTX_PARALLEL(i) = ZSTD_createCCtx()) == NULL) { + MSG("Can't allocate ZSTD_CCtx.\n"); + return FALSE; + } +#endif } info->num_buffers = PAGE_DATA_NUM * info->num_threads; @@ -3994,6 +4036,10 @@ if (WRKMEM_PARALLEL(i) != NULL) free(WRKMEM_PARALLEL(i)); #endif +#ifdef USEZSTD + if (ZSTD_CCTX_PARALLEL(i) != NULL) + ZSTD_freeCCtx(ZSTD_CCTX_PARALLEL(i)); +#endif } free(info->threads); @@ -4167,6 +4213,14 @@ } #endif +#ifndef USEZSTD + if (info->flag_compress == DUMP_DH_COMPRESSED_ZSTD) { + MSG("'-z' option is disabled, "); + MSG("because this binary doesn't support zstd compression.\n"); + MSG("Try `make USEZSTD=on` when building.\n"); + } +#endif + if (info->flag_exclude_xen_dom && !is_xen_memory()) { MSG("'-X' option is disable,"); MSG("because %s is not Xen's memory core image.\n", info->name_memory); @@ -4713,29 +4767,65 @@ } int -write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name) +write_and_check_space(int fd, void *buf, size_t buf_size, const char* desc, + const char *file_name) { - int status, written_size = 0; + size_t limit, done = 0; + int retval = 0; + off_t pos; + + if (fd == STDOUT_FILENO || info->flag_dry_run) { + pos = write_bytes; + } else { + pos = lseek(fd, 0, SEEK_CUR); + if (pos == -1) { + ERRMSG("Can't seek the dump file(%s). %s\n", + file_name, strerror(errno)); + return FALSE; + } + } - write_bytes += buf_size; + if (info->size_limit != -1 && pos + buf_size > info->size_limit) { + if (pos > info->size_limit) + limit = 0; + else + limit = info->size_limit - pos; + info->flag_nospace = TRUE; + } else { + limit = buf_size; + } if (info->flag_dry_run) - return TRUE; + done = limit; - while (written_size < buf_size) { - status = write(fd, buf + written_size, - buf_size - written_size); - if (0 < status) { - written_size += status; - continue; + while (done < limit) { + retval = write(fd, buf, limit - done); + if (retval > 0) { + done += retval; + buf += retval; + } else { + if (retval == -1) { + if (errno == EINTR) + continue; + if (errno == ENOSPC) + info->flag_nospace = TRUE; + else + info->flag_nospace = FALSE; + MSG("\nCan't write the %s file(%s). %s\n", + desc, file_name, strerror(errno)); + } + break; } - if (errno == ENOSPC) - info->flag_nospace = TRUE; - MSG("\nCan't write the dump file(%s). %s\n", - file_name, strerror(errno)); - return FALSE; } - return TRUE; + + write_bytes += done; + + if (retval != -1 && done < buf_size) { + MSG("\nCan't write the %s file(%s). Size limit(%llu) reached.\n", + desc, file_name, (unsigned long long) info->size_limit); + } + + return done == buf_size; } int @@ -4757,7 +4847,8 @@ fdh.offset = bswap_64(offset); fdh.buf_size = bswap_64(buf_size); } - if (!write_and_check_space(fd, &fdh, sizeof(fdh), file_name)) + if (!write_and_check_space(fd, &fdh, sizeof(fdh), "dump", + file_name)) return FALSE; } else if (!info->flag_dry_run && lseek(fd, offset, SEEK_SET) == failed) { @@ -4765,7 +4856,7 @@ return FALSE; } - if (!write_and_check_space(fd, buf, buf_size, file_name)) + if (!write_and_check_space(fd, buf, buf_size, "dump", file_name)) return FALSE; return TRUE; @@ -5084,6 +5175,9 @@ int check_and_modify_headers() { + if (info->flag_dry_run) + return TRUE; + if (info->flag_elf_dumpfile) return check_and_modify_elf_headers(info->name_dumpfile); else @@ -5281,7 +5375,7 @@ } static int -dump_log_entry(char *logptr, int fp) +dump_log_entry(char *logptr, int fp, const char *file_name) { char *msg, *p, *bufp; unsigned int i, text_len, indent_len, buf_need; @@ -5307,7 +5401,8 @@ for (i = 0, p = msg; i < text_len; i++, p++) { if (bufp - buf >= sizeof(buf) - buf_need) { - if (write(info->fd_dumpfile, buf, bufp - buf) < 0) + if (!write_and_check_space(fp, buf, bufp - buf, "log", + file_name)) return FALSE; bufp = buf; } @@ -5322,10 +5417,7 @@ *bufp++ = '\n'; - if (write(info->fd_dumpfile, buf, bufp - buf) < 0) - return FALSE; - else - return TRUE; + return write_and_check_space(fp, buf, bufp - buf, "log", file_name); } /* @@ -5507,7 +5599,9 @@ ERRMSG("Can't open output file.\n"); goto out; } - if (write(info->fd_dumpfile, log_buffer, length_log) < 0) + if (!write_and_check_space(info->fd_dumpfile, log_buffer, + length_log, "log", + info->name_dumpfile)) goto out; if (!close_files_for_creating_dumpfile()) @@ -5532,7 +5626,8 @@ idx = log_first_idx; while (idx != log_next_idx) { log_ptr = log_from_idx(idx, log_buffer); - if (!dump_log_entry(log_ptr, info->fd_dumpfile)) + if (!dump_log_entry(log_ptr, info->fd_dumpfile, + info->name_dumpfile)) goto out; idx = log_next(idx, log_buffer); } @@ -5715,7 +5810,7 @@ for (i = 0; i < sz; i++, p++) { if (*p == 0) continue; - else if (*p == 0xff) { + else if ((*p & 0xff) == 0xff) { cnt += 8; continue; } @@ -6369,15 +6464,15 @@ int init_save_control() { + char *basename = "makedumpfilepfns"; + size_t len; int flags; - char *filename; - filename = malloc(50); - *filename = '\0'; - strcpy(filename, info->working_dir); - strcat(filename, "/"); - strcat(filename, "makedumpfilepfns"); - sc.sc_filename = filename; + /* +2 for '/' and terminating '\0' */ + len = strlen(info->working_dir) + strlen(basename) + 2; + sc.sc_filename = malloc(len); + snprintf(sc.sc_filename, len, "%s/%s", info->working_dir, basename); + flags = O_RDWR|O_CREAT|O_TRUNC; if ((sc.sc_fd = open(sc.sc_filename, flags, S_IRUSR|S_IWUSR)) < 0) { ERRMSG("Can't open the pfn file %s.\n", sc.sc_filename); @@ -6390,6 +6485,8 @@ ERRMSG("Can't allocate a page for pfn buf.\n"); return FALSE; } + memset(sc.sc_buf, 0, info->page_size); + sc.sc_buflen = info->page_size; sc.sc_bufposition = 0; sc.sc_fileposition = 0; @@ -6930,7 +7027,7 @@ if (!info->flag_flatten) return FALSE; - strcpy(fh.signature, MAKEDUMPFILE_SIGNATURE); + strncpy(fh.signature, MAKEDUMPFILE_SIGNATURE, sizeof(fh.signature)); /* * For sending dump data to a different architecture, change the values @@ -6947,8 +7044,9 @@ memset(buf, 0, sizeof(buf)); memcpy(buf, &fh, sizeof(fh)); - if (!write_and_check_space(info->fd_dumpfile, buf, MAX_SIZE_MDF_HEADER, - info->name_dumpfile)) + if (!write_and_check_space(info->fd_dumpfile, buf, + MAX_SIZE_MDF_HEADER, "dump", + info->name_dumpfile)) return FALSE; return TRUE; @@ -6966,7 +7064,7 @@ fdh.buf_size = END_FLAG_FLAT_HEADER; if (!write_and_check_space(info->fd_dumpfile, &fdh, sizeof(fdh), - info->name_dumpfile)) + "dump", info->name_dumpfile)) return FALSE; return TRUE; @@ -7243,6 +7341,10 @@ else if (info->flag_compress & DUMP_DH_COMPRESSED_SNAPPY) dh->status |= DUMP_DH_COMPRESSED_SNAPPY; #endif +#ifdef USEZSTD + else if (info->flag_compress & DUMP_DH_COMPRESSED_ZSTD) + dh->status |= DUMP_DH_COMPRESSED_ZSTD; +#endif size = sizeof(struct disk_dump_header); if (!write_buffer(info->fd_dumpfile, 0, dh, size, info->name_dumpfile)) @@ -7764,7 +7866,7 @@ if (!get_phdr_memory(i, &load)) return FALSE; - if (load.p_type != PT_LOAD) + if (load.p_type != PT_LOAD || load.p_paddr == NOT_PADDR) continue; off_memory= load.p_offset; @@ -7965,7 +8067,11 @@ int size, file_end, nr_pages; page_desc_t *pd = buf; - file_end = lseek(cd_page->fd, 0, SEEK_END); + if (info->flag_dry_run) + file_end = write_bytes; + else + file_end = lseek(cd_page->fd, 0, SEEK_END); + if (file_end < 0) { ERRMSG("Can't seek end of the dump file(%s).\n", cd_page->file_name); return -1; @@ -7993,8 +8099,8 @@ * write the buffer cd_header into dumpfile and then write the cd_page. * With that, when enospc occurs, we can save more useful information. */ - if (cd_header->buf_size + sizeof(*pd) > cd_header->cache_size - || cd_page->buf_size + pd->size > cd_page->cache_size){ + if (cd_header->buf_size + sizeof(*pd) >= cd_header->cache_size || + cd_page->buf_size + pd->size >= cd_page->cache_size) { if( !write_cd_buf(cd_header) ) { memset(cd_header->buf, 0, cd_header->cache_size); write_cd_buf(cd_header); @@ -8101,6 +8207,9 @@ #ifdef USELZO lzo_bytep wrkmem = WRKMEM_PARALLEL(kdump_thread_args->thread_num); #endif +#ifdef USEZSTD + ZSTD_CCtx *cctx = ZSTD_CCTX_PARALLEL(kdump_thread_args->thread_num); +#endif buf = BUF_PARALLEL(kdump_thread_args->thread_num); buf_out = BUF_OUT_PARALLEL(kdump_thread_args->thread_num); @@ -8234,6 +8343,17 @@ page_data_buf[index].size = size_out; memcpy(page_data_buf[index].buf, buf_out, size_out); #endif +#ifdef USEZSTD + } else if ((info->flag_compress & DUMP_DH_COMPRESSED_ZSTD) + && (size_out = ZSTD_compressCCtx(cctx, + buf_out, kdump_thread_args->len_buf_out, + buf, info->page_size, 1)) + && (!ZSTD_isError(size_out)) + && (size_out < info->page_size)) { + page_data_buf[index].flags = DUMP_DH_COMPRESSED_ZSTD; + page_data_buf[index].size = size_out; + memcpy(page_data_buf[index].buf, buf_out, size_out); +#endif } else { page_data_buf[index].flags = 0; page_data_buf[index].size = info->page_size; @@ -8508,6 +8628,9 @@ #ifdef USELZO lzo_bytep wrkmem = NULL; #endif +#ifdef USEZSTD + ZSTD_CCtx *cctx = NULL; +#endif if (info->flag_elf_dumpfile) return FALSE; @@ -8527,6 +8650,14 @@ goto out; } #endif +#ifdef USEZSTD + if (info->flag_compress & DUMP_DH_COMPRESSED_ZSTD) { + if ((cctx = ZSTD_createCCtx()) == NULL) { + ERRMSG("Can't allocate ZSTD_CCtx.\n"); + goto out; + } + } +#endif len_buf_out = calculate_len_buf_out(info->page_size); @@ -8610,6 +8741,16 @@ pd.flags = DUMP_DH_COMPRESSED_SNAPPY; pd.size = size_out; #endif +#ifdef USEZSTD + } else if ((info->flag_compress & DUMP_DH_COMPRESSED_ZSTD) + && (size_out = ZSTD_compressCCtx(cctx, + buf_out, len_buf_out, + buf, info->page_size, 1)) + && (!ZSTD_isError(size_out)) + && (size_out < info->page_size)) { + pd.flags = DUMP_DH_COMPRESSED_ZSTD; + pd.size = size_out; +#endif } else { pd.flags = 0; pd.size = info->page_size; @@ -8629,6 +8770,10 @@ out: if (buf_out != NULL) free(buf_out); +#ifdef USEZSTD + if (cctx != NULL) + ZSTD_freeCCtx(cctx); +#endif #ifdef USELZO if (wrkmem != NULL) free(wrkmem); @@ -9272,6 +9417,7 @@ { off_t offset_xen_crash_info; unsigned long size_xen_crash_info; + int ret = FALSE; void *buf; get_xen_crash_info(&offset_xen_crash_info, &size_xen_crash_info); @@ -9296,13 +9442,13 @@ if (lseek(info->fd_memory, offset_xen_crash_info, SEEK_SET) < 0) { ERRMSG("Can't seek the dump memory(%s). %s\n", info->name_memory, strerror(errno)); - return FALSE; + goto out_error; } if (read(info->fd_memory, buf, size_xen_crash_info) != size_xen_crash_info) { ERRMSG("Can't read the dump memory(%s). %s\n", info->name_memory, strerror(errno)); - return FALSE; + goto out_error; } info->xen_crash_info.com = buf; @@ -9313,7 +9459,11 @@ else info->xen_crash_info_v = 0; - return TRUE; + ret = TRUE; + +out_error: + free(buf); + return ret; } int @@ -11585,6 +11735,7 @@ } info->file_vmcoreinfo = NULL; info->fd_vmlinux = -1; + info->size_limit = -1; info->fd_xen_syms = -1; info->fd_memory = -1; info->fd_dumpfile = -1; @@ -11605,9 +11756,12 @@ info->block_order = DEFAULT_ORDER; message_level = DEFAULT_MSG_LEVEL; - while ((opt = getopt_long(argc, argv, "b:cDd:eEFfg:hi:lpRvXx:", longopts, + while ((opt = getopt_long(argc, argv, "b:cDd:eEFfg:hi:lL:pRvXx:z", longopts, NULL)) != -1) { switch (opt) { + unsigned long long val; + char *endptr; + case OPT_BLOCK_ORDER: info->block_order = atoi(optarg); break; @@ -11624,6 +11778,14 @@ if (!parse_dump_level(optarg)) goto out; break; + case OPT_SIZE_LIMIT: + val = memparse(optarg, &endptr); + if (*endptr || val == 0) { + MSG("Limit size(%s) is invalid.\n", optarg); + goto out; + } + info->size_limit = val; + break; case OPT_ELF_DUMPFILE: info->flag_elf_dumpfile = 1; break; @@ -11677,6 +11839,9 @@ case OPT_COMPRESS_SNAPPY: info->flag_compress = DUMP_DH_COMPRESSED_SNAPPY; break; + case OPT_COMPRESS_ZSTD: + info->flag_compress = DUMP_DH_COMPRESSED_ZSTD; + break; case OPT_XEN_PHYS_START: info->xen_phys_start = strtoul(optarg, NULL, 0); break; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/makedumpfile.conf.5 new/makedumpfile-1.7.0/makedumpfile.conf.5 --- old/makedumpfile-1.6.9/makedumpfile.conf.5 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/makedumpfile.conf.5 2021-11-08 01:36:15.000000000 +0100 @@ -1,4 +1,4 @@ -.TH MAKEDUMPFILE.CONF 5 "13 May 2021" "makedumpfile v1.6.9" "Linux System Administrator's Manual" +.TH MAKEDUMPFILE.CONF 5 "8 Nov 2021" "makedumpfile v1.7.0" "Linux System Administrator's Manual" .SH NAME makedumpfile.conf \- The filter configuration file for makedumpfile(8). .SH DESCRIPTION diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/makedumpfile.h new/makedumpfile-1.7.0/makedumpfile.h --- old/makedumpfile-1.6.9/makedumpfile.h 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/makedumpfile.h 2021-11-08 01:36:15.000000000 +0100 @@ -38,6 +38,9 @@ #ifdef USESNAPPY #include <snappy-c.h> #endif +#ifdef USEZSTD +#include <zstd.h> +#endif #include "common.h" #include "dwarf_info.h" #include "diskdump_mod.h" @@ -195,7 +198,7 @@ * 2. it has been verified that (1UL<<2) was never set, so it is * safe to mask that bit off even in old kernels. */ -#define SECTION_MAP_LAST_BIT (1UL<<4) +#define SECTION_MAP_LAST_BIT (1UL<<5) #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) #define NR_SECTION_ROOTS() divideup(num_section, SECTIONS_PER_ROOT()) #define SECTION_NR_TO_PFN(sec) ((sec) << PFN_SECTION_SHIFT()) @@ -481,6 +484,9 @@ #ifdef USELZO #define WRKMEM_PARALLEL(i) info->parallel_info[i].wrkmem #endif +#ifdef USEZSTD +#define ZSTD_CCTX_PARALLEL(i) info->parallel_info[i].zstd_cctx +#endif /* * kernel version * @@ -495,12 +501,11 @@ #define KVER_MIN_SHIFT 16 #define KERNEL_VERSION(x,y,z) (((x) << KVER_MAJ_SHIFT) | ((y) << KVER_MIN_SHIFT) | (z)) #define OLDEST_VERSION KERNEL_VERSION(2, 6, 15) /* linux-2.6.15 */ -#define LATEST_VERSION KERNEL_VERSION(5, 12, 1) /* linux-5.12.1 */ +#define LATEST_VERSION KERNEL_VERSION(5, 15, 0) /* linux-5.15.0 */ /* * vmcoreinfo in /proc/vmcore */ -#define VMCOREINFO_BYTES (4096) #define FILENAME_VMCOREINFO "/tmp/vmcoreinfoXXXXXX" /* @@ -1325,6 +1330,9 @@ #ifdef USELZO lzo_bytep wrkmem; #endif +#ifdef USEZSTD + ZSTD_CCtx *zstd_cctx; +#endif }; struct ppc64_vmemmap { @@ -1344,6 +1352,7 @@ int max_dump_level; /* maximum dump level */ int num_dump_level; /* number of dump level */ int array_dump_level[NUM_ARRAY_DUMP_LEVEL]; + off_t size_limit; /* dump file size limit */ int flag_compress; /* flag of compression */ int flag_lzo_support; /* flag of LZO compression support */ int flag_elf_dumpfile; /* flag of creating ELF dumpfile */ @@ -1655,6 +1664,7 @@ unsigned long long pgdat_list; unsigned long long contig_page_data; unsigned long long prb; + unsigned long long clear_seq; unsigned long long log_buf; unsigned long long log_buf_len; unsigned long long log_end; @@ -1748,6 +1758,7 @@ long printk_ringbuffer; long prb_desc; long printk_info; + long latched_seq; /* * for Xen extraction @@ -1972,6 +1983,10 @@ long counter; } atomic_long_t; + struct latched_seq_s { + long val; + } latched_seq; + /* * symbols on ppc64 arch */ @@ -2305,6 +2320,9 @@ static inline int is_cyclic_region(mdf_pfn_t pfn, struct cycle *cycle) { + if (!cycle) + return FALSE; + if (pfn < cycle->start_pfn || cycle->end_pfn <= pfn) return FALSE; else @@ -2458,11 +2476,13 @@ #define OPT_HELP 'h' #define OPT_READ_VMCOREINFO 'i' #define OPT_COMPRESS_LZO 'l' +#define OPT_SIZE_LIMIT 'L' #define OPT_COMPRESS_SNAPPY 'p' #define OPT_REARRANGE 'R' #define OPT_VERSION 'v' #define OPT_EXCLUDE_XEN_DOM 'X' #define OPT_VMLINUX 'x' +#define OPT_COMPRESS_ZSTD 'z' #define OPT_START 256 #define OPT_SPLIT OPT_START+0 #define OPT_REASSEMBLE OPT_START+1 @@ -2510,8 +2530,10 @@ int hexadecimal(char *s, int count); int decimal(char *s, int count); int file_exists(char *file); - +int write_and_check_space(int fd, void *buf, size_t buf_size, + const char* desc, const char *file_name); int open_dump_file(void); int dump_lockless_dmesg(void); +unsigned long long memparse(char *ptr, char **retptr); #endif /* MAKEDUMPFILE_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/makedumpfile.spec new/makedumpfile-1.7.0/makedumpfile.spec --- old/makedumpfile-1.6.9/makedumpfile.spec 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/makedumpfile.spec 2021-11-08 01:36:15.000000000 +0100 @@ -1,6 +1,6 @@ Name: makedumpfile Summary: makedumpfile package -Version: 1.6.9 +Version: 1.7.0 Release: 1 Group: Applications/Text License: GPL diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/print_info.c new/makedumpfile-1.7.0/print_info.c --- old/makedumpfile-1.6.9/print_info.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/print_info.c 2021-11-08 01:36:15.000000000 +0100 @@ -39,6 +39,11 @@ #else MSG("snappy\tdisabled\n"); #endif +#ifdef USEZSTD + MSG("zstd\tenabled\n"); +#else + MSG("zstd\tdisabled\n"); +#endif MSG("\n"); } @@ -58,19 +63,25 @@ #else MSG(" disabled ('-p' option will be ignored.)\n"); #endif + MSG("zstd support:\n"); +#ifdef USEZSTD + MSG(" enabled\n"); +#else + MSG(" disabled ('-z' option will be ignored.)\n"); +#endif MSG("\n"); MSG("Usage:\n"); MSG(" Creating DUMPFILE:\n"); - MSG(" # makedumpfile [-c|-l|-p|-E] [-d DL] [-e] [-x VMLINUX|-i VMCOREINFO] VMCORE\n"); + MSG(" # makedumpfile [-c|-l|-p|-z|-E] [-d DL] [-e] [-x VMLINUX|-i VMCOREINFO] VMCORE\n"); MSG(" DUMPFILE\n"); MSG("\n"); MSG(" Creating DUMPFILE with filtered kernel data specified through filter config\n"); MSG(" file or eppic macro:\n"); - MSG(" # makedumpfile [-c|-l|-p|-E] [-d DL] -x VMLINUX [--config FILTERCONFIGFILE]\n"); + MSG(" # makedumpfile [-c|-l|-p|-z|-E] [-d DL] -x VMLINUX [--config FILTERCONFIGFILE]\n"); MSG(" [--eppic EPPICMACRO] VMCORE DUMPFILE\n"); MSG("\n"); MSG(" Outputting the dump data in the flattened format to the standard output:\n"); - MSG(" # makedumpfile -F [-c|-l|-p|-E] [-d DL] [-x VMLINUX|-i VMCOREINFO] VMCORE\n"); + MSG(" # makedumpfile -F [-c|-l|-p|-z|-E] [-d DL] [-x VMLINUX|-i VMCOREINFO] VMCORE\n"); MSG("\n"); MSG(" Rearranging the dump data in the flattened format to a readable DUMPFILE:\n"); MSG(" # makedumpfile -R DUMPFILE\n"); @@ -94,26 +105,27 @@ MSG("\n"); MSG("\n"); MSG(" Creating DUMPFILE of Xen:\n"); - MSG(" # makedumpfile [-c|-l|-p|-E] [--xen-syms XEN-SYMS|--xen-vmcoreinfo VMCOREINFO]\n"); + MSG(" # makedumpfile [-c|-l|-p|-z|-E] [--xen-syms XEN-SYMS|--xen-vmcoreinfo VMCOREINFO]\n"); MSG(" VMCORE DUMPFILE\n"); MSG("\n"); MSG(" Filtering domain-0 of Xen:\n"); - MSG(" # makedumpfile [-c|-l|-p|-E] -d DL -x vmlinux VMCORE DUMPFILE\n"); + MSG(" # makedumpfile [-c|-l|-p|-z|-E] -d DL -x vmlinux VMCORE DUMPFILE\n"); MSG("\n"); MSG(" Generating VMCOREINFO of Xen:\n"); MSG(" # makedumpfile -g VMCOREINFO --xen-syms XEN-SYMS\n"); MSG("\n"); MSG("\n"); MSG(" Creating DUMPFILE from multiple VMCOREs generated on sadump diskset configuration:\n"); - MSG(" # makedumpfile [-c|-l|-p] [-d DL] -x VMLINUX --diskset=VMCORE1 --diskset=VMCORE2\n"); + MSG(" # makedumpfile [-c|-l|-p|-z] [-d DL] -x VMLINUX --diskset=VMCORE1 --diskset=VMCORE2\n"); MSG(" [--diskset=VMCORE3 ..] DUMPFILE\n"); MSG("\n"); MSG("\n"); MSG("Available options:\n"); - MSG(" [-c|-l|-p]:\n"); + MSG(" [-c|-l|-p|-z]:\n"); MSG(" Compress dump data by each page using zlib for -c option, lzo for -l option\n"); - MSG(" or snappy for -p option. A user cannot specify either of these options with\n"); - MSG(" -E option, because the ELF format does not support compressed data.\n"); + MSG(" snappy for -p option or zstd for -z option. A user cannot specify either of\n"); + MSG(" these options with -E option, because the ELF format does not support\n"); + MSG(" compressed data.\n"); MSG(" THIS IS ONLY FOR THE CRASH UTILITY.\n"); MSG("\n"); MSG(" [-e]:\n"); @@ -144,6 +156,9 @@ MSG(" 16 | X\n"); MSG(" 31 | X X X X X\n"); MSG("\n"); + MSG(" [-L SIZE]:\n"); + MSG(" Limit the size of the output file to SIZE bytes.\n"); + MSG("\n"); MSG(" [-E]:\n"); MSG(" Create DUMPFILE in the ELF format.\n"); MSG(" This option cannot be specified with the -c, -l or -p options,\n"); @@ -365,21 +380,24 @@ } } -/* produce less than 12 bytes on msg */ -static int eta_to_human_short (unsigned long secs, char* msg) +static int eta_to_human_short (unsigned long secs, char *msg, size_t len) { - strcpy(msg, "eta: "); - msg += strlen("eta: "); + unsigned long minutes, hours, days; + + minutes = secs / 60; + hours = minutes / 60; + days = hours / 24; + if (secs < 100) - sprintf(msg, "%lus", secs); - else if (secs < 100 * 60) - sprintf(msg, "%lum%lus", secs / 60, secs % 60); - else if (secs < 48 * 3600) - sprintf(msg, "%luh%lum", secs / 3600, (secs / 60) % 60); - else if (secs < 100 * 86400) - sprintf(msg, "%lud%luh", secs / 86400, (secs / 3600) % 24); + snprintf(msg, len, "eta: %lus", secs); + else if (minutes < 100) + snprintf(msg, len, "eta: %lum%lus", minutes, secs % 60); + else if (hours < 48) + snprintf(msg, len, "eta: %luh%lum", hours, minutes % 60); + else if (days < 100) + snprintf(msg, len, "eta: %lud%luh", days, hours % 24); else - sprintf(msg, ">2day"); + snprintf(msg, len, "eta: >100day"); return 0; } @@ -394,7 +412,7 @@ static const char *spinner = "/|\\-"; struct timespec delta; unsigned long eta; - char eta_msg[16] = " "; + char eta_msg[32] = " "; if (current < end) { tm = time(NULL); @@ -409,7 +427,7 @@ calc_delta(start, &delta); eta = 1000 * delta.tv_sec + delta.tv_nsec / (NSEC_PER_SEC / 1000); eta = eta / progress - delta.tv_sec; - eta_to_human_short(eta, eta_msg); + eta_to_human_short(eta, eta_msg, sizeof(eta_msg)); } if (flag_ignore_r_char) { PROGRESS_MSG("%-" PROGRESS_MAXLEN "s: [%3u.%u %%] %c %16s\n", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/printk.c new/makedumpfile-1.7.0/printk.c --- old/makedumpfile-1.6.9/printk.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/printk.c 2021-11-08 01:36:15.000000000 +0100 @@ -53,7 +53,7 @@ return DESC_STATE(state_val); } -static void +static int dump_record(struct prb_map *m, unsigned long id) { unsigned long long ts_nsec; @@ -80,7 +80,7 @@ state_var = ULONG(desc + OFFSET(prb_desc.state_var) + OFFSET(atomic_long_t.counter)); state = get_desc_state(id, state_var); if (state != desc_committed && state != desc_finalized) - return; + return TRUE; begin = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.begin)) % m->text_data_ring_size; @@ -89,7 +89,7 @@ /* skip data-less text blocks */ if (begin == next) - return; + return TRUE; inf = m->infos + ((id % m->desc_ring_count) * SIZE(printk_info)); @@ -121,8 +121,10 @@ for (i = 0, p = text; i < text_len; i++, p++) { if (bufp - buf >= sizeof(buf) - buf_need) { - if (write(info->fd_dumpfile, buf, bufp - buf) < 0) - return; + if (!write_and_check_space(info->fd_dumpfile, buf, + bufp - buf, "log", + info->name_dumpfile)) + return FALSE; bufp = buf; } @@ -136,12 +138,14 @@ *bufp++ = '\n'; - write(info->fd_dumpfile, buf, bufp - buf); + return write_and_check_space(info->fd_dumpfile, buf, bufp - buf, + "log", info->name_dumpfile); } int dump_lockless_dmesg(void) { + unsigned long long clear_seq; unsigned long head_id; unsigned long tail_id; unsigned long kaddr; @@ -213,17 +217,38 @@ OFFSET(atomic_long_t.counter)); head_id = ULONG(m.desc_ring + OFFSET(prb_desc_ring.head_id) + OFFSET(atomic_long_t.counter)); + if (info->flag_partial_dmesg && SYMBOL(clear_seq) != NOT_FOUND_SYMBOL) { + if (!readmem(VADDR, SYMBOL(clear_seq), &clear_seq, + sizeof(clear_seq))) { + ERRMSG("Can't get clear_seq.\n"); + goto out_text_data; + } + if (SIZE(latched_seq) != NOT_FOUND_STRUCTURE) { + kaddr = SYMBOL(clear_seq) + OFFSET(latched_seq.val) + + (clear_seq & 0x1) * sizeof(clear_seq); + if (!readmem(VADDR, kaddr, &clear_seq, + sizeof(clear_seq))) { + ERRMSG("Can't get latched clear_seq.\n"); + goto out_text_data; + } + } + tail_id = head_id - head_id % m.desc_ring_count + + clear_seq % m.desc_ring_count; + } if (!open_dump_file()) { ERRMSG("Can't open output file.\n"); goto out_text_data; } - for (id = tail_id; id != head_id; id = (id + 1) & DESC_ID_MASK) - dump_record(&m, id); + for (id = tail_id; id != head_id; id = (id + 1) & DESC_ID_MASK) { + if (!dump_record(&m, id)) + goto out_text_data; + } /* dump head record */ - dump_record(&m, id); + if (!dump_record(&m, id)) + goto out_text_data; if (!close_files_for_creating_dumpfile()) goto out_text_data; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/sadump_info.c new/makedumpfile-1.7.0/sadump_info.c --- old/makedumpfile-1.6.9/sadump_info.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/sadump_info.c 2021-11-08 01:36:15.000000000 +0100 @@ -1059,46 +1059,6 @@ } /* - * Parse a string of [size[KMG]@]offset[KMG] - * Import from Linux kernel(lib/cmdline.c) - */ -static ulong memparse(char *ptr, char **retptr) -{ - char *endptr; - - unsigned long long ret = strtoull(ptr, &endptr, 0); - - switch (*endptr) { - case 'E': - case 'e': - ret <<= 10; - case 'P': - case 'p': - ret <<= 10; - case 'T': - case 't': - ret <<= 10; - case 'G': - case 'g': - ret <<= 10; - case 'M': - case 'm': - ret <<= 10; - case 'K': - case 'k': - ret <<= 10; - endptr++; - default: - break; - } - - if (retptr) - *retptr = endptr; - - return ret; -} - -/* * Find "elfcorehdr=" in the boot parameter of kernel and return the address * of elfcorehdr. */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/makedumpfile-1.6.9/tools.c new/makedumpfile-1.7.0/tools.c --- old/makedumpfile-1.6.9/tools.c 2021-05-12 07:43:37.000000000 +0200 +++ new/makedumpfile-1.7.0/tools.c 2021-11-08 01:36:15.000000000 +0100 @@ -147,7 +147,6 @@ str[i] = NULLCHAR; /* keep falling... */ case NULLCHAR: - argv[j] = NULLCHAR; return(j); } } @@ -276,19 +275,27 @@ char * strip_beginning_whitespace(char *line) { - char buf[BUFSIZE]; + size_t len; char *p; - if (line == NULL || strlen(line) == 0) - return(line); + if (line == NULL) + return line; + + len = strlen(line); - strcpy(buf, line); - p = &buf[0]; - while (*p == ' ' || *p == '\t') + if (len == 0) + return line; + + p = line; + while (whitespace(*p)) { p++; - strcpy(line, p); + len--; + } + /* for memmove src and dest may overlap */ + memmove(line, p, len); + line[len + 1] = '\0'; - return(line); + return line; } /* @@ -458,37 +465,6 @@ } /* - * Append a two-character string to a number to make 1, 2, 3 and 4 into - * 1st, 2nd, 3rd, 4th, and so on... - */ -char * -ordinal(ulong val, char *buf) -{ - char *p1; - - sprintf(buf, "%ld", val); - p1 = &buf[strlen(buf)-1]; - - switch (*p1) - { - case '1': - strcat(buf, "st"); - break; - case '2': - strcat(buf, "nd"); - break; - case '3': - strcat(buf, "rd"); - break; - default: - strcat(buf, "th"); - break; - } - - return buf; -} - -/* * Determine whether a string contains only decimal characters. * If count is non-zero, limit the search to count characters. */ @@ -764,3 +740,43 @@ return only; } + +/* + * Parse a string of [size[KMG]@]offset[KMG] + * Import from Linux kernel(lib/cmdline.c) + */ +unsigned long long memparse(char *ptr, char **retptr) +{ + char *endptr; + + unsigned long long ret = strtoull(ptr, &endptr, 0); + + switch (*endptr) { + case 'E': + case 'e': + ret <<= 10; + case 'P': + case 'p': + ret <<= 10; + case 'T': + case 't': + ret <<= 10; + case 'G': + case 'g': + ret <<= 10; + case 'M': + case 'm': + ret <<= 10; + case 'K': + case 'k': + ret <<= 10; + endptr++; + default: + break; + } + + if (retptr) + *retptr = endptr; + + return ret; +} ++++++ makedumpfile-override-libtinfo.patch ++++++ --- /var/tmp/diff_new_pack.hnrWTd/_old 2021-11-20 22:48:19.195804632 +0100 +++ /var/tmp/diff_new_pack.hnrWTd/_new 2021-11-20 22:48:19.195804632 +0100 @@ -13,7 +13,7 @@ --- a/Makefile +++ b/Makefile @@ -66,6 +66,8 @@ LIBS := -lsnappy $(LIBS) - CFLAGS += -DUSESNAPPY + #CFLAGS += -fanalyzer endif +TINFOLIB = -ltinfo
