From de725212b14c31caf8d4a1929b3e14f46052b4f5 Mon Sep 17 00:00:00 2001 From: "Gromadzki, Tomasz" Date: Wed, 5 Apr 2023 08:51:56 +0200 Subject: [PATCH 001/182] common: use sudo for ipmctl command ipmctl requires root priviledge for execution. Signed-off-by: Gromadzki, Tomasz --- utils/gha-runners/get-system-info.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/gha-runners/get-system-info.sh b/utils/gha-runners/get-system-info.sh index ad061d1ce08..f7d412d63b8 100755 --- a/utils/gha-runners/get-system-info.sh +++ b/utils/gha-runners/get-system-info.sh @@ -13,8 +13,8 @@ function system_info { echo "libndctl: $(pkg-config --modversion libndctl || echo 'libndctl not found')" echo "valgrind: $(pkg-config --modversion valgrind || echo 'valgrind not found')" echo "******************** memory-info *******************" - ipmctl show -dimm || true - ipmctl show -topology || true + sudo ipmctl show -dimm || true + sudo ipmctl show -topology || true echo "*************** list-existing-namespaces ***************" ndctl list -M -N echo "*************** installed-packages ***************" @@ -45,6 +45,7 @@ function system_info { echo "**********list-avaialble-pmem-devices**********" ls -la /dev/dax* ls -la /dev/pmem* + ls -la /mnt/pmem* echo "**********list-nd-resources**********" ls -la /sys/bus/nd/devices/ndbus*/region*/resource ls -la /sys/bus/nd/devices/ndbus*/region*/dax*/resource From c9fead322cfa173c96cc6688370d5078a2467467 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 30 Nov 2023 08:47:46 -0500 Subject: [PATCH 002/182] common: ... and libdaxctl... Signed-off-by: Jan Michalski --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index ec94c2b8cf2..0937555c09b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -20,7 +20,7 @@ You will need to install the following required packages on the build system: The following packages are required only by selected PMDK components or features: -PMDK depends on libndctl to support RAS features. It is possible +PMDK depends on libndctl and libdaxctl to support RAS features. It is possible to disable this support by passing `NDCTL_ENABLE=n` to `make`, but we strongly discourage users from doing that. Disabling NDCTL strips PMDK from ability to detect hardware failures, which may lead to silent data corruption. From c54cdf6ac92cc725ec64785975adf3033fb6479a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 6 Dec 2023 15:24:17 +0100 Subject: [PATCH 003/182] common: remove duplicated functions names Signed-off-by: Tomasz Gromadzki --- src/libpmem2/x86_64/init.c | 8 ++++---- utils/call_stacks_analysis/make_extra.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index bc21183301c..90f5ab2a9a9 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -64,7 +64,7 @@ flush_clwb(const void *addr, size_t len) #define PMEM2_F_MEM_MOV (PMEM2_F_MEM_WB | PMEM2_F_MEM_TEMPORAL) static void * -pmem_memmove_nodrain(void *dest, const void *src, size_t len, unsigned flags, +pmem2_memmove_nodrain(void *dest, const void *src, size_t len, unsigned flags, flush_func flushf, const struct memmove_nodrain *memmove_funcs) { /* suppress unused-parameter errors */ @@ -88,7 +88,7 @@ pmem_memmove_nodrain(void *dest, const void *src, size_t len, unsigned flags, } static void * -pmem_memmove_nodrain_eadr(void *dest, const void *src, size_t len, +pmem2_memmove_nodrain_eadr(void *dest, const void *src, size_t len, unsigned flags, flush_func flushf, const struct memmove_nodrain *memmove_funcs) { @@ -155,8 +155,8 @@ pmem_memset_nodrain_eadr(void *dest, int c, size_t len, unsigned flags, static void pmem_set_mem_funcs(struct pmem2_arch_info *info) { - info->memmove_nodrain = pmem_memmove_nodrain; - info->memmove_nodrain_eadr = pmem_memmove_nodrain_eadr; + info->memmove_nodrain = pmem2_memmove_nodrain; + info->memmove_nodrain_eadr = pmem2_memmove_nodrain_eadr; info->memset_nodrain = pmem_memset_nodrain; info->memset_nodrain_eadr = pmem_memset_nodrain_eadr; } diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index ade4d321961..cc22367a24c 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -51,7 +51,7 @@ def pmem_function_pointers(calls: Calls) -> Calls: calls['pmem_flush'] = flush_all # '.static' suffix added to differentiate between libpmem API function and a static helper. - memmove_nodrain_all = ['memmove_nodrain_libc', 'memmove_nodrain_generic', 'pmem_memmove_nodrain.static', 'pmem_memmove_nodrain_eadr.static'] + memmove_nodrain_all = ['memmove_nodrain_libc', 'memmove_nodrain_generic', 'pmem2_memmove_nodrain', 'pmem2_memmove_nodrain_eadr'] calls['pmem_memmove'] = memmove_nodrain_all calls['pmem_memcpy'] = memmove_nodrain_all calls['pmem_memmove_nodrain'] = memmove_nodrain_all @@ -103,12 +103,12 @@ def pmem_function_pointers(calls: Calls) -> Calls: memmove_funcs['nt']['empty'].extend(memmove_funcs_extras['nt']['empty']) memmove_funcs['nt']['flush'].extend(memmove_funcs_extras['nt']['flush']) - calls['pmem_memmove_nodrain.static'] = \ + calls['pmem2_memmove_nodrain'] = \ memmove_funcs['t']['noflush'] + \ memmove_funcs['nt']['flush'] + \ memmove_funcs['t']['flush'] - calls['pmem_memmove_nodrain_eadr.static'] = \ + calls['pmem2_memmove_nodrain_eadr'] = \ memmove_funcs['t']['noflush'] + \ memmove_funcs['nt']['empty'] + \ memmove_funcs['t']['empty'] From 2f59b6e0a9fcf8d86767d631c064fd77494fb896 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepanek <100217377+szczepax@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:55:27 +0100 Subject: [PATCH 004/182] common: Unify PMEM setup scripts --- utils/ansible/README.md | 59 +++++++------ utils/ansible/configure-pmem.yml | 86 ++++++++++++------- .../ansible/configure-self-hosted-runner.yml | 47 +++++----- utils/ansible/opensuse-setup.yml | 63 +++++++------- utils/ansible/rockylinux-setup.yml | 70 +++++++-------- 5 files changed, 175 insertions(+), 150 deletions(-) diff --git a/utils/ansible/README.md b/utils/ansible/README.md index 2da277aa391..28db8397a7e 100644 --- a/utils/ansible/README.md +++ b/utils/ansible/README.md @@ -56,10 +56,10 @@ Use the below command to configure persistent memory on Intel servers to be used for PMDK libraries tests execution. ```sh export TARGET_IP= # ip of the target -export ROOT_PASSWORD= # a password of root on the target +export USER_PASSWORD= # a password on the target ansible-playbook -i $TARGET_IP, configure-pmem.yml \ - --extra-vars "host=all ansible_user=root ansible_password=$ROOT_PASSWORD \ - newRegions=true testUser=pmdkuser" + --extra-vars "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD \ + newRegions=true" ``` The script creates a new region and set of namespaces regardless of the configuration already available on the target platform. @@ -81,10 +81,9 @@ the test environment. parameter in this case. ```sh export TARGET_IP= # ip of the target -export ROOT_PASSWORD= # a password of root on the target +export USER_PASSWORD= # a password on the target ansible-playbook -i $TARGET_IP, configure-pmem.yml \ - --extra-vars "host=all ansible_user=root ansible_password=$ROOT_PASSWORD \ - testUser=pmdkuser" + --extra-vars "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD" ``` # Installing a GitHub Action self-hosted runner using Ansible palybook @@ -94,16 +93,16 @@ the pmem/pmdk repository. ```sh export TARGET_IP= # ip of the target -export ROOT_PASSWORD= # a password of root on the target +export USER_PASSWORD= # a password on the target export GHA_TOKEN= # GitHub token generated for a new self-hosted runner export HOST_NAME= # host's name that will be visible on GitHub export LABELS= # rhel or opensuse export VARS_GHA= # e.g. proxy settings: http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars - "host=all ansible_user=root ansible_password=$ROOT_PASSWORD testUser=pmdkuser \ + "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD \ runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" ``` -**Note**: To obtain a token for a new self hosted runer visit +**Note**: To obtain a token for a new self-hosted runer visit [Create self-hosted runner](https://gib.com/pmem/pmdk/settings/actions/runners/new) . @@ -127,15 +126,15 @@ export SETUP_SCRIPT= # opensuse-setup.yml or rockylinux-setup.yml sudo ansible-playbook $SETUP_SCRIPT --extra-vars "testUser=pmdkuser" ``` **Note**: If a reboot is necessary, as described above, perform it manually and -rerun the playbook withot in question. +rerun the playbook without in question. -And next: +And next log in as `pmdkuser`: ```sh -sudo ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser newRegions=true" +ansible-playbook configure-pmem.yml --extra-vars "newRegions=true" # you will have to perform a reboot manually -reboot +sudo reboot # and re-run the playbook without newRegions=true to finalize the setup -sudo ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser" +ansible-playbook configure-pmem.yml ``` # Example - GitHub self-hosted runner setup @@ -163,19 +162,24 @@ reboot # ... cd pmdk/utils/ansible ansible-playbook rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass" +``` +Log in as `pmdkuser` and execute: +```sh +# as pmdkuser +cd pmdk/utils/ansible ansible-playbook configure-pmem.yml --extra-vars "newRegions=true" -reboot +sudo reboot # ... cd pmdk/utils/ansible # note - no newRegions=true when running the playbook after the reboot -ansible-playbook configure-pmem.yml --extra-vars "testUser=pmdkuser" +ansible-playbook configure-pmem.yml export GHA_TOKEN= # GitHub token generated for a new self-hosted runner export HOST_NAME=`hostname` -export LABELS= rhel +export LABELS=rhel export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 ansible-playbook configure-self-hosted-runner.yml -extra-vars \ -"testUser=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" +"runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" cd rm -rf pmdk ``` @@ -192,25 +196,30 @@ Update playbooks to be used directly on the target as described [above](#provisi and execute: ```sh # as root: -ansible-playbook ./opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass" +ansible-playbook opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass" # reboot shall be performed only if the playbook requests to do it. reboot # ... cd pmdk/utils/ansible -ansible-playbook ./opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass" -ansible-playbook ./configure-pmem.yml --extra-vars "newRegions=true" -reboot +ansible-playbook opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass" +``` +Log in as `pmdkuser` and execute: +```sh +# as pmdkuser: +cd pmdk/utils/ansible +ansible-playbook configure-pmem.yml --extra-vars "newRegions=true" +sudo reboot # ... cd pmdk/utils/ansible # note - no newRegions=true when running the playbook after the reboot -ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser" +ansible-playbook configure-pmem.yml export GHA_TOKEN= # GitHub token generated for a new self-hosted runner export HOST_NAME=`hostname` -export LABELS= opensuse +export LABELS=opensuse export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 ansible-playbook configure-self-hosted-runner.yml -extra-vars \ -"testUser=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" +"runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" cd rm -rf pmdk ``` diff --git a/utils/ansible/configure-pmem.yml b/utils/ansible/configure-pmem.yml index 6390487ec20..4d78003132a 100644 --- a/utils/ansible/configure-pmem.yml +++ b/utils/ansible/configure-pmem.yml @@ -16,11 +16,26 @@ # # Below are examples of how to use this file: # -# 1) setup PMem for the first time (establish regions): -# sudo ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser newRegions='true'" +# 1) remotely +# export TARGET_IP= # ip of the target +# export USER_PASSWORD= # a password on the target +# a) setup PMem for the first time (establish regions): +# ansible-playbook -i $TARGET_IP, configure-pmem.yml --extra-vars \ +# "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD newRegions=true" +# b) setup PMem if it already has been initialized before: +# ansible-playbook -i $TARGET_IP, configure-pmem.yml --extra-vars \ +# "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD" # -# 2) setup PMem if it already has been initialized before: -# sudo ansible-playbook ./configure-pmem.yml --extra-vars "testUser=pmdkuser" +# 2) locally +# For a playbook to be used on a local server please log in as pmdkuser: +# a) comment out the first command: # -hosts: "{{ host }}" +# b) uncomment the next two lines: +# - hosts: localhost +# connection: local +# c) setup PMem for the first time (establish regions): +# ansible-playbook configure-pmem.yml --extra-vars "newRegions=true" +# d) setup PMem if it already has been initialized before: +# ansible-playbook configure-pmem.yml # - hosts: "{{ host }}" @@ -28,45 +43,50 @@ # connection: local vars: newRegions: false - testUser: pmdkuser mountPoint: /mnt/pmem0 tasks: - - name: "Test if ndctl is installed" + - name: Test if ndctl is installed shell: which ndctl - - name: "Remove fstab entry if it exist" + - name: Remove fstab entry if it exist ansible.posix.mount: path: "{{ mountPoint }}" state: absent_from_fstab backup: true + become: true - - name: "Unmount namespaces if they exist" - shell: sudo umount /dev/pmem* || true + - name: Unmount namespaces if they exist + shell: umount /dev/pmem* || true + become: true - - name: "Disable current namespaces" - shell: sudo ndctl disable-namespace all || true + - name: Disable current namespaces + shell: ndctl disable-namespace all || true register: namespaces + become: true - - name: "Destroy current namespaces" - shell: sudo ndctl destroy-namespace all || true + - name: Destroy current namespaces + shell: ndctl destroy-namespace all || true register: namespaces + become: true - debug: var=namespaces - - name: "Create new regions" + - name: Create new regions block: - - name: "Test if ipmctl is installed" + - name: Test if ipmctl is installed shell: which ipmctl - - name: "Create goal in AppDirectInterleaved mode" + - name: Create goal in AppDirectInterleaved mode shell: ipmctl create -f -goal + become: true - - name: "Reboot machine in order to apply new AppDirectInterleaved goal" + - name: Reboot machine in order to apply new AppDirectInterleaved goal reboot: when: newRegions == 'true' + become: true - - name: "Create new namespace configuration" + - name: Create new namespace configuration shell: | #!/usr/bin/env bash DEV_DAX_R=0x0000 @@ -74,7 +94,7 @@ function check_alignment() { local size=$1 - local interleave_width=$(sudo ipmctl show -dimm -socket 1 | grep "0x1" | wc -l) + local interleave_width=$(ipmctl show -dimm -socket 1 | grep "0x1" | wc -l) local size_alignment=$(expr $size % $interleave_width) if [ "$size_alignment" -gt "0" ]; then @@ -93,7 +113,7 @@ size_option="" fi - local cmd="sudo ndctl create-namespace --mode devdax -a ${align} ${size_option} -r ${DEV_DAX_R} -f" + local cmd="ndctl create-namespace --mode devdax -a ${align} ${size_option} -r ${DEV_DAX_R} -f" result=$(${cmd}) if [ $? -ne 0 ]; then exit 1; @@ -101,7 +121,7 @@ } function create_fsdax() { - local cmd="sudo ndctl create-namespace --mode fsdax -r ${FS_DAX_R} -f" + local cmd="ndctl create-namespace --mode fsdax -r ${FS_DAX_R} -f" result=$(${cmd}) if [ $? -ne 0 ]; then exit 1; @@ -125,27 +145,28 @@ pmem_name=$(create_fsdax) if [ ! -d "{{ mountPoint }}" ]; then - sudo mkdir {{ mountPoint }} + mkdir {{ mountPoint }} fi - sudo mkfs.ext4 -F /dev/${pmem_name} - sudo mount -o dax=always /dev/${pmem_name} {{ mountPoint }} - sudo chown -R {{ testUser }} {{ mountPoint }} + mkfs.ext4 -F /dev/${pmem_name} + mount -o dax=always /dev/${pmem_name} {{ mountPoint }} + chown -R $(id -u {{ ansible_user }}):$(id -g {{ ansible_user }}) {{ mountPoint }} - sudo chmod 777 /dev/dax* || true - sudo chmod a+rw /sys/bus/nd/devices/region*/deep_flush - sudo chmod +r /sys/bus/nd/devices/ndbus*/region*/resource - sudo chmod +r /sys/bus/nd/devices/ndbus*/region*/dax*/resource + chmod 777 /dev/dax* + chmod +rw /sys/bus/nd/devices/region*/deep_flush + chmod +r /sys/bus/nd/devices/ndbus*/region*/resource + chmod +r /sys/bus/nd/devices/ndbus*/region*/dax*/resource register: script + become: true - debug: var=script - - name: "Get PMEM device name for {{ mountPoint }} mount point" + - name: Get PMEM device name for {{ mountPoint }} mount point shell: | - mount | sed -nr "s/^.*(\/dev\/\S+) on \/mnt\/pmem0.*$/\1/p" + mount | sed -nr 's/^.*(\/dev\/\S+) on \/mnt\/pmem0.*$/\1/p' register: pmem_name - - name: "Add /etc/fstab entry for PMEM" + - name: Add /etc/fstab entry for PMEM ansible.posix.mount: path: "{{ mountPoint }}" src: "{{ pmem_name.stdout }}" @@ -153,3 +174,4 @@ opts: rw,relatime,dax=always state: present backup: true + become: true diff --git a/utils/ansible/configure-self-hosted-runner.yml b/utils/ansible/configure-self-hosted-runner.yml index b2b8f28b1a8..1b2c6020d2f 100644 --- a/utils/ansible/configure-self-hosted-runner.yml +++ b/utils/ansible/configure-self-hosted-runner.yml @@ -5,17 +5,17 @@ # Examples below show how to use this file: # 1) remotely # export TARGET_IP= # ip of the target -# export ROOT_PASSWORD= # a password of root on the target +# export USER_PASSWORD= # a password on the target # export GHA_TOKEN= # a GitHub token generated for a new self-hosted runner # export HOST_NAME= # host's name that will be visible on GitHub # export LABELS= # rhel or opensuse # export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912 # ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars \ -# "host=all ansible_user=root ansible_password=$ROOT_PASSWORD testUser=pmdkuser \ +# "host=all ansible_user=pmdkuser ansible_password=$USER_PASSWORD \ # runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA" # # 2) locally -# For a playbook to be used on a local server please: +# For a playbook to be used on a local server please log in as pmdkuser: # a) comment out the first command: # -hosts: "{{ host }}" # b) uncomment the next two lines: # - hosts: localhost @@ -36,9 +36,8 @@ #- hosts: localhost # connection: local vars: - testUser: pmdkuser - package_url: https://github.com/actions/runner/releases/download/v2.306.0/actions-runner-linux-x64-2.306.0.tar.gz - runner_folder: /home/{{ testUser }}/actions-runner + package_url: https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-linux-x64-2.311.0.tar.gz + runner_folder: /home/{{ ansible_user }}/actions-runner repo_url: https://github.com/pmem/pmdk vars_list: "{{ vars_gha.split(',') }}" # token: # a GitHub token generated for a new self-hosted runner @@ -46,24 +45,21 @@ # runner_name: # Host name that will be visible on GitHub tasks: - - name: "Create a runner folder" + - name: Create a runner folder file: - path: '{{ runner_folder }}' + path: "{{ runner_folder }}" state: directory force: yes - - name: "Download and extract the installer" + - name: Download and extract the installer unarchive: - src: '{{ package_url }}' - dest: '{{ runner_folder }}' + src: "{{ package_url }}" + dest: "{{ runner_folder }}" remote_src: yes - - name: "Change owner to {{ testUser }}" - shell: chown -R $(id -u {{ testUser }}):$(id -g {{ testUser }}) {{ runner_folder }} - # Make sure the following environment variables are present in the env # to ensure propagation to the actions-runner's environment. - - name: "Add env variables into env.sh checklist" + - name: Add env variables into env.sh checklist lineinfile: path: "{{ runner_folder }}/env.sh" line: " '{{ item.line }}'" @@ -72,30 +68,29 @@ - line: PKG_CONFIG_PATH - line: HOME - - name: "Add runner to GHA" + - name: Add runner to GHA shell: | cd {{ runner_folder }} ./config.sh --url {{ repo_url }} --token {{ token }} --name {{ runner_name }} --labels {{ labels }} --runnergroup Default --work _work - become: yes - become_user: '{{ testUser }}' - - name: "Install runner service" - shell: | - cd {{ runner_folder }} - ./svc.sh install {{ testUser }} + - name: Install runner service + shell: ./svc.sh install {{ ansible_user }} + args: + chdir: "{{ runner_folder }}" become: true - become_user: root - - name: "Insert variables into runsvc.sh file" + - name: Insert variables into runsvc.sh file lineinfile: path: "{{ runner_folder }}/runsvc.sh" line: "export {{ item }}" insertbefore: "insert anything to setup env when running as a service" loop: "{{ vars_list }}" - - name: "Enable and restart runner service" + - name: Enable and restart runner service + # Note: The service name must match the repo_url. + # repo_url: https://github.com/{OWNER}/{REPO} + # service: actions.runner.{OWNER}-{REPO}.{{ runner_name }}.service shell: | systemctl enable actions.runner.pmem-pmdk.{{ runner_name }}.service systemctl restart actions.runner.pmem-pmdk.{{ runner_name }}.service become: true - become_user: root diff --git a/utils/ansible/opensuse-setup.yml b/utils/ansible/opensuse-setup.yml index b6dcd9a1b47..e6a2bb2dbbd 100644 --- a/utils/ansible/opensuse-setup.yml +++ b/utils/ansible/opensuse-setup.yml @@ -14,41 +14,40 @@ testUserPass: pmdkpass tasks: - - - name: "Update kernel packages" + - name: Update kernel packages package: name: "kernel-default" state: latest register: isUpdated - - name: "Update OS packages" + - name: Update OS packages package: name: "*" state: latest - - name: "Reboot platform to apply updates" + - name: Reboot platform to apply updates reboot: when: isUpdated.changed - - name: "Add permanent pkg config variable to the system" + - name: Add permanent pkg config variable to the system env: state: present name: PKG_CONFIG_PATH value: /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig - - name: "Add permanent ld library path to the system" + - name: Add permanent ld library path to the system env: state: present name: LD_LIBRARY_PATH value: /usr/lib64:/usr/lib - - name: "Add openSUSE Leap 15.4 Oss repo" + - name: Add openSUSE Leap 15.4 Oss repo zypper_repository: name: oss - repo: 'http://download.opensuse.org/distribution/leap/15.4/repo/oss' + repo: "http://download.opensuse.org/distribution/leap/15.4/repo/oss" state: present - - name: "Install Valgrind dependencies" + - name: Install Valgrind dependencies package: state: present name: @@ -58,7 +57,7 @@ - findutils - git - - name: "Install PMDK base dependencies" + - name: Install PMDK base dependencies package: state: present name: @@ -70,13 +69,13 @@ - systemd - libndctl-devel - - name: "Install benchmarks dependencies (optional)" + - name: Install benchmarks dependencies (optional) package: state: present name: - glib2-devel - - name: "Install examples dependencies (optional)" + - name: Install examples dependencies (optional) package: state: present name: @@ -85,13 +84,13 @@ - ncurses-devel - libuv-devel - - name: "Install documentation dependencies (optional)" + - name: Install documentation dependencies (optional) package: state: present name: - pandoc - - name: "Install tests dependencies" + - name: Install tests dependencies package: state: present name: @@ -100,14 +99,14 @@ - libunwind-devel - strace - - name: "Install packaging dependencies" + - name: Install packaging dependencies package: state: present name: - rpm-build - rpmdevtools - - name: "Install miscellaneous dependencies" + - name: Install miscellaneous dependencies package: state: present name: @@ -123,7 +122,7 @@ - xmlto - jq - - name: "Install ndctl dependencies" + - name: Install ndctl dependencies package: state: present name: @@ -136,13 +135,13 @@ - libuuid-devel - systemd-devel - - name: "Install ipmctl" + - name: Install ipmctl package: state: present name: - ipmctl - - name: "Install valgrind from source" + - name: Install valgrind from source script: ../docker/images/install-valgrind.sh # Disable AppArmor. @@ -157,7 +156,7 @@ ignore_errors: yes when: ansible_facts['os_family'] == 'Suse' - - name: "Add new user" + - name: Add new user shell: | #!/usr/bin/env bash export USER={{ testUser }} @@ -173,26 +172,26 @@ gpasswd wheel -a $USER when: testUser != None - - name: "Set variable OS" + - name: Set variable OS env: state: present - name: 'OS' - value: 'opensuse/leap' + name: "OS" + value: "opensuse/leap" - - name: "Set variable OS_VER" + - name: Set variable OS_VER env: state: present - name: 'OS_VER' - value: '15' + name: "OS_VER" + value: "15" - - name: "Set variable PACKAGE_MANAGER" + - name: Set variable PACKAGE_MANAGER env: state: present - name: 'PACKAGE_MANAGER' - value: 'rpm' + name: "PACKAGE_MANAGER" + value: "rpm" - - name: "Set variable NOTTY" + - name: Set variable NOTTY env: state: present - name: 'NOTTY' - value: '1' + name: "NOTTY" + value: "1" diff --git a/utils/ansible/rockylinux-setup.yml b/utils/ansible/rockylinux-setup.yml index a5c0771e15c..50ef95c2b54 100644 --- a/utils/ansible/rockylinux-setup.yml +++ b/utils/ansible/rockylinux-setup.yml @@ -14,22 +14,22 @@ testUserPass: pmdkpass tasks: - - name: "Update kernel packages" + - name: Update kernel packages package: name: "kernel.x86_64" state: latest register: isUpdated - - name: "Update OS packages" + - name: Update OS packages package: name: "*" state: latest - - name: "Reboot platform to apply updates" + - name: Reboot platform to apply updates reboot: when: isUpdated.changed - - name: "Add permanent pkg config variable to the system" + - name: Add permanent pkg config variable to the system env: state: present name: PKG_CONFIG_PATH @@ -37,20 +37,20 @@ # For `ansible_distribution_*` variables see: # https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html#commonly-used-facts - - name: "Rocky - adding additional repositories" + - name: Rocky - adding additional repositories block: - - name: "Rocky - adding epel repository" + - name: Rocky - adding epel repository shell: yum install epel-release -y - - name: "Rocky 9 - enabling Power Tools" + - name: Rocky 9 - enabling Power Tools shell: dnf config-manager --enable crb when: ansible_distribution_major_version == "9" - - name: "Rocky 8 - enabling Power Tools" + - name: Rocky 8 - enabling Power Tools shell: dnf config-manager --enable powertools when: ansible_distribution_major_version == "8" - - name: "Install Valgrind dependencies" + - name: Install Valgrind dependencies package: state: present name: @@ -60,7 +60,7 @@ - findutils - git - - name: "Install PMDK base dependencies" + - name: Install PMDK base dependencies package: state: present name: @@ -71,13 +71,13 @@ - passwd - pkgconfig - - name: "Install benchmarks dependencies (optional)" + - name: Install benchmarks dependencies (optional) package: state: present name: - glib2-devel - - name: "Install examples dependencies (optional)" + - name: Install examples dependencies (optional) package: state: present name: @@ -86,13 +86,13 @@ - ncurses-devel - libuv-devel - - name: "Install documentation dependencies (optional)" + - name: Install documentation dependencies (optional) package: state: present name: - pandoc - - name: "Install tests dependencies" + - name: Install tests dependencies package: state: present name: @@ -103,7 +103,7 @@ - openssh-server - strace - - name: "Install packaging dependencies" + - name: Install packaging dependencies package: state: present name: @@ -111,7 +111,7 @@ - rpm-build-libs - rpmdevtools - - name: "Install miscellaneous dependencies" + - name: Install miscellaneous dependencies package: state: present name: @@ -128,13 +128,13 @@ - xmlto - jq - - name: "Install ipmctl" + - name: Install ipmctl package: state: present name: - ipmctl - - name: "Install valgrind from source" + - name: Install valgrind from source script: ../docker/images/install-valgrind.sh # Disable SELinux. @@ -145,9 +145,9 @@ selinux: state: disabled ignore_errors: yes - when: ansible_facts['os_family'] != 'Debian' + when: ansible_facts["os_family"] != "Debian" - - name: "Add new user" + - name: Add new user shell: | #!/usr/bin/env bash export USER={{ testUser }} @@ -158,34 +158,34 @@ echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers when: testUser != none - - name: "Set variable OS" + - name: Set variable OS env: state: present - name: 'OS' - value: 'rockylinux/rockylinux' + name: "OS" + value: "rockylinux/rockylinux" - - name: "Set variable OS_VER (9)" + - name: Set variable OS_VER (9) env: state: present - name: 'OS_VER' - value: '9' + name: "OS_VER" + value: "9" when: ansible_distribution_major_version == "9" - - name: "Set variable OS_VER (8)" + - name: Set variable OS_VER (8) env: state: present - name: 'OS_VER' - value: '8' + name: "OS_VER" + value: "8" when: ansible_distribution_major_version == "8" - - name: "Set variable PACKAGE_MANAGER" + - name: Set variable PACKAGE_MANAGER env: state: present - name: 'PACKAGE_MANAGER' - value: 'rpm' + name: "PACKAGE_MANAGER" + value: "rpm" - - name: "Set variable NOTTY" + - name: Set variable NOTTY env: state: present - name: 'NOTTY' - value: '1' + name: "NOTTY" + value: "1" From 4f4e402d19ecdabb4fbf658f4985490410ee6494 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 17 Jan 2024 11:15:21 +0100 Subject: [PATCH 005/182] common: remove obsolete custom print function Remove possibility to use a custom function for all logging messages. Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 56 ++------- src/core/out.h | 6 +- src/test/Makefile | 4 +- src/test/traces_custom_function/.gitignore | 1 - src/test/traces_custom_function/Makefile | 15 --- src/test/traces_custom_function/TEST0 | 24 ---- src/test/traces_custom_function/TEST1 | 24 ---- .../traces_custom_function/out0.log.match | 35 ------ .../traces_custom_function/out1.log.match | 37 ------ .../traces_custom_function.c | 106 ------------------ src/test/traces_pmem/.gitignore | 1 - src/test/traces_pmem/Makefile | 13 --- src/test/traces_pmem/TEST0 | 33 ------ .../traces_pmem/trace_pmem_head0.log.match | 3 - .../traces_pmem/trace_pmemobj_head0.log.match | 3 - src/test/traces_pmem/traces_pmem.c | 21 ---- utils/call_stacks_analysis/make_extra.py | 3 +- utils/call_stacks_analysis/white_list.json | 2 - 18 files changed, 15 insertions(+), 372 deletions(-) delete mode 100644 src/test/traces_custom_function/.gitignore delete mode 100644 src/test/traces_custom_function/Makefile delete mode 100755 src/test/traces_custom_function/TEST0 delete mode 100755 src/test/traces_custom_function/TEST1 delete mode 100644 src/test/traces_custom_function/out0.log.match delete mode 100644 src/test/traces_custom_function/out1.log.match delete mode 100644 src/test/traces_custom_function/traces_custom_function.c delete mode 100644 src/test/traces_pmem/.gitignore delete mode 100644 src/test/traces_pmem/Makefile delete mode 100755 src/test/traces_pmem/TEST0 delete mode 100644 src/test/traces_pmem/trace_pmem_head0.log.match delete mode 100644 src/test/traces_pmem/trace_pmemobj_head0.log.match delete mode 100644 src/test/traces_pmem/traces_pmem.c diff --git a/src/core/out.c b/src/core/out.c index a7f5f6eb340..a836565cd9a 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * out.c -- support for logging, tracing, and assertion output @@ -260,7 +260,7 @@ out_fini(void) } /* - * out_print_func -- default print_func, goes to stderr or Out_fp + * out_print_func -- print function, goes to Out_fp (stderr by default) */ static void out_print_func(const char *s) @@ -278,38 +278,6 @@ out_print_func(const char *s) #endif } -/* - * calling Print(s) calls the current print_func... - */ -typedef void (*Print_func)(const char *s); -typedef int (*Vsnprintf_func)(char *str, size_t size, const char *format, - va_list ap); -static Print_func Print = out_print_func; -static Vsnprintf_func Vsnprintf = vsnprintf; - -/* - * out_set_print_func -- allow override of print_func used by out module - */ -void -out_set_print_func(void (*print_func)(const char *s)) -{ - LOG(3, "print %p", print_func); - - Print = (print_func == NULL) ? out_print_func : print_func; -} - -/* - * out_set_vsnprintf_func -- allow override of vsnprintf_func used by out module - */ -void -out_set_vsnprintf_func(int (*vsnprintf_func)(char *str, size_t size, - const char *format, va_list ap)) -{ - LOG(3, "vsnprintf %p", vsnprintf_func); - - Vsnprintf = (vsnprintf_func == NULL) ? vsnprintf : vsnprintf_func; -} - /* * out_snprintf -- (internal) custom snprintf implementation */ @@ -321,7 +289,7 @@ out_snprintf(char *str, size_t size, const char *format, ...) va_list ap; va_start(ap, format); - ret = Vsnprintf(str, size, format, ap); + ret = vsnprintf(str, size, format, ap); va_end(ap); return (ret); @@ -351,7 +319,7 @@ out_common(const char *file, int line, const char *func, int level, "<%s>: <%d> [%s:%d %s] ", Log_prefix, level, file, line, func); if (ret < 0) { - Print("out_snprintf failed"); + out_print_func("out_snprintf failed"); goto end; } cc += (unsigned)ret; @@ -375,9 +343,9 @@ out_common(const char *file, int line, const char *func, int level, } } - ret = Vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap); + ret = vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap); if (ret < 0) { - Print("Vsnprintf failed"); + out_print_func("vsnprintf failed"); goto end; } cc += (unsigned)ret; @@ -385,7 +353,7 @@ out_common(const char *file, int line, const char *func, int level, out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s%s", sep, errstr, suffix); - Print(buf); + out_print_func(buf); end: errno = oerrno; @@ -408,7 +376,7 @@ out_error(const char *file, int line, const char *func, char *errormsg = (char *)out_get_errormsg(); if (errormsg == NULL) { - Print("There's no memory to properly format error strings."); + out_print_func("No memory to properly format error strings."); return; } @@ -426,9 +394,9 @@ out_error(const char *file, int line, const char *func, } } - ret = Vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap); + ret = vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap); if (ret < 0) { - strcpy(errormsg, "Vsnprintf failed"); + strcpy(errormsg, "vsnprintf failed"); goto end; } cc += (unsigned)ret; @@ -449,7 +417,7 @@ out_error(const char *file, int line, const char *func, "<%s>: <1> [%s:%d %s] ", Log_prefix, file, line, func); if (ret < 0) { - Print("out_snprintf failed"); + out_print_func("out_snprintf failed"); goto end; } cc += (unsigned)ret; @@ -462,7 +430,7 @@ out_error(const char *file, int line, const char *func, out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", errormsg, suffix); - Print(buf); + out_print_func(buf); } #else /* suppress unused-parameter errors */ diff --git a/src/core/out.h b/src/core/out.h index d44c9ca06a6..e7feb48a67c 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * out.h -- definitions for "out" module @@ -198,10 +198,6 @@ void out_err(const char *file, int line, const char *func, const char *fmt, ...) FORMAT_PRINTF(4, 5); void NORETURN out_fatal(const char *file, int line, const char *func, const char *fmt, ...) FORMAT_PRINTF(4, 5); -void out_set_print_func(void (*print_func)(const char *s)); -void out_set_vsnprintf_func(int (*vsnprintf_func)(char *str, size_t size, - const char *format, va_list ap)); - const char *out_get_errormsg(void); #ifdef __cplusplus diff --git a/src/test/Makefile b/src/test/Makefile index 761cfa73f1f..e4c0a8e9302 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # @@ -120,8 +120,6 @@ OTHER_TESTS = \ scope\ set_funcs\ traces\ - traces_custom_function\ - traces_pmem\ unicode_match_script\ util_badblock\ util_ctl\ diff --git a/src/test/traces_custom_function/.gitignore b/src/test/traces_custom_function/.gitignore deleted file mode 100644 index 47a458e4892..00000000000 --- a/src/test/traces_custom_function/.gitignore +++ /dev/null @@ -1 +0,0 @@ -traces_custom_function diff --git a/src/test/traces_custom_function/Makefile b/src/test/traces_custom_function/Makefile deleted file mode 100644 index e84a1d46a99..00000000000 --- a/src/test/traces_custom_function/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2016, Intel Corporation - -# -# src/test/traces_custom_function/Makefile -- build traces unit test -# -TARGET = traces_custom_function -OBJS = traces_custom_function.o - -BUILD_STATIC_DEBUG=n -BUILD_STATIC_NONDEBUG=n - -LIBPMEMCOMMON=y -include ../Makefile.inc -CFLAGS += -DDEBUG diff --git a/src/test/traces_custom_function/TEST0 b/src/test/traces_custom_function/TEST0 deleted file mode 100755 index 8c3d74c5c5f..00000000000 --- a/src/test/traces_custom_function/TEST0 +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2019, Intel Corporation - -# -# src/test/traces_custom_function/TEST0 -- unit test for traces custom -# print function -# - -. ../unittest/unittest.sh - -require_test_type medium - -require_fs_type none -require_build_type debug - -setup - -export TRACE_LOG_LEVEL=4 -expect_normal_exit ./traces_custom_function$EXESUFFIX p - -check - -pass diff --git a/src/test/traces_custom_function/TEST1 b/src/test/traces_custom_function/TEST1 deleted file mode 100755 index b3cdc35ca48..00000000000 --- a/src/test/traces_custom_function/TEST1 +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2019, Intel Corporation - -# -# src/test/traces_custom_function/TEST1 -- unit test for traces custom -# vsnprintf function -# - -. ../unittest/unittest.sh - -require_test_type medium - -require_fs_type none -require_build_type debug - -setup - -export TRACE_LOG_LEVEL=4 -expect_normal_exit ./traces_custom_function$EXESUFFIX v - -check - -pass diff --git a/src/test/traces_custom_function/out0.log.match b/src/test/traces_custom_function/out0.log.match deleted file mode 100644 index dbac0022d18..00000000000 --- a/src/test/traces_custom_function/out0.log.match +++ /dev/null @@ -1,35 +0,0 @@ -traces_custom_function$(nW)TEST0: START: traces_custom_function - $(nW)traces_custom_function$(nW) p -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)pid $(N): program: $(nW) - -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)trace_func version $(S) - -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)src version: $(nW) - -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind pmemcheck -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind helgrind -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind memcheck -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind drd -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for shutdown state -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with libndctl 63+ -$(OPT) -CUSTOM_PRINT: : <3> [$(nW):$(N) util_mmap_init]$(W) - -CUSTOM_PRINT: : <0> [$(nW):$(N) main]$(W)Log level NONE - -CUSTOM_PRINT: : <1> [$(nW):$(N) main]$(W)Log level ERROR - -CUSTOM_PRINT: : <2> [$(nW):$(N) main]$(W)Log level WARNING - -CUSTOM_PRINT: : <3> [$(nW):$(N) main]$(W)Log level INFO - -CUSTOM_PRINT: : <4> [$(nW):$(N) main]$(W)Log level DEBUG - -CUSTOM_PRINT: : <3> [$(nW):$(N) util_mmap_fini]$(W) - -traces_custom_function$(nW)TEST0: DONE diff --git a/src/test/traces_custom_function/out1.log.match b/src/test/traces_custom_function/out1.log.match deleted file mode 100644 index 4c739a5c40c..00000000000 --- a/src/test/traces_custom_function/out1.log.match +++ /dev/null @@ -1,37 +0,0 @@ -traces_custom_function$(nW)TEST1: START: traces_custom_function - $(nW)traces_custom_function$(nW) v -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)pid $(N): program: $(nW) - -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)trace_func version $(S) - -CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)src version: $(nW) - -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind pmemcheck -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind helgrind -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind memcheck -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for Valgrind drd -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with support for shutdown state -$(OPT) -$(OPT)CUSTOM_PRINT: : <1> [$(nW):$(N) out_init]$(W)compiled with libndctl 63+ -$(OPT) -CUSTOM_PRINT: : <3> [$(nW):$(N) util_mmap_init]$(W) - -CUSTOM_PRINT: : <3> [$(nW):$(N) out_set_vsnprintf_func]$(W)vsnprintf $(nW)$(X) - -CUSTOM_PRINT: <@@trace_func>: <@@0> [@@$(nW):@@$(N) @@main]$(W)no format@@@@@@ - -CUSTOM_PRINT: <@@trace_func>: <@@0> [@@$(nW):@@$(N) @@main]$(W)pointer: @@$(nW)12345678@@@@@@ - -CUSTOM_PRINT: <@@trace_func>: <@@0> [@@$(nW):@@$(N) @@main]$(W)string: @@Hello world!@@@@@@ - -CUSTOM_PRINT: <@@trace_func>: <@@0> [@@$(nW):@@$(N) @@main]$(W)number: @@12345678@@@@@@ - -CUSTOM_PRINT: <@@trace_func>: <@@0> [@@$(nW):@@$(N) @@main]$(W)error@@: @@Invalid argument@@ - -CUSTOM_PRINT: <@@trace_func>: <@@3> [@@$(nW):@@$(N) @@util_mmap_fini] @@@@@@ - -traces_custom_function$(nW)TEST1: DONE diff --git a/src/test/traces_custom_function/traces_custom_function.c b/src/test/traces_custom_function/traces_custom_function.c deleted file mode 100644 index 19168a84811..00000000000 --- a/src/test/traces_custom_function/traces_custom_function.c +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2017, Intel Corporation */ - -/* - * traces_custom_function.c -- unit test for traces with custom print or - * vsnprintf functions - * - * usage: traces_custom_function [v|p] - * - */ - -#define LOG_PREFIX "trace_func" -#define LOG_LEVEL_VAR "TRACE_LOG_LEVEL" -#define LOG_FILE_VAR "TRACE_LOG_FILE" -#define MAJOR_VERSION 1 -#define MINOR_VERSION 0 - -#include -#include -#include "pmemcommon.h" -#include "unittest.h" - -/* - * print_custom_function -- Custom function to handle output - * - * This is called from the library to print text instead of output to stderr. - */ -static void -print_custom_function(const char *s) -{ - if (s) { - UT_OUT("CUSTOM_PRINT: %s", s); - } else { - UT_OUT("CUSTOM_PRINT(NULL)"); - } -} - -/* - * vsnprintf_custom_function -- Custom vsnprintf implementation - * - * It modifies format by adding @@ in front of each conversion specification. - */ -static int -vsnprintf_custom_function(char *str, size_t size, const char *format, - va_list ap) -{ - char *format2 = MALLOC(strlen(format) * 3); - int i = 0; - int ret_val; - - while (*format != '\0') { - if (*format == '%') { - format2[i++] = '@'; - format2[i++] = '@'; - } - format2[i++] = *format++; - } - format2[i++] = '\0'; - - ret_val = vsnprintf(str, size, format2, ap); - FREE(format2); - - return ret_val; -} - -int -main(int argc, char *argv[]) -{ - START(argc, argv, "traces_custom_function"); - - if (argc != 2) - UT_FATAL("usage: %s [v|p]", argv[0]); - - out_set_print_func(print_custom_function); - - common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, - MAJOR_VERSION, MINOR_VERSION); - - switch (argv[1][0]) { - case 'p': { - LOG(0, "Log level NONE"); - LOG(1, "Log level ERROR"); - LOG(2, "Log level WARNING"); - LOG(3, "Log level INFO"); - LOG(4, "Log level DEBUG"); - } - break; - case 'v': - out_set_vsnprintf_func(vsnprintf_custom_function); - - LOG(0, "no format"); - LOG(0, "pointer: %p", (void *)0x12345678); - LOG(0, "string: %s", "Hello world!"); - LOG(0, "number: %u", 12345678); - errno = EINVAL; - LOG(0, "!error"); - break; - default: - UT_FATAL("usage: %s [v|p]", argv[0]); - } - - /* Cleanup */ - common_fini(); - - DONE(NULL); -} diff --git a/src/test/traces_pmem/.gitignore b/src/test/traces_pmem/.gitignore deleted file mode 100644 index fb2885648e8..00000000000 --- a/src/test/traces_pmem/.gitignore +++ /dev/null @@ -1 +0,0 @@ -traces_pmem diff --git a/src/test/traces_pmem/Makefile b/src/test/traces_pmem/Makefile deleted file mode 100644 index 662a1bb3a48..00000000000 --- a/src/test/traces_pmem/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation - -# -# src/test/traces_pmem/Makefile -- build traces for library pmem -# -TARGET = traces_pmem -OBJS = traces_pmem.o - -LIBPMEM=y -LIBPMEMOBJ=y - -include ../Makefile.inc diff --git a/src/test/traces_pmem/TEST0 b/src/test/traces_pmem/TEST0 deleted file mode 100755 index 4b299d1d54e..00000000000 --- a/src/test/traces_pmem/TEST0 +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation - -# -# src/test/traces_pmem/TEST0 -- unit test traces for libraries pmem -# - -. ../unittest/unittest.sh - -require_test_type medium - -require_fs_type none -require_build_type debug static_debug - -setup - -export PMEM_LOG_LEVEL=4 -export PMEM_LOG_FILE=./trace_pmem$UNITTEST_NUM.log -export PMEMOBJ_LOG_LEVEL=4 -export PMEMOBJ_LOG_FILE=./trace_pmemobj$UNITTEST_NUM.log - -expect_normal_exit ./traces_pmem$EXESUFFIX - -# We want to check if traces are enabled and correctness of printed -# string format. We can't rely on full output (because of different -# machines configurations), hence comparison of only first 3 lines. -head -n 3 $PMEM_LOG_FILE > ./trace_pmem_head$UNITTEST_NUM.log -head -n 3 $PMEMOBJ_LOG_FILE > ./trace_pmemobj_head$UNITTEST_NUM.log - -check - -pass diff --git a/src/test/traces_pmem/trace_pmem_head0.log.match b/src/test/traces_pmem/trace_pmem_head0.log.match deleted file mode 100644 index 709ecb2df74..00000000000 --- a/src/test/traces_pmem/trace_pmem_head0.log.match +++ /dev/null @@ -1,3 +0,0 @@ -: <$(N)> [out.c:$(N) $(*)] pid $(N): program: $(*) -: <$(N)> [out.c:$(N) $(*)] libpmem version $(N).$(N) -: <$(N)> [out.c:$(N) $(*)] src version: $(*) diff --git a/src/test/traces_pmem/trace_pmemobj_head0.log.match b/src/test/traces_pmem/trace_pmemobj_head0.log.match deleted file mode 100644 index a7d81a0b690..00000000000 --- a/src/test/traces_pmem/trace_pmemobj_head0.log.match +++ /dev/null @@ -1,3 +0,0 @@ -: <$(N)> [out.c:$(N) $(*)] pid $(N): program: $(*) -: <$(N)> [out.c:$(N) $(*)] libpmemobj version $(N).$(N) -: <$(N)> [out.c:$(N) $(*)] src version: $(*) diff --git a/src/test/traces_pmem/traces_pmem.c b/src/test/traces_pmem/traces_pmem.c deleted file mode 100644 index d88fd047913..00000000000 --- a/src/test/traces_pmem/traces_pmem.c +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ - -/* - * traces_pmem.c -- unit test traces for libraries pmem - */ - -#include "unittest.h" - -int -main(int argc, char *argv[]) -{ - START(argc, argv, "traces_pmem"); - - UT_ASSERT(!pmem_check_version(PMEM_MAJOR_VERSION, - PMEM_MINOR_VERSION)); - UT_ASSERT(!pmemobj_check_version(PMEMOBJ_MAJOR_VERSION, - PMEMOBJ_MINOR_VERSION)); - - DONE(NULL); -} diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index ade4d321961..4b396f2857f 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2023, Intel Corporation +# Copyright 2023-2024, Intel Corporation import json from typing import Dict, List @@ -24,7 +24,6 @@ def inlines(calls: Calls) -> Calls: calls['core_init'] = ['util_init', 'out_init'] calls['core_fini'] = ['out_fini'] calls['ERR'] = ['out_err'] - calls['Print'] = ['out_print_func'] calls['common_init'] = ['core_init', 'util_mmap_init'] calls['common_fini'] = ['util_mmap_fini', 'core_fini'] calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 331951beca6..35bb4133ba6 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -128,8 +128,6 @@ "out_fatal", "out_log", "out_nonl", - "out_set_print_func", - "out_set_vsnprintf_func", "pmalloc_operation_hold_no_start", "pmalloc", "pmem2_badblock_clear", From 97dee5f7ec9c0eba3a526a8e28820525b3f5b281 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 15 Jan 2024 19:19:27 -0500 Subject: [PATCH 006/182] common: introduce a new logging mechanism Derived from the one developed for pmem/rpma. Signed-off-by: Jan Michalski --- src/core/log.c | 176 ++++++++++++++++++++++ src/core/log_default.c | 182 +++++++++++++++++++++++ src/core/log_default.h | 19 +++ src/core/log_internal.h | 163 +++++++++++++++++++++ src/core/pmemcore.h | 5 +- src/core/pmemcore.inc | 5 +- src/include/libpmemobj/log.h | 236 ++++++++++++++++++++++++++++++ src/libpmem/Makefile | 4 +- src/libpmemobj/Makefile | 3 +- src/libpmemobj/libpmemobj.link.in | 3 + src/libpmemobj/obj_log.c | 49 +++++++ src/test/Makefile.inc | 6 +- src/test/scope/out5.log.match | 3 + 13 files changed, 849 insertions(+), 5 deletions(-) create mode 100644 src/core/log.c create mode 100644 src/core/log_default.c create mode 100644 src/core/log_default.h create mode 100644 src/core/log_internal.h create mode 100644 src/include/libpmemobj/log.h create mode 100644 src/libpmemobj/obj_log.c diff --git a/src/core/log.c b/src/core/log.c new file mode 100644 index 00000000000..e00b223179f --- /dev/null +++ b/src/core/log.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2020-2024, Intel Corporation */ + +/* + * log.c -- support for logging output to either syslog or stderr or + * via user defined function + */ + +#include +#include +#include +#include +#ifdef ATOMIC_OPERATIONS_SUPPORTED +#include +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +#include + +#include "log_internal.h" +#include "log_default.h" + +/* + * Default levels of the logging thresholds + */ +#ifdef DEBUG +#define CORE_LOG_THRESHOLD_DEFAULT CORE_LOG_LEVEL_DEBUG +#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_LEVEL_WARNING +#else +#define CORE_LOG_THRESHOLD_DEFAULT CORE_LOG_LEVEL_WARNING +#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_DISABLED +#endif + +/* + * Core_log_function -- pointer to the logging function saved as uintptr_t to + * make it _Atomic, because function pointers cannot be _Atomic. By default it + * is core_log_default_function(), but could be a user-defined logging function + * provided via core_log_set_function(). + */ +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +uintptr_t Core_log_function; + +/* the logging function's context */ +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +void *Core_log_function_context; + +/* threshold levels */ +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +enum core_log_level Core_log_threshold[] = { + CORE_LOG_THRESHOLD_DEFAULT, + CORE_LOG_THRESHOLD_AUX_DEFAULT +}; + +/* + * core_log_init -- initialize and set the default logging function + */ +void +core_log_init() +{ + /* enable the default logging function */ + core_log_default_init(); + while (EAGAIN == + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL)) + ; +} + +/* + * core_log_fini -- disable logging and cleanup the default logging function + */ +void +core_log_fini() +{ + /* + * NULL-ed function pointer turns off the logging. No matter if + * the previous value was the default logging function or a user + * logging function. + */ + Core_log_function = 0; + Core_log_function_context = NULL; + + /* cleanup the default logging function */ + core_log_default_fini(); +} + +/* + * core_log_set_function -- set the log function pointer either to + * a user-provided function pointer or to the default logging function. + */ +int +core_log_set_function(core_log_function *log_function, void *context) +{ + + if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) + log_function = core_log_default_function; + +#ifdef ATOMIC_OPERATIONS_SUPPORTED + atomic_store_explicit(&Core_log_function, (uintptr_t)log_function, + __ATOMIC_SEQ_CST); + atomic_store_explicit(&Core_log_function_context, context, + __ATOMIC_SEQ_CST); + return 0; +#else + uintptr_t core_log_function_old = Core_log_function; + if (__sync_bool_compare_and_swap(&Core_log_function, + core_log_function_old, (uintptr_t)log_function)) + return 0; + else + return EAGAIN; + + void *context_old = Core_log_function_context; + if (__sync_bool_compare_and_swap(&Core_log_function_context, + context_old, context)) + return 0; + else + return EAGAIN; +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +} + +/* + * core_log_set_threshold -- set the log level threshold + */ +int +core_log_set_threshold(enum core_log_threshold threshold, + enum core_log_level level) +{ + if (threshold != CORE_LOG_THRESHOLD && + threshold != CORE_LOG_THRESHOLD_AUX) + return EINVAL; + + if (level < CORE_LOG_DISABLED || level > CORE_LOG_LEVEL_DEBUG) + return EINVAL; + +#ifdef ATOMIC_OPERATIONS_SUPPORTED + atomic_store_explicit(&Log_threshold[threshold], level, + __ATOMIC_SEQ_CST); + return 0; +#else + enum core_log_level level_old; + while (EAGAIN == core_log_get_threshold(threshold, &level_old)) + ; + + if (__sync_bool_compare_and_swap(&Core_log_threshold[threshold], + level_old, level)) + return 0; + else + return EAGAIN; +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +} + +/* + * core_log_get_threshold -- get the log level threshold + */ +int +core_log_get_threshold(enum core_log_threshold threshold, + enum core_log_level *level) +{ + if (threshold != CORE_LOG_THRESHOLD && + threshold != CORE_LOG_THRESHOLD_AUX) + return EINVAL; + + if (level == NULL) + return EINVAL; + +#ifdef ATOMIC_OPERATIONS_SUPPORTED + *level = atomic_load_explicit(&Log_threshold[threshold], + __ATOMIC_SEQ_CST); +#else + *level = Core_log_threshold[threshold]; +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ + + return 0; +} diff --git a/src/core/log_default.c b/src/core/log_default.c new file mode 100644 index 00000000000..c8066cddaae --- /dev/null +++ b/src/core/log_default.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2020-2024, Intel Corporation */ + +/* + * log_default.c -- the default logging function with support for logging either + * to syslog or to stderr + */ + +#define _GNU_SOURCE +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "log_internal.h" +#include "log_default.h" +#include "os.h" +#include "util.h" + +static const char log_level_names[6][9] = { + [CORE_LOG_LEVEL_FATAL] = "*FATAL* ", + [CORE_LOG_LEVEL_ERROR] = "*ERROR* ", + [CORE_LOG_LEVEL_WARNING] = "*WARN* ", + [CORE_LOG_LEVEL_NOTICE] = "*NOTE* ", + [CORE_LOG_LEVEL_INFO] = "*INFO* ", + [CORE_LOG_LEVEL_DEBUG] = "*DEBUG* ", +}; + +static const int log_level_syslog_severity[] = { + [CORE_LOG_LEVEL_FATAL] = LOG_CRIT, + [CORE_LOG_LEVEL_ERROR] = LOG_ERR, + [CORE_LOG_LEVEL_WARNING] = LOG_WARNING, + [CORE_LOG_LEVEL_NOTICE] = LOG_NOTICE, + [CORE_LOG_LEVEL_INFO] = LOG_INFO, + [CORE_LOG_LEVEL_DEBUG] = LOG_DEBUG, +}; + +/* + * get_timestamp_prefix -- provide actual time in a readable string + * + * NOTE + * This function is static now, so we know all possible calls of snprintf() + * and we conclude it can not fail. + * + * ASSUMPTIONS: + * - buf != NULL && buf_size >= 16 + */ +static void +get_timestamp_prefix(char *buf, size_t buf_size) +{ + struct tm info; + char date[24]; + struct timespec ts; + long usec; + + const char error_message[] = "[time error] "; + + if (os_clock_gettime(CLOCK_REALTIME, &ts)) + goto err_message; + + if (NULL == localtime_r(&ts.tv_sec, &info)) + goto err_message; + + usec = ts.tv_nsec / 1000; + if (!strftime(date, sizeof(date), "%b %d %H:%M:%S", &info)) + goto err_message; + + /* it cannot fail - please see the note above */ + (void) snprintf(buf, buf_size, "%s.%06ld ", date, usec); + if (strnlen(buf, buf_size) == buf_size) + goto err_message; + + return; + +err_message: + memcpy(buf, error_message, sizeof(error_message)); +} + +/* + * core_log_default_function -- default logging function used to log a message + * to syslog and/or stderr + * + * The message is started with prefix composed from file, line, func parameters + * followed by string pointed by format. If format includes format specifiers + * (subsequences beginning with %), the additional arguments following format + * are formatted and inserted in the message. + * + * ASSUMPTIONS: + * - level >= CORE_LOG_LEVEL_FATAL && level <= CORE_LOG_LEVEL_DEBUG + * - level <= Core_log_threshold[LOG_THRESHOLD] + * - file == NULL || (file != NULL && function != NULL) + */ +void +core_log_default_function(void *context, enum core_log_level level, + const char *file_name, const int line_no, const char *function_name, + const char *message_format, ...) +{ + SUPPRESS_UNUSED(context); + + char file_info_buffer[256] = ""; + const char *file_info = file_info_buffer; + char message[1024] = ""; + const char file_info_error[] = "[file info error]: "; + + if (CORE_LOG_DISABLED == level) + return; + + va_list arg; + va_start(arg, message_format); + if (vsnprintf(message, sizeof(message), message_format, arg) < 0) { + va_end(arg); + return; + } + va_end(arg); + + if (file_name) { + /* extract base_file_name */ + const char *base_file_name = strrchr(file_name, '/'); + if (!base_file_name) + base_file_name = file_name; + else + /* skip '/' */ + base_file_name++; + + if (snprintf(file_info_buffer, sizeof(file_info_buffer), + "%s: %3d: %s: ", base_file_name, line_no, + function_name) < 0) { + file_info = file_info_error; + } + } + + if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX] || + level == CORE_LOG_LEVEL_ALWAYS) { + char times_tamp[45] = ""; + get_timestamp_prefix(times_tamp, sizeof(times_tamp)); + (void) fprintf(stderr, "%s[%ld] %s%s%s", times_tamp, + syscall(SYS_gettid), + log_level_names[(level == CORE_LOG_LEVEL_ALWAYS) ? + CORE_LOG_LEVEL_DEBUG : level], + file_info, message); + } + + /* do not log to syslog in case of CORE_LOG_LEVEL_ALWAYS */ + if (CORE_LOG_LEVEL_ALWAYS == level) + return; + + /* assumed: level <= Core_log_threshold[CORE_LOG_THRESHOLD] */ + syslog(log_level_syslog_severity[level], "%s%s%s", + log_level_names[level], file_info, message); +} + +/* + * core_log_default_init -- explain why not calling openlog(3) + */ +void +core_log_default_init() +{ + /* + * Despite the default logging function prints to the syslog it is + * undesirable to call openlog(3) here since other software components + * might already configured the syslog. It is also unnecessary since + * the first syslog(3) call will call it. + */ +} + +/* + * core_log_default_fini -- explain why not calling closelog(3) + */ +void +core_log_default_fini(void) +{ + /* + * Since the PMDK libraries might not be the only software components + * making use of the syslog it is undesirable to call closelog(3) + * explicitly. Note its use is optional. + */ +} diff --git a/src/core/log_default.h b/src/core/log_default.h new file mode 100644 index 00000000000..613e0e594c9 --- /dev/null +++ b/src/core/log_default.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2020-2024, Intel Corporation */ + +/* + * log_default.h -- the default logging function definitions + */ + +#ifndef CORE_LOG_DEFAULT_H +#define CORE_LOG_DEFAULT_H + +void core_log_default_function(void *context, enum core_log_level level, + const char *file_name, const int line_no, const char *function_name, + const char *message_format, ...); + +void core_log_default_init(void); + +void core_log_default_fini(void); + +#endif /* CORE_LOG_DEFAULT_H */ diff --git a/src/core/log_internal.h b/src/core/log_internal.h new file mode 100644 index 00000000000..a502d0d8134 --- /dev/null +++ b/src/core/log_internal.h @@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2020-2024, Intel Corporation */ + +/* + * log_internal.h -- internal logging interfaces + */ + +#ifndef CORE_LOG_INTERNAL_H +#define CORE_LOG_INTERNAL_H + +#include +#include +#include +#include +#ifdef ATOMIC_OPERATIONS_SUPPORTED +#include +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ + +enum core_log_level { + /* all messages will be suppressed */ + CORE_LOG_DISABLED = -1, + /* an error that causes the library to stop working immediately */ + CORE_LOG_LEVEL_FATAL, + /* an error that causes the library to stop working properly */ + CORE_LOG_LEVEL_ERROR, + /* an errors that could be handled in the upper level */ + CORE_LOG_LEVEL_WARNING, + /* non-massive info mainly related to public API function completions */ + CORE_LOG_LEVEL_NOTICE, + /* massive info e.g. every write operation indication */ + CORE_LOG_LEVEL_INFO, + /* debug info e.g. write operation dump */ + CORE_LOG_LEVEL_DEBUG, +}; + +enum core_log_threshold { + /* + * the main threshold level - the logging messages above this level + * won't trigger the logging functions + */ + CORE_LOG_THRESHOLD, + /* + * the auxiliary threshold level - may or may not be used by the logging + * function + */ + CORE_LOG_THRESHOLD_AUX, + CORE_LOG_THRESHOLD_MAX +}; + +int core_log_set_threshold(enum core_log_threshold threshold, + enum core_log_level level); + +int core_log_get_threshold(enum core_log_threshold threshold, + enum core_log_level *level); + +/* + * the type used for defining logging functions + */ +typedef void core_log_function( + /* the context provided when setting the log function */ + void *context, + /* the log level of the message */ + enum core_log_level level, + /* name of the source file where the message coming from */ + const char *file_name, + /* the source file line where the message coming from */ + const int line_no, + /* the function name where the message coming from */ + const char *function_name, + /* printf(3)-like format string of the message */ + const char *message_format, + /* additional arguments of the message format string */ + ...); + +#define CORE_LOG_USE_DEFAULT_FUNCTION (NULL) + +int core_log_set_function(core_log_function *log_function, void *context); + +/* pointer to the logging function */ +extern +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +uintptr_t Core_log_function; + +/* the logging function's context */ +extern +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +void *Core_log_function_context; + +/* threshold levels */ +extern +#ifdef ATOMIC_OPERATIONS_SUPPORTED +_Atomic +#endif /* ATOMIC_OPERATIONS_SUPPORTED */ +enum core_log_level Core_log_threshold[CORE_LOG_THRESHOLD_MAX]; + +void core_log_init(void); + +void core_log_fini(void); + +#define CORE_LOG(level, format, ...) \ + do { \ + if (level <= Core_log_threshold[RPMA_LOG_THRESHOLD] && \ + 0 != Core_log_function) { \ + ((log_function *)Core_log_function)( \ + Core_log_function_context, level, __FILE__, \ + __LINE__, __func__, format, ##__VA_ARGS__); \ + } \ + } while (0) + +#define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1) + +void core_log_default_function(void *context, enum core_log_level level, + const char *file_name, const int line_no, const char *function_name, + const char *message_format, ...); + +/* + * Set of macros that should be used as the primary API for logging. + * Direct call to log shall be used only in exceptional, corner cases. + */ +#define CORE_LOG_DEBUG(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_DEBUG, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_INFO(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_INFO, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_NOTICE(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_NOTICE, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_WARNING(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_WARNING, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_ERROR(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_ERROR, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_FATAL(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format "\n", ##__VA_ARGS__) + +#define CORE_LOG_ALWAYS(format, ...) \ + CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format "\n", ##__VA_ARGS__) + +/* + * 'f' stands here for 'function' or 'format' where the latter may accept + * additional arguments. + */ +#define LOG_ERROR_WITH_ERRNO(e, f, ...) \ + LOG_ERROR(f " failed: %s", ##__VA_ARGS__, strerror(abs(e))); + +static inline int +core_log_error_translate(int ret) +{ + if (ret != 0) { + errno = ret; + return 1; + } + + return 0; +} + +#endif /* CORE_LOG_INTERNAL_H */ diff --git a/src/core/pmemcore.h b/src/core/pmemcore.h index 8291ad1a35e..4eb7f7dffe0 100644 --- a/src/core/pmemcore.h +++ b/src/core/pmemcore.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2020, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * pmemcore.h -- definitions for "core" module @@ -10,6 +10,7 @@ #include "util.h" #include "out.h" +#include "log_internal.h" #ifdef __cplusplus extern "C" { @@ -24,6 +25,7 @@ core_init(const char *log_prefix, const char *log_level_var, int minor_version) { util_init(); + core_log_init(); out_init(log_prefix, log_level_var, log_file_var, major_version, minor_version); } @@ -35,6 +37,7 @@ static inline void core_fini(void) { out_fini(); + core_log_fini(); } #ifdef __cplusplus diff --git a/src/core/pmemcore.inc b/src/core/pmemcore.inc index d701ab0cb97..e07f5a8f7e1 100644 --- a/src/core/pmemcore.inc +++ b/src/core/pmemcore.inc @@ -40,4 +40,7 @@ SOURCE +=\ $(CORE)/ravl.c\ $(CORE)/ravl_interval.c\ $(CORE)/util.c\ - $(CORE)/util_posix.c + $(CORE)/util_posix.c \ + $(CORE)/log.c \ + $(CORE)/log_default.c + diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h new file mode 100644 index 00000000000..4a0be3966ce --- /dev/null +++ b/src/include/libpmemobj/log.h @@ -0,0 +1,236 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2024, Intel Corporation */ + +/* + * libpmemobj/log.h -- the controls for the libpmemobj's logging output + */ + +#ifndef LIBPMEMOBJ_LOG_H +#define LIBPMEMOBJ_LOG_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Available log levels. Log levels (except for PMEMOBJ_LOG_DISABLED) are used + * in the logging API calls to indicate logging message severity. Log levels are + * also used to define thresholds for the logging. + */ +enum pmemobj_log_level { + /* all messages will be suppressed */ + PMEMOBJ_LOG_DISABLED = -1, + /* an error that causes the library to stop working immediately */ + PMEMOBJ_LOG_LEVEL_FATAL, + /* an error that causes the library to stop working properly */ + PMEMOBJ_LOG_LEVEL_ERROR, + /* an errors that could be handled in the upper level */ + PMEMOBJ_LOG_LEVEL_WARNING, + /* non-massive info mainly related to public API function completions */ + PMEMOBJ_LOG_LEVEL_NOTICE, + /* massive info e.g. every write operation indication */ + PMEMOBJ_LOG_LEVEL_INFO, + /* debug info e.g. write operation dump */ + PMEMOBJ_LOG_LEVEL_DEBUG, +}; + +enum pmemobj_log_threshold { + /* + * the main threshold level - the logging messages above this level + * won't trigger the logging functions + */ + PMEMOBJ_LOG_THRESHOLD, + /* + * the auxiliary threshold level - may or may not be used by the logging + * function + */ + PMEMOBJ_LOG_THRESHOLD_AUX, + PMEMOBJ_LOG_THRESHOLD_MAX +}; + +/* + * pmemobj_log_set_threshold - set the logging threshold level + * + * SYNOPSIS + * + * int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, + * enum pmemobj_log_level level); + * + * enum log_level { + * PMEMOBJ_LOG_DISABLED, + * PMEMOBJ_LOG_LEVEL_FATAL, + * PMEMOBJ_LOG_LEVEL_ERROR, + * PMEMOBJ_LOG_LEVEL_WARNING, + * PMEMOBJ_LOG_LEVEL_NOTICE, + * PMEMOBJ_LOG_LEVEL_INFO, + * PMEMOBJ_LOG_LEVEL_DEBUG, + * }; + * + * enum log_threshold { + * PMEMOBJ_LOG_THRESHOLD, + * PMEMOBJ_LOG_THRESHOLD_AUX, + * PMEMOBJ_LOG_THRESHOLD_MAX + * }; + * + * DESCRIPTION + * pmemobj_log_set_threshold() sets the logging threshold level. + * + * Available thresholds are: + * - PMEMOBJ_LOG_THRESHOLD - the main threshold used to filter out undesired + * logging messages. Messages on a higher level than the primary threshold + * level are ignored. PMEMOBJ_LOG_DISABLED shall be used to suppress logging. + * The default value is PMEMOBJ_LOG_WARNING. + * - PMEMOBJ_LOG_THRESHOLD_AUX - the auxiliary threshold intended for use inside + * the logging function (please see log_get_threshold(3)). The logging + * function may or may not take this threshold into consideration. The default + * value is PMEMOBJ_LOG_DISABLED. + * + * Available threshold levels are defined by enum log_level: + * - PMEMOBJ_LOG_DISABLED - all messages will be suppressed + * - PMEMOBJ_LOG_LEVEL_FATAL - an error that causes the library to stop working + * immediately + * - PMEMOBJ_LOG_LEVEL_ERROR - an error that causes the library to stop working + * properly + * - PMEMOBJ_LOG_LEVEL_WARNING - an error that could be handled in the upper + * level + * - PMEMOBJ_LOG_LEVEL_NOTICE - non-massive info mainly related to public API + * function completions + * - PMEMOBJ_LOG_LEVEL_INFO - massive info e.g. every write operation indication + * - PMEMOBJ_LOG_LEVEL_DEBUG - debug info e.g. write operation dump + * + * THE DEFAULT LOGGING FUNCTION + * The default logging function writes messages to syslog(3) and to stderr(3), + * where syslog(3) is the primary destination (PMEMOBJ_LOG_THRESHOLD applies) + * whereas stderr(3) is the secondary destination (PMEMOBJ_LOG_THRESHOLD_AUX + * applies). + * + * RETURN VALUE + * pmemobj_log_set_threshold() function returns 0 on success or returns + * a non-zero value and sets errno on failure. + * + * ERRORS + * pmemobj_log_set_threshold() can set the following errno values on fail: + * - EINVAL - threshold is not PMEMOBJ_LOG_THRESHOLD nor + * PMEMOBJ_LOG_THRESHOLD_AUX + * - EINVAL - level is not a value defined by enum log_level type + * - EAGAIN - a temporary error occurred, the retry may fix the problem + * + * SEE ALSO + * pmemobj_log_get_threshold(3), pmemobj_log_set_function(3). + */ +int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level level); + +/* + * pmemobj_log_get_threshold - get the logging threshold level + * + * SYNOPSIS + * + * int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, + * enum pmemobj_log_level *level); + * + * DESCRIPTION + * pmemobj_log_get_threshold() gets the current level of the threshold. + * See pmemobj_log_set_threshold(3) for available thresholds and levels. + * + * RETURN VALUE + * pmemobj_log_get_threshold() function returns 0 on success or returns + * a non-zero value and sets errno on failure. + * + * ERRORS + * pmemobj_log_get_threshold() can fail with the following errors: + * - EINVAL - threshold is not CORE_LOG_THRESHOLD nor CORE_LOG_THRESHOLD_AUX + * - EINVAL - *level is NULL + * + * SEE ALSO + * pmemobj_log_set_function(3), pmemobj_log_set_threshold(3). + */ +int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level *level); + +/* + * the type used for defining logging functions + */ +typedef void pmemobj_log_function( + /* the context provided when setting the log function */ + void *context, + /* the log level of the message */ + enum pmemobj_log_level level, + /* name of the source file where the message coming from */ + const char *file_name, + /* the source file line where the message coming from */ + const int line_no, + /* the function name where the message coming from */ + const char *function_name, + /* printf(3)-like format string of the message */ + const char *message_format, + /* additional arguments of the message format string */ + ...); + +#define PMEMOBJ_LOG_USE_DEFAULT_FUNCTION (NULL) + +/* + * pmemobj_log_set_function - set the logging function + * + * SYNOPSIS + * + * typedef void pmemobj_log_function( + * void *context, + * enum pmemobj_log_level level, + * const char *file_name, + * const int line_no, + * const char *function_name, + * const char *message_format, + * ...); + * + * int pmemobj_log_set_function(pmemobj_log_function *log_function, + * void *context); + * + * DESCRIPTION + * pmemobj_log_set_function() allows choosing the function which will get all + * the generated logging messages. The log_function can be either + * PMEMOBJ_LOG_USE_DEFAULT_FUNCTION which will use the default logging function + * (built into the library) or a pointer to a user-defined function. + * The context allows to pass an additional value which will be passed along + * with all the logging messages to the logging function. When the provided + * log_function is PMEMOBJ_LOG_USE_DEFAULT_FUNCTION the provided context is + * ignored. + * + * Parameters of a user-defined log function are as follow: + * - level - the log level of the message + * - file_name - name of the source file where the message coming from. It could + * be set to NULL and + * in such case neither line_no nor function_name are provided. + * - line_no - the source file line where the message coming from + * - function_name - the function name where the message coming from + * - message_format - printf(3)-like format string of the message + * - "..." - additional arguments of the message format string + * + * THE DEFAULT LOGGING FUNCTION + * The initial value of the logging function is CORE_LOG_USE_DEFAULT_FUNCTION. + * This function writes messages to syslog(3) (the primary destination) and to + * stderr(3) (the secondary destination). + * + * RETURN VALUE + * pmemobj_log_set_function() function returns 0 on success or returns + * a non-zero value and sets errno on failure. + * + * ERRORS + * - EAGAIN - a temporary error occurred, the retry may fix the problem + * + * NOTE + * The logging messages on the levels above the CORE_LOG_THRESHOLD level won't + * trigger the logging function. + * + * The user defined function must be thread-safe. + * + * SEE ALSO + * pmemobj_log_get_threshold(3), pmemobj_log_set_threshold(3). + */ +int pmemobj_log_set_function(pmemobj_log_function *log_function, void *context); + +#ifdef __cplusplus +} +#endif + +#endif /* libpmemobj/log.h */ diff --git a/src/libpmem/Makefile b/src/libpmem/Makefile index 54eda860469..a3f8a70e064 100644 --- a/src/libpmem/Makefile +++ b/src/libpmem/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # src/libpmem/Makefile -- Makefile for libpmem @@ -18,6 +18,8 @@ SOURCE =\ $(CORE)/out.c\ $(CORE)/util.c\ $(CORE)/util_posix.c\ + $(CORE)/log.c\ + $(CORE)/log_default.c\ $(COMMON)/file.c\ $(COMMON)/file_posix.c\ $(COMMON)/mmap.c\ diff --git a/src/libpmemobj/Makefile b/src/libpmemobj/Makefile index af013dd3cc8..44ad0cc4933 100644 --- a/src/libpmemobj/Makefile +++ b/src/libpmemobj/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # src/libpmemobj/Makefile -- Makefile for libpmemobj @@ -26,6 +26,7 @@ SOURCE +=\ memblock.c\ memops.c\ obj.c\ + obj_log.c\ palloc.c\ pmalloc.c\ recycler.c\ diff --git a/src/libpmemobj/libpmemobj.link.in b/src/libpmemobj/libpmemobj.link.in index 5b730caa6b0..0bb0aea2e02 100644 --- a/src/libpmemobj/libpmemobj.link.in +++ b/src/libpmemobj/libpmemobj.link.in @@ -56,6 +56,9 @@ LIBPMEMOBJ_1.0 { pmemobj_list_insert_new; pmemobj_list_remove; pmemobj_list_move; + pmemobj_log_get_threshold; + pmemobj_log_set_function; + pmemobj_log_set_threshold; pmemobj_tx_begin; pmemobj_tx_stage; pmemobj_tx_abort; diff --git a/src/libpmemobj/obj_log.c b/src/libpmemobj/obj_log.c new file mode 100644 index 00000000000..3984e9e5d5e --- /dev/null +++ b/src/libpmemobj/obj_log.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * obj_log.c -- the public interface to control the logging output + */ +#include + +#include "log_internal.h" +#include "util.h" + +/* + * pmemobj_log_set_threshold -- set the log level threshold + */ +int +pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level level) +{ + int ret = core_log_set_threshold((enum core_log_threshold)threshold, + (enum core_log_level)level); + return core_log_error_translate(ret); +} + +/* + * pmemobj_log_get_threshold -- get the log level threshold + */ +int +pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level *level) +{ + int ret = core_log_get_threshold((enum core_log_threshold)threshold, + (enum core_log_level *)level); + return core_log_error_translate(ret); +} + +/* + * pmemobj_log_set_function -- set the log function pointer either to + * a user-provided function pointer or to the default logging function. + */ +int +pmemobj_log_set_function(pmemobj_log_function *log_function, void *context) +{ + if (log_function == PMEMOBJ_LOG_USE_DEFAULT_FUNCTION) + context = NULL; + + int ret = core_log_set_function((core_log_function *)log_function, + context); + return core_log_error_translate(ret); +} diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index 2d893b96618..bf066cf7b71 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # @@ -388,6 +388,8 @@ ifeq ($(LIBPMEMCORE), internal-nondebug) OBJS +=\ $(TOP)/src/nondebug/core/alloc.o\ $(TOP)/src/nondebug/core/fs_posix.o\ + $(TOP)/src/nondebug/core/log.o\ + $(TOP)/src/nondebug/core/log_default.o\ $(TOP)/src/nondebug/core/os_posix.o\ $(TOP)/src/nondebug/core/os_thread_posix.o\ $(TOP)/src/nondebug/core/out.o\ @@ -403,6 +405,8 @@ ifeq ($(LIBPMEMCORE), internal-debug) OBJS +=\ $(TOP)/src/debug/core/alloc.o\ $(TOP)/src/debug/core/fs_posix.o\ + $(TOP)/src/debug/core/log.o\ + $(TOP)/src/debug/core/log_default.o\ $(TOP)/src/debug/core/os_posix.o\ $(TOP)/src/debug/core/os_thread_posix.o\ $(TOP)/src/debug/core/out.o\ diff --git a/src/test/scope/out5.log.match b/src/test/scope/out5.log.match index 3ad10d14459..d88824a39f1 100644 --- a/src/test/scope/out5.log.match +++ b/src/test/scope/out5.log.match @@ -31,6 +31,9 @@ pmemobj_list_insert$(nW) pmemobj_list_insert_new$(nW) pmemobj_list_move$(nW) pmemobj_list_remove$(nW) +pmemobj_log_get_threshold$(nW) +pmemobj_log_set_function$(nW) +pmemobj_log_set_threshold$(nW) pmemobj_memcpy$(nW) pmemobj_memcpy_persist$(nW) pmemobj_memmove$(nW) From 8835b8180ca0cb0ddfeae6f8697eb8f3d4bd6439 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 16 Jan 2024 20:36:26 +0100 Subject: [PATCH 007/182] common: avoid custom log function overwriting by default lib setup. Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/log.c b/src/core/log.c index e00b223179f..942f769a0f8 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -38,7 +38,7 @@ #ifdef ATOMIC_OPERATIONS_SUPPORTED _Atomic #endif /* ATOMIC_OPERATIONS_SUPPORTED */ -uintptr_t Core_log_function; +uintptr_t Core_log_function = 0; /* the logging function's context */ #ifdef ATOMIC_OPERATIONS_SUPPORTED @@ -61,6 +61,13 @@ enum core_log_level Core_log_threshold[] = { void core_log_init() { + /* + * The core log might be already initialized. + * It might happen in the case of some unit tests. + */ + if (Core_log_function != 0) + return; + /* enable the default logging function */ core_log_default_init(); while (EAGAIN == @@ -105,6 +112,7 @@ core_log_set_function(core_log_function *log_function, void *context) return 0; #else uintptr_t core_log_function_old = Core_log_function; + if (__sync_bool_compare_and_swap(&Core_log_function, core_log_function_old, (uintptr_t)log_function)) return 0; From ef0c124419556a38b2d85eae5db13ce63e6d4f32 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 17 Jan 2024 12:42:48 +0100 Subject: [PATCH 008/182] common: full implementation of ut log function Signed-off-by: Tomasz Gromadzki --- src/core/log_default.c | 4 ++-- src/core/log_internal.h | 14 +++++++------- src/core/out.c | 16 +++++++++++----- src/core/out.h | 2 ++ src/test/unittest/Makefile | 5 +++-- src/test/unittest/unittest.h | 6 ++++++ src/test/unittest/ut_log.c | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 src/test/unittest/ut_log.c diff --git a/src/core/log_default.c b/src/core/log_default.c index c8066cddaae..62b6e6af660 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -138,7 +138,7 @@ core_log_default_function(void *context, enum core_log_level level, level == CORE_LOG_LEVEL_ALWAYS) { char times_tamp[45] = ""; get_timestamp_prefix(times_tamp, sizeof(times_tamp)); - (void) fprintf(stderr, "%s[%ld] %s%s%s", times_tamp, + (void) fprintf(stderr, "%s[%ld] %s%s%s\n", times_tamp, syscall(SYS_gettid), log_level_names[(level == CORE_LOG_LEVEL_ALWAYS) ? CORE_LOG_LEVEL_DEBUG : level], @@ -150,7 +150,7 @@ core_log_default_function(void *context, enum core_log_level level, return; /* assumed: level <= Core_log_threshold[CORE_LOG_THRESHOLD] */ - syslog(log_level_syslog_severity[level], "%s%s%s", + syslog(log_level_syslog_severity[level], "%s%s%s\n", log_level_names[level], file_info, message); } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index a502d0d8134..890c45f1d8d 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -122,25 +122,25 @@ void core_log_default_function(void *context, enum core_log_level level, * Direct call to log shall be used only in exceptional, corner cases. */ #define CORE_LOG_DEBUG(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_DEBUG, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) #define CORE_LOG_INFO(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_INFO, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_INFO, format, ##__VA_ARGS__) #define CORE_LOG_NOTICE(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_NOTICE, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_NOTICE, format, ##__VA_ARGS__) #define CORE_LOG_WARNING(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_WARNING, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) #define CORE_LOG_ERROR(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_ERROR, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) #define CORE_LOG_ALWAYS(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format "\n", ##__VA_ARGS__) + CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) /* * 'f' stands here for 'function' or 'format' where the latter may accept diff --git a/src/core/out.c b/src/core/out.c index a836565cd9a..262a5f14bb2 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -473,19 +473,25 @@ out_nonl(int level, const char *fmt, ...) } /* - * out_log -- output a log line if Log_level >= level + * out_log_va/out_log -- output a log line if Log_level >= level */ +void +out_log_va(const char *file, int line, const char *func, int level, + const char *fmt, va_list ap) +{ + if (Log_level < level) + return; + out_common(file, line, func, level, "\n", fmt, ap); +} + void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) { va_list ap; - if (Log_level < level) - return; - va_start(ap, fmt); - out_common(file, line, func, level, "\n", fmt, ap); + out_log_va(file, line, func, level, fmt, ap); va_end(ap); } diff --git a/src/core/out.h b/src/core/out.h index e7feb48a67c..5fe9daebfd8 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -192,6 +192,8 @@ void out_init(const char *log_prefix, const char *log_level_var, void out_fini(void); void out(const char *fmt, ...) FORMAT_PRINTF(1, 2); void out_nonl(int level, const char *fmt, ...) FORMAT_PRINTF(2, 3); +void out_log_va(const char *file, int line, const char *func, int level, + const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); void out_err(const char *file, int line, const char *func, diff --git a/src/test/unittest/Makefile b/src/test/unittest/Makefile index acbeeb55a42..481bf8b0849 100644 --- a/src/test/unittest/Makefile +++ b/src/test/unittest/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # src/test/unittest/Makefile -- build unittest support library @@ -16,7 +16,8 @@ vpath %.h $(TOP)/src/core TARGET_UT = libut.a OBJS_UT = ut.o ut_alloc.o ut_file.o ut_pthread.o ut_signal.o ut_backtrace.o\ - os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o + os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o\ + ut_log.o TARGET_UT_PMEM2 = ut_pmem2.a OBJS_UT_PMEM2 = ut_pmem2_config.o ut_pmem2_utils.o diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 13a47ffb91f..685dee4b0b2 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -733,6 +733,12 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); ((void)(addr), (void)(size)) #endif +#include "log_internal.h" +void +ut_log_function(void *context, enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, + const char *message_format, ...); + #ifdef __cplusplus } #endif diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c new file mode 100644 index 00000000000..b71d0b2bfa2 --- /dev/null +++ b/src/test/unittest/ut_log.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * ut_log.c -- unit test log function + * + */ + +#include "unittest.h" +#include "out.h" + +static const int core_log_level_to_out_level[] = { + [CORE_LOG_LEVEL_FATAL] = 1, + [CORE_LOG_LEVEL_ERROR] = 1, + [CORE_LOG_LEVEL_WARNING] = 2, + [CORE_LOG_LEVEL_NOTICE] = 3, + [CORE_LOG_LEVEL_INFO] = 4, + [CORE_LOG_LEVEL_DEBUG] = 4, +}; + +void +ut_log_function(void *context, enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, + const char *message_format, ...) +{ + if (level == CORE_LOG_LEVEL_ALWAYS) + level = CORE_LOG_LEVEL_ERROR; + + va_list arg; + va_start(arg, message_format); + out_log_va(file_name, line_no, function_name, + core_log_level_to_out_level[(int)level],message_format, arg); + va_end(arg); +} From d3215c4188e560f1733de5e3c062353d674c313c Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 17 Jan 2024 12:34:42 +0100 Subject: [PATCH 009/182] common: pmemcore ut logging initialization Logging initialization for all pmemcore unit tests. Signed-off-by: Tomasz Gromadzki --- src/test/Makefile.inc | 7 +++++++ src/test/unittest/unittest.h | 16 +++++++++++++--- src/test/unittest/ut_log.c | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index bf066cf7b71..b4f02d73e89 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -382,6 +382,7 @@ ifeq ($(LIBPMEMCORE), y) LIBPMEM=y OBJS += $(LIBS_DIR)/debug/libpmemcore.a INCS += -I$(TOP)/src/core +USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEMCORE), internal-nondebug) @@ -399,6 +400,7 @@ OBJS +=\ $(TOP)/src/nondebug/core/util_posix.o INCS += -I$(TOP)/src/core +USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEMCORE), internal-debug) @@ -416,6 +418,7 @@ OBJS +=\ $(TOP)/src/debug/core/util_posix.o INCS += -I$(TOP)/src/core +USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEM),y) @@ -521,6 +524,10 @@ CFLAGS += -DFAULT_INJECTION=1 CXXFLAGS += -DFAULT_INJECTION=1 endif +ifeq ($(USE_LOG_PMEMCORE),y) +CFLAGS += -DUSE_LOG_PMEMCORE +endif + ifneq ($(SANITIZE),) CFLAGS += -fsanitize=$(SANITIZE) CXXFLAGS += -fsanitize=$(SANITIZE) diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 685dee4b0b2..8a6fd24a706 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * unittest.h -- the mundane stuff shared by all unit tests @@ -87,6 +87,7 @@ extern "C" { #include "os.h" #include "os_thread.h" #include "util.h" +#include "log_internal.h" int ut_get_uuid_str(char *); #define UT_MAX_ERR_MSG 128 @@ -115,9 +116,19 @@ void ut_err(const char *file, int line, const char *func, const char *fmt, ...) __attribute__((format(printf, 4, 5))); +#ifdef USE_LOG_PMEMCORE +#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL); +#else +#define LOG_SET_PMEMCORE_FUNC +#endif + /* indicate the start of the test */ #define START(argc, argv, ...)\ - ut_start(__FILE__, __LINE__, __func__, argc, argv, __VA_ARGS__) + do {\ + ut_start(__FILE__, __LINE__, __func__, argc, argv,\ + __VA_ARGS__);\ + LOG_SET_PMEMCORE_FUNC\ + } while (0) /* normal exit from test */ #define DONE(...)\ @@ -733,7 +744,6 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); ((void)(addr), (void)(size)) #endif -#include "log_internal.h" void ut_log_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c index b71d0b2bfa2..76767d01cd2 100644 --- a/src/test/unittest/ut_log.c +++ b/src/test/unittest/ut_log.c @@ -29,6 +29,6 @@ ut_log_function(void *context, enum core_log_level level, const char *file_name, va_list arg; va_start(arg, message_format); out_log_va(file_name, line_no, function_name, - core_log_level_to_out_level[(int)level],message_format, arg); + core_log_level_to_out_level[(int)level], message_format, arg); va_end(arg); } From b7dd25a2abf95e7643744704881aae64c1f8523f Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 18 Jan 2024 07:50:29 +0100 Subject: [PATCH 010/182] common: conditional linking of ut_log.o Signed-off-by: Tomasz Gromadzki --- src/test/Makefile.inc | 1 + src/test/pmem2_persist_valgrind/Makefile | 8 ++++---- src/test/unittest/Makefile | 3 +-- src/test/unittest/unittest.h | 9 ++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index b4f02d73e89..32d1faff57d 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -526,6 +526,7 @@ endif ifeq ($(USE_LOG_PMEMCORE),y) CFLAGS += -DUSE_LOG_PMEMCORE +OBJS += $(TOP)/src/test/unittest/ut_log.o endif ifneq ($(SANITIZE),) diff --git a/src/test/pmem2_persist_valgrind/Makefile b/src/test/pmem2_persist_valgrind/Makefile index fff52176d4c..a1150a4cf5b 100644 --- a/src/test/pmem2_persist_valgrind/Makefile +++ b/src/test/pmem2_persist_valgrind/Makefile @@ -10,12 +10,12 @@ vpath %.c $(TOP)/src/core vpath %.c $(TOP)/src/test/unittest TARGET = pmem2_persist_valgrind -OBJS = alloc.o\ +OBJS = pmem2_persist_valgrind.o\ + ut_pmem2_utils.o\ out.o\ - pmem2_persist_valgrind.o\ - util.o\ util_posix.o\ - ut_pmem2_utils.o + log.o\ + log_default.o LIBPMEM2=y diff --git a/src/test/unittest/Makefile b/src/test/unittest/Makefile index 481bf8b0849..3d35431cc86 100644 --- a/src/test/unittest/Makefile +++ b/src/test/unittest/Makefile @@ -16,8 +16,7 @@ vpath %.h $(TOP)/src/core TARGET_UT = libut.a OBJS_UT = ut.o ut_alloc.o ut_file.o ut_pthread.o ut_signal.o ut_backtrace.o\ - os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o\ - ut_log.o + os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o TARGET_UT_PMEM2 = ut_pmem2.a OBJS_UT_PMEM2 = ut_pmem2_config.o ut_pmem2_utils.o diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 8a6fd24a706..0d2d654fbf7 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -117,6 +117,10 @@ void ut_err(const char *file, int line, const char *func, __attribute__((format(printf, 4, 5))); #ifdef USE_LOG_PMEMCORE +void +ut_log_function(void *context, enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, + const char *message_format, ...); #define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL); #else #define LOG_SET_PMEMCORE_FUNC @@ -744,11 +748,6 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); ((void)(addr), (void)(size)) #endif -void -ut_log_function(void *context, enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, - const char *message_format, ...); - #ifdef __cplusplus } #endif From 6f0d95e3ff3c09e537305d291d76d49886875ab8 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 18 Jan 2024 12:53:20 +0100 Subject: [PATCH 011/182] common: remove unneeded logging initialization Signed-off-by: Tomasz Gromadzki --- src/test/pmem2_persist_valgrind/Makefile | 6 +----- src/test/pmem2_persist_valgrind/pmem2_persist_valgrind.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/test/pmem2_persist_valgrind/Makefile b/src/test/pmem2_persist_valgrind/Makefile index a1150a4cf5b..519e4b05c8e 100644 --- a/src/test/pmem2_persist_valgrind/Makefile +++ b/src/test/pmem2_persist_valgrind/Makefile @@ -11,11 +11,7 @@ vpath %.c $(TOP)/src/test/unittest TARGET = pmem2_persist_valgrind OBJS = pmem2_persist_valgrind.o\ - ut_pmem2_utils.o\ - out.o\ - util_posix.o\ - log.o\ - log_default.o + ut_pmem2_utils.o LIBPMEM2=y diff --git a/src/test/pmem2_persist_valgrind/pmem2_persist_valgrind.c b/src/test/pmem2_persist_valgrind/pmem2_persist_valgrind.c index 02d21f4f0f0..9a21e74533a 100644 --- a/src/test/pmem2_persist_valgrind/pmem2_persist_valgrind.c +++ b/src/test/pmem2_persist_valgrind/pmem2_persist_valgrind.c @@ -1,11 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * pmem2_persist_valgrind.c -- pmem2_persist_valgrind tests */ -#include "out.h" #include "unittest.h" #include "ut_pmem2_utils.h" @@ -208,9 +207,6 @@ int main(int argc, char *argv[]) { START(argc, argv, "pmem2_persist_valgrind"); - out_init("pmem2_persist_valgrind", "TEST_LOG_LEVEL", "TEST_LOG_FILE", 0, - 0); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); - out_fini(); DONE(NULL); } From 53b6f18ec36995d0fa1fc0245cbb6236349c4459 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 15 Jan 2024 19:31:22 +0100 Subject: [PATCH 012/182] common: always log library info to logging system Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 1 - src/core/log_default.c | 21 +++++++++------------ src/core/log_internal.h | 4 ++-- src/core/out.c | 20 +++++++++++--------- src/test/pmem2_persist_valgrind/Makefile | 2 +- src/test/util_ravl/Makefile | 4 ++-- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 942f769a0f8..8ecbe9531e0 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -112,7 +112,6 @@ core_log_set_function(core_log_function *log_function, void *context) return 0; #else uintptr_t core_log_function_old = Core_log_function; - if (__sync_bool_compare_and_swap(&Core_log_function, core_log_function_old, (uintptr_t)log_function)) return 0; diff --git a/src/core/log_default.c b/src/core/log_default.c index 62b6e6af660..353fc2dc76e 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -134,24 +134,21 @@ core_log_default_function(void *context, enum core_log_level level, } } - if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX] || - level == CORE_LOG_LEVEL_ALWAYS) { + if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX] && + level != CORE_LOG_LEVEL_ALWAYS) { char times_tamp[45] = ""; get_timestamp_prefix(times_tamp, sizeof(times_tamp)); (void) fprintf(stderr, "%s[%ld] %s%s%s\n", times_tamp, - syscall(SYS_gettid), - log_level_names[(level == CORE_LOG_LEVEL_ALWAYS) ? - CORE_LOG_LEVEL_DEBUG : level], - file_info, message); + syscall(SYS_gettid), log_level_names[level], file_info, + message); } - /* do not log to syslog in case of CORE_LOG_LEVEL_ALWAYS */ - if (CORE_LOG_LEVEL_ALWAYS == level) - return; - + level = (level == CORE_LOG_LEVEL_ALWAYS)? CORE_LOG_LEVEL_NOTICE: level; /* assumed: level <= Core_log_threshold[CORE_LOG_THRESHOLD] */ - syslog(log_level_syslog_severity[level], "%s%s%s\n", - log_level_names[level], file_info, message); + syslog(log_level_syslog_severity[level], + "%s%s%s", + log_level_names[level], + file_info, message); } /* diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 890c45f1d8d..cc78e3bcd80 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -103,9 +103,9 @@ void core_log_fini(void); #define CORE_LOG(level, format, ...) \ do { \ - if (level <= Core_log_threshold[RPMA_LOG_THRESHOLD] && \ + if (level <= Core_log_threshold[CORE_LOG_THRESHOLD] && \ 0 != Core_log_function) { \ - ((log_function *)Core_log_function)( \ + ((core_log_function *)Core_log_function)( \ Core_log_function_context, level, __FILE__, \ __LINE__, __func__, format, ##__VA_ARGS__); \ } \ diff --git a/src/core/out.c b/src/core/out.c index 262a5f14bb2..a8fedead9fb 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -20,6 +20,7 @@ #include "os_thread.h" #include "valgrind_internal.h" #include "util.h" +#include "log_internal.h" static const char *Log_prefix; static int Log_level; @@ -197,14 +198,15 @@ out_init(const char *log_prefix, const char *log_level_var, #ifdef DEBUG static char namepath[PATH_MAX]; - LOG(1, "pid %d: program: %s", getpid(), + CORE_LOG_ALWAYS("pid %d: program: %s", getpid(), util_getexecname(namepath, PATH_MAX)); #endif - LOG(1, "%s version %d.%d", log_prefix, major_version, minor_version); + CORE_LOG_ALWAYS("%s version %d.%d", log_prefix, major_version, + minor_version); static __attribute__((used)) const char *version_msg = "src version: " SRCVERSION; - LOG(1, "%s", version_msg); + CORE_LOG_ALWAYS("%s", version_msg); #if VG_PMEMCHECK_ENABLED /* * Attribute "used" to prevent compiler from optimizing out the variable @@ -212,32 +214,32 @@ out_init(const char *log_prefix, const char *log_level_var, */ static __attribute__((used)) const char *pmemcheck_msg = "compiled with support for Valgrind pmemcheck"; - LOG(1, "%s", pmemcheck_msg); + CORE_LOG_ALWAYS("%s", pmemcheck_msg); #endif /* VG_PMEMCHECK_ENABLED */ #if VG_HELGRIND_ENABLED static __attribute__((used)) const char *helgrind_msg = "compiled with support for Valgrind helgrind"; - LOG(1, "%s", helgrind_msg); + CORE_LOG_ALWAYS("%s", helgrind_msg); #endif /* VG_HELGRIND_ENABLED */ #if VG_MEMCHECK_ENABLED static __attribute__((used)) const char *memcheck_msg = "compiled with support for Valgrind memcheck"; - LOG(1, "%s", memcheck_msg); + CORE_LOG_ALWAYS("%s", memcheck_msg); #endif /* VG_MEMCHECK_ENABLED */ #if VG_DRD_ENABLED static __attribute__((used)) const char *drd_msg = "compiled with support for Valgrind drd"; - LOG(1, "%s", drd_msg); + CORE_LOG_ALWAYS("%s", drd_msg); #endif /* VG_DRD_ENABLED */ #if SDS_ENABLED static __attribute__((used)) const char *shutdown_state_msg = "compiled with support for shutdown state"; - LOG(1, "%s", shutdown_state_msg); + CORE_LOG_ALWAYS("%s", shutdown_state_msg); #endif #if NDCTL_ENABLED static __attribute__((used)) const char *ndctl_ge_63_msg = "compiled with libndctl 63+"; - LOG(1, "%s", ndctl_ge_63_msg); + CORE_LOG_ALWAYS("%s", ndctl_ge_63_msg); #endif Last_errormsg_key_alloc(); diff --git a/src/test/pmem2_persist_valgrind/Makefile b/src/test/pmem2_persist_valgrind/Makefile index 519e4b05c8e..7afa7521e22 100644 --- a/src/test/pmem2_persist_valgrind/Makefile +++ b/src/test/pmem2_persist_valgrind/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2020, Intel Corporation +# Copyright 2020-2024, Intel Corporation # # src/test/pmem2_persist_valgrind/Makefile -- build pmem2_persist_valgrind test diff --git a/src/test/util_ravl/Makefile b/src/test/util_ravl/Makefile index d5be4c0e747..75050e36ee0 100644 --- a/src/test/util_ravl/Makefile +++ b/src/test/util_ravl/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2020, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # @@ -7,7 +7,7 @@ # TARGET = util_ravl -OBJS = util_ravl.o alloc.o ravl.o out.o util_posix.o util.o +OBJS = util_ravl.o alloc.o ravl.o out.o util_posix.o util.o log.o log_default.o INCS += -I$(TOP)/src/common include ../Makefile.inc From 88c235f769179d0ed77babcd051fc99bd76696d1 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 18 Jan 2024 14:06:29 +0100 Subject: [PATCH 013/182] common: valgrind fixes --- src/test/drd-log.supp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/drd-log.supp b/src/test/drd-log.supp index d99f69bfe26..5d9db8c9650 100644 --- a/src/test/drd-log.supp +++ b/src/test/drd-log.supp @@ -7,6 +7,7 @@ ... fun:out_print_func fun:out_common + fun:out_log_va fun:out_log } { @@ -18,6 +19,7 @@ ... fun:out_print_func fun:out_common + fun:out_log_va fun:out_log } { From d7245f747e5abf7c305cfe7720e920089cd2ec62 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 18 Jan 2024 14:04:47 +0100 Subject: [PATCH 014/182] common: valgrind fixes --- src/test/helgrind-log.supp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/helgrind-log.supp b/src/test/helgrind-log.supp index 95f90df3623..6b29d37b022 100644 --- a/src/test/helgrind-log.supp +++ b/src/test/helgrind-log.supp @@ -7,6 +7,7 @@ ... fun:out_print_func fun:out_common + fun:out_log_va fun:out_log } { @@ -17,6 +18,7 @@ fun:fputs fun:out_print_func fun:out_common + fun:out_log_va fun:out_log } { From 721de3307907f88a35d85c59c4821be03eb734eb Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 17 Jan 2024 16:00:05 +0100 Subject: [PATCH 015/182] common: use ut-dedicated logging function for pmemobj logs Signed-off-by: Tomasz Gromadzki Signed-off-by: Jan Michalski --- src/test/Makefile.inc | 31 +++++++++++++++++++++++++------ src/test/unittest/Makefile | 13 ++++--------- src/test/unittest/unittest.h | 19 ++++++++++++++++--- src/test/util_ravl/Makefile | 3 ++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index 32d1faff57d..e143aa7eb65 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -47,6 +47,7 @@ endif ifeq ($(LIBPMEMOBJ), y) LIBPMEM=y +USE_LOG_PMEMOBJ=y DYNAMIC_LIBS += -lpmemobj STATIC_DEBUG_LIBS += $(LIBS_DIR)/debug/libpmemobj.a STATIC_NONDEBUG_LIBS += $(LIBS_DIR)/nondebug/libpmemobj.a @@ -54,6 +55,7 @@ endif ifeq ($(LIBPMEMOBJ), internal-debug) LIBPMEM=y +USE_LOG_PMEMOBJ=y LIBPMEMCOMMON=internal-debug OBJS += $(TOP)/src/debug/libpmemobj/alloc_class.o\ $(TOP)/src/debug/libpmemobj/bucket.o\ @@ -74,13 +76,15 @@ OBJS += $(TOP)/src/debug/libpmemobj/alloc_class.o\ $(TOP)/src/debug/libpmemobj/ulog.o\ $(TOP)/src/debug/libpmemobj/sync.o\ $(TOP)/src/debug/libpmemobj/tx.o\ - $(TOP)/src/debug/libpmemobj/stats.o + $(TOP)/src/debug/libpmemobj/stats.o\ + $(TOP)/src/debug/libpmemobj/obj_log.o INCS += -I$(TOP)/src/libpmemobj endif ifeq ($(LIBPMEMOBJ), internal-nondebug) LIBPMEM=y +USE_LOG_PMEMOBJ=y LIBPMEMCOMMON=internal-nondebug OBJS += $(TOP)/src/nondebug/libpmemobj/alloc_class.o\ $(TOP)/src/nondebug/libpmemobj/bucket.o\ @@ -101,7 +105,8 @@ OBJS += $(TOP)/src/nondebug/libpmemobj/alloc_class.o\ $(TOP)/src/nondebug/libpmemobj/ulog.o\ $(TOP)/src/nondebug/libpmemobj/sync.o\ $(TOP)/src/nondebug/libpmemobj/tx.o\ - $(TOP)/src/nondebug/libpmemobj/stats.o + $(TOP)/src/nondebug/libpmemobj/stats.o\ + $(TOP)/src/nondebug/libpmemobj/obj_log.o INCS += -I$(TOP)/src/libpmemobj endif @@ -380,12 +385,13 @@ endif ifeq ($(LIBPMEMCORE), y) LIBPMEM=y +USE_LOG_PMEMCORE=y OBJS += $(LIBS_DIR)/debug/libpmemcore.a INCS += -I$(TOP)/src/core -USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEMCORE), internal-nondebug) +USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/nondebug/core/alloc.o\ $(TOP)/src/nondebug/core/fs_posix.o\ @@ -400,10 +406,10 @@ OBJS +=\ $(TOP)/src/nondebug/core/util_posix.o INCS += -I$(TOP)/src/core -USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEMCORE), internal-debug) +USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/debug/core/alloc.o\ $(TOP)/src/debug/core/fs_posix.o\ @@ -418,7 +424,6 @@ OBJS +=\ $(TOP)/src/debug/core/util_posix.o INCS += -I$(TOP)/src/core -USE_LOG_PMEMCORE=y endif ifeq ($(LIBPMEM),y) @@ -526,7 +531,21 @@ endif ifeq ($(USE_LOG_PMEMCORE),y) CFLAGS += -DUSE_LOG_PMEMCORE -OBJS += $(TOP)/src/test/unittest/ut_log.o +endif + +ifeq ($(USE_LOG_PMEMOBJ),y) +CFLAGS += -DUSE_LOG_PMEMOBJ +endif + +# USE_LOG_PMEMCORE != y means the binary is built without directly linking with +# core units which are required by libut.a (ut_log.c to be exact). +# In case the binary is built with directly linking with core units it is +# assumed the following are among them already. +ifneq ($(USE_LOG_PMEMCORE),y) +OBJS += $(TOP)/src/debug/core/out.o +OBJS += $(TOP)/src/debug/core/log.o +OBJS += $(TOP)/src/debug/core/log_default.o +OBJS += $(TOP)/src/debug/core/util_posix.o endif ifneq ($(SANITIZE),) diff --git a/src/test/unittest/Makefile b/src/test/unittest/Makefile index 3d35431cc86..59e580e3ac4 100644 --- a/src/test/unittest/Makefile +++ b/src/test/unittest/Makefile @@ -16,10 +16,8 @@ vpath %.h $(TOP)/src/core TARGET_UT = libut.a OBJS_UT = ut.o ut_alloc.o ut_file.o ut_pthread.o ut_signal.o ut_backtrace.o\ - os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o - -TARGET_UT_PMEM2 = ut_pmem2.a -OBJS_UT_PMEM2 = ut_pmem2_config.o ut_pmem2_utils.o + os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o\ + ut_log.o CFLAGS = -I$(TOP)/src/include CFLAGS += -I$(TOP)/src/common @@ -79,14 +77,11 @@ CFLAGS += $(EXTRA_CFLAGS) LIBS += $(LIBUTIL) -all test: $(TARGET_UT) $(TARGET_UT_PMEM2) +all test: $(TARGET_UT) $(TARGET_UT): $(OBJS_UT) $(AR) rv $@ $(OBJS_UT) -$(TARGET_UT_PMEM2): $(OBJS_UT_PMEM2) - $(AR) rv $@ $(OBJS_UT_PMEM2) - ifneq ($(CSTYLEON),0) $(TARGET): unittest.htmp endif @@ -106,7 +101,7 @@ clean: $(RM) *.o core a.out unittest.htmp clobber: clean - $(RM) $(TARGET_UT) $(TARGET_UT_PMEM2) + $(RM) $(TARGET_UT) $(RM) -r .deps test check pcheck pycheck: all diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 0d2d654fbf7..0874996ccd7 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -89,6 +89,10 @@ extern "C" { #include "util.h" #include "log_internal.h" +#ifdef USE_LOG_PMEMOBJ +#include "libpmemobj/log.h" +#endif + int ut_get_uuid_str(char *); #define UT_MAX_ERR_MSG 128 #define UT_POOL_HDR_UUID_STR_LEN 37 /* uuid string length */ @@ -116,22 +120,31 @@ void ut_err(const char *file, int line, const char *func, const char *fmt, ...) __attribute__((format(printf, 4, 5))); -#ifdef USE_LOG_PMEMCORE void ut_log_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message_format, ...); -#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL); + +#ifdef USE_LOG_PMEMCORE +#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL) #else #define LOG_SET_PMEMCORE_FUNC #endif +#ifdef USE_LOG_PMEMOBJ +#define LOG_SET_PMEMOBJ_FUNC \ + pmemobj_log_set_function((pmemobj_log_function *)ut_log_function, NULL) +#else +#define LOG_SET_PMEMOBJ_FUNC +#endif + /* indicate the start of the test */ #define START(argc, argv, ...)\ do {\ ut_start(__FILE__, __LINE__, __func__, argc, argv,\ __VA_ARGS__);\ - LOG_SET_PMEMCORE_FUNC\ + LOG_SET_PMEMCORE_FUNC; \ + LOG_SET_PMEMOBJ_FUNC; \ } while (0) /* normal exit from test */ diff --git a/src/test/util_ravl/Makefile b/src/test/util_ravl/Makefile index 75050e36ee0..f7cfc19f936 100644 --- a/src/test/util_ravl/Makefile +++ b/src/test/util_ravl/Makefile @@ -7,7 +7,8 @@ # TARGET = util_ravl -OBJS = util_ravl.o alloc.o ravl.o out.o util_posix.o util.o log.o log_default.o +OBJS = util_ravl.o +LIBPMEMCORE = y INCS += -I$(TOP)/src/common include ../Makefile.inc From 6e8b584feea0d142586003fa307ba8e33b904959 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 22 Jan 2024 14:24:58 -0500 Subject: [PATCH 016/182] common: upload test logs Signed-off-by: Jan Michalski --- .github/workflows/ubuntu.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 3f81c6057de..d92ac089b9c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -41,3 +41,17 @@ jobs: env: TEST_BUILD: ${{ matrix.TEST_BUILD }} run: cd $WORKDIR && ./build-CI.sh + continue-on-error: true + id: build + + - name: Archive logs + if: steps.build.outcome != 'success' + uses: actions/upload-artifact@v4.2.0 + with: + name: logs-${{ matrix.TEST_BUILD }} + path: ${{env.HOST_WORKDIR}}/src/test/**/*.log + + - name: Exit code + run: | + [ "${{steps.build.outcome}}" != "success" ] && exit 1 + exit 0 From 7cd6cd4d9ae949866eb731cac3c05f43b1d173c2 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 22 Jan 2024 13:24:34 +0100 Subject: [PATCH 017/182] common: create pmem pool always with shutdown state Does not allow create pmem pool wihout support of unsafe shutdown counter. Disable unsafe shutdown counter for non-pmem tests. Disable unsafe shutdown counter for pmem tests in Dockers. Signed-off-by: Tomasz Gromadzki --- ChangeLog | 6 ++++++ src/common/ctl.c | 4 ++-- src/common/shutdown_state.c | 10 ++++------ src/test/ctl_cow/TEST0 | 4 ++-- src/test/ctl_cow/TEST3 | 4 ++-- src/test/obj_ctl_arenas/TEST8 | 4 ++-- src/test/obj_ctl_arenas/TEST9 | 4 ++-- src/test/obj_defrag/TESTS.py | 4 ++-- src/test/obj_defrag_advanced/TESTS.py | 4 ++-- src/test/obj_extend/TEST1 | 4 ++-- src/test/obj_pool_open_mt/TESTS.py | 4 ++-- src/test/obj_tx_user_data/TESTS.py | 4 ++-- src/test/pmem2_granularity_detection/TESTS.py | 4 ++-- src/test/pmempool_check/common.sh | 4 ++-- src/test/pmempool_feature/TEST14 | 4 ++-- src/test/pmempool_feature/TEST15 | 4 ++-- src/test/unittest/basetest.py | 10 +++++++++- src/test/unittest/unittest.sh | 13 +++++++++++-- utils/docker/build-CI.sh | 3 ++- 19 files changed, 60 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d3265fe76e..22693e1bb95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +XXX + * Version XXX + + This release + - does not allow opening pmem pool without unsafe shoutdown counter if not explicitly disabled + Mon Dec 4 2023 Oksana Sałyk * Version 2.0.1 diff --git a/src/common/ctl.c b/src/common/ctl.c index b86690fb814..28346eed1cc 100644 --- a/src/common/ctl.c +++ b/src/common/ctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * ctl.c -- implementation of the interface for examination and modification of @@ -13,7 +13,7 @@ #define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */ -#define CTL_STRING_QUERY_SEPARATOR ";" +#define CTL_STRING_QUERY_SEPARATOR ";:" #define CTL_NAME_VALUE_SEPARATOR "=" #define CTL_QUERY_NODE_SEPARATOR "." #define CTL_VALUE_ARG_SEPARATOR "," diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index 3a2bb11fa2e..bf75997a652 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2017-2020, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * shutdown_state.c -- unsafe shudown detection @@ -71,9 +71,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, int ret = pmem2_source_device_usc(src, &usc); - if (ret == PMEM2_E_NOSUPP) { - usc = 0; - } else if (ret != 0) { + if (ret != 0) { if (ret == -EPERM) { /* overwrite error message */ ERR( @@ -84,7 +82,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, } ret = pmem2_source_device_id(src, NULL, &len); - if (ret != PMEM2_E_NOSUPP && ret != 0) { + if (ret != 0) { ERR("cannot read uuid of %d", fd); goto err; } @@ -98,7 +96,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, } ret = pmem2_source_device_id(src, uid, &len); - if (ret != PMEM2_E_NOSUPP && ret != 0) { + if (ret != 0) { ERR("cannot read uuid of %d", fd); Free(uid); goto err; diff --git a/src/test/ctl_cow/TEST0 b/src/test/ctl_cow/TEST0 index 589e1831889..f1b2649fcc3 100755 --- a/src/test/ctl_cow/TEST0 +++ b/src/test/ctl_cow/TEST0 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019, Intel Corporation +# Copyright 2019-2024, Intel Corporation # # src/test/ctl_cow/TEST0 -- unit test which checks copy on write feature @@ -26,7 +26,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX create obj $DIR/$POOLSET POOL_BEFORE=`md5sum -b $DIR/$POOL` REPLICA_BEFORE=`md5sum -b $DIR/$REPLICA` -PMEMOBJ_CONF="${PMEMOBJ_CONF}copy_on_write.at_open=1" +PMEMOBJ_CONF="${PMEMOBJ_CONF};copy_on_write.at_open=1" expect_normal_exit ./ctl_cow$EXESUFFIX $DIR/$POOLSET obj diff --git a/src/test/ctl_cow/TEST3 b/src/test/ctl_cow/TEST3 index ab658fb282a..d673a2ca9b4 100755 --- a/src/test/ctl_cow/TEST3 +++ b/src/test/ctl_cow/TEST3 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019, Intel Corporation +# Copyright 2019-2024, Intel Corporation # # src/test/ctl_cow/TEST3 -- unit test which checks if opening pool located @@ -24,7 +24,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX create obj $POOLSET_DAX expect_normal_exit $PMEMPOOL$EXESUFFIX create -s 32MB obj $POOL -PMEMOBJ_CONF="copy_on_write.at_open=1;" +PMEMOBJ_CONF="${PMEMOBJ_CONF};copy_on_write.at_open=1;" # check if opening non-dax pool does not fail expect_normal_exit ./ctl_cow$EXESUFFIX $POOL dax diff --git a/src/test/obj_ctl_arenas/TEST8 b/src/test/obj_ctl_arenas/TEST8 index 8db2691513a..c913bbe760b 100755 --- a/src/test/obj_ctl_arenas/TEST8 +++ b/src/test/obj_ctl_arenas/TEST8 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2021, Intel Corporation +# Copyright 2021-2024, Intel Corporation # # src/test/obj_ctl_arenas/TEST8 -- test for global arena type assignment @@ -13,7 +13,7 @@ require_fs_type any setup -PMEMOBJ_CONF="heap.arenas_assignment_type=global"\ +PMEMOBJ_CONF="${PMEMOBJ_CONF};heap.arenas_assignment_type=global"\ expect_normal_exit ./obj_ctl_arenas$EXESUFFIX $DIR/testset1 p pass diff --git a/src/test/obj_ctl_arenas/TEST9 b/src/test/obj_ctl_arenas/TEST9 index 82900cb6de2..534ed084a61 100755 --- a/src/test/obj_ctl_arenas/TEST9 +++ b/src/test/obj_ctl_arenas/TEST9 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2021, Intel Corporation +# Copyright 2021-2024, Intel Corporation # # src/test/obj_ctl_arenas/TEST9 -- test for global arena type assignment @@ -13,7 +13,7 @@ require_fs_type any setup -PMEMOBJ_CONF="heap.arenas_assignment_type=thread"\ +PMEMOBJ_CONF="${PMEMOBJ_CONF};heap.arenas_assignment_type=thread"\ expect_normal_exit ./obj_ctl_arenas$EXESUFFIX $DIR/testset1 d pass diff --git a/src/test/obj_defrag/TESTS.py b/src/test/obj_defrag/TESTS.py index 42b6a8b23a4..2c7ca30dd38 100755 --- a/src/test/obj_defrag/TESTS.py +++ b/src/test/obj_defrag/TESTS.py @@ -1,13 +1,13 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2020, Intel Corporation +# Copyright 2019-2024, Intel Corporation # from os import path import testframework as t -class BASE(t.BaseTest): +class BASE(t.Test): test_type = t.Medium def run(self, ctx): diff --git a/src/test/obj_defrag_advanced/TESTS.py b/src/test/obj_defrag_advanced/TESTS.py index a33200c44dd..1ad4885e588 100755 --- a/src/test/obj_defrag_advanced/TESTS.py +++ b/src/test/obj_defrag_advanced/TESTS.py @@ -1,6 +1,6 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2020-2023, Intel Corporation +# Copyright 2020-2024, Intel Corporation # import testframework as t @@ -11,7 +11,7 @@ # These tests last too long under drd # Exceptions: test no. 2 @t.require_valgrind_disabled('drd') -class ObjDefragAdvanced(t.BaseTest): +class ObjDefragAdvanced(t.Test): test_type = t.Short max_nodes = 50 diff --git a/src/test/obj_extend/TEST1 b/src/test/obj_extend/TEST1 index 91815017da8..c5543002e47 100755 --- a/src/test/obj_extend/TEST1 +++ b/src/test/obj_extend/TEST1 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # src/test/obj_extend/TEST1 -- unit test for extending the pool @@ -22,7 +22,7 @@ create_poolset $DIR/testset2\ $RESVSIZE:$DIR/testdir21:d\ O SINGLEHDR -PMEMOBJ_CONF="heap.size.granularity=$GRANULARITY"\ +PMEMOBJ_CONF="${PMEMOBJ_CONF};heap.size.granularity=$GRANULARITY"\ expect_normal_exit ./obj_extend$EXESUFFIX $DIR/testset2 check diff --git a/src/test/obj_pool_open_mt/TESTS.py b/src/test/obj_pool_open_mt/TESTS.py index 64a73239695..e0670c69d80 100644 --- a/src/test/obj_pool_open_mt/TESTS.py +++ b/src/test/obj_pool_open_mt/TESTS.py @@ -1,12 +1,12 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2021, Intel Corporation +# Copyright 2021-2024, Intel Corporation # import testframework as t -class BASE(t.BaseTest): +class BASE(t.Test): test_type = t.Medium niter = 2 diff --git a/src/test/obj_tx_user_data/TESTS.py b/src/test/obj_tx_user_data/TESTS.py index 3c2e11d2d88..c9c4fc6bd77 100755 --- a/src/test/obj_tx_user_data/TESTS.py +++ b/src/test/obj_tx_user_data/TESTS.py @@ -1,13 +1,13 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2020, Intel Corporation +# Copyright 2019-2024, Intel Corporation # import testframework as t -class TEST0(t.BaseTest): +class TEST0(t.Test): test_type = t.Short def run(self, ctx): diff --git a/src/test/pmem2_granularity_detection/TESTS.py b/src/test/pmem2_granularity_detection/TESTS.py index e446154c5d2..453880ae434 100755 --- a/src/test/pmem2_granularity_detection/TESTS.py +++ b/src/test/pmem2_granularity_detection/TESTS.py @@ -1,6 +1,6 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2020, Intel Corporation +# Copyright 2019-2024, Intel Corporation # @@ -10,7 +10,7 @@ @g.require_granularity(g.ANY) -class PMEM2_CONFIG(t.BaseTest): +class PMEM2_CONFIG(t.Test): test_type = t.Short diff --git a/src/test/pmempool_check/common.sh b/src/test/pmempool_check/common.sh index f6ead577006..38e91d1d3da 100644 --- a/src/test/pmempool_check/common.sh +++ b/src/test/pmempool_check/common.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2020, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_check/common.sh -- checking pools helpers @@ -37,7 +37,7 @@ function pmempool_check_sds_init() { local conf="sds.at_create=1" fi - PMEMOBJ_CONF="${PMEMOBJ_CONF}$conf;" + PMEMOBJ_CONF="${PMEMOBJ_CONF};$conf;" expect_normal_exit $PMEMPOOL$EXESUFFIX create --layout=$LAYOUT obj $POOLSET } diff --git a/src/test/pmempool_feature/TEST14 b/src/test/pmempool_feature/TEST14 index 2dbcf0c5cd0..c96bb490d4e 100755 --- a/src/test/pmempool_feature/TEST14 +++ b/src/test/pmempool_feature/TEST14 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_feature/TEST14 -- unit test for SHUTDOWN_STATE + ctl @@ -15,7 +15,7 @@ require_sds $PMEMPOOL$EXESUFFIX setup . ./common.sh -PMEMOBJ_CONF="${PMEMOBJ_CONF}sds.at_create=0" +PMEMOBJ_CONF="${PMEMOBJ_CONF};sds.at_create=0" pmempool_feature_create_poolset "no_dax_device" pmempool_feature_query SHUTDOWN_STATE normal diff --git a/src/test/pmempool_feature/TEST15 b/src/test/pmempool_feature/TEST15 index 61b8e490b91..01aa8d10dba 100755 --- a/src/test/pmempool_feature/TEST15 +++ b/src/test/pmempool_feature/TEST15 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_feature/TEST15 -- unit test for SHUTDOWN_STATE + ctl @@ -17,7 +17,7 @@ setup require_usc_permission $DIR -PMEMOBJ_CONF="${PMEMOBJ_CONF}sds.at_create=1" +PMEMOBJ_CONF="${PMEMOBJ_CONF};sds.at_create=1" pmempool_feature_create_poolset "no_dax_device" pmempool_feature_query SHUTDOWN_STATE normal diff --git a/src/test/unittest/basetest.py b/src/test/unittest/basetest.py index da514e73abd..560aa8bb8fa 100644 --- a/src/test/unittest/basetest.py +++ b/src/test/unittest/basetest.py @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2023, Intel Corporation +# Copyright 2019-2024, Intel Corporation """Base tests class and its functionalities. @@ -66,6 +66,7 @@ def clean(self, ctx): from configurator import Configurator from consts import LIBS_LIST, ROOTDIR +import granularity as g import futils import test_types import shutil @@ -339,6 +340,13 @@ def setup(self, ctx): self.env.update(self._get_utenv()) self.env.update(self._debug_log_env()) self.ctx.add_env(self.env) + # disable shutdown state control for non-pmem (Page granularity) + if isinstance(ctx.granularity, g.Page): + pmemobj_conf = os.getenv('PMEMOBJ_CONF', default='') + if 'sds.at_create=0' not in pmemobj_conf: + env = dict() + env['PMEMOBJ_CONF'] = 'sds.at_create=0' + self.ctx.add_env(env) self.remove_log_files() diff --git a/src/test/unittest/unittest.sh b/src/test/unittest/unittest.sh index 00cef128631..b9a8fcfdfdf 100644 --- a/src/test/unittest/unittest.sh +++ b/src/test/unittest/unittest.sh @@ -1,6 +1,6 @@ # # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # Copyright (c) 2016, Microsoft Corporation. All rights reserved. # @@ -1650,6 +1650,10 @@ function require_sds() { msg "$UNITTEST_NAME: SKIP not compiled with support for shutdown state" exit 0 fi + if [[ $PMEMOBJ_CONF = *'sds.at_create=0'* ]]; then + msg "$UNITTEST_NAME: SKIP the shutdown state has been disabled by the PMEMOBJ_CONF environment variable" + exit 0 + fi return 0 } @@ -1859,7 +1863,12 @@ function setup() { lock_devdax fi - export PMEMOBJ_CONF="fallocate.at_create=0;" + export PMEMOBJ_CONF="${PMEMOBJ_CONF};fallocate.at_create=0" + + # disable SDS for non-pmem tests + if [ "$REAL_FS" = "non-pmem" ]; then + export PMEMOBJ_CONF="${PMEMOBJ_CONF};sds.at_create=0" + fi } # diff --git a/utils/docker/build-CI.sh b/utils/docker/build-CI.sh index 670411fd61c..e253f2f8dda 100755 --- a/utils/docker/build-CI.sh +++ b/utils/docker/build-CI.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2023, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # build-CI.sh - runs a Docker container from a Docker image with environment @@ -100,6 +100,7 @@ docker run --rm --name=$containerName -i \ --env CI_RUN=$CI_RUN \ --env SRC_CHECKERS=$SRC_CHECKERS \ --env BLACKLIST_FILE=$BLACKLIST_FILE \ + --env PMEMOBJ_CONF="sds.at_create=0" \ $ndctl_enable \ --tmpfs /tmp:rw,relatime,suid,dev,exec,size=6G \ -v $HOST_WORKDIR:$WORKDIR \ From 9c6cd78fd2597c8c7673712e263fe6456af33dca Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 24 Jan 2024 14:21:56 +0100 Subject: [PATCH 018/182] common: Preserve PMEMOBJ_CONF variable in Debian package build. https://manpages.ubuntu.com/manpages/xenial/en/man1/debuild.1.html#environment%20variables --- utils/build-dpkg.sh | 8 ++++++-- utils/build-rpm.sh | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/utils/build-dpkg.sh b/utils/build-dpkg.sh index a895c85a0f8..00304c4154f 100755 --- a/utils/build-dpkg.sh +++ b/utils/build-dpkg.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # build-dpkg.sh - Script for building deb packages @@ -610,13 +610,17 @@ echo "" >> debian/changelog tail -n1 $CHANGELOG_TMP >> debian/changelog rm $CHANGELOG_TMP -# This is our first release but we do +# Required for PMEMOBJ tests to not attempt creating an SDS which will fail +# in the simulated test environment. +PMEMOBJ_CONF='sds.at_create=0' + debuild --preserve-envvar=EXTRA_CFLAGS_RELEASE \ --preserve-envvar=EXTRA_CFLAGS_DEBUG \ --preserve-envvar=EXTRA_CFLAGS \ --preserve-envvar=EXTRA_CXXFLAGS \ --preserve-envvar=EXTRA_LDFLAGS \ --preserve-envvar=NDCTL_ENABLE \ + --preserve-envvar=PMEMOBJ_CONF \ -us -uc -b cd $OLD_DIR diff --git a/utils/build-rpm.sh b/utils/build-rpm.sh index 6a878a4244b..c0c4fbeed61 100755 --- a/utils/build-rpm.sh +++ b/utils/build-rpm.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # build-rpm.sh - Script for building rpm packages @@ -238,6 +238,10 @@ mkdir -v BUILD SPECS echo "opts: ${RPMBUILD_OPTS[@]}" +# Required for PMEMOBJ tests to not attempt creating an SDS which will fail +# in the simulated test environment. +PMEMOBJ_CONF='sds.at_create=0' + rpmbuild --define "_topdir `pwd`"\ --define "_rpmdir ${OUT_DIR}"\ --define "_srcrpmdir ${OUT_DIR}"\ From 1193bdf36828515e3e3430a6eace49b8e571a223 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 24 Jan 2024 21:11:01 +0100 Subject: [PATCH 019/182] common: fix coverity issue 1969782 Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 8ecbe9531e0..7ee2208152e 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -112,18 +112,18 @@ core_log_set_function(core_log_function *log_function, void *context) return 0; #else uintptr_t core_log_function_old = Core_log_function; - if (__sync_bool_compare_and_swap(&Core_log_function, + void *context_old = Core_log_function_context; + if (!__sync_bool_compare_and_swap(&Core_log_function, core_log_function_old, (uintptr_t)log_function)) - return 0; - else return EAGAIN; - - void *context_old = Core_log_function_context; if (__sync_bool_compare_and_swap(&Core_log_function_context, context_old, context)) return 0; - else - return EAGAIN; + + __sync_bool_compare_and_swap(&Core_log_function, + (uintptr_t)log_function, core_log_function_old); + return EAGAIN; + #endif /* ATOMIC_OPERATIONS_SUPPORTED */ } From d41608d7e83c6f7cb2ec5dfb14b64552f8eb0e98 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 25 Jan 2024 10:44:30 -0500 Subject: [PATCH 020/182] common: skip checking changelog for master and stable-* branches xD Signed-off-by: Jan Michalski --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 09eb864b837..6a5fc9edd42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,10 @@ jobs: fetch-depth: 50 - name: Check changelog + # Skip for pmem/pmdk/master and stable-* branches + if: | + !(github.repository == 'pmem/pmdk' && + (github.ref_name == 'master' || startsWith(github.ref_name, 'stable-'))) uses: Zomzog/changelog-checker@v1.3.0 with: fileName: ChangeLog From c2db02a236939a95ad1e016cbfc5095dd6c7f773 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 12:41:19 +0100 Subject: [PATCH 021/182] common: Removing the annoying test directory suffix Removing the Braille test directory suffix to simplify manual test reproduction. Signed-off-by: Tomasz Gromadzki --- src/test/unittest/unittest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unittest/unittest.sh b/src/test/unittest/unittest.sh index b9a8fcfdfdf..95f46348e99 100644 --- a/src/test/unittest/unittest.sh +++ b/src/test/unittest/unittest.sh @@ -126,7 +126,7 @@ fi [ "$CHECK_POOL" ] || CHECK_POOL=0 [ "$VERBOSE" ] || VERBOSE=0 [ "$TEST_LABEL" ] || TEST_LABEL= -[ -n "${SUFFIX+x}" ] || SUFFIX="😘⠏⠍⠙⠅ɗPMDKӜ⥺🙋" +[ -n "${SUFFIX+x}" ] || SUFFIX="" export UNITTEST_LOG_LEVEL GREP TEST FS BUILD CHECK_TYPE CHECK_POOL VERBOSE SUFFIX From 4f9cf63c5381a18340ae52d609eb2e0a9fed78dd Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 19 Jan 2024 12:13:02 +0100 Subject: [PATCH 022/182] common: replace ERR("!...", ... ) by ERR_W_ERRNO(...) ERR() macro uses CORE_LOG_ERROR to push mesages to ouputs Introduce to separate macros to report errors w/ and w/o errno. test for CORE_LOG_ERROR_WITH_ERRNO Signed-off-by: Tomasz Gromadzki --- src/common/bad_blocks.c | 8 +-- src/common/ctl.c | 10 ++-- src/common/file.c | 26 +++++----- src/common/file_posix.c | 4 +- src/common/mmap.c | 18 +++---- src/common/mmap_posix.c | 6 +-- src/common/set.c | 70 ++++++++++++++------------- src/common/set_badblocks.c | 4 +- src/common/shutdown_state.c | 2 +- src/common/vec.h | 4 +- src/common/vecq.h | 4 +- src/core/log_internal.h | 5 +- src/core/out.c | 13 ++++- src/core/out.h | 13 +++++ src/core/ravl.c | 6 +-- src/core/sys_util.h | 4 +- src/core/util_posix.c | 10 ++-- src/libpmem/pmem.c | 10 ++-- src/libpmem2/auto_flush_linux.c | 12 ++--- src/libpmem2/badblocks.c | 4 +- src/libpmem2/badblocks_ndctl.c | 10 ++-- src/libpmem2/deep_flush_linux.c | 4 +- src/libpmem2/extent_linux.c | 8 +-- src/libpmem2/map_posix.c | 18 +++---- src/libpmem2/mcsafe_ops_posix.c | 10 ++-- src/libpmem2/numa_ndctl.c | 4 +- src/libpmem2/persist_posix.c | 4 +- src/libpmem2/pmem2_utils.c | 8 +-- src/libpmem2/pmem2_utils_linux.c | 6 +-- src/libpmem2/pmem2_utils_ndctl.c | 6 +-- src/libpmem2/region_namespace_ndctl.c | 18 +++---- src/libpmem2/source_posix.c | 8 +-- src/libpmem2/usc_ndctl.c | 6 +-- src/libpmem2/vm_reservation_posix.c | 8 +-- src/libpmemobj/critnib.c | 6 +-- src/libpmemobj/heap.c | 4 +- src/libpmemobj/lane.c | 8 +-- src/libpmemobj/list.c | 4 +- src/libpmemobj/memops.c | 8 +-- src/libpmemobj/obj.c | 14 +++--- src/libpmemobj/stats.c | 4 +- src/libpmemobj/tx.c | 10 ++-- src/libpmempool/check_util.c | 8 +-- src/libpmempool/libpmempool.c | 8 +-- src/libpmempool/pool.c | 10 ++-- src/libpmempool/replica.c | 55 +++++++++++++-------- src/libpmempool/transform.c | 6 +-- src/test/Makefile | 3 +- src/test/log_errno/.gitignore | 1 + src/test/log_errno/Makefile | 13 +++++ src/test/log_errno/TEST0 | 20 ++++++++ src/test/log_errno/err0.log.match | 1 + src/test/log_errno/log_errno.c | 28 +++++++++++ src/test/out_err/out_err.c | 6 +-- src/test/pmem2_perror/pmem2_perror.c | 6 +-- 55 files changed, 338 insertions(+), 236 deletions(-) create mode 100644 src/test/log_errno/.gitignore create mode 100644 src/test/log_errno/Makefile create mode 100755 src/test/log_errno/TEST0 create mode 100644 src/test/log_errno/err0.log.match create mode 100644 src/test/log_errno/log_errno.c diff --git a/src/common/bad_blocks.c b/src/common/bad_blocks.c index 28bf2843a26..8657060bfdc 100644 --- a/src/common/bad_blocks.c +++ b/src/common/bad_blocks.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * bad_blocks.c - implementation of the bad block API using libpmem2 library @@ -59,7 +59,7 @@ badblocks_get(const char *file, struct badblocks *bbs) int fd = os_open(file, O_RDONLY); if (fd == -1) { - ERR("!open %s", file); + ERR_W_ERRNO("open %s", file); return -1; } @@ -138,7 +138,7 @@ badblocks_clear(const char *file, struct badblocks *bbs) int fd = os_open(file, O_RDWR); if (fd == -1) { - ERR("!open %s", file); + ERR_W_ERRNO("open %s", file); return -1; } @@ -196,7 +196,7 @@ badblocks_clear_all(const char *file) int fd = os_open(file, O_RDWR); if (fd == -1) { - ERR("!open %s", file); + ERR_W_ERRNO("open %s", file); return -1; } diff --git a/src/common/ctl.c b/src/common/ctl.c index 28346eed1cc..4252437d8a9 100644 --- a/src/common/ctl.c +++ b/src/common/ctl.c @@ -128,7 +128,7 @@ ctl_parse_args(const struct ctl_argument *arg_proto, char *arg) char *dest_arg = Malloc(arg_proto->dest_size); if (dest_arg == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return NULL; } @@ -138,7 +138,7 @@ ctl_parse_args(const struct ctl_argument *arg_proto, char *arg) p->parser != NULL; ++p) { ASSERT(p->dest_offset + p->dest_size <= arg_proto->dest_size); if (arg_sep == NULL) { - ERR("!strtok_r"); + ERR_W_ERRNO("strtok_r"); goto error_parsing; } @@ -396,7 +396,7 @@ ctl_load_config_from_string(struct ctl *ctl, void *ctx, const char *cfg_string) char *buf = Strdup(cfg_string); if (buf == NULL) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); return -1; } @@ -441,7 +441,7 @@ ctl_load_config_from_file(struct ctl *ctl, void *ctx, const char *cfg_file) char *buf = Zalloc((size_t)fsize + 1); /* +1 for NULL-termination */ if (buf == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); goto error_file_parse; } @@ -475,7 +475,7 @@ ctl_new(void) { struct ctl *c = Zalloc(sizeof(struct ctl)); if (c == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); return NULL; } diff --git a/src/common/file.c b/src/common/file.c index c378a6f6845..5263d79cba5 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * file.c -- file utilities @@ -37,7 +37,7 @@ util_file_exists(const char *path) return 1; if (errno != ENOENT) { - ERR("!os_access \"%s\"", path); + ERR_W_ERRNO("os_access \"%s\"", path); return -1; } @@ -91,7 +91,7 @@ util_fd_get_type(int fd) os_stat_t st; if (os_fstat(fd, &st) < 0) { - ERR("!fstat"); + ERR_W_ERRNO("fstat"); return OTHER_ERROR; } @@ -123,7 +123,7 @@ util_file_get_type(const char *path) os_stat_t st; if (os_stat(path, &st) < 0) { - ERR("!stat"); + ERR_W_ERRNO("stat"); return OTHER_ERROR; } @@ -140,7 +140,7 @@ util_file_get_size(const char *path) int fd = os_open(path, O_RDONLY); if (fd < 0) { - ERR("!open"); + ERR_W_ERRNO("open"); return -1; } @@ -203,7 +203,7 @@ util_file_map_whole(const char *path) int flags = O_RDWR; if ((fd = os_open(path, flags)) < 0) { - ERR("!open \"%s\"", path); + ERR_W_ERRNO("open \"%s\"", path); return NULL; } @@ -241,7 +241,7 @@ util_file_zero(const char *path, os_off_t off, size_t len) int flags = O_RDWR; if ((fd = os_open(path, flags)) < 0) { - ERR("!open \"%s\"", path); + ERR_W_ERRNO("open \"%s\"", path); return -1; } @@ -423,17 +423,17 @@ util_file_create(const char *path, size_t size, size_t minsize) * initialization completes. */ if ((fd = os_open(path, flags, mode)) < 0) { - ERR("!open \"%s\"", path); + ERR_W_ERRNO("open \"%s\"", path); return -1; } if ((errno = os_posix_fallocate(fd, 0, (os_off_t)size)) != 0) { - ERR("!posix_fallocate \"%s\", %zu", path, size); + ERR_W_ERRNO("posix_fallocate \"%s\", %zu", path, size); goto err; } if (os_flock(fd, OS_LOCK_EX | OS_LOCK_NB) < 0) { - ERR("!flock \"%s\"", path); + ERR_W_ERRNO("flock \"%s\"", path); goto err; } @@ -462,12 +462,12 @@ util_file_open(const char *path, size_t *size, size_t minsize, int flags) int fd; if ((fd = os_open(path, flags)) < 0) { - ERR("!open \"%s\"", path); + ERR_W_ERRNO("open \"%s\"", path); return -1; } if (os_flock(fd, OS_LOCK_EX | OS_LOCK_NB) < 0) { - ERR("!flock \"%s\"", path); + ERR_W_ERRNO("flock \"%s\"", path); (void) os_close(fd); return -1; } @@ -500,7 +500,7 @@ util_file_open(const char *path, size_t *size, size_t minsize, int flags) err: oerrno = errno; if (os_flock(fd, OS_LOCK_UN)) - ERR("!flock unlock"); + ERR_W_ERRNO("flock unlock"); (void) os_close(fd); errno = oerrno; return -1; diff --git a/src/common/file_posix.c b/src/common/file_posix.c index 60dbcfe5976..2a1dc19870d 100644 --- a/src/common/file_posix.c +++ b/src/common/file_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * file_posix.c -- Posix versions of file APIs @@ -155,7 +155,7 @@ util_ddax_region_find(const char *path, unsigned *region_id) int ret; if (os_stat(path, &st) < 0) { - ERR("!stat \"%s\"", path); + ERR_W_ERRNO("stat \"%s\"", path); return -1; } diff --git a/src/common/mmap.c b/src/common/mmap.c index bfb99565f99..f7d9b535b5e 100644 --- a/src/common/mmap.c +++ b/src/common/mmap.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * mmap.c -- mmap utilities @@ -101,7 +101,7 @@ util_map(int fd, os_off_t off, size_t len, int flags, int rdonly, int proto = rdonly ? PROT_READ : PROT_READ|PROT_WRITE; base = util_map_sync(addr, len, proto, flags, fd, off, map_sync); if (base == MAP_FAILED) { - ERR("!mmap %zu bytes", len); + ERR_W_ERRNO("mmap %zu bytes", len); return NULL; } @@ -123,7 +123,7 @@ util_unmap(void *addr, size_t len) int retval = munmap(addr, len); if (retval < 0) - ERR("!munmap"); + ERR_W_ERRNO("munmap"); return retval; } @@ -152,7 +152,7 @@ util_range_ro(void *addr, size_t len) uptr = (uintptr_t)addr & ~(Pagesize - 1); if ((retval = mprotect((void *)uptr, len, PROT_READ)) < 0) - ERR("!mprotect: PROT_READ"); + ERR_W_ERRNO("mprotect: PROT_READ"); return retval; } @@ -181,7 +181,7 @@ util_range_rw(void *addr, size_t len) uptr = (uintptr_t)addr & ~(Pagesize - 1); if ((retval = mprotect((void *)uptr, len, PROT_READ|PROT_WRITE)) < 0) - ERR("!mprotect: PROT_READ|PROT_WRITE"); + ERR_W_ERRNO("mprotect: PROT_READ|PROT_WRITE"); return retval; } @@ -210,7 +210,7 @@ util_range_none(void *addr, size_t len) uptr = (uintptr_t)addr & ~(Pagesize - 1); if ((retval = mprotect((void *)uptr, len, PROT_NONE)) < 0) - ERR("!mprotect: PROT_NONE"); + ERR_W_ERRNO("mprotect: PROT_NONE"); return retval; } @@ -294,7 +294,7 @@ util_range_register(const void *addr, size_t len, const char *path, struct map_tracker *mt; mt = Malloc(sizeof(struct map_tracker)); if (mt == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return -1; } @@ -357,7 +357,7 @@ util_range_split(struct map_tracker *mt, const void *addrp, const void *endp) /* new mapping at the beginning */ mtb = Malloc(sizeof(struct map_tracker)); if (mtb == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); goto err; } @@ -372,7 +372,7 @@ util_range_split(struct map_tracker *mt, const void *addrp, const void *endp) /* new mapping at the end */ mte = Malloc(sizeof(struct map_tracker)); if (mte == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); goto err; } diff --git a/src/common/mmap_posix.c b/src/common/mmap_posix.c index 29d45a19e41..7a594b277e1 100644 --- a/src/common/mmap_posix.c +++ b/src/common/mmap_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * mmap_posix.c -- memory-mapped files for Posix @@ -40,7 +40,7 @@ util_map_hint_unused(void *minaddr, size_t len, size_t align) FILE *fp; if ((fp = os_fopen(Mmap_mapfile, "r")) == NULL) { - ERR("!%s", Mmap_mapfile); + ERR_W_ERRNO("%s", Mmap_mapfile); return MAP_FAILED; } @@ -138,7 +138,7 @@ util_map_hint(size_t len, size_t req_align) char *addr = mmap(NULL, len + align, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) { - ERR("!mmap MAP_ANONYMOUS"); + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); } else { LOG(4, "system choice %p", addr); hint_addr = (char *)roundup((uintptr_t)addr, align); diff --git a/src/common/set.c b/src/common/set.c index 1cd908eb14c..33db82002ba 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * @@ -191,7 +191,7 @@ util_map_hdr(struct pool_set_part *part, int flags, int rdonly) void *hdrp = util_map_sync(addr, hdrsize, prot, flags, part->fd, 0, &part->hdr_map_sync); if (hdrp == MAP_FAILED) { - ERR("!mmap: %s", part->path); + ERR_W_ERRNO("mmap: %s", part->path); return -1; } @@ -248,7 +248,7 @@ util_map_part(struct pool_set_part *part, void *addr, size_t size, void *addrp = util_map_sync(addr, size, prot, flags, part->fd, (os_off_t)offset, &part->map_sync); if (addrp == MAP_FAILED) { - ERR("!mmap: %s", part->path); + ERR_W_ERRNO("mmap: %s", part->path); return -1; } @@ -279,7 +279,7 @@ util_unmap_part(struct pool_set_part *part) LOG(4, "munmap: addr %p size %zu", part->addr, part->size); VALGRIND_REMOVE_PMEM_MAPPING(part->addr, part->size); if (munmap(part->addr, part->size) != 0) { - ERR("!munmap: %s", part->path); + ERR_W_ERRNO("munmap: %s", part->path); } part->addr = NULL; @@ -365,7 +365,8 @@ util_replica_close_local(struct pool_replica *rep, unsigned repn, LOG(4, "unlink %s", rep->part[p].path); int olderrno = errno; if (util_unlink(rep->part[p].path) && errno != ENOENT) { - ERR("!unlink %s failed (part %u, replica %u)", + ERR_W_ERRNO( + "unlink %s failed (part %u, replica %u)", rep->part[p].path, p, repn); return -1; } @@ -417,7 +418,8 @@ util_poolset_chmod(struct pool_set *set, mode_t mode) os_stat_t stbuf; if (os_fstat(part->fd, &stbuf) != 0) { - ERR("!fstat %d %s", part->fd, part->path); + ERR_W_ERRNO("fstat %d %s", part->fd, + part->path); return -1; } @@ -429,7 +431,7 @@ util_poolset_chmod(struct pool_set *set, mode_t mode) } if (os_chmod(part->path, mode)) { - ERR("!chmod %u/%u/%s", r, p, part->path); + ERR_W_ERRNO("chmod %u/%u/%s", r, p, part->path); return -1; } } @@ -511,7 +513,7 @@ parser_read_line(char *line, size_t *size, char **path) *path = Strdup(path_str); if (!(*path)) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); return PARSER_OUT_OF_MEMORY; } @@ -615,7 +617,7 @@ parser_read_replica(char *line, char **node_addr, char **pool_desc) *pool_desc = Strdup(desc_str); if (!(*node_addr) || !(*pool_desc)) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); if (*node_addr) Free(*node_addr); if (*pool_desc) @@ -641,7 +643,7 @@ util_replica_reserve(struct pool_replica **repp, unsigned n) rep = Realloc(rep, sizeof(struct pool_replica) + (n) * sizeof(struct pool_set_part)); if (rep == NULL) { - ERR("!Realloc"); + ERR_W_ERRNO("Realloc"); return -1; } @@ -832,7 +834,7 @@ util_parse_add_replica(struct pool_set **setp) set = Realloc(set, sizeof(struct pool_set) + (set->nreplicas + 1) * sizeof(struct pool_replica *)); if (set == NULL) { - ERR("!Realloc"); + ERR_W_ERRNO("Realloc"); return -1; } *setp = set; @@ -840,7 +842,7 @@ util_parse_add_replica(struct pool_set **setp) struct pool_replica *rep; rep = Zalloc(sizeof(struct pool_replica)); if (rep == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); return -1; } @@ -1017,7 +1019,7 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory) struct fs *f = fs_new(directory); if (f == NULL) { - ERR("!fs_new: \"%s\"", directory); + ERR_W_ERRNO("fs_new: \"%s\"", directory); return -1; } @@ -1050,7 +1052,7 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory) } if ((path = Strdup(entry->path)) == NULL) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); goto err; } @@ -1128,7 +1130,7 @@ util_poolset_directories_load(struct pool_set *set) if (VEC_SIZE(&set->replica[r]->directory) == 0) { errno = ENOENT; - ERR("!no directories in replica"); + ERR_W_ERRNO("no directories in replica"); return -1; } @@ -1145,7 +1147,7 @@ util_poolset_directories_load(struct pool_set *set) size_t path_len = strlen(d->path) + PMEM_FILE_MAX_LEN; if ((p->path = Malloc(path_len)) == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return -1; } @@ -1185,19 +1187,19 @@ util_poolset_parse(struct pool_set **setp, const char *path, int fd) int oerrno; if (os_lseek(fd, 0, SEEK_SET) != 0) { - ERR("!lseek %d", fd); + ERR_W_ERRNO("lseek %d", fd); return -1; } fd = dup(fd); if (fd < 0) { - ERR("!dup"); + ERR_W_ERRNO("dup"); return -1; } /* associate a stream with the file descriptor */ if ((fs = os_fdopen(fd, "r")) == NULL) { - ERR("!fdopen %d", fd); + ERR_W_ERRNO("fdopen %d", fd); os_close(fd); return -1; } @@ -1208,20 +1210,20 @@ util_poolset_parse(struct pool_set **setp, const char *path, int fd) /* read the first line */ line = util_readline(fs); if (line == NULL) { - ERR("!Reading poolset file"); + ERR_W_ERRNO("Reading poolset file"); goto err; } nlines++; set = Zalloc(sizeof(struct pool_set)); if (set == NULL) { - ERR("!Malloc for pool set"); + ERR_W_ERRNO("Malloc for pool set"); goto err; } set->path = Strdup(path); if (set->path == NULL) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); goto err; } @@ -1394,13 +1396,13 @@ util_poolset_single(const char *path, size_t filesize, int create, set = Zalloc(sizeof(struct pool_set) + sizeof(struct pool_replica *)); if (set == NULL) { - ERR("!Malloc for pool set"); + ERR_W_ERRNO("Malloc for pool set"); return NULL; } set->path = Strdup(path); if (set->path == NULL) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); Free(set); return NULL; } @@ -1409,7 +1411,7 @@ util_poolset_single(const char *path, size_t filesize, int create, rep = Zalloc(sizeof(struct pool_replica) + sizeof(struct pool_set_part)); if (rep == NULL) { - ERR("!Malloc for pool set replica"); + ERR_W_ERRNO("Malloc for pool set replica"); Free(set->path); Free(set); return NULL; @@ -1492,8 +1494,8 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) (os_off_t)size); if (ret != 0) { errno = ret; - ERR("!posix_fallocate \"%s\", %zu", part->path, - size); + ERR_W_ERRNO("posix_fallocate \"%s\", %zu", + part->path, size); return -1; } } @@ -1561,7 +1563,7 @@ util_poolset_read(struct pool_set **setp, const char *path) int fd; if ((fd = os_open(path, O_RDONLY)) < 0) { - ERR("!open: path \"%s\"", path); + ERR_W_ERRNO("open: path \"%s\"", path); return -1; } @@ -1620,7 +1622,7 @@ util_poolset_create_set(struct pool_set **setp, const char *path, */ ret = (int)read(fd, signature, POOLSET_HDR_SIG_LEN); if (ret < 0) { - ERR("!read %d", fd); + ERR_W_ERRNO("read %d", fd); goto err; } } @@ -1743,7 +1745,7 @@ util_header_create(struct pool_set *set, unsigned repidx, unsigned partidx, os_stat_t stbuf; if (os_fstat(rep->part[partidx].fd, &stbuf) != 0) { - ERR("!fstat"); + ERR_W_ERRNO("fstat"); return -1; } ASSERT(stbuf.st_ctime); @@ -2193,7 +2195,7 @@ util_poolset_append_new_part(struct pool_set *set, size_t size) path_len = strlen(d->path) + PMEM_FILE_MAX_LEN; if ((path = Malloc(path_len)) == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); goto err_part_init; } @@ -2980,7 +2982,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, if ((*setp)->replica[0]->nparts == 0) { errno = ENOENT; - ERR("!no parts in replicas"); + ERR_W_ERRNO("no parts in replicas"); goto err_poolset_free; } @@ -3111,7 +3113,7 @@ util_is_poolset_file(const char *path) rd += (size_t)sret; } while (sret > 0); if (sret < 0) { - ERR("!read"); + ERR_W_ERRNO("read"); ret = -1; goto out; } else if (rd != sizeof(signature)) { @@ -3175,7 +3177,7 @@ util_poolset_foreach_part(const char *path, int fd = os_open(path, O_RDONLY); if (fd < 0) { - ERR("!open: path \"%s\"", path); + ERR_W_ERRNO("open: path \"%s\"", path); return -1; } diff --git a/src/common/set_badblocks.c b/src/common/set_badblocks.c index f2bfac805da..0eb04a2b46d 100644 --- a/src/common/set_badblocks.c +++ b/src/common/set_badblocks.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2023, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * set_badblocks.c - common part of implementation of bad blocks API @@ -164,7 +164,7 @@ badblocks_recovery_file_alloc(const char *file, unsigned rep, unsigned part) path = Malloc(len_path + 1); if (path == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return NULL; } diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index bf75997a652..9c831dad340 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -91,7 +91,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, uid = Zalloc(len); if (uid == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); goto err; } diff --git a/src/common/vec.h b/src/common/vec.h index c1ba60c9539..4ef4cc24047 100644 --- a/src/common/vec.h +++ b/src/common/vec.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2020, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * vec.h -- vector interface @@ -59,7 +59,7 @@ vec_reserve(void *vec, size_t ncapacity, size_t s) VEC(vvec, void) *vecp = (struct vvec *)vec; void *tbuf = Realloc(vecp->buffer, s * ncap); if (tbuf == NULL) { - ERR("!Realloc"); + ERR_W_ERRNO("Realloc"); return -1; } vecp->buffer = tbuf; diff --git a/src/common/vecq.h b/src/common/vecq.h index 98c77b615ff..cface8ba93d 100644 --- a/src/common/vecq.h +++ b/src/common/vecq.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * vecq.h -- vector queue (FIFO) interface @@ -65,7 +65,7 @@ realloc_set(void **buf, size_t s) { void *tbuf = Realloc(*buf, s); if (tbuf == NULL) { - ERR("!Realloc"); + ERR_W_ERRNO("Realloc"); return -1; } *buf = tbuf; diff --git a/src/core/log_internal.h b/src/core/log_internal.h index cc78e3bcd80..b8b01b8f8c0 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -143,11 +143,12 @@ void core_log_default_function(void *context, enum core_log_level level, CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) /* + * Replacement for ERR("!*") macro (w/ errno). * 'f' stands here for 'function' or 'format' where the latter may accept * additional arguments. */ -#define LOG_ERROR_WITH_ERRNO(e, f, ...) \ - LOG_ERROR(f " failed: %s", ##__VA_ARGS__, strerror(abs(e))); +#define CORE_LOG_ERROR_WITH_ERRNO(f, ...) \ + CORE_LOG_ERROR(f ": %s", ##__VA_ARGS__, strerror(errno)) static inline int core_log_error_translate(int ret) diff --git a/src/core/out.c b/src/core/out.c index a8fedead9fb..0f23df85ef4 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -371,6 +371,7 @@ out_error(const char *file, int line, const char *func, int oerrno = errno; unsigned long olast_error = 0; unsigned cc = 0; + unsigned print_msg = 1; int ret; const char *sep = ""; char errstr[UTIL_MAX_ERR_MSG] = ""; @@ -383,6 +384,14 @@ out_error(const char *file, int line, const char *func, } if (fmt) { + /* + * '*' at the begining means 'do not push message to output' + */ + if (*fmt == '*') { + print_msg = 0; + fmt++; + } + if (*fmt == '!') { sep = ": "; fmt++; @@ -407,7 +416,7 @@ out_error(const char *file, int line, const char *func, } #ifdef DEBUG - if (Log_level >= 1) { + if (Log_level >= 1 && print_msg) { char buf[MAXPRINT]; cc = 0; @@ -436,7 +445,7 @@ out_error(const char *file, int line, const char *func, } #else /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, suffix); + SUPPRESS_UNUSED(file, line, func, suffix, print_msg); #endif end: diff --git a/src/core/out.h b/src/core/out.h index 5fe9daebfd8..22d9b520a2f 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -13,6 +13,7 @@ #include #include "util.h" +#include "log_internal.h" #ifdef __cplusplus extern "C" { @@ -186,6 +187,18 @@ out_fatal_abort(const char *file, int line, const char *func, #define ERR(...)\ out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define ERR_W_ERRNO(f, ...)\ + do {\ + ERR("*!" f, ##__VA_ARGS__);\ + CORE_LOG_ERROR_WITH_ERRNO(f, ##__VA_ARGS__);\ + } while (0) + +#define ERR_WO_ERRNO(f, ...)\ + do {\ + ERR("*" f, ##__VA_ARGS__);\ + CORE_LOG_ERROR(f, ##__VA_ARGS__);\ + } while (0) + void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version); diff --git a/src/core/ravl.c b/src/core/ravl.c index a316a60310d..b0537e653ae 100644 --- a/src/core/ravl.c +++ b/src/core/ravl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2021, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * ravl.c -- implementation of a RAVL tree @@ -46,7 +46,7 @@ ravl_new_sized(ravl_compare *compare, size_t data_size) { struct ravl *r = Malloc(sizeof(*r)); if (r == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return r; } @@ -162,7 +162,7 @@ ravl_new_node(struct ravl *ravl, ravl_constr constr, const void *arg) { struct ravl_node *n = Malloc(sizeof(*n) + ravl->data_size); if (n == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return n; } diff --git a/src/core/sys_util.h b/src/core/sys_util.h index fbe0c10d632..58a4fb0208e 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2016-2020, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * sys_util.h -- internal utility wrappers around system functions @@ -178,7 +178,7 @@ util_spin_init(os_spinlock_t *lock, int pshared) int tmp = os_spin_init(lock, pshared); if (tmp) { errno = tmp; - ERR("!os_spin_init"); + ERR_W_ERRNO("os_spin_init"); } return tmp; } diff --git a/src/core/util_posix.c b/src/core/util_posix.c index 4b23400c178..b3bd924f34a 100644 --- a/src/core/util_posix.c +++ b/src/core/util_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * util_posix.c -- Abstraction layer for misc utilities (Posix implementation) @@ -56,7 +56,7 @@ util_compare_file_inodes(const char *path1, const char *path2) struct stat sb1, sb2; if (os_stat(path1, &sb1)) { if (errno != ENOENT) { - ERR("!stat failed for %s", path1); + ERR_W_ERRNO("stat failed for %s", path1); return -1; } LOG(1, "stat failed for %s", path1); @@ -66,7 +66,7 @@ util_compare_file_inodes(const char *path1, const char *path2) if (os_stat(path2, &sb2)) { if (errno != ENOENT) { - ERR("!stat failed for %s", path2); + ERR_W_ERRNO("stat failed for %s", path2); return -1; } LOG(1, "stat failed for %s", path2); @@ -106,7 +106,7 @@ util_tmpfile_mkstemp(const char *dir, const char *templ) umask(prev_umask); if (fd < 0) { - ERR("!mkstemp"); + ERR_W_ERRNO("mkstemp"); goto err; } @@ -145,7 +145,7 @@ util_tmpfile(const char *dir, const char *templ, int flags) if (fd >= 0) return fd; if (errno != EOPNOTSUPP) { - ERR("!open"); + ERR_W_ERRNO("open"); return -1; } #endif diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 9257e9f8d7d..e53aad79eed 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * pmem.c -- pmem entry points for libpmem @@ -277,7 +277,7 @@ pmem_msync(const void *addr, size_t len) int ret; if ((ret = msync((void *)uptr, len, MS_SYNC)) < 0) - ERR("!msync"); + ERR_W_ERRNO("msync"); VALGRIND_DO_ENABLE_ERROR_REPORTING; @@ -480,7 +480,7 @@ pmem_map_fileU(const char *path, size_t len, int flags, } } else { if ((fd = os_open(path, open_flags, mode)) < 0) { - ERR("!open %s", path); + ERR_W_ERRNO("open %s", path); return NULL; } if ((flags & PMEM_FILE_CREATE) && (flags & PMEM_FILE_EXCL)) @@ -493,13 +493,13 @@ pmem_map_fileU(const char *path, size_t len, int flags, * (May either extend or truncate existing file.) */ if (os_ftruncate(fd, (os_off_t)len) != 0) { - ERR("!ftruncate"); + ERR_W_ERRNO("ftruncate"); goto err; } if ((flags & PMEM_FILE_SPARSE) == 0) { if ((errno = os_posix_fallocate(fd, 0, (os_off_t)len)) != 0) { - ERR("!posix_fallocate"); + ERR_W_ERRNO("posix_fallocate"); goto err; } } diff --git a/src/libpmem2/auto_flush_linux.c b/src/libpmem2/auto_flush_linux.c index ca12e348b4e..ad02af43cc7 100644 --- a/src/libpmem2/auto_flush_linux.c +++ b/src/libpmem2/auto_flush_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * auto_flush_linux.c -- Linux auto flush detection @@ -41,7 +41,7 @@ check_cpu_cache(const char *domain_path) DOMAIN_VALUE_LEN); if (len < 0) { - ERR("!read(%d, %p, %d)", domain_fd, + ERR_W_ERRNO("read(%d, %p, %d)", domain_fd, domain_value, DOMAIN_VALUE_LEN); cpu_cache = -1; goto end; @@ -53,7 +53,7 @@ check_cpu_cache(const char *domain_path) cpu_cache = -1; goto end; } else if (domain_value[len - 1] != '\n') { - ERR("!read(%d, %p, %d) invalid format", + ERR_W_ERRNO("read(%d, %p, %d) invalid format", domain_fd, domain_value, DOMAIN_VALUE_LEN); cpu_cache = -1; @@ -92,7 +92,7 @@ check_domain_in_region(const char *region_path) reg = fs_new(region_path); if (reg == NULL) { - ERR("!fs_new: \"%s\"", region_path); + ERR_W_ERRNO("fs_new: \"%s\"", region_path); cpu_cache = -1; goto end; } @@ -112,7 +112,7 @@ check_domain_in_region(const char *region_path) int ret = util_snprintf(domain_path, PATH_MAX, "%s/"PERSISTENCE_DOMAIN, region_path); if (ret < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); cpu_cache = -1; goto end; } @@ -153,7 +153,7 @@ pmem2_auto_flush(void) struct fs *dev = fs_new(device_path); if (dev == NULL) { - ERR("!fs_new: \"%s\"", device_path); + ERR_W_ERRNO("fs_new: \"%s\"", device_path); return -1; } diff --git a/src/libpmem2/badblocks.c b/src/libpmem2/badblocks.c index e126f3e2955..c702d4f65cd 100644 --- a/src/libpmem2/badblocks.c +++ b/src/libpmem2/badblocks.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * badblocks.c -- implementation of common bad blocks API @@ -19,7 +19,7 @@ badblocks_new(void) struct badblocks *bbs = Zalloc(sizeof(struct badblocks)); if (bbs == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); } return bbs; diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index d9e988d46a2..0da18172711 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2017-2022, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * badblocks_ndctl.c -- implementation of DIMMs API based on the ndctl library @@ -161,7 +161,7 @@ badblocks_get_namespace_bounds(struct ndctl_region *region, unsigned long long region_offset = ndctl_region_get_resource(region); if (region_offset == ULLONG_MAX) { - ERR("!cannot read offset of the region"); + ERR_W_ERRNO("cannot read offset of the region"); return PMEM2_E_ERRNO; } @@ -272,7 +272,7 @@ pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } @@ -703,13 +703,13 @@ pmem2_badblock_clear_fsdax(int fd, const struct pmem2_badblock *bb) /* deallocate bad blocks */ if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, length)) { - ERR("!fallocate"); + ERR_W_ERRNO("fallocate"); return PMEM2_E_ERRNO; } /* allocate new blocks */ if (fallocate(fd, FALLOC_FL_KEEP_SIZE, offset, length)) { - ERR("!fallocate"); + ERR_W_ERRNO("fallocate"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/deep_flush_linux.c b/src/libpmem2/deep_flush_linux.c index 567174b4253..ff4d547bcb9 100644 --- a/src/libpmem2/deep_flush_linux.c +++ b/src/libpmem2/deep_flush_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * deep_flush_linux.c -- deep_flush functionality @@ -34,7 +34,7 @@ pmem2_deep_flush_write(unsigned region_id) if (util_snprintf(deep_flush_path, PATH_MAX, "/sys/bus/nd/devices/region%u/deep_flush", region_id) < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/extent_linux.c b/src/libpmem2/extent_linux.c index 6491e67b6fb..1d1806f54d5 100644 --- a/src/libpmem2/extent_linux.c +++ b/src/libpmem2/extent_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * extent_linux.c - implementation of the linux fs extent query API @@ -37,7 +37,7 @@ pmem2_extents_create_get(int fd, struct extents **exts) os_stat_t st; if (os_fstat(fd, &st) < 0) { - ERR("!fstat %d", fd); + ERR_W_ERRNO("fstat %d", fd); return PMEM2_E_ERRNO; } @@ -80,7 +80,7 @@ pmem2_extents_create_get(int fd, struct extents **exts) fmap->fm_mapped_extents = 0; if (ioctl(fd, FS_IOC_FIEMAP, fmap) != 0) { - ERR("!fiemap ioctl() for fd=%d failed", fd); + ERR_W_ERRNO("fiemap ioctl() for fd=%d failed", fd); ret = PMEM2_E_ERRNO; goto error_free; } @@ -99,7 +99,7 @@ pmem2_extents_create_get(int fd, struct extents **exts) fmap->fm_mapped_extents = 0; if (ioctl(fd, FS_IOC_FIEMAP, fmap) != 0) { - ERR("!fiemap ioctl() for fd=%d failed", fd); + ERR_W_ERRNO("fiemap ioctl() for fd=%d failed", fd); ret = PMEM2_E_ERRNO; goto error_free; } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 9e232fc2614..3298f13badb 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * map_posix.c -- pmem2_map (POSIX) @@ -129,10 +129,10 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (daddr == MAP_FAILED) { if (errno == EEXIST) { - ERR("!mmap MAP_FIXED_NOREPLACE"); + ERR_W_ERRNO("mmap MAP_FIXED_NOREPLACE"); return PMEM2_E_MAPPING_EXISTS; } - ERR("!mmap MAP_ANONYMOUS"); + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); return PMEM2_E_ERRNO; } @@ -170,7 +170,7 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, const size_t before = (uintptr_t)(*reserv) - (uintptr_t)daddr; if (before) { if (munmap(daddr, before)) { - ERR("!munmap"); + ERR_W_ERRNO("munmap"); return PMEM2_E_ERRNO; } } @@ -180,7 +180,7 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, void *end = (void *)((uintptr_t)(*reserv) + (uintptr_t)*reslen); if (after) if (munmap(end, after)) { - ERR("!munmap"); + ERR_W_ERRNO("munmap"); return PMEM2_E_ERRNO; } @@ -212,7 +212,7 @@ file_map(void *reserv, size_t len, int proto, int flags, if (flags & MAP_PRIVATE) { *base = mmap(reserv, len, proto, flags, fd, offset); if (*base == MAP_FAILED) { - ERR("!mmap"); + ERR_W_ERRNO("mmap"); return PMEM2_E_ERRNO; } LOG(4, "mmap with MAP_PRIVATE succeeded"); @@ -240,7 +240,7 @@ file_map(void *reserv, size_t len, int proto, int flags, } } - ERR("!mmap"); + ERR_W_ERRNO("mmap"); return PMEM2_E_ERRNO; } @@ -252,7 +252,7 @@ unmap(void *addr, size_t len) { int retval = munmap(addr, len); if (retval < 0) { - ERR("!munmap"); + ERR_W_ERRNO("munmap"); return PMEM2_E_ERRNO; } @@ -275,7 +275,7 @@ vm_reservation_mend(struct pmem2_vm_reservation *rsv, void *addr, size_t size) char *daddr = mmap(addr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); if (daddr == MAP_FAILED) { - ERR("!mmap MAP_ANONYMOUS"); + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/mcsafe_ops_posix.c b/src/libpmem2/mcsafe_ops_posix.c index 4fe76d7cca8..acc082829b4 100644 --- a/src/libpmem2/mcsafe_ops_posix.c +++ b/src/libpmem2/mcsafe_ops_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2021-2022, Intel Corporation */ +/* Copyright 2021-2024, Intel Corporation */ #include #include @@ -51,7 +51,7 @@ mcsafe_op_reg_read(struct pmem2_source *src, void *buf, size_t size, return PMEM2_E_IO_FAIL; } - ERR("!pread"); + ERR_W_ERRNO("pread"); return PMEM2_E_ERRNO; } @@ -77,7 +77,7 @@ mcsafe_op_reg_write(struct pmem2_source *src, void *buf, size_t size, return PMEM2_E_IO_FAIL; } - ERR("!pwrite"); + ERR_W_ERRNO("pwrite"); return PMEM2_E_ERRNO; } @@ -126,7 +126,7 @@ handle_sigbus_execute_mcsafe_op(struct pmem2_source *src, void *buf, struct sigaction old_act; /* register a custom signal handler */ if (sigaction(SIGBUS, &custom_act, &old_act) == -1) { - ERR("!sigaction"); + ERR_W_ERRNO("sigaction"); return PMEM2_E_ERRNO; } @@ -149,7 +149,7 @@ handle_sigbus_execute_mcsafe_op(struct pmem2_source *src, void *buf, /* restore the previous signal handler */ if (sigaction(SIGBUS, &old_act, NULL) == -1) { - ERR("!sigaction"); + ERR_W_ERRNO("sigaction"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/numa_ndctl.c b/src/libpmem2/numa_ndctl.c index 80d3f508008..549d2eedced 100644 --- a/src/libpmem2/numa_ndctl.c +++ b/src/libpmem2/numa_ndctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020, Intel Corporation */ +/* Copyright 2024, Intel Corporation */ #include #include @@ -33,7 +33,7 @@ pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/persist_posix.c b/src/libpmem2/persist_posix.c index d36f0969ce4..52938a482d4 100644 --- a/src/libpmem2/persist_posix.c +++ b/src/libpmem2/persist_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2021, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * persist_posix.c -- POSIX-specific part of persist implementation @@ -37,7 +37,7 @@ pmem2_flush_file_buffers_os(struct pmem2_map *map, const void *addr, size_t len, ret = msync((void *)addr, len, MS_SYNC); if (ret < 0) { - ERR("!msync"); + ERR_W_ERRNO("msync"); } else { /* full flush */ VALGRIND_DO_PERSIST((uintptr_t)addr, len); diff --git a/src/libpmem2/pmem2_utils.c b/src/libpmem2/pmem2_utils.c index 6f06b1b6236..3daf76929a1 100644 --- a/src/libpmem2/pmem2_utils.c +++ b/src/libpmem2/pmem2_utils.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * pmem2_utils.c -- libpmem2 utilities functions @@ -22,7 +22,7 @@ pmem2_malloc(size_t size, int *err) *err = 0; if (ptr == NULL) { - ERR("!malloc(%zu)", size); + ERR_W_ERRNO("malloc(%zu)", size); *err = PMEM2_E_ERRNO; } @@ -39,7 +39,7 @@ pmem2_zalloc(size_t size, int *err) *err = 0; if (ptr == NULL) { - ERR("!malloc(%zu)", size); + ERR_W_ERRNO("malloc(%zu)", size); *err = PMEM2_E_ERRNO; } @@ -56,7 +56,7 @@ pmem2_realloc(void *ptr, size_t size, int *err) *err = 0; if (newptr == NULL) { - ERR("!realloc(%zu)", size); + ERR_W_ERRNO("realloc(%zu)", size); *err = PMEM2_E_ERRNO; } diff --git a/src/libpmem2/pmem2_utils_linux.c b/src/libpmem2/pmem2_utils_linux.c index 9352ea51f69..377220cd2dd 100644 --- a/src/libpmem2/pmem2_utils_linux.c +++ b/src/libpmem2/pmem2_utils_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -50,7 +50,7 @@ pmem2_get_type_from_stat(const os_stat_t *st, enum pmem2_file_type *type) os_minor(st->st_rdev)); if (ret < 0) { /* impossible */ - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); ASSERTinfo(0, "snprintf failed"); return PMEM2_E_ERRNO; } @@ -60,7 +60,7 @@ pmem2_get_type_from_stat(const os_stat_t *st, enum pmem2_file_type *type) char npath[PATH_MAX]; char *rpath = realpath(spath, npath); if (rpath == NULL) { - ERR("!realpath \"%s\"", spath); + ERR_W_ERRNO("realpath \"%s\"", spath); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/pmem2_utils_ndctl.c b/src/libpmem2/pmem2_utils_ndctl.c index fed82306378..c20540f7af1 100644 --- a/src/libpmem2/pmem2_utils_ndctl.c +++ b/src/libpmem2/pmem2_utils_ndctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ #include #include @@ -24,7 +24,7 @@ pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } @@ -63,7 +63,7 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/region_namespace_ndctl.c b/src/libpmem2/region_namespace_ndctl.c index 675f82d61cd..b8fb71955b6 100644 --- a/src/libpmem2/region_namespace_ndctl.c +++ b/src/libpmem2/region_namespace_ndctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2023, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * region_namespace_ndctl.c -- common ndctl functions @@ -39,12 +39,12 @@ pmem2_devdax_match(dev_t st_rdev, const char *devname) os_stat_t stat; if (util_snprintf(path, PATH_MAX, "/dev/%s", devname) < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); return PMEM2_E_ERRNO; } if (os_stat(path, &stat)) { - ERR("!stat %s", path); + ERR_W_ERRNO("stat %s", path); return PMEM2_E_ERRNO; } @@ -77,26 +77,26 @@ pmem2_fsdax_match(dev_t st_dev, const char *devname) char dev_id[BUFF_LENGTH]; if (util_snprintf(path, PATH_MAX, "/sys/block/%s/dev", devname) < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); return PMEM2_E_ERRNO; } if (util_snprintf(dev_id, BUFF_LENGTH, "%d:%d", major(st_dev), minor(st_dev)) < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); return PMEM2_E_ERRNO; } int fd = os_open(path, O_RDONLY); if (fd < 0) { - ERR("!open \"%s\"", path); + ERR_W_ERRNO("open \"%s\"", path); return PMEM2_E_ERRNO; } char buff[BUFF_LENGTH]; ssize_t nread = read(fd, buff, BUFF_LENGTH); if (nread < 0) { - ERR("!read"); + ERR_W_ERRNO("read"); int oerrno = errno; /* save the errno */ os_close(fd); errno = oerrno; @@ -170,7 +170,7 @@ pmem2_region_namespace(struct ndctl_ctx *ctx, struct daxctl_region *dax_region; dax_region = ndctl_dax_get_daxctl_region(dax); if (!dax_region) { - ERR("!cannot find dax region"); + ERR_W_ERRNO("cannot find dax region"); return PMEM2_E_DAX_REGION_NOT_FOUND; } struct daxctl_dev *dev; @@ -239,7 +239,7 @@ pmem2_get_region_id(const struct pmem2_source *src, unsigned *region_id) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 92f61860977..88474c6e580 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2020, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ #include #include @@ -28,7 +28,7 @@ pmem2_source_from_fd(struct pmem2_source **src, int fd) int flags = fcntl(fd, F_GETFL); if (flags == -1) { - ERR("!fcntl"); + ERR_W_ERRNO("fcntl"); if (errno == EBADF) return PMEM2_E_INVALID_FILE_HANDLE; return PMEM2_E_ERRNO; @@ -50,7 +50,7 @@ pmem2_source_from_fd(struct pmem2_source **src, int fd) os_stat_t st; if (os_fstat(fd, &st) < 0) { - ERR("!fstat"); + ERR_W_ERRNO("fstat"); if (errno == EBADF) return PMEM2_E_INVALID_FILE_HANDLE; return PMEM2_E_ERRNO; @@ -102,7 +102,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) os_stat_t st; if (os_fstat(src->value.fd, &st) < 0) { - ERR("!fstat"); + ERR_W_ERRNO("fstat"); if (errno == EBADF) return PMEM2_E_INVALID_FILE_HANDLE; return PMEM2_E_ERRNO; diff --git a/src/libpmem2/usc_ndctl.c b/src/libpmem2/usc_ndctl.c index db658c7e10f..081797b73f9 100644 --- a/src/libpmem2/usc_ndctl.c +++ b/src/libpmem2/usc_ndctl.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2022, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * usc_ndctl.c -- pmem2 usc function for platforms using ndctl @@ -38,7 +38,7 @@ pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } @@ -96,7 +96,7 @@ pmem2_source_device_id(const struct pmem2_source *src, char *id, size_t *len) errno = ndctl_new(&ctx) * (-1); if (errno) { - ERR("!ndctl_new"); + ERR_W_ERRNO("ndctl_new"); return PMEM2_E_ERRNO; } diff --git a/src/libpmem2/vm_reservation_posix.c b/src/libpmem2/vm_reservation_posix.c index 1a59c52eced..3c6cd513c9c 100644 --- a/src/libpmem2/vm_reservation_posix.c +++ b/src/libpmem2/vm_reservation_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2021, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * vm_reservation_posix.c -- implementation of virtual memory @@ -75,10 +75,10 @@ vm_reservation_reserve_memory(void *addr, size_t size, void **raddr, MAP_PRIVATE | MAP_ANONYMOUS | mmap_flag, -1, 0); if (mmap_addr == MAP_FAILED) { if (errno == EEXIST) { - ERR("!mmap MAP_FIXED_NOREPLACE"); + ERR_W_ERRNO("mmap MAP_FIXED_NOREPLACE"); return PMEM2_E_MAPPING_EXISTS; } - ERR("!mmap MAP_ANONYMOUS"); + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); return PMEM2_E_ERRNO; } @@ -109,7 +109,7 @@ int vm_reservation_release_memory(void *addr, size_t size) { if (munmap(addr, size)) { - ERR("!munmap"); + ERR_W_ERRNO("munmap"); return PMEM2_E_ERRNO; } diff --git a/src/libpmemobj/critnib.c b/src/libpmemobj/critnib.c index ff13479c90f..601ae0a5c8e 100644 --- a/src/libpmemobj/critnib.c +++ b/src/libpmemobj/critnib.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2021, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * critnib.c -- implementation of critnib tree @@ -276,7 +276,7 @@ alloc_node(struct critnib *__restrict c) if (!c->deleted_node) { struct critnib_node *n = Malloc(sizeof(struct critnib_node)); if (n == NULL) - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return n; } @@ -313,7 +313,7 @@ alloc_leaf(struct critnib *__restrict c) if (!c->deleted_leaf) { struct critnib_leaf *k = Malloc(sizeof(struct critnib_leaf)); if (k == NULL) - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return k; } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 926fb77e8d2..9dfcd2799af 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * heap.c -- heap implementation @@ -184,7 +184,7 @@ heap_arena_new(struct palloc_heap *heap, int automatic) struct arena *arena = Zalloc(sizeof(struct arena)); if (arena == NULL) { - ERR("!heap: arena malloc error"); + ERR_W_ERRNO("heap: arena malloc error"); return NULL; } arena->nthreads = 0; diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 9d98649262a..26350bea714 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * lane.c -- lane implementation @@ -264,7 +264,7 @@ lane_boot(PMEMobjpool *pop) pop->lanes_desc.lane = Malloc(sizeof(struct lane) * pop->nlanes); if (pop->lanes_desc.lane == NULL) { err = ENOMEM; - ERR("!Malloc of volatile lanes"); + ERR_W_ERRNO("Malloc of volatile lanes"); goto error_lanes_malloc; } @@ -273,7 +273,7 @@ lane_boot(PMEMobjpool *pop) pop->lanes_desc.lane_locks = Zalloc(sizeof(*pop->lanes_desc.lane_locks) * pop->nlanes); if (pop->lanes_desc.lane_locks == NULL) { - ERR("!Malloc for lane locks"); + ERR_W_ERRNO("Malloc for lane locks"); goto error_locks_malloc; } @@ -286,7 +286,7 @@ lane_boot(PMEMobjpool *pop) struct lane_layout *layout = lane_get_layout(pop, i); if ((err = lane_init(pop, &pop->lanes_desc.lane[i], layout))) { - ERR("!lane_init"); + ERR_W_ERRNO("lane_init"); goto error_lane_init; } } diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index 9eb1b7070f6..bb93f004fb1 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2019, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * list.c -- implementation of persistent atomic lists module @@ -468,7 +468,7 @@ list_insert_new(PMEMobjpool *pop, struct pobj_action reserved; if (palloc_reserve(&pop->heap, size, constructor, arg, type_num, 0, 0, 0, &reserved) != 0) { - ERR("!palloc_reserve"); + ERR_W_ERRNO("palloc_reserve"); ret = -1; goto err_pmalloc; } diff --git a/src/libpmemobj/memops.c b/src/libpmemobj/memops.c index fc5fe7d227a..c69146db037 100644 --- a/src/libpmemobj/memops.c +++ b/src/libpmemobj/memops.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2022, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * memops.c -- aggregated memory operations helper implementation @@ -87,7 +87,7 @@ operation_log_transient_init(struct operation_log *log) struct ulog *src = Zalloc(sizeof(struct ulog) + ULOG_BASE_SIZE); if (src == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); return -1; } @@ -113,7 +113,7 @@ operation_log_persistent_init(struct operation_log *log, struct ulog *src = Zalloc(sizeof(struct ulog) + ULOG_BASE_SIZE); if (src == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); return -1; } @@ -174,7 +174,7 @@ operation_new(struct ulog *ulog, size_t ulog_base_nbytes, { struct operation_context *ctx = Zalloc(sizeof(*ctx)); if (ctx == NULL) { - ERR("!Zalloc"); + ERR_W_ERRNO("Zalloc"); goto error_ctx_alloc; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 8b23a54db1c..7caaedaf534 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * obj.c -- transactional object store implementation @@ -660,12 +660,12 @@ obj_runtime_init_common(PMEMobjpool *pop) LOG(3, "pop %p", pop); if ((errno = lane_boot(pop)) != 0) { - ERR("!lane_boot"); + ERR_W_ERRNO("lane_boot"); return errno; } if ((errno = lane_recover_and_section_boot(pop)) != 0) { - ERR("!lane_recover_and_section_boot"); + ERR_W_ERRNO("lane_recover_and_section_boot"); return errno; } @@ -723,7 +723,7 @@ obj_descr_create(PMEMobjpool *pop, const char *layout, size_t poolsize) errno = palloc_init((char *)pop + pop->heap_offset, heap_size, &pop->heap_size, p_ops); if (errno != 0) { - ERR("!palloc_init"); + ERR_W_ERRNO("palloc_init"); return -1; } @@ -962,12 +962,12 @@ obj_runtime_init(PMEMobjpool *pop, int rdonly, int boot, unsigned nlanes) obj_pool_init(); if ((errno = critnib_insert(pools_ht, pop->uuid_lo, pop))) { - ERR("!critnib_insert to pools_ht"); + ERR_W_ERRNO("critnib_insert to pools_ht"); goto err_critnib_insert; } if ((errno = critnib_insert(pools_tree, (uint64_t)pop, pop))) { - ERR("!critnib_insert to pools_tree"); + ERR_W_ERRNO("critnib_insert to pools_tree"); goto err_tree_insert; } } @@ -982,7 +982,7 @@ obj_runtime_init(PMEMobjpool *pop, int rdonly, int boot, unsigned nlanes) operation_user_buffer_range_cmp, sizeof(struct user_buffer_def)); if (pop->ulog_user_buffers.map == NULL) { - ERR("!ravl_new_sized"); + ERR_W_ERRNO("ravl_new_sized"); goto err_user_buffers_map; } pop->ulog_user_buffers.verify = 0; diff --git a/src/libpmemobj/stats.c b/src/libpmemobj/stats.c index 423c94ee31a..8799c4830c6 100644 --- a/src/libpmemobj/stats.c +++ b/src/libpmemobj/stats.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2017-2021, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * stats.c -- implementation of statistics @@ -117,7 +117,7 @@ stats_new(PMEMobjpool *pop) { struct stats *s = Malloc(sizeof(*s)); if (s == NULL) { - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); return NULL; } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index b119230dac9..3ab1ca2f145 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2021, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * tx.c -- transactions implementation @@ -495,7 +495,7 @@ add_to_tx_and_lock(struct tx *tx, enum pobj_tx_param type, void *lock) retval = pmemobj_mutex_lock(tx->pop, txl->lock.mutex); if (retval) { - ERR("!pmemobj_mutex_lock"); + ERR_W_ERRNO("pmemobj_mutex_lock"); goto err; } break; @@ -504,7 +504,7 @@ add_to_tx_and_lock(struct tx *tx, enum pobj_tx_param type, void *lock) retval = pmemobj_rwlock_wrlock(tx->pop, txl->lock.rwlock); if (retval) { - ERR("!pmemobj_rwlock_wrlock"); + ERR_W_ERRNO("pmemobj_rwlock_wrlock"); goto err; } break; @@ -771,7 +771,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) struct tx_data *txd = Malloc(sizeof(*txd)); if (txd == NULL) { err = errno; - ERR("!Malloc"); + ERR_W_ERRNO("Malloc"); goto err_abort; } @@ -940,7 +940,7 @@ obj_tx_abort(int errnum, int user) tx->last_errnum = errnum; errno = errnum; if (user) - ERR("!explicit transaction abort"); + ERR_W_ERRNO("explicit transaction abort"); /* ONABORT */ obj_tx_callback(tx); diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 0715d6f5acb..4e39bdd37c5 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * check_util.c -- check utility functions @@ -72,7 +72,7 @@ check_data_alloc(void) struct check_data *data = calloc(1, sizeof(*data)); if (data == NULL) { - ERR("!calloc"); + ERR_W_ERRNO("calloc"); return NULL; } @@ -329,7 +329,7 @@ check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type, int ret = util_snprintf(st->msg + p, MAX_MSG_STR_SIZE - (size_t)p, ": %s", buff); if (ret < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); status_release(st); return -1; } @@ -603,7 +603,7 @@ check_get_time_str(time_t time) else { int ret = util_snprintf(str_buff, STR_MAX, "unknown"); if (ret < 0) { - ERR("!snprintf"); + ERR_W_ERRNO("snprintf"); return ""; } } diff --git a/src/libpmempool/libpmempool.c b/src/libpmempool/libpmempool.c index e8031a2a164..a842f519e69 100644 --- a/src/libpmempool/libpmempool.c +++ b/src/libpmempool/libpmempool.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * libpmempool.c -- entry points for libpmempool @@ -171,7 +171,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) PMEMpoolcheck *ppc = calloc(1, sizeof(*ppc)); if (ppc == NULL) { - ERR("!calloc"); + ERR_W_ERRNO("calloc"); return NULL; } @@ -179,7 +179,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) memcpy(&ppc->args, args, sizeof(ppc->args)); ppc->path = strdup(args->path); if (!ppc->path) { - ERR("!strdup"); + ERR_W_ERRNO("strdup"); goto error_path_malloc; } ppc->args.path = ppc->path; @@ -187,7 +187,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) if (args->backup_path != NULL) { ppc->backup_path = strdup(args->backup_path); if (!ppc->backup_path) { - ERR("!strdup"); + ERR_W_ERRNO("strdup"); goto error_backup_path_malloc; } ppc->args.backup_path = ppc->backup_path; diff --git a/src/libpmempool/pool.c b/src/libpmempool/pool.c index b96d659a5ad..68a340565dc 100644 --- a/src/libpmempool/pool.c +++ b/src/libpmempool/pool.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * pool.c -- pool processing functions @@ -206,7 +206,7 @@ pool_params_parse(const PMEMpoolcheck *ppc, struct pool_params *params, */ if (mprotect(addr, set->replica[0]->repsize, PROT_READ) < 0) { - ERR("!mprotect"); + ERR_W_ERRNO("mprotect"); goto out_unmap; } params->is_dev_dax = set->replica[0]->part[0].is_dev_dax; @@ -362,7 +362,7 @@ pool_data_alloc(PMEMpoolcheck *ppc) struct pool_data *pool = calloc(1, sizeof(*pool)); if (!pool) { - ERR("!calloc"); + ERR_W_ERRNO("calloc"); return NULL; } @@ -374,7 +374,7 @@ pool_data_alloc(PMEMpoolcheck *ppc) if (prv && pool->params.is_dev_dax) { errno = ENOTSUP; - ERR("!cannot perform a dry run on dax device"); + ERR_W_ERRNO("cannot perform a dry run on dax device"); goto error; } @@ -554,7 +554,7 @@ pool_set_part_copy(struct pool_set_part *dpart, struct pool_set_part *spart, os_stat_t stat_buf; if (os_fstat(spart->fd, &stat_buf)) { - ERR("!util_stat"); + ERR_W_ERRNO("util_stat"); return -1; } diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index 6b51c3dd66d..94ab1d38893 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * replica.c -- groups all commands for replica manipulation @@ -139,7 +139,7 @@ replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn, } if (type == TYPE_NORMAL && util_unlink(part->path)) { - ERR("!removing part %u from replica %u failed", + ERR_W_ERRNO("removing part %u from replica %u failed", partn, repn); return -1; } @@ -165,7 +165,7 @@ create_replica_health_status(struct pool_set *set, unsigned repn) replica_hs = Zalloc(sizeof(struct replica_health_status) + nparts * sizeof(struct part_health_status)); if (replica_hs == NULL) { - ERR("!Zalloc for replica health status"); + ERR_W_ERRNO("Zalloc for replica health status"); return NULL; } @@ -187,7 +187,8 @@ replica_part_remove_recovery_file(struct part_health_status *phs) return 0; if (os_unlink(phs->recovery_file_name) < 0) { - ERR("!removing the bad block recovery file failed -- '%s'", + ERR_W_ERRNO( + "removing the bad block recovery file failed -- '%s'", phs->recovery_file_name); return -1; } @@ -256,7 +257,7 @@ replica_create_poolset_health_status(struct pool_set *set, set_hs = Zalloc(sizeof(struct poolset_health_status) + nreplicas * sizeof(struct replica_health_status *)); if (set_hs == NULL) { - ERR("!Zalloc for poolset health state"); + ERR_W_ERRNO("Zalloc for poolset health state"); return -1; } set_hs->nreplicas = nreplicas; @@ -673,14 +674,16 @@ replica_badblocks_recovery_file_save(struct part_health_status *part_hs) int fd = os_open(path, O_WRONLY | O_TRUNC); if (fd < 0) { - ERR("!opening bad block recovery file failed -- '%s'", path); + ERR_W_ERRNO( + "opening bad block recovery file failed -- '%s'", + path); return -1; } FILE *recovery_file_name = os_fdopen(fd, "w"); if (recovery_file_name == NULL) { - ERR( - "!opening a file stream for bad block recovery file failed -- '%s'", + ERR_W_ERRNO( + "opening a file stream for bad block recovery file failed -- '%s'", path); os_close(fd); return -1; @@ -694,12 +697,16 @@ replica_badblocks_recovery_file_save(struct part_health_status *part_hs) } if (fflush(recovery_file_name) == EOF) { - ERR("!flushing bad block recovery file failed -- '%s'", path); + ERR_W_ERRNO( + "flushing bad block recovery file failed -- '%s'", + path); goto exit_error; } if (os_fsync(fd) < 0) { - ERR("!syncing bad block recovery file failed -- '%s'", path); + ERR_W_ERRNO( + "syncing bad block recovery file failed -- '%s'", + path); goto exit_error; } @@ -707,12 +714,16 @@ replica_badblocks_recovery_file_save(struct part_health_status *part_hs) fprintf(recovery_file_name, "0 0\n"); if (fflush(recovery_file_name) == EOF) { - ERR("!flushing bad block recovery file failed -- '%s'", path); + ERR_W_ERRNO( + "flushing bad block recovery file failed -- '%s'", + path); goto exit_error; } if (os_fsync(fd) < 0) { - ERR("!syncing bad block recovery file failed -- '%s'", path); + ERR_W_ERRNO( + "syncing bad block recovery file failed -- '%s'", + path); goto exit_error; } @@ -745,7 +756,8 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) FILE *recovery_file = os_fopen(path, "r"); if (!recovery_file) { - ERR("!opening the recovery file for reading failed -- '%s'", + ERR_W_ERRNO( + "opening the recovery file for reading failed -- '%s'", path); return -1; } @@ -755,7 +767,8 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) do { if (fscanf(recovery_file, "%zu %zu\n", &bb.offset, &bb.length) < 2) { - LOG(1, "incomplete bad block recovery file -- '%s'", + LOG(1, + "incomplete bad block recovery file -- '%s'", path); ret = 1; goto error_exit; @@ -973,8 +986,8 @@ replica_badblocks_recovery_files_create_empty(struct pool_set *set, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd < 0) { - ERR( - "!creating an empty bad block recovery file failed -- '%s' (part file '%s')", + ERR_W_ERRNO( + "creating an empty bad block recovery file failed -- '%s' (part file '%s')", part_hs->recovery_file_name, path); return -1; } @@ -983,7 +996,7 @@ replica_badblocks_recovery_files_create_empty(struct pool_set *set, char *file_name = Strdup(part_hs->recovery_file_name); if (file_name == NULL) { - ERR("!Strdup"); + ERR_W_ERRNO("Strdup"); return -1; } @@ -991,8 +1004,8 @@ replica_badblocks_recovery_files_create_empty(struct pool_set *set, /* fsync the file's directory */ if (os_fsync_dir(dir_name) < 0) { - ERR( - "!syncing the directory of the bad block recovery file failed -- '%s' (part file '%s')", + ERR_W_ERRNO( + "syncing the directory of the bad block recovery file failed -- '%s' (part file '%s')", dir_name, path); Free(file_name); return -1; @@ -1070,8 +1083,8 @@ replica_badblocks_get(struct pool_set *set, int ret = badblocks_get(path, &part_hs->bbs); if (ret < 0) { - ERR( - "!checking the pool part for bad blocks failed -- '%s'", + ERR_W_ERRNO( + "checking the pool part for bad blocks failed -- '%s'", path); return -1; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index 32a5fe7ab2b..cb5a8b45ad3 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2022, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * transform.c -- a module for poolset transforming @@ -60,7 +60,7 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) errno = 0; path = strdup(PART(rep, partn)->path); if (path == NULL) { - ERR("!strdup"); + ERR_W_ERRNO("strdup"); return -1; } } @@ -194,7 +194,7 @@ create_poolset_compare_status(struct pool_set *set, set_s = Zalloc(sizeof(struct poolset_compare_status) + set->nreplicas * sizeof(unsigned)); if (set_s == NULL) { - ERR("!Zalloc for poolset status"); + ERR_W_ERRNO("Zalloc for poolset status"); return -1; } for (unsigned r = 0; r < set->nreplicas; ++r) diff --git a/src/test/Makefile b/src/test/Makefile index e4c0a8e9302..bec0d1126fa 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -140,7 +140,8 @@ OTHER_TESTS = \ util_sds\ util_uuid_generate\ util_vec\ - util_vecq + util_vecq\ + log_errno ifeq ($(ARCH), x86_64) OTHER_TESTS += \ diff --git a/src/test/log_errno/.gitignore b/src/test/log_errno/.gitignore new file mode 100644 index 00000000000..1c6ea52f0aa --- /dev/null +++ b/src/test/log_errno/.gitignore @@ -0,0 +1 @@ +log_errno diff --git a/src/test/log_errno/Makefile b/src/test/log_errno/Makefile new file mode 100644 index 00000000000..98cb6888878 --- /dev/null +++ b/src/test/log_errno/Makefile @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +# +# src/test/log_errno/Makefile -- build unit test for log_errno +# +TARGET = log_errno +OBJS = log_errno.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +include ../Makefile.inc diff --git a/src/test/log_errno/TEST0 b/src/test/log_errno/TEST0 new file mode 100755 index 00000000000..2cc70cc5569 --- /dev/null +++ b/src/test/log_errno/TEST0 @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +# +# src/test/log_errno/TEST0 -- unit test for CORE_LOG_ERROR_WITH_ERRNO macro +# + +. ../unittest/unittest.sh + +require_test_type short + +require_fs_type none +setup + +expect_normal_exit ./log_errno$EXESUFFIX 2>$ERR_LOG_FILE + +check + +pass diff --git a/src/test/log_errno/err0.log.match b/src/test/log_errno/err0.log.match new file mode 100644 index 00000000000..846f021cffd --- /dev/null +++ b/src/test/log_errno/err0.log.match @@ -0,0 +1 @@ +$(*) [$(*)] *ERROR* log_errno.c: $(N): main: open file lolek: Success diff --git a/src/test/log_errno/log_errno.c b/src/test/log_errno/log_errno.c new file mode 100644 index 00000000000..38c4ea190ed --- /dev/null +++ b/src/test/log_errno/log_errno.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * log_errno.c -- unit test for CORE_LOG_ERROR_WITH_ERRNO macro + */ +#include + +#include "unittest.h" +#include "log_internal.h" + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "log_errno"); + + core_log_init(); + CORE_LOG_ERROR_WITH_ERRNO("open file %s", "lolek"); + core_log_fini(); + /* + * The fini function above intentionally does not close the syslog + * socket. It has to be closed separately so it won't be accounted as + * an unclosed file descriptor. + */ + closelog(); + + DONE(NULL); +} diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index f97ed7ff9ef..31230b197a9 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * traces.c -- unit test for traces @@ -32,11 +32,11 @@ main(int argc, char *argv[]) UT_OUT("%s", out_get_errormsg()); errno = 0; - ERR("!ERR #%d", 2); + ERR_W_ERRNO("ERR #%d", 2); UT_OUT("%s", out_get_errormsg()); errno = EINVAL; - ERR("!ERR #%d", 3); + ERR_W_ERRNO("ERR #%d", 3); UT_OUT("%s", out_get_errormsg()); errno = EBADF; diff --git a/src/test/pmem2_perror/pmem2_perror.c b/src/test/pmem2_perror/pmem2_perror.c index b21f53c3c47..65de96605d6 100644 --- a/src/test/pmem2_perror/pmem2_perror.c +++ b/src/test/pmem2_perror/pmem2_perror.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2023, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * pmem2_perror.c -- pmem2_perror unittests @@ -59,7 +59,7 @@ test_fail_system_func_simple(const struct test_case *tc, int argc, char *argv[]) /* "randomly" chosen function to be failed */ int ret = os_open("XXX", O_RDONLY); UT_ASSERTeq(ret, -1); - ERR("!open"); + ERR_W_ERRNO("open"); pmem2_perror("test"); @@ -76,7 +76,7 @@ test_fail_system_func_format(const struct test_case *tc, int argc, char *argv[]) /* "randomly" chosen function to be failed */ int ret = os_open("XXX", O_RDONLY); UT_ASSERTeq(ret, -1); - ERR("!open"); + ERR_W_ERRNO("open"); pmem2_perror("test %d", 123); From a224c734c26f1156ab5963d8433de5951f4b16f6 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 22 Jan 2024 07:26:32 +0100 Subject: [PATCH 023/182] test: suppress CORE_LOG_ERROR() messages in some pmempool tests Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_sync/TEST10 | 7 +++++-- src/test/pmempool_sync/TEST23 | 7 +++++-- src/test/pmempool_sync/TEST24 | 7 +++++-- src/test/pmempool_sync/TEST9 | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/test/pmempool_sync/TEST10 b/src/test/pmempool_sync/TEST10 index 95975d11a0c..14556f9b60f 100755 --- a/src/test/pmempool_sync/TEST10 +++ b/src/test/pmempool_sync/TEST10 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_sync/TEST10 -- test for checking pmempool sync; @@ -51,7 +51,10 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST23 b/src/test/pmempool_sync/TEST23 index e56c748547b..a37ed0af7cd 100755 --- a/src/test/pmempool_sync/TEST23 +++ b/src/test/pmempool_sync/TEST23 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST23 -- test for pmempool sync @@ -63,6 +63,9 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST24 b/src/test/pmempool_sync/TEST24 index 4dd1e6e52c8..8784b2e31d5 100755 --- a/src/test/pmempool_sync/TEST24 +++ b/src/test/pmempool_sync/TEST24 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST24 -- test for checking pmempool sync @@ -60,7 +60,10 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST9 b/src/test/pmempool_sync/TEST9 index df59e4db997..9bb26f4d8fe 100755 --- a/src/test/pmempool_sync/TEST9 +++ b/src/test/pmempool_sync/TEST9 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_sync/TEST9 -- test for checking pmempool sync; @@ -58,7 +58,10 @@ rm -f $DIR/part01 # Try to synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass From efdbc71449bcce27ef5499bbd5bd81f3d09b68e7 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 24 Jan 2024 21:00:30 +0100 Subject: [PATCH 024/182] common: disable obj_tx_add_range until issue #5972 is fixed Disable test until issue #5972 is fixed. https://github.com/pmem/pmdk/issues/5972 Signed-off-by: Tomasz Gromadzki --- src/test/obj_tx_add_range/TESTS.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/obj_tx_add_range/TESTS.py b/src/test/obj_tx_add_range/TESTS.py index 9c8ce14f339..8f739cc5707 100755 --- a/src/test/obj_tx_add_range/TESTS.py +++ b/src/test/obj_tx_add_range/TESTS.py @@ -1,6 +1,6 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2020, Intel Corporation +# Copyright 2019-2024, Intel Corporation """unit tests for pmemobj_tx_add_range and pmemobj_tx_xadd_range""" @@ -38,6 +38,9 @@ def run(self, ctx): ctx.exec('obj_tx_add_range', testfile, '1') +# XXX disable test until issue #5972 is fixed +# https://github.com/pmem/pmdk/issues/5972 +@t.DISABLED() @t.require_valgrind_enabled('memcheck') @t.require_build('debug') class TEST3(t.Test): From fa781926c0c95f8de3d93a0f25727cf7fb49946b Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 07:11:03 +0100 Subject: [PATCH 025/182] common: disable obj_tx_add_range_direct until issue #5974 is fixed Disable test until issue #5974 is fixed. https://github.com/pmem/pmdk/issues/5974 Signed-off-by: Tomasz Gromadzki --- src/test/obj_tx_add_range_direct/TESTS.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/obj_tx_add_range_direct/TESTS.py b/src/test/obj_tx_add_range_direct/TESTS.py index f1482d9bf97..cce27cf874d 100755 --- a/src/test/obj_tx_add_range_direct/TESTS.py +++ b/src/test/obj_tx_add_range_direct/TESTS.py @@ -1,6 +1,6 @@ #!../env.py # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2019-2020, Intel Corporation +# Copyright 2019-2024, Intel Corporation """ unit tests for pmemobj_tx_add_range_direct @@ -32,6 +32,9 @@ def run(self, ctx): ctx.exec('obj_tx_add_range_direct', testfile) +# XXX disable test until issue #5974 is fixed +# https://github.com/pmem/pmdk/issues/5974 +@t.DISABLED() @t.require_valgrind_enabled('memcheck') @t.require_build('debug') class TEST2(t.Test): From ac4f3c9eeac2c03b2837541249e40c634d70a424 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 13:41:31 +0100 Subject: [PATCH 026/182] pmem: disable flag verification until #5979 is fixed Signed-off-by: Tomasz Gromadzki --- src/libpmem/pmem.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 9257e9f8d7d..907fd750b6e 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * pmem.c -- pmem entry points for libpmem @@ -573,10 +573,18 @@ pmem_memmove(void *pmemdest, const void *src, size_t len, unsigned flags) LOG(15, "pmemdest %p src %p len %zu flags 0x%x", pmemdest, src, len, flags); +/* + * XXX + * Disable this warning until #5979 is fixed + * https://github.com/pmem/pmdk/issues/5979 + */ +#if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) ERR("invalid flags 0x%x", flags); #endif +#endif + PMEM_API_START(); Funcs.memmove_nodrain(pmemdest, src, len, flags & ~PMEM_F_MEM_NODRAIN, Funcs.flush, &Funcs.memmove_funcs); @@ -597,10 +605,17 @@ pmem_memcpy(void *pmemdest, const void *src, size_t len, unsigned flags) LOG(15, "pmemdest %p src %p len %zu flags 0x%x", pmemdest, src, len, flags); +/* + * Disable this warning until #5979 is fixed + * https://github.com/pmem/pmdk/issues/5979 + */ +#if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) ERR("invalid flags 0x%x", flags); #endif +#endif + PMEM_API_START(); Funcs.memmove_nodrain(pmemdest, src, len, flags & ~PMEM_F_MEM_NODRAIN, Funcs.flush, &Funcs.memmove_funcs); @@ -621,9 +636,16 @@ pmem_memset(void *pmemdest, int c, size_t len, unsigned flags) LOG(15, "pmemdest %p c 0x%x len %zu flags 0x%x", pmemdest, c, len, flags); +/* + * XXX + * Disable this warning until #5979 is fixed + * https://github.com/pmem/pmdk/issues/5979 + */ +#if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) ERR("invalid flags 0x%x", flags); +#endif #endif PMEM_API_START(); From c7b4085d094b6af35c6bd74cbbc784eba3e713d8 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 19 Jan 2024 13:31:41 +0100 Subject: [PATCH 027/182] common: replace ERR("...", ... ) by ERR_WO_ERRNO(...) Signed-off-by: Tomasz Gromadzki --- src/common/ctl.c | 14 +-- src/common/file.c | 12 +-- src/common/mmap.c | 6 +- src/common/mmap_posix.c | 2 +- src/common/pool_hdr.c | 22 ++-- src/common/set.c | 139 ++++++++++++++------------ src/common/set_badblocks.c | 9 +- src/common/shutdown_state.c | 9 +- src/core/out.c | 2 +- src/libpmem/libpmem.c | 8 +- src/libpmem/pmem.c | 29 +++--- src/libpmem2/auto_flush_linux.c | 5 +- src/libpmem2/badblocks_ndctl.c | 35 ++++--- src/libpmem2/config.c | 18 ++-- src/libpmem2/deep_flush.c | 4 +- src/libpmem2/deep_flush_other.c | 4 +- src/libpmem2/extent_linux.c | 2 +- src/libpmem2/map.c | 8 +- src/libpmem2/map_posix.c | 31 +++--- src/libpmem2/mcsafe_ops_posix.c | 20 ++-- src/libpmem2/numa_ndctl.c | 4 +- src/libpmem2/numa_none.c | 5 +- src/libpmem2/persist.c | 20 ++-- src/libpmem2/pmem2_utils.h | 4 +- src/libpmem2/pmem2_utils_linux.c | 3 +- src/libpmem2/pmem2_utils_ndctl.c | 2 +- src/libpmem2/pmem2_utils_none.c | 7 +- src/libpmem2/pmem2_utils_other.c | 8 +- src/libpmem2/region_namespace_ndctl.c | 8 +- src/libpmem2/source_posix.c | 12 ++- src/libpmem2/usc_ndctl.c | 9 +- src/libpmem2/usc_none.c | 6 +- src/libpmem2/vm_reservation.c | 50 +++++---- src/libpmem2/vm_reservation_posix.c | 2 +- src/libpmemobj/alloc_class.c | 5 +- src/libpmemobj/heap.c | 30 +++--- src/libpmemobj/libpmemobj.c | 8 +- src/libpmemobj/memops.c | 6 +- src/libpmemobj/obj.c | 57 +++++------ src/libpmemobj/palloc.c | 8 +- src/libpmemobj/pmalloc.c | 32 +++--- src/libpmemobj/stats.c | 2 +- src/libpmemobj/sync.c | 6 +- src/libpmemobj/tx.c | 65 ++++++------ src/libpmempool/check_backup.c | 6 +- src/libpmempool/check_pool_hdr.c | 14 +-- src/libpmempool/check_sds.c | 4 +- src/libpmempool/check_util.c | 4 +- src/libpmempool/feature.c | 34 ++++--- src/libpmempool/libpmempool.c | 17 ++-- src/libpmempool/pool.c | 19 ++-- src/libpmempool/replica.c | 77 +++++++------- src/libpmempool/rm.c | 12 +-- src/libpmempool/sync.c | 39 ++++---- src/libpmempool/transform.c | 80 +++++++-------- src/test/out_err/out_err.c | 2 +- 56 files changed, 555 insertions(+), 491 deletions(-) diff --git a/src/common/ctl.c b/src/common/ctl.c index 4252437d8a9..99d2ece7dc0 100644 --- a/src/common/ctl.c +++ b/src/common/ctl.c @@ -211,7 +211,7 @@ ctl_exec_query_read(void *ctx, const struct ctl_node *n, enum ctl_query_source source, void *arg, struct ctl_indexes *indexes) { if (arg == NULL) { - ERR("read queries require non-NULL argument"); + ERR_WO_ERRNO("read queries require non-NULL argument"); errno = EINVAL; return -1; } @@ -227,7 +227,7 @@ ctl_exec_query_write(void *ctx, const struct ctl_node *n, enum ctl_query_source source, void *arg, struct ctl_indexes *indexes) { if (arg == NULL) { - ERR("write queries require non-NULL argument"); + ERR_WO_ERRNO("write queries require non-NULL argument"); errno = EINVAL; return -1; } @@ -274,7 +274,7 @@ ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source, ctl, ctx, source, name, type, arg); if (name == NULL) { - ERR("invalid query"); + ERR_WO_ERRNO("invalid query"); errno = EINVAL; return -1; } @@ -298,7 +298,7 @@ ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source, } if (n == NULL || n->type != CTL_NODE_LEAF || n->cb[type] == NULL) { - ERR("invalid query entry point %s", name); + ERR_WO_ERRNO("invalid query entry point %s", name); errno = EINVAL; goto out; } @@ -370,7 +370,7 @@ ctl_load_config(struct ctl *ctl, void *ctx, char *buf) while (qbuf != NULL) { r = ctl_parse_query(qbuf, &name, &value); if (r != 0) { - ERR("failed to parse query %s", qbuf); + ERR_WO_ERRNO("failed to parse query %s", qbuf); return -1; } @@ -432,7 +432,7 @@ ctl_load_config_from_file(struct ctl *ctl, void *ctx, const char *cfg_file) goto error_file_parse; if (fsize > MAX_CONFIG_FILE_LEN) { - ERR("Config file too large"); + ERR_WO_ERRNO("Config file too large"); goto error_file_parse; } @@ -558,7 +558,7 @@ ctl_arg_integer(const void *arg, void *dest, size_t dest_size) *(uint8_t *)dest = (uint8_t)val; break; default: - ERR("invalid destination size %zu", dest_size); + ERR_WO_ERRNO("invalid destination size %zu", dest_size); errno = EINVAL; return -1; } diff --git a/src/common/file.c b/src/common/file.c index 5263d79cba5..9d4574f470e 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -108,7 +108,7 @@ util_file_get_type(const char *path) LOG(3, "path \"%s\"", path); if (path == NULL) { - ERR("invalid (NULL) path"); + ERR_WO_ERRNO("invalid (NULL) path"); errno = EINVAL; return OTHER_ERROR; } @@ -179,7 +179,7 @@ util_fd_get_size(int fd) /* size is unsigned, this function returns signed */ if (size >= INT64_MAX) { errno = ERANGE; - ERR( + ERR_WO_ERRNO( "file size (%ld) too big to be represented in 64-bit signed integer", size); return -1; @@ -402,13 +402,13 @@ util_file_create(const char *path, size_t size, size_t minsize) ASSERTne(size, 0); if (size < minsize) { - ERR("size %zu smaller than %zu", size, minsize); + ERR_WO_ERRNO("size %zu smaller than %zu", size, minsize); errno = EINVAL; return -1; } if (((os_off_t)size) < 0) { - ERR("invalid size (%zu) for os_off_t", size); + ERR_WO_ERRNO("invalid size (%zu) for os_off_t", size); errno = EFBIG; return -1; } @@ -478,13 +478,13 @@ util_file_open(const char *path, size_t *size, size_t minsize, int flags) ssize_t actual_size = util_fd_get_size(fd); if (actual_size < 0) { - ERR("stat \"%s\": negative size", path); + ERR_WO_ERRNO("stat \"%s\": negative size", path); errno = EINVAL; goto err; } if ((size_t)actual_size < minsize) { - ERR("size %zu smaller than %zu", + ERR_WO_ERRNO("size %zu smaller than %zu", (size_t)actual_size, minsize); errno = EINVAL; goto err; diff --git a/src/common/mmap.c b/src/common/mmap.c index f7d9b535b5e..546f11a08e7 100644 --- a/src/common/mmap.c +++ b/src/common/mmap.c @@ -284,7 +284,7 @@ util_range_register(const void *addr, size_t len, const char *path, /* check if not tracked already */ if (util_range_find((uintptr_t)addr, len) != NULL) { - ERR( + ERR_WO_ERRNO( "duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu", addr, len); errno = ENOMEM; @@ -305,7 +305,7 @@ util_range_register(const void *addr, size_t len, const char *path, unsigned region_id; int ret = util_ddax_region_find(path, ®ion_id); if (ret < 0) { - ERR("Cannot find DAX device region id"); + ERR_WO_ERRNO("Cannot find DAX device region id"); return -1; } mt->region_id = region_id; @@ -333,7 +333,7 @@ util_range_split(struct map_tracker *mt, const void *addrp, const void *endp) uintptr_t end = (uintptr_t)endp; ASSERTne(mt, NULL); if (addr == end || addr % Mmap_align != 0 || end % Mmap_align != 0) { - ERR( + ERR_WO_ERRNO( "invalid munmap length, must be non-zero and page aligned"); return -1; } diff --git a/src/common/mmap_posix.c b/src/common/mmap_posix.c index 7a594b277e1..faf6a8018d0 100644 --- a/src/common/mmap_posix.c +++ b/src/common/mmap_posix.c @@ -87,7 +87,7 @@ util_map_hint_unused(void *minaddr, size_t len, size_t align) * space, but is not large enough. (very unlikely) */ if ((raddr != NULL) && (UINTPTR_MAX - (uintptr_t)raddr < len)) { - ERR("end of address space reached"); + ERR_WO_ERRNO("end of address space reached"); raddr = MAP_FAILED; } diff --git a/src/common/pool_hdr.c b/src/common/pool_hdr.c index 13486a09b34..495e39c9bed 100644 --- a/src/common/pool_hdr.c +++ b/src/common/pool_hdr.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2021, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * pool_hdr.c -- pool header utilities @@ -112,27 +112,27 @@ util_check_arch_flags(const struct arch_flags *arch_flags) if (!util_is_zeroed(&arch_flags->reserved, sizeof(arch_flags->reserved))) { - ERR("invalid reserved values"); + ERR_WO_ERRNO("invalid reserved values"); ret = -1; } if (arch_flags->machine != cur_af.machine) { - ERR("invalid machine value"); + ERR_WO_ERRNO("invalid machine value"); ret = -1; } if (arch_flags->data != cur_af.data) { - ERR("invalid data value"); + ERR_WO_ERRNO("invalid data value"); ret = -1; } if (arch_flags->machine_class != cur_af.machine_class) { - ERR("invalid machine_class value"); + ERR_WO_ERRNO("invalid machine_class value"); ret = -1; } if (arch_flags->alignment_desc != cur_af.alignment_desc) { - ERR("invalid alignment_desc value"); + ERR_WO_ERRNO("invalid alignment_desc value"); ret = -1; } @@ -169,16 +169,18 @@ util_feature_check(struct pool_hdr *hdrp, features_t known) /* check incompatible ("must support") features */ if (unknown.incompat) { - ERR("unsafe to continue due to unknown incompat "\ - "features: %#x", unknown.incompat); + ERR_WO_ERRNO( + "unsafe to continue due to unknown incompat features: %#x", + unknown.incompat); errno = EINVAL; return -1; } /* check RO-compatible features (force RO if unsupported) */ if (unknown.ro_compat) { - ERR("switching to read-only mode due to unknown ro_compat "\ - "features: %#x", unknown.ro_compat); + ERR_WO_ERRNO( + "switching to read-only mode due to unknown ro_compat features: %#x", + unknown.ro_compat); return 0; } diff --git a/src/common/set.c b/src/common/set.c index 33db82002ba..487e755c65d 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -253,7 +253,7 @@ util_map_part(struct pool_set_part *part, void *addr, size_t size, } if (addr != NULL && (flags & MAP_FIXED) && addrp != addr) { - ERR("unable to map at requested address %p", addr); + ERR_WO_ERRNO("unable to map at requested address %p", addr); munmap(addrp, size); return -1; } @@ -472,7 +472,8 @@ util_autodetect_size(const char *path) return -1; if (type == TYPE_NORMAL) { - ERR("size autodetection is supported only for device dax"); + ERR_WO_ERRNO( + "size autodetection is supported only for device dax"); return -1; } @@ -727,7 +728,7 @@ util_parse_add_part(struct pool_set *set, const char *path, size_t filesize) ASSERTne(set, NULL); if (set->directory_based) { - ERR("cannot mix directories and files in a set"); + ERR_WO_ERRNO("cannot mix directories and files in a set"); errno = EINVAL; return -1; } @@ -753,7 +754,8 @@ util_parse_add_directory(struct pool_set *set, const char *path, if (set->directory_based == 0) { if (rep->nparts > 0 || set->nreplicas > 1) { - ERR("cannot mix directories and files in a set"); + ERR_WO_ERRNO( + "cannot mix directories and files in a set"); errno = EINVAL; return -1; } @@ -762,7 +764,7 @@ util_parse_add_directory(struct pool_set *set, const char *path, char *rpath = util_part_realpath(path); if (rpath == NULL) { - ERR("cannot resolve realpath of new directory"); + ERR_WO_ERRNO("cannot resolve realpath of new directory"); return -1; } @@ -774,7 +776,8 @@ util_parse_add_directory(struct pool_set *set, const char *path, dpath = util_part_realpath(dir->path); ASSERTne(dpath, NULL); /* must have been resolved */ if (strcmp(rpath, dpath) == 0) { - ERR("cannot use the same directory twice"); + ERR_WO_ERRNO( + "cannot use the same directory twice"); errno = EEXIST; free(dpath); free(rpath); @@ -870,7 +873,8 @@ util_replica_check_map_sync(struct pool_set *set, unsigned repidx, for (unsigned p = 1; p < rep->nparts; p++) { if (map_sync != rep->part[p].map_sync) { - ERR("replica #%u part %u %smapped with MAP_SYNC", + ERR_WO_ERRNO( + "replica #%u part %u %smapped with MAP_SYNC", repidx, p, rep->part[p].map_sync ? "" : "not"); return -1; } @@ -879,9 +883,9 @@ util_replica_check_map_sync(struct pool_set *set, unsigned repidx, if (check_hdr) { for (unsigned p = 0; p < rep->nhdrs; p++) { if (map_sync != rep->part[p].hdr_map_sync) { - ERR("replica #%u part %u header %smapped " - "with MAP_SYNC", repidx, p, - rep->part[p].hdr_map_sync ? + ERR_WO_ERRNO( + "replica #%u part %u header %smapped with MAP_SYNC", + repidx, p, rep->part[p].hdr_map_sync ? "" : "not"); return -1; } @@ -908,7 +912,7 @@ util_poolset_check_devdax(struct pool_set *set) for (unsigned p = 0; p < rep->nparts; p++) { if (rep->part[p].is_dev_dax != is_dev_dax) { - ERR( + ERR_WO_ERRNO( "either all the parts must be Device DAX or none"); return -1; } @@ -918,7 +922,7 @@ util_poolset_check_devdax(struct pool_set *set) OPTION_NOHDRS)) == 0 && util_file_device_dax_alignment(rep->part[p].path) != Pagesize) { - ERR( + ERR_WO_ERRNO( "Multiple DAX devices with alignment other than 4KB. Use the SINGLEHDR poolset option."); return -1; } @@ -937,8 +941,8 @@ util_poolset_check_options(struct pool_set *set) LOG(3, "set %p", set); if ((set->options & OPTION_SINGLEHDR) && (set->options & OPTION_NOHDRS)) { - ERR( - "both SINGLEHDR and NOHDR poolset options used at the same time"); + ERR_WO_ERRNO( + "both SINGLEHDR and NOHDR poolset options used at the same time"); return -1; } return 0; @@ -1058,7 +1062,7 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory) if (util_replica_add_part_by_idx(repp, path, (size_t)size, (unsigned)part_idx) != 0) { - ERR("unable to load part %s", entry->path); + ERR_WO_ERRNO("unable to load part %s", entry->path); goto err; } nparts++; @@ -1097,7 +1101,8 @@ util_poolset_directories_load(struct pool_set *set) nparts = util_poolset_directory_load(&set->replica[r], d->path); if (nparts < 0) { - ERR("failed to load parts from directory %s", + ERR_WO_ERRNO( + "failed to load parts from directory %s", d->path); return -1; } @@ -1293,9 +1298,8 @@ util_poolset_parse(struct pool_set **setp, const char *path, int fd) &node_addr, &pool_desc); if (result == PARSER_CONTINUE) { /* remote REPLICA */ - ERR( - "Remote replicas are no longer supported. " - "This functionality is deprecated."); + ERR_WO_ERRNO( + "Remote replicas are no longer supported. This functionality is deprecated."); goto err; } } else if (nparts >= 1) { @@ -1331,7 +1335,7 @@ util_poolset_parse(struct pool_set **setp, const char *path, int fd) } if (result != PARSER_FORMAT_OK) { - ERR("%s [%s:%d]", path, parser_errstr[result], nlines); + ERR_WO_ERRNO("%s [%s:%d]", path, parser_errstr[result], nlines); switch (result) { case PARSER_CANNOT_READ_SIZE: case PARSER_OUT_OF_MEMORY: @@ -1349,7 +1353,7 @@ util_poolset_parse(struct pool_set **setp, const char *path, int fd) } if (util_poolset_directories_load(set) != 0) { - ERR("cannot load part files from directories"); + ERR_WO_ERRNO("cannot load part files from directories"); goto err; } @@ -1502,7 +1506,8 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) /* check if filesize matches */ if (part->filesize != size) { - ERR("file size does not match config: %s, %zu != %zu", + ERR_WO_ERRNO( + "file size does not match config: %s, %zu != %zu", part->path, size, part->filesize); errno = EINVAL; return -1; @@ -1599,7 +1604,7 @@ util_poolset_create_set(struct pool_set **setp, const char *path, if (poolsize != 0) { if (type == TYPE_DEVDAX) { - ERR("size must be zero for device dax"); + ERR_WO_ERRNO("size must be zero for device dax"); return -1; } *setp = util_poolset_single(path, poolsize, 1, ignore_sds); @@ -1633,8 +1638,9 @@ util_poolset_create_set(struct pool_set **setp, const char *path, (void) os_close(fd); if (size < minsize) { - ERR("file is not a poolset file and its size (%zu)" - " is smaller than %zu", size, minsize); + ERR_WO_ERRNO( + "file is not a poolset file and its size (%zu) is smaller than %zu", + size, minsize); errno = EINVAL; return -1; } @@ -1669,7 +1675,7 @@ util_poolset_check_header_options(struct pool_set *set, uint32_t incompat) if (((set->options & OPTION_SINGLEHDR) == 0) != ((incompat & POOL_FEAT_SINGLEHDR) == 0)) { - ERR( + ERR_WO_ERRNO( "poolset file options (%u) do not match incompat feature flags (%#x)", set->options, incompat); errno = EINVAL; @@ -1697,7 +1703,7 @@ util_header_create(struct pool_set *set, unsigned repidx, unsigned partidx, /* check if the pool header is all zeros */ if (!util_is_zeroed(hdrp, sizeof(*hdrp)) && !overwrite) { - ERR("Non-empty file detected"); + ERR_WO_ERRNO("Non-empty file detected"); errno = EEXIST; return -1; } @@ -1805,24 +1811,24 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, /* to be valid, a header must have a major version of at least 1 */ if (hdr.major == 0) { - ERR("invalid major version (0)"); + ERR_WO_ERRNO("invalid major version (0)"); errno = EINVAL; return -1; } /* check signature */ if (memcmp(hdr.signature, attr->signature, POOL_HDR_SIG_LEN)) { - ERR("wrong pool type: \"%.8s\"", hdr.signature); + ERR_WO_ERRNO("wrong pool type: \"%.8s\"", hdr.signature); errno = EINVAL; return -1; } /* check format version number */ if (hdr.major != attr->major) { - ERR("pool version %d (library expects %d)", hdr.major, + ERR_WO_ERRNO("pool version %d (library expects %d)", hdr.major, attr->major); if (hdr.major < attr->major) - ERR( + ERR_WO_ERRNO( "Please run the pmdk-convert utility to upgrade the pool."); errno = EINVAL; return -1; @@ -1847,7 +1853,7 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, */ if (!util_checksum(&hdr, sizeof(hdr), &hdr.checksum, 0, POOL_HDR_CSUM_END_OFF(&hdr))) { - ERR("invalid checksum of pool header"); + ERR_WO_ERRNO("invalid checksum of pool header"); errno = EINVAL; return -1; } @@ -1855,7 +1861,7 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, LOG(3, "valid header, signature \"%.8s\"", hdr.signature); if (util_check_arch_flags(&hdr.arch_flags)) { - ERR("wrong architecture flags"); + ERR_WO_ERRNO("wrong architecture flags"); errno = EINVAL; return -1; } @@ -1863,7 +1869,7 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, /* check pool set UUID */ if (memcmp(HDR(REP(set, 0), 0)->poolset_uuid, hdr.poolset_uuid, POOL_HDR_UUID_LEN)) { - ERR("wrong pool set UUID"); + ERR_WO_ERRNO("wrong pool set UUID"); errno = EINVAL; return -1; } @@ -1873,14 +1879,14 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, POOL_HDR_UUID_LEN) || memcmp(HDRN(rep, partidx)->uuid, hdr.next_part_uuid, POOL_HDR_UUID_LEN)) { - ERR("wrong part UUID"); + ERR_WO_ERRNO("wrong part UUID"); errno = EINVAL; return -1; } /* check format version */ if (HDR(rep, 0)->major != hdrp->major) { - ERR("incompatible pool format"); + ERR_WO_ERRNO("incompatible pool format"); errno = EINVAL; return -1; } @@ -1889,7 +1895,7 @@ util_header_check(struct pool_set *set, unsigned repidx, unsigned partidx, if (HDR(rep, 0)->features.compat != hdrp->features.compat || HDR(rep, 0)->features.incompat != hdrp->features.incompat || HDR(rep, 0)->features.ro_compat != hdrp->features.ro_compat) { - ERR("incompatible feature flags"); + ERR_WO_ERRNO("incompatible feature flags"); errno = EINVAL; return -1; } @@ -2235,20 +2241,20 @@ util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize) LOG(3, "set %p size %zu minpartsize %zu", set, *size, minpartsize); if (*size == 0) { - ERR("cannot extend pool by 0 bytes"); + ERR_WO_ERRNO("cannot extend pool by 0 bytes"); return NULL; } if ((set->options & OPTION_SINGLEHDR) == 0) { - ERR( - "extending the pool by appending parts with headers is not supported!"); + ERR_WO_ERRNO( + "extending the pool by appending parts with headers is not supported!"); return NULL; } if (set->poolsize + *size > set->resvsize) { *size = set->resvsize - set->poolsize; if (*size < minpartsize) { - ERR("exceeded reservation size"); + ERR_WO_ERRNO("exceeded reservation size"); return NULL; } LOG(4, "extend size adjusted to not exceed reservation size"); @@ -2257,7 +2263,7 @@ util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize) size_t old_poolsize = set->poolsize; if (util_poolset_append_new_part(set, *size) != 0) { - ERR("unable to append a new part to the pool"); + ERR_WO_ERRNO("unable to append a new part to the pool"); return NULL; } @@ -2272,7 +2278,7 @@ util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize) struct pool_set_part *p = &rep->part[pidx]; if (util_part_open(p, 0, 1 /* create */) != 0) { - ERR("cannot open the new part"); + ERR_WO_ERRNO("cannot open the new part"); goto err; } @@ -2282,7 +2288,7 @@ util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize) if (util_map_part(p, addr, 0, hdrsize, MAP_SHARED | MAP_FIXED, 0) != 0) { - ERR("cannot map the new part"); + ERR_WO_ERRNO("cannot map the new part"); goto err; } @@ -2292,9 +2298,10 @@ util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize) */ if (p->map_sync != rep->part[0].map_sync) { if (p->map_sync) - ERR("new part cannot be mapped with MAP_SYNC"); + ERR_WO_ERRNO( + "new part cannot be mapped with MAP_SYNC"); else - ERR("new part mapped with MAP_SYNC"); + ERR_WO_ERRNO("new part mapped with MAP_SYNC"); goto err; } } @@ -2337,7 +2344,8 @@ util_print_bad_files_cb(struct part_file *pf, void *arg) SUPPRESS_UNUSED(arg); if (pf->part && pf->part->has_bad_blocks) - ERR("file contains bad blocks -- '%s'", pf->part->path); + ERR_WO_ERRNO("file contains bad blocks -- '%s'", + pf->part->path); return 0; } @@ -2370,7 +2378,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, /* check if file exists */ if (poolsize > 0 && exists) { - ERR("file %s already exists", path); + ERR_WO_ERRNO("file %s already exists", path); errno = EEXIST; return -1; } @@ -2387,28 +2395,28 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, ASSERT(set->nreplicas > 0); if (set->options & OPTION_NOHDRS) { - ERR( + ERR_WO_ERRNO( "the NOHDRS poolset option is not supported for local poolsets"); errno = EINVAL; goto err_poolset_free; } if ((attr == NULL) != ((set->options & OPTION_NOHDRS) != 0)) { - ERR( + ERR_WO_ERRNO( "pool attributes are not supported for poolsets without headers (with the NOHDRS option)"); errno = EINVAL; goto err_poolset_free; } if (set->directory_based && ((set->options & OPTION_SINGLEHDR) == 0)) { - ERR( + ERR_WO_ERRNO( "directory based pools are not supported for poolsets with headers (without SINGLEHDR option)"); errno = EINVAL; goto err_poolset_free; } if (set->resvsize < minsize) { - ERR("reservation pool size %zu smaller than %zu", + ERR_WO_ERRNO("reservation pool size %zu smaller than %zu", set->resvsize, minsize); errno = EINVAL; goto err_poolset_free; @@ -2416,7 +2424,8 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, if (set->directory_based && set->poolsize == 0 && util_poolset_append_new_part(set, minsize) != 0) { - ERR("cannot create a new part in provided directories"); + ERR_WO_ERRNO( + "cannot create a new part in provided directories"); goto err_poolset_free; } @@ -2434,7 +2443,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, util_poolset_foreach_part_struct(set, util_print_bad_files_cb, NULL); - ERR( + ERR_WO_ERRNO( "pool set contains bad blocks and cannot be created, run 'pmempool create --clear-bad-blocks' utility to clear bad blocks and create a pool"); errno = EIO; goto err_poolset_free; @@ -2442,14 +2451,14 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, } if (set->poolsize < minsize) { - ERR("net pool size %zu smaller than %zu", + ERR_WO_ERRNO("net pool size %zu smaller than %zu", set->poolsize, minsize); errno = EINVAL; goto err_poolset_free; } if (!can_have_rep && set->nreplicas > 1) { - ERR("replication not supported"); + ERR_WO_ERRNO("replication not supported"); errno = ENOTSUP; goto err_poolset_free; } @@ -2608,7 +2617,7 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) ALIGN_DOWN(part->filesize - hdrsize, part->alignment); if (targetsize > rep->resvsize) { - ERR( + ERR_WO_ERRNO( "pool mapping failed - address space reservation too small"); errno = EINVAL; goto err; @@ -2778,7 +2787,7 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) memcmp(HDR(REPN(set, r), 0)->uuid, HDR(REP(set, r), 0)->next_repl_uuid, POOL_HDR_UUID_LEN)) { - ERR("wrong replica UUID"); + ERR_WO_ERRNO("wrong replica UUID"); errno = EINVAL; return -1; } @@ -2834,7 +2843,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) int cow = flags & POOL_OPEN_COW; if (cow && util_pool_has_device_dax(set)) { - ERR("device dax cannot be mapped privately"); + ERR_WO_ERRNO("device dax cannot be mapped privately"); errno = ENOTSUP; return -1; } @@ -2849,7 +2858,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) /* check if any bad block recovery file exists */ int bfe = badblocks_recovery_file_exists(set); if (bfe > 0) { - ERR( + ERR_WO_ERRNO( "error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); errno = EINVAL; return -1; @@ -2871,7 +2880,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) LOG(1, "WARNING: pool set contains bad blocks, ignoring"); } else { - ERR( + ERR_WO_ERRNO( "pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); errno = EIO; return -1; @@ -2987,7 +2996,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, } if (cow && (*setp)->replica[0]->part[0].is_dev_dax) { - ERR("device dax cannot be mapped privately"); + ERR_WO_ERRNO("device dax cannot be mapped privately"); errno = ENOTSUP; goto err_poolset_free; } @@ -3007,7 +3016,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, /* check if any bad block recovery file exists */ int bfe = badblocks_recovery_file_exists(set); if (bfe > 0) { - ERR( + ERR_WO_ERRNO( "error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); errno = EINVAL; goto err_poolset_free; @@ -3033,7 +3042,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, "WARNING: pool set contains bad blocks, ignoring -- '%s'", path); } else { - ERR( + ERR_WO_ERRNO( "pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool -- '%s'", path); errno = EIO; @@ -3184,7 +3193,7 @@ util_poolset_foreach_part(const char *path, struct pool_set *set; int ret = util_poolset_parse(&set, path, fd); if (ret) { - ERR("util_poolset_parse failed -- '%s'", path); + ERR_WO_ERRNO("util_poolset_parse failed -- '%s'", path); ret = -1; goto err_close; } diff --git a/src/common/set_badblocks.c b/src/common/set_badblocks.c index 0eb04a2b46d..e12d73bf323 100644 --- a/src/common/set_badblocks.c +++ b/src/common/set_badblocks.c @@ -43,13 +43,15 @@ badblocks_check_file_cb(struct part_file *pf, void *arg) int ret = badblocks_check_file(pf->part->path); if (ret < 0) { - ERR("checking the pool file for bad blocks failed -- '%s'", + ERR_WO_ERRNO( + "checking the pool file for bad blocks failed -- '%s'", pf->part->path); return -1; } if (ret > 0) { - ERR("part file contains bad blocks -- '%s'", pf->part->path); + ERR_WO_ERRNO("part file contains bad blocks -- '%s'", + pf->part->path); pcfcb->n_files_bbs++; pf->part->has_bad_blocks = 1; } @@ -114,7 +116,8 @@ badblocks_clear_poolset_cb(struct part_file *pf, void *arg) int ret = badblocks_clear_all(pf->part->path); if (ret < 0) { - ERR("clearing bad blocks in the pool file failed -- '%s'", + ERR_WO_ERRNO( + "clearing bad blocks in the pool file failed -- '%s'", pf->part->path); errno = EIO; return -1; diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index 9c831dad340..919bc29c528 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -74,7 +74,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, if (ret != 0) { if (ret == -EPERM) { /* overwrite error message */ - ERR( + ERR_WO_ERRNO( "Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); } LOG(2, "cannot read unsafe shutdown count for %d", fd); @@ -83,7 +83,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, ret = pmem2_source_device_id(src, NULL, &len); if (ret != 0) { - ERR("cannot read uuid of %d", fd); + ERR_WO_ERRNO("cannot read uuid of %d", fd); goto err; } @@ -97,7 +97,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, ret = pmem2_source_device_id(src, uid, &len); if (ret != 0) { - ERR("cannot read uuid of %d", fd); + ERR_WO_ERRNO("cannot read uuid of %d", fd); Free(uid); goto err; } @@ -227,6 +227,7 @@ shutdown_state_check(struct shutdown_state *curr_sds, return 0; } /* an ADR failure - the pool might be corrupted */ - ERR("an ADR failure was detected, the pool might be corrupted"); + ERR_WO_ERRNO( + "an ADR failure was detected, the pool might be corrupted"); return 1; } diff --git a/src/core/out.c b/src/core/out.c index 0f23df85ef4..4d220a64358 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -167,7 +167,7 @@ out_init(const char *log_prefix, const char *log_level_var, if (len > 0 && log_file[len - 1] == '-') { if (util_snprintf(log_file_pid, PATH_MAX, "%s%d", log_file, getpid()) < 0) { - ERR("snprintf: %d", errno); + ERR_W_ERRNO("snprintf"); abort(); } log_file = log_file_pid; diff --git a/src/libpmem/libpmem.c b/src/libpmem/libpmem.c index e6733fea3c3..c2e999e3fab 100644 --- a/src/libpmem/libpmem.c +++ b/src/libpmem/libpmem.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * libpmem.c -- pmem entry points for libpmem @@ -53,13 +53,15 @@ pmem_check_versionU(unsigned major_required, unsigned minor_required) major_required, minor_required); if (major_required != PMEM_MAJOR_VERSION) { - ERR("libpmem major version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmem major version mismatch (need %u, found %u)", major_required, PMEM_MAJOR_VERSION); return out_get_errormsg(); } if (minor_required > PMEM_MINOR_VERSION) { - ERR("libpmem minor version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmem minor version mismatch (need %u, found %u)", minor_required, PMEM_MINOR_VERSION); return out_get_errormsg(); } diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index b281af3f9aa..5b4241ba2c7 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -410,14 +410,15 @@ pmem_map_fileU(const char *path, size_t len, int flags, return NULL; if (flags & ~(PMEM_FILE_ALL_FLAGS)) { - ERR("invalid flag specified %x", flags); + ERR_WO_ERRNO("invalid flag specified %x", flags); errno = EINVAL; return NULL; } if (file_type == TYPE_DEVDAX) { if (flags & ~(PMEM_DAX_VALID_FLAGS)) { - ERR("flag unsupported for Device DAX %x", flags); + ERR_WO_ERRNO( + "flag unsupported for Device DAX %x", flags); errno = EINVAL; return NULL; } else { @@ -425,13 +426,13 @@ pmem_map_fileU(const char *path, size_t len, int flags, flags = 0; ssize_t actual_len = util_file_get_size(path); if (actual_len < 0) { - ERR("unable to read Device DAX size"); + ERR_WO_ERRNO("unable to read Device DAX size"); errno = EINVAL; return NULL; } if (len != 0 && len != (size_t)actual_len) { - ERR("Device DAX length must be either 0 or " - "the exact size of the device: %zu", + ERR_WO_ERRNO( + "Device DAX length must be either 0 or the exact size of the device: %zu", actual_len); errno = EINVAL; return NULL; @@ -442,7 +443,7 @@ pmem_map_fileU(const char *path, size_t len, int flags, if (flags & PMEM_FILE_CREATE) { if ((os_off_t)len < 0) { - ERR("invalid file length %zu", len); + ERR_WO_ERRNO("invalid file length %zu", len); errno = EINVAL; return NULL; } @@ -453,19 +454,21 @@ pmem_map_fileU(const char *path, size_t len, int flags, open_flags |= O_EXCL; if ((len != 0) && !(flags & PMEM_FILE_CREATE)) { - ERR("non-zero 'len' not allowed without PMEM_FILE_CREATE"); + ERR_WO_ERRNO( + "non-zero 'len' not allowed without PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } if ((len == 0) && (flags & PMEM_FILE_CREATE)) { - ERR("zero 'len' not allowed with PMEM_FILE_CREATE"); + ERR_WO_ERRNO("zero 'len' not allowed with PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } if ((flags & PMEM_FILE_TMPFILE) && !(flags & PMEM_FILE_CREATE)) { - ERR("PMEM_FILE_TMPFILE not allowed without PMEM_FILE_CREATE"); + ERR_WO_ERRNO( + "PMEM_FILE_TMPFILE not allowed without PMEM_FILE_CREATE"); errno = EINVAL; return NULL; } @@ -506,7 +509,7 @@ pmem_map_fileU(const char *path, size_t len, int flags, } else { ssize_t actual_size = util_fd_get_size(fd); if (actual_size < 0) { - ERR("stat %s: negative size", path); + ERR_WO_ERRNO("stat %s: negative size", path); errno = EINVAL; goto err; } @@ -581,7 +584,7 @@ pmem_memmove(void *pmemdest, const void *src, size_t len, unsigned flags) #if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif #endif @@ -612,7 +615,7 @@ pmem_memcpy(void *pmemdest, const void *src, size_t len, unsigned flags) #if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif #endif @@ -644,7 +647,7 @@ pmem_memset(void *pmemdest, int c, size_t len, unsigned flags) #if 0 #ifdef DEBUG if (flags & ~PMEM_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif #endif diff --git a/src/libpmem2/auto_flush_linux.c b/src/libpmem2/auto_flush_linux.c index ad02af43cc7..951dc791833 100644 --- a/src/libpmem2/auto_flush_linux.c +++ b/src/libpmem2/auto_flush_linux.c @@ -47,9 +47,8 @@ check_cpu_cache(const char *domain_path) goto end; } else if (len == 0) { errno = EIO; - ERR("read(%d, %p, %d) empty string", - domain_fd, domain_value, - DOMAIN_VALUE_LEN); + ERR_WO_ERRNO("read(%d, %p, %d) empty string", + domain_fd, domain_value, DOMAIN_VALUE_LEN); cpu_cache = -1; goto end; } else if (domain_value[len - 1] != '\n') { diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index 0da18172711..c2205d8c61d 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -115,13 +115,14 @@ badblocks_get_namespace_bounds(struct ndctl_region *region, if (pfn) { *ns_offset = ndctl_pfn_get_resource(pfn); if (*ns_offset == ULLONG_MAX) { - ERR("(pfn) cannot read offset of the namespace"); + ERR_WO_ERRNO( + "(pfn) cannot read offset of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } *ns_size = ndctl_pfn_get_size(pfn); if (*ns_size == ULLONG_MAX) { - ERR("(pfn) cannot read size of the namespace"); + ERR_WO_ERRNO("(pfn) cannot read size of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } @@ -130,13 +131,14 @@ badblocks_get_namespace_bounds(struct ndctl_region *region, } else if (dax) { *ns_offset = ndctl_dax_get_resource(dax); if (*ns_offset == ULLONG_MAX) { - ERR("(dax) cannot read offset of the namespace"); + ERR_WO_ERRNO( + "(dax) cannot read offset of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } *ns_size = ndctl_dax_get_size(dax); if (*ns_size == ULLONG_MAX) { - ERR("(dax) cannot read size of the namespace"); + ERR_WO_ERRNO("(dax) cannot read size of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } @@ -145,13 +147,15 @@ badblocks_get_namespace_bounds(struct ndctl_region *region, } else { /* raw or btt */ *ns_offset = ndctl_namespace_get_resource(ndns); if (*ns_offset == ULLONG_MAX) { - ERR("(raw/btt) cannot read offset of the namespace"); + ERR_WO_ERRNO( + "(raw/btt) cannot read offset of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } *ns_size = ndctl_namespace_get_size(ndns); if (*ns_size == ULLONG_MAX) { - ERR("(raw/btt) cannot read size of the namespace"); + ERR_WO_ERRNO( + "(raw/btt) cannot read size of the namespace"); return PMEM2_E_CANNOT_READ_BOUNDS; } @@ -188,14 +192,14 @@ badblocks_devdax_clear_one_badblock(struct ndctl_bus *bus, struct ndctl_cmd *cmd_ars_cap = ndctl_bus_cmd_new_ars_cap(bus, address, length); if (cmd_ars_cap == NULL) { - ERR("ndctl_bus_cmd_new_ars_cap() failed (bus '%s')", + ERR_WO_ERRNO("ndctl_bus_cmd_new_ars_cap() failed (bus '%s')", ndctl_bus_get_provider(bus)); return PMEM2_E_ERRNO; } ret = ndctl_cmd_submit(cmd_ars_cap); if (ret) { - ERR("ndctl_cmd_submit() failed (bus '%s')", + ERR_WO_ERRNO("ndctl_cmd_submit() failed (bus '%s')", ndctl_bus_get_provider(bus)); /* ndctl_cmd_submit() returns -errno */ goto out_ars_cap; @@ -204,7 +208,7 @@ badblocks_devdax_clear_one_badblock(struct ndctl_bus *bus, struct ndctl_range range; ret = ndctl_cmd_ars_cap_get_range(cmd_ars_cap, &range); if (ret) { - ERR("ndctl_cmd_ars_cap_get_range() failed"); + ERR_WO_ERRNO("ndctl_cmd_ars_cap_get_range() failed"); /* ndctl_cmd_ars_cap_get_range() returns -errno */ goto out_ars_cap; } @@ -214,7 +218,7 @@ badblocks_devdax_clear_one_badblock(struct ndctl_bus *bus, ret = ndctl_cmd_submit(cmd_clear_error); if (ret) { - ERR("ndctl_cmd_submit() failed (bus '%s')", + ERR_WO_ERRNO("ndctl_cmd_submit() failed (bus '%s')", ndctl_bus_get_provider(bus)); /* ndctl_cmd_submit() returns -errno */ goto out_clear_error; @@ -227,7 +231,7 @@ badblocks_devdax_clear_one_badblock(struct ndctl_bus *bus, ASSERT(cleared <= length); if (cleared < length) { - ERR("failed to clear %llu out of %llu bad blocks", + ERR_WO_ERRNO("failed to clear %llu out of %llu bad blocks", length - cleared, length); errno = ENXIO; /* ndctl handles such error in this way */ ret = PMEM2_E_ERRNO; @@ -256,7 +260,7 @@ pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, ASSERTne(bbctx, NULL); if (src->type == PMEM2_SOURCE_ANON) { - ERR("Anonymous source does not support bad blocks"); + ERR_WO_ERRNO("Anonymous source does not support bad blocks"); return PMEM2_E_NOSUPP; } @@ -547,7 +551,8 @@ pmem2_badblock_next(struct pmem2_badblock_context *bbctx, int ret; if (bbctx->rgn.region == NULL && bbctx->ndns == NULL) { - ERR("Cannot find any matching device, no bad blocks found"); + ERR_WO_ERRNO( + "Cannot find any matching device, no bad blocks found"); return PMEM2_E_NO_BAD_BLOCK_FOUND; } @@ -687,13 +692,13 @@ pmem2_badblock_clear_fsdax(int fd, const struct pmem2_badblock *bb) /* fallocate() takes offset as the off_t type */ if (bb->offset > (size_t)INT64_MAX) { - ERR("bad block's offset is greater than INT64_MAX"); + ERR_WO_ERRNO("bad block's offset is greater than INT64_MAX"); return PMEM2_E_OFFSET_OUT_OF_RANGE; } /* fallocate() takes length as the off_t type */ if (bb->length > (size_t)INT64_MAX) { - ERR("bad block's length is greater than INT64_MAX"); + ERR_WO_ERRNO("bad block's length is greater than INT64_MAX"); return PMEM2_E_LENGTH_OUT_OF_RANGE; } diff --git a/src/libpmem2/config.c b/src/libpmem2/config.c index 3795b3e3959..959c3644d90 100644 --- a/src/libpmem2/config.c +++ b/src/libpmem2/config.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * config.c -- pmem2_config implementation @@ -77,7 +77,7 @@ pmem2_config_set_required_store_granularity(struct pmem2_config *cfg, case PMEM2_GRANULARITY_PAGE: break; default: - ERR("unknown granularity value %d", g); + ERR_WO_ERRNO("unknown granularity value %d", g); return PMEM2_E_GRANULARITY_NOT_SUPPORTED; } @@ -96,7 +96,7 @@ pmem2_config_set_offset(struct pmem2_config *cfg, size_t offset) /* mmap func takes offset as a type of off_t */ if (offset > (size_t)INT64_MAX) { - ERR("offset is greater than INT64_MAX"); + ERR_WO_ERRNO("offset is greater than INT64_MAX"); return PMEM2_E_OFFSET_OUT_OF_RANGE; } @@ -129,19 +129,19 @@ pmem2_config_validate_length(const struct pmem2_config *cfg, ASSERTne(alignment, 0); if (file_len == 0) { - ERR("file length is equal 0"); + ERR_WO_ERRNO("file length is equal 0"); return PMEM2_E_SOURCE_EMPTY; } if (cfg->length % alignment) { - ERR("length is not a multiple of %lu", alignment); + ERR_WO_ERRNO("length is not a multiple of %lu", alignment); return PMEM2_E_LENGTH_UNALIGNED; } /* overflow check */ const size_t end = cfg->offset + cfg->length; if (end < cfg->offset) { - ERR("overflow of offset and length"); + ERR_WO_ERRNO("overflow of offset and length"); return PMEM2_E_MAP_RANGE; } @@ -149,7 +149,7 @@ pmem2_config_validate_length(const struct pmem2_config *cfg, * Validate the file size to be sure the mapping will fit in the file. */ if (end > file_len) { - ERR("mapping larger than file size"); + ERR_WO_ERRNO("mapping larger than file size"); return PMEM2_E_MAP_RANGE; } @@ -170,7 +170,7 @@ pmem2_config_set_sharing(struct pmem2_config *cfg, enum pmem2_sharing_type type) cfg->sharing = type; break; default: - ERR("unknown sharing value %d", type); + ERR_WO_ERRNO("unknown sharing value %d", type); return PMEM2_E_INVALID_SHARING_VALUE; } @@ -206,7 +206,7 @@ pmem2_config_set_protection(struct pmem2_config *cfg, unsigned unknown_prot = prot & ~(PMEM2_PROT_READ | PMEM2_PROT_WRITE | PMEM2_PROT_EXEC | PMEM2_PROT_NONE); if (unknown_prot) { - ERR("invalid flag %u", prot); + ERR_WO_ERRNO("invalid flag %u", prot); return PMEM2_E_INVALID_PROT_FLAG; } diff --git a/src/libpmem2/deep_flush.c b/src/libpmem2/deep_flush.c index 585772ae1e1..1882ab7fca9 100644 --- a/src/libpmem2/deep_flush.c +++ b/src/libpmem2/deep_flush.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020, Intel Corporation */ +/* Copyright 2024, Intel Corporation */ /* * deep_flush.c -- pmem2_deep_flush implementation @@ -27,7 +27,7 @@ pmem2_deep_flush(struct pmem2_map *map, void *ptr, size_t size) uintptr_t flush_end = flush_addr + size; if (flush_addr < map_addr || flush_end > map_end) { - ERR("requested deep flush rage ptr %p size %zu" + ERR_WO_ERRNO("requested deep flush rage ptr %p size %zu" "exceeds map range %p", ptr, size, map); return PMEM2_E_DEEP_FLUSH_RANGE; } diff --git a/src/libpmem2/deep_flush_other.c b/src/libpmem2/deep_flush_other.c index ec5067c2819..4b4b8ebb394 100644 --- a/src/libpmem2/deep_flush_other.c +++ b/src/libpmem2/deep_flush_other.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2021, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * deep_flush_other.c -- deep_flush functionality @@ -40,7 +40,7 @@ pmem2_deep_flush_write(unsigned region_id) SUPPRESS_UNUSED(region_id); const char *err = "BUG: pmem2_deep_flush_write should never be called on this OS"; - ERR("%s", err); + ERR_WO_ERRNO("%s", err); ASSERTinfo(0, err); /* not supported */ diff --git a/src/libpmem2/extent_linux.c b/src/libpmem2/extent_linux.c index 1d1806f54d5..3202b614e58 100644 --- a/src/libpmem2/extent_linux.c +++ b/src/libpmem2/extent_linux.c @@ -47,7 +47,7 @@ pmem2_extents_create_get(int fd, struct extents **exts) /* directories do not have any extents */ if (pmem2_type == PMEM2_FTYPE_DIR) { - ERR( + ERR_WO_ERRNO( "checking extents does not make sense in case of directories"); return PMEM2_E_INVALID_FILE_TYPE; } diff --git a/src/libpmem2/map.c b/src/libpmem2/map.c index 1e02ee1f753..ea78bec1309 100644 --- a/src/libpmem2/map.c +++ b/src/libpmem2/map.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * map.c -- pmem2_map (common) @@ -125,7 +125,7 @@ pmem2_validate_offset(const struct pmem2_config *cfg, size_t *offset, { ASSERTne(alignment, 0); if (cfg->offset % alignment) { - ERR("offset is not a multiple of %lu", alignment); + ERR_WO_ERRNO("offset is not a multiple of %lu", alignment); return PMEM2_E_OFFSET_UNALIGNED; } @@ -213,7 +213,7 @@ pmem2_unregister_mapping(struct pmem2_map *map) util_rwlock_wrlock(&State.range_map_lock); node = ravl_interval_find_equal(State.range_map, map); if (!(node && !ravl_interval_remove(State.range_map, node))) { - ERR("Cannot find mapping %p to delete", map); + ERR_WO_ERRNO("Cannot find mapping %p to delete", map); ret = PMEM2_E_MAPPING_NOT_FOUND; } @@ -274,7 +274,7 @@ pmem2_map_from_existing(struct pmem2_map **map_ptr, ret = pmem2_register_mapping(map); if (ret) { if (ret == -EEXIST) { - ERR( + ERR_WO_ERRNO( "Provided mapping(addr %p len %zu) is already registered by libpmem2", addr, len); ret = PMEM2_E_MAP_EXISTS; diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 3298f13badb..9fe3ec616e6 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -298,7 +298,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, *map_ptr = NULL; if (cfg->requested_max_granularity == PMEM2_GRANULARITY_INVALID) { - ERR( + ERR_WO_ERRNO( "please define the max granularity requested for the mapping"); return PMEM2_E_GRANULARITY_NOT_SET; @@ -348,7 +348,8 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, if (src->type == PMEM2_SOURCE_FD) { if (src->value.ftype == PMEM2_FTYPE_DIR) { - ERR("the directory is not a supported file type"); + ERR_WO_ERRNO( + "the directory is not a supported file type"); return PMEM2_E_INVALID_FILE_TYPE; } @@ -357,8 +358,8 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, if (cfg->sharing == PMEM2_PRIVATE && src->value.ftype == PMEM2_FTYPE_DEVDAX) { - ERR( - "device DAX does not support mapping with MAP_PRIVATE"); + ERR_WO_ERRNO( + "device DAX does not support mapping with MAP_PRIVATE"); return PMEM2_E_SRC_DEVDAX_PRIVATE; } } @@ -387,27 +388,26 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, if (rsv_offset % Mmap_align) { ret = PMEM2_E_OFFSET_UNALIGNED; - ERR( + ERR_WO_ERRNO( "virtual memory reservation offset %zu is not a multiple of %llu", - rsv_offset, Mmap_align); + rsv_offset, Mmap_align); return ret; } if (rsv_offset + reserved_length > rsv_size) { ret = PMEM2_E_LENGTH_OUT_OF_RANGE; - ERR( + ERR_WO_ERRNO( "Reservation %p has not enough space for the intended content", - rsv); + rsv); return ret; } reserv_region = (char *)rsv_addr + rsv_offset; if ((size_t)reserv_region % alignment) { ret = PMEM2_E_ADDRESS_UNALIGNED; - ERR( - "base mapping address %p (virtual memory reservation address + offset)" \ - " is not a multiple of %zu required by device DAX", - reserv_region, alignment); + ERR_WO_ERRNO( + "base mapping address %p (virtual memory reservation address + offset) is not a multiple of %zu required by device DAX", + reserv_region, alignment); return ret; } @@ -415,9 +415,8 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, if (vm_reservation_map_find_acquire(rsv, rsv_offset, reserved_length)) { ret = PMEM2_E_MAPPING_EXISTS; - ERR( - "region of the reservation %p at the offset %zu and " - "length %zu is at least partly occupied by other mapping", + ERR_WO_ERRNO( + "region of the reservation %p at the offset %zu and length %zu is at least partly occupied by other mapping", rsv, rsv_offset, reserved_length); goto err_reservation_release; } @@ -490,7 +489,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, "requested_max_granularity: %d", available_min_granularity, cfg->requested_max_granularity); - ERR("%s", err); + ERR_WO_ERRNO("%s", err); ret = PMEM2_E_GRANULARITY_NOT_SUPPORTED; goto err_undo_mapping; } diff --git a/src/libpmem2/mcsafe_ops_posix.c b/src/libpmem2/mcsafe_ops_posix.c index acc082829b4..1da8c1c9200 100644 --- a/src/libpmem2/mcsafe_ops_posix.c +++ b/src/libpmem2/mcsafe_ops_posix.c @@ -46,8 +46,8 @@ mcsafe_op_reg_read(struct pmem2_source *src, void *buf, size_t size, ssize_t retsize = pread(fd, buf, size, (off_t)offset); if (retsize == -1) { if (errno == EIO) { - ERR("physical I/O error occurred on read operation, " - "possible bad block"); + ERR_WO_ERRNO( + "physical I/O error occurred on read operation, possible bad block"); return PMEM2_E_IO_FAIL; } @@ -72,8 +72,8 @@ mcsafe_op_reg_write(struct pmem2_source *src, void *buf, size_t size, ssize_t retsize = pwrite(fd, buf, size, (off_t)offset); if (retsize == -1) { if (errno == EIO) { - ERR("physical I/O error occurred on write operation, " - "possible bad block"); + ERR_WO_ERRNO( + "physical I/O error occurred on write operation, possible bad block"); return PMEM2_E_IO_FAIL; } @@ -134,7 +134,7 @@ handle_sigbus_execute_mcsafe_op(struct pmem2_source *src, void *buf, /* sigsetjmp returns nonzero only when returning from siglongjmp */ if (sigsetjmp(mcsafe_jmp_buf, 1)) { - ERR("physical I/O error occurred, possible bad block"); + ERR_WO_ERRNO("physical I/O error occurred, possible bad block"); ret = PMEM2_E_IO_FAIL; goto clnup_null_global_jmp; } @@ -274,9 +274,8 @@ static int pmem2_source_type_check_mcsafe_supp(struct pmem2_source *src) { if (src->type != PMEM2_SOURCE_FD && src->type != PMEM2_SOURCE_HANDLE) { - ERR("operation doesn't support provided source type, only "\ - "sources created from file descriptor or file handle "\ - "are supported"); + ERR_WO_ERRNO( + "operation doesn't support provided source type, only sources created from file descriptor or file handle are supported"); return PMEM2_E_SOURCE_TYPE_NOT_SUPPORTED; } @@ -297,8 +296,9 @@ pmem2_source_check_op_size(struct pmem2_source *src, size_t size, size_t offset) size_t max_size = (size_t)(src_size - offset); if (size > max_size) { - ERR("size of read %zu from offset %zu goes beyond the file " - "length %zu", size, offset, max_size); + ERR_WO_ERRNO( + "size of read %zu from offset %zu goes beyond the file length %zu", + size, offset, max_size); return PMEM2_E_LENGTH_OUT_OF_RANGE; } diff --git a/src/libpmem2/numa_ndctl.c b/src/libpmem2/numa_ndctl.c index 549d2eedced..15e1e700e3c 100644 --- a/src/libpmem2/numa_ndctl.c +++ b/src/libpmem2/numa_ndctl.c @@ -25,7 +25,7 @@ pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node) struct ndctl_region *region = NULL; if (src->type == PMEM2_SOURCE_ANON) { - ERR("Anonymous sources are not bound to numa nodes."); + ERR_WO_ERRNO("Anonymous sources are not bound to numa nodes."); return PMEM2_E_NOSUPP; } @@ -44,7 +44,7 @@ pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node) } if (region == NULL) { - ERR("unknown region"); + ERR_WO_ERRNO("unknown region"); ret = PMEM2_E_DAX_REGION_NOT_FOUND; goto end; } diff --git a/src/libpmem2/numa_none.c b/src/libpmem2/numa_none.c index 941d696ed1e..54f0106f742 100644 --- a/src/libpmem2/numa_none.c +++ b/src/libpmem2/numa_none.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2021, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ #include "libpmem2.h" #include "out.h" @@ -13,7 +13,8 @@ int pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node) { SUPPRESS_UNUSED(src, numa_node); - ERR("Cannot get numa node from source - ndctl is not available"); + ERR_WO_ERRNO( + "Cannot get numa node from source - ndctl is not available"); return PMEM2_E_NOSUPP; } diff --git a/src/libpmem2/persist.c b/src/libpmem2/persist.c index d54d69b61ec..defe99d8a4f 100644 --- a/src/libpmem2/persist.c +++ b/src/libpmem2/persist.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2022, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * persist.c -- pmem2_get_[persist|flush|drain]_fn @@ -31,7 +31,7 @@ memmove_nodrain_libc(void *pmemdest, const void *src, size_t len, { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif LOG(15, "pmemdest %p src %p len %zu flags 0x%x", pmemdest, src, len, flags); @@ -55,7 +55,7 @@ memset_nodrain_libc(void *pmemdest, int c, size_t len, unsigned flags, { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif LOG(15, "pmemdest %p c 0x%x len %zu flags 0x%x", pmemdest, c, len, flags); @@ -338,7 +338,7 @@ pmem2_deep_flush_byte(struct pmem2_map *map, void *ptr, size_t size) LOG(3, "map %p ptr %p size %zu", map, ptr, size); if (map->source.type == PMEM2_SOURCE_ANON) { - ERR("Anonymous source does not support deep flush"); + ERR_WO_ERRNO("Anonymous source does not support deep flush"); return PMEM2_E_NOSUPP; } @@ -436,7 +436,7 @@ pmem2_memmove_nonpmem(void *pmemdest, const void *src, size_t len, { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memmove"); Info.memmove_nodrain(pmemdest, src, len, @@ -458,7 +458,7 @@ pmem2_memset_nonpmem(void *pmemdest, int c, size_t len, unsigned flags) { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memset"); Info.memset_nodrain(pmemdest, c, len, @@ -481,7 +481,7 @@ pmem2_memmove(void *pmemdest, const void *src, size_t len, { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memmove"); Info.memmove_nodrain(pmemdest, src, len, flags, Info.flush, @@ -501,7 +501,7 @@ pmem2_memset(void *pmemdest, int c, size_t len, unsigned flags) { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memset"); Info.memset_nodrain(pmemdest, c, len, flags, Info.flush, @@ -522,7 +522,7 @@ pmem2_memmove_eadr(void *pmemdest, const void *src, size_t len, { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memmove"); Info.memmove_nodrain_eadr(pmemdest, src, len, flags, Info.flush, @@ -542,7 +542,7 @@ pmem2_memset_eadr(void *pmemdest, int c, size_t len, unsigned flags) { #ifdef DEBUG if (flags & ~PMEM2_F_MEM_VALID_FLAGS) - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); #endif PMEM2_API_START("pmem2_memset"); Info.memset_nodrain_eadr(pmemdest, c, len, flags, Info.flush, diff --git a/src/libpmem2/pmem2_utils.h b/src/libpmem2/pmem2_utils.h index 39654d1adf4..be113eb7f14 100644 --- a/src/libpmem2/pmem2_utils.h +++ b/src/libpmem2/pmem2_utils.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * pmem2_utils.h -- libpmem2 utilities functions @@ -18,7 +18,7 @@ static inline int pmem2_assert_errno(void) { if (!errno) { - ERR("errno is not set"); + ERR_WO_ERRNO("errno is not set"); ASSERTinfo(0, "errno is not set"); return -EINVAL; } diff --git a/src/libpmem2/pmem2_utils_linux.c b/src/libpmem2/pmem2_utils_linux.c index 377220cd2dd..94a63fb4ccb 100644 --- a/src/libpmem2/pmem2_utils_linux.c +++ b/src/libpmem2/pmem2_utils_linux.c @@ -40,7 +40,8 @@ pmem2_get_type_from_stat(const os_stat_t *st, enum pmem2_file_type *type) } if (!S_ISCHR(st->st_mode)) { - ERR("file type 0%o not supported", st->st_mode & S_IFMT); + ERR_WO_ERRNO("file type 0%o not supported", + st->st_mode & S_IFMT); return PMEM2_E_INVALID_FILE_TYPE; } diff --git a/src/libpmem2/pmem2_utils_ndctl.c b/src/libpmem2/pmem2_utils_ndctl.c index c20540f7af1..0de3c774129 100644 --- a/src/libpmem2/pmem2_utils_ndctl.c +++ b/src/libpmem2/pmem2_utils_ndctl.c @@ -79,7 +79,7 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) *size = ndctl_dax_get_size(dax); } else { ret = PMEM2_E_DAX_REGION_NOT_FOUND; - ERR("Issue while reading Device Dax size - cannot " + ERR_WO_ERRNO("Issue while reading Device Dax size - cannot " "find dax region"); } diff --git a/src/libpmem2/pmem2_utils_none.c b/src/libpmem2/pmem2_utils_none.c index 0863c7dbe11..5dac1801184 100644 --- a/src/libpmem2/pmem2_utils_none.c +++ b/src/libpmem2/pmem2_utils_none.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2022, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ #include @@ -17,7 +17,8 @@ pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment) { SUPPRESS_UNUSED(src, alignment); - ERR("Cannot read Device Dax alignment - ndctl is not available"); + ERR_WO_ERRNO( + "Cannot read Device Dax alignment - ndctl is not available"); return PMEM2_E_NOSUPP; } @@ -31,7 +32,7 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) { SUPPRESS_UNUSED(src, size); - ERR("Cannot read Device Dax size - ndctl is not available"); + ERR_WO_ERRNO("Cannot read Device Dax size - ndctl is not available"); return PMEM2_E_NOSUPP; } diff --git a/src/libpmem2/pmem2_utils_other.c b/src/libpmem2/pmem2_utils_other.c index 6b2c140187a..efbc7b65cd2 100644 --- a/src/libpmem2/pmem2_utils_other.c +++ b/src/libpmem2/pmem2_utils_other.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -21,7 +21,7 @@ pmem2_get_type_from_stat(const os_stat_t *st, enum pmem2_file_type *type) return 0; } - ERR("file type 0%o not supported", st->st_mode & S_IFMT); + ERR_WO_ERRNO("file type 0%o not supported", st->st_mode & S_IFMT); return PMEM2_E_INVALID_FILE_TYPE; } @@ -35,7 +35,7 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) SUPPRESS_UNUSED(src, size); const char *err = "BUG: pmem2_device_dax_size should never be called on this OS"; - ERR("%s", err); + ERR_WO_ERRNO("%s", err); ASSERTinfo(0, err); return PMEM2_E_NOSUPP; } @@ -50,7 +50,7 @@ pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment) SUPPRESS_UNUSED(src, alignment); const char *err = "BUG: pmem2_device_dax_alignment should never be called on this OS"; - ERR("%s", err); + ERR_WO_ERRNO("%s", err); ASSERTinfo(0, err); return PMEM2_E_NOSUPP; } diff --git a/src/libpmem2/region_namespace_ndctl.c b/src/libpmem2/region_namespace_ndctl.c index b8fb71955b6..f9893d4c897 100644 --- a/src/libpmem2/region_namespace_ndctl.c +++ b/src/libpmem2/region_namespace_ndctl.c @@ -106,12 +106,12 @@ pmem2_fsdax_match(dev_t st_dev, const char *devname) os_close(fd); if (nread == 0) { - ERR("%s is empty", path); + ERR_WO_ERRNO("%s is empty", path); return PMEM2_E_INVALID_DEV_FORMAT; } if (buff[nread - 1] != '\n') { - ERR("%s doesn't end with new line", path); + ERR_WO_ERRNO("%s doesn't end with new line", path); return PMEM2_E_INVALID_DEV_FORMAT; } @@ -152,7 +152,7 @@ pmem2_region_namespace(struct ndctl_ctx *ctx, *pndns = NULL; if (src->value.ftype == PMEM2_FTYPE_DIR) { - ERR("cannot check region or namespace of a directory"); + ERR_WO_ERRNO("cannot check region or namespace of a directory"); return PMEM2_E_INVALID_FILE_TYPE; } @@ -250,7 +250,7 @@ pmem2_get_region_id(const struct pmem2_source *src, unsigned *region_id) } if (!region) { - ERR("unknown region"); + ERR_WO_ERRNO("unknown region"); rv = PMEM2_E_DAX_REGION_NOT_FOUND; goto end; } diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 88474c6e580..6f811170f59 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -35,7 +35,7 @@ pmem2_source_from_fd(struct pmem2_source **src, int fd) } if ((flags & O_ACCMODE) == O_WRONLY) { - ERR("fd must be open with O_RDONLY or O_RDWR"); + ERR_WO_ERRNO("fd must be open with O_RDONLY or O_RDWR"); return PMEM2_E_INVALID_FILE_HANDLE; } @@ -62,7 +62,8 @@ pmem2_source_from_fd(struct pmem2_source **src, int fd) return ret; if (ftype == PMEM2_FTYPE_DIR) { - ERR("cannot set fd to directory in pmem2_source_from_fd"); + ERR_WO_ERRNO( + "cannot set fd to directory in pmem2_source_from_fd"); return PMEM2_E_INVALID_FILE_TYPE; } @@ -117,7 +118,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) } case PMEM2_FTYPE_REG: if (st.st_size < 0) { - ERR( + ERR_WO_ERRNO( "kernel says size of regular file is negative (%ld)", st.st_size); return PMEM2_E_INVALID_FILE_HANDLE; @@ -166,7 +167,8 @@ pmem2_source_alignment(const struct pmem2_source *src, size_t *alignment) } if (!util_is_pow2(*alignment)) { - ERR("alignment (%zu) has to be a power of two", *alignment); + ERR_WO_ERRNO( + "alignment (%zu) has to be a power of two", *alignment); return PMEM2_E_INVALID_ALIGNMENT_VALUE; } @@ -187,7 +189,7 @@ pmem2_source_get_fd(const struct pmem2_source *src, int *fd) if (src->type == PMEM2_SOURCE_FD) { *fd = src->value.fd; } else { - ERR( + ERR_WO_ERRNO( "File descriptor is not set, source type does not support fd"); return PMEM2_E_FILE_DESCRIPTOR_NOT_SET; } diff --git a/src/libpmem2/usc_ndctl.c b/src/libpmem2/usc_ndctl.c index 081797b73f9..9ce2097274f 100644 --- a/src/libpmem2/usc_ndctl.c +++ b/src/libpmem2/usc_ndctl.c @@ -26,7 +26,8 @@ pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc) PMEM2_ERR_CLR(); if (src->type == PMEM2_SOURCE_ANON) { - ERR("Anonymous source does not support unsafe shutdown count"); + ERR_WO_ERRNO( + "Anonymous source does not support unsafe shutdown count"); return PMEM2_E_NOSUPP; } @@ -51,7 +52,7 @@ pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc) ret = PMEM2_E_NOSUPP; if (region == NULL) { - ERR( + ERR_WO_ERRNO( "Unsafe shutdown count is not supported for this source"); goto err; } @@ -62,7 +63,7 @@ pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc) long long dimm_usc = ndctl_dimm_get_dirty_shutdown(dimm); if (dimm_usc < 0) { ret = PMEM2_E_NOSUPP; - ERR( + ERR_WO_ERRNO( "Unsafe shutdown count is not supported for this source"); goto err; } @@ -88,7 +89,7 @@ pmem2_source_device_id(const struct pmem2_source *src, char *id, size_t *len) const char *dimm_uid; if (src->type == PMEM2_SOURCE_ANON) { - ERR("Anonymous source does not have device id"); + ERR_WO_ERRNO("Anonymous source does not have device id"); return PMEM2_E_NOSUPP; } diff --git a/src/libpmem2/usc_none.c b/src/libpmem2/usc_none.c index db559525648..a4f61d2124a 100644 --- a/src/libpmem2/usc_none.c +++ b/src/libpmem2/usc_none.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2022, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * usc_none.c -- pmem2 usc function for non supported platform @@ -13,7 +13,7 @@ pmem2_source_device_id(const struct pmem2_source *src, char *id, size_t *len) { SUPPRESS_UNUSED(src, id, len); - ERR("Cannot read device id - ndctl is not available"); + ERR_WO_ERRNO("Cannot read device id - ndctl is not available"); return PMEM2_E_NOSUPP; } @@ -23,7 +23,7 @@ pmem2_source_device_usc(const struct pmem2_source *src, uint64_t *usc) { SUPPRESS_UNUSED(src, usc); - ERR("Cannot read device usc - ndctl is not available"); + ERR_WO_ERRNO("Cannot read device usc - ndctl is not available"); return PMEM2_E_NOSUPP; } diff --git a/src/libpmem2/vm_reservation.c b/src/libpmem2/vm_reservation.c index 982d14c7d3e..473b5c1e2e1 100644 --- a/src/libpmem2/vm_reservation.c +++ b/src/libpmem2/vm_reservation.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2020-2023, Intel Corporation */ +/* Copyright 2020-2024, Intel Corporation */ /* * vm_reservation.c -- implementation of virtual memory allocation API @@ -113,13 +113,13 @@ pmem2_vm_reservation_new(struct pmem2_vm_reservation **rsv_ptr, * on Windows and to the 'page size' otherwise */ if (addr && (unsigned long long)addr % Mmap_align) { - ERR("address %p is not a multiple of 0x%llx", addr, + ERR_WO_ERRNO("address %p is not a multiple of 0x%llx", addr, Mmap_align); return PMEM2_E_ADDRESS_UNALIGNED; } if (size % Mmap_align) { - ERR("reservation size %zu is not a multiple of %llu", + ERR_WO_ERRNO("reservation size %zu is not a multiple of %llu", size, Mmap_align); return PMEM2_E_LENGTH_UNALIGNED; } @@ -187,7 +187,7 @@ pmem2_vm_reservation_delete(struct pmem2_vm_reservation **rsv_ptr) struct pmem2_map *any_map; /* check if reservation contains any mapping */ if (!pmem2_vm_reservation_map_find(rsv, 0, rsv->size, &any_map)) { - ERR("vm reservation %p isn't empty", rsv); + ERR_WO_ERRNO("vm reservation %p isn't empty", rsv); return PMEM2_E_VM_RESERVATION_NOT_EMPTY; } @@ -223,8 +223,9 @@ pmem2_vm_reservation_map_find(struct pmem2_vm_reservation *rsv, struct ravl_interval_node *node; node = ravl_interval_find(rsv->itree, &dummy_map); if (!node) { - ERR("mapping not found at the range (offset %zu, size %zu) in" \ - " reservation %p", reserv_offset, len, rsv); + ERR_WO_ERRNO( + "mapping not found at the range (offset %zu, size %zu) in reservation %p", + reserv_offset, len, rsv); return PMEM2_E_MAPPING_NOT_FOUND; } @@ -249,7 +250,7 @@ pmem2_vm_reservation_map_find_prev(struct pmem2_vm_reservation *rsv, struct ravl_interval_node *node; node = ravl_interval_find_prev(rsv->itree, map); if (!node) { - ERR("mapping previous to mapping %p not found", map); + ERR_WO_ERRNO("mapping previous to mapping %p not found", map); return PMEM2_E_MAPPING_NOT_FOUND; } @@ -274,7 +275,7 @@ pmem2_vm_reservation_map_find_next(struct pmem2_vm_reservation *rsv, struct ravl_interval_node *node; node = ravl_interval_find_next(rsv->itree, map); if (!node) { - ERR("mapping next to mapping %p not found", map); + ERR_WO_ERRNO("mapping next to mapping %p not found", map); return PMEM2_E_MAPPING_NOT_FOUND; } @@ -299,7 +300,7 @@ pmem2_vm_reservation_map_find_first(struct pmem2_vm_reservation *rsv, struct ravl_interval_node *node; node = ravl_interval_find_first(rsv->itree); if (!node) { - ERR("reservation %p stores no mapping", rsv); + ERR_WO_ERRNO("reservation %p stores no mapping", rsv); return PMEM2_E_MAPPING_NOT_FOUND; } @@ -324,7 +325,7 @@ pmem2_vm_reservation_map_find_last(struct pmem2_vm_reservation *rsv, struct ravl_interval_node *node; node = ravl_interval_find_last(rsv->itree); if (!node) { - ERR("reservation %p stores no mapping", rsv); + ERR_WO_ERRNO("reservation %p stores no mapping", rsv); return PMEM2_E_MAPPING_NOT_FOUND; } @@ -344,7 +345,7 @@ vm_reservation_map_register_release(struct pmem2_vm_reservation *rsv, { int ret = ravl_interval_insert(rsv->itree, map); if (ret == -EEXIST) { - ERR( + ERR_WO_ERRNO( "mapping at the given region of the reservation already exists"); ret = PMEM2_E_MAPPING_EXISTS; } @@ -368,8 +369,8 @@ vm_reservation_map_unregister_release(struct pmem2_vm_reservation *rsv, node = ravl_interval_find_equal(rsv->itree, map); if (!(node && !ravl_interval_remove(rsv->itree, node))) { - ERR("Cannot find mapping %p in the reservation %p", - map, rsv); + ERR_WO_ERRNO("Cannot find mapping %p in the reservation %p", + map, rsv); ret = PMEM2_E_MAPPING_NOT_FOUND; } @@ -431,7 +432,8 @@ pmem2_vm_reservation_extend(struct pmem2_vm_reservation *rsv, size_t size) PMEM2_ERR_CLR(); if (size % Mmap_align) { - ERR("reservation extension size %zu is not a multiple of %llu", + ERR_WO_ERRNO( + "reservation extension size %zu is not a multiple of %llu", size, Pagesize); return PMEM2_E_LENGTH_UNALIGNED; } @@ -483,49 +485,53 @@ pmem2_vm_reservation_shrink(struct pmem2_vm_reservation *rsv, size_t offset, PMEM2_ERR_CLR(); if (offset % Mmap_align) { - ERR("reservation shrink offset %zu is not a multiple of %llu", + ERR_WO_ERRNO( + "reservation shrink offset %zu is not a multiple of %llu", offset, Mmap_align); return PMEM2_E_OFFSET_UNALIGNED; } if (size % Mmap_align) { - ERR("reservation shrink size %zu is not a multiple of %llu", + ERR_WO_ERRNO( + "reservation shrink size %zu is not a multiple of %llu", size, Mmap_align); return PMEM2_E_LENGTH_UNALIGNED; } if (offset >= rsv->size) { - ERR("reservation shrink offset %zu is out of reservation range", + ERR_WO_ERRNO( + "reservation shrink offset %zu is out of reservation range", offset); return PMEM2_E_OFFSET_OUT_OF_RANGE; } if (size == 0) { - ERR("reservation shrink size %zu cannot be zero", + ERR_WO_ERRNO("reservation shrink size %zu cannot be zero", size); return PMEM2_E_LENGTH_OUT_OF_RANGE; } if ((offset + size) > rsv->size) { - ERR( + ERR_WO_ERRNO( "reservation shrink size %zu stands out of reservation range", size); return PMEM2_E_LENGTH_OUT_OF_RANGE; } if (offset != 0 && (offset + size) != rsv->size) { - ERR("shrinking reservation from the middle is not supported"); + ERR_WO_ERRNO( + "shrinking reservation from the middle is not supported"); return PMEM2_E_NOSUPP; } if (offset == 0 && size == rsv->size) { - ERR("shrinking whole reservation is not supported"); + ERR_WO_ERRNO("shrinking whole reservation is not supported"); return PMEM2_E_NOSUPP; } struct pmem2_map *any_map; if (!pmem2_vm_reservation_map_find(rsv, offset, size, &any_map)) { - ERR( + ERR_WO_ERRNO( "reservation region (offset %zu, size %zu) to be shrunk is occupied by a mapping", offset, size); return PMEM2_E_VM_RESERVATION_NOT_EMPTY; diff --git a/src/libpmem2/vm_reservation_posix.c b/src/libpmem2/vm_reservation_posix.c index 3c6cd513c9c..bd87a845b5e 100644 --- a/src/libpmem2/vm_reservation_posix.c +++ b/src/libpmem2/vm_reservation_posix.c @@ -91,7 +91,7 @@ vm_reservation_reserve_memory(void *addr, size_t size, void **raddr, */ if (addr && mmap_addr != addr) { munmap(mmap_addr, mmap_size); - ERR("mapping exists in the given address"); + ERR_WO_ERRNO("mapping exists in the given address"); return PMEM2_E_MAPPING_EXISTS; } diff --git a/src/libpmemobj/alloc_class.c b/src/libpmemobj/alloc_class.c index 6b2b80bc301..af261412d46 100644 --- a/src/libpmemobj/alloc_class.c +++ b/src/libpmemobj/alloc_class.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * alloc_class.c -- implementation of allocation classes @@ -226,7 +226,8 @@ alloc_class_new(int id, struct alloc_class_collection *ac, flags_s, size_idx_s); if (critnib_insert(ac->class_map_by_unit_size, k, c) != 0) { - ERR("unable to register allocation class"); + ERR_WO_ERRNO( + "unable to register allocation class"); goto error_map_insert; } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 9dfcd2799af..1090e607ad6 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -763,7 +763,9 @@ heap_reclaim_run(struct palloc_heap *heap, struct memory_block *m, int startup) c->rdsc.nallocs); if (recycler == NULL || recycler_put(recycler, e) < 0) - ERR("lost runtime tracking info of %u run due to OOM", c->id); + ERR_WO_ERRNO( + "lost runtime tracking info of %u run due to OOM", + c->id); return 0; } @@ -1042,7 +1044,7 @@ heap_reuse_from_recycler(struct palloc_heap *heap, struct recycler *recycler = heap_get_recycler(heap, aclass->id, aclass->rdsc.nallocs); if (recycler == NULL) { - ERR("lost runtime tracking info of %u run due to OOM", + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", aclass->id); return 0; } @@ -1158,7 +1160,7 @@ heap_memblock_on_free(struct palloc_heap *heap, const struct memory_block *m) struct recycler *recycler = heap_get_recycler(heap, c->id, c->rdsc.nallocs); if (recycler == NULL) { - ERR("lost runtime tracking info of %u run due to OOM", + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", c->id); } else { recycler_inc_unaccounted(recycler, m); @@ -1401,7 +1403,7 @@ heap_set_arena_auto(struct palloc_heap *heap, unsigned arena_id, a = VEC_ARR(&heap->rt->arenas.vec)[arena_id - 1]; if (!automatic && nautomatic <= 1 && a->automatic) { - ERR("at least one automatic arena must exist"); + ERR_WO_ERRNO("at least one automatic arena must exist"); ret = -1; goto out; } @@ -1596,7 +1598,7 @@ heap_boot(struct palloc_heap *heap, void *heap_start, uint64_t heap_size, } if (heap_size < *sizep) { - ERR("mapped region smaller than the heap size"); + ERR_WO_ERRNO("mapped region smaller than the heap size"); return EINVAL; } @@ -1778,12 +1780,12 @@ static int heap_verify_header(struct heap_header *hdr) { if (util_checksum(hdr, sizeof(*hdr), &hdr->checksum, 0, 0) != 1) { - ERR("heap: invalid header's checksum"); + ERR_WO_ERRNO("heap: invalid header's checksum"); return -1; } if (memcmp(hdr->signature, HEAP_SIGNATURE, HEAP_SIGNATURE_LEN) != 0) { - ERR("heap: invalid signature"); + ERR_WO_ERRNO("heap: invalid signature"); return -1; } @@ -1801,7 +1803,7 @@ heap_verify_zone_header(struct zone_header *hdr) return 0; if (hdr->size_idx == 0) { - ERR("heap: invalid zone size"); + ERR_WO_ERRNO("heap: invalid zone size"); return -1; } @@ -1816,17 +1818,17 @@ static int heap_verify_chunk_header(struct chunk_header *hdr) { if (hdr->type == CHUNK_TYPE_UNKNOWN) { - ERR("heap: invalid chunk type"); + ERR_WO_ERRNO("heap: invalid chunk type"); return -1; } if (hdr->type >= MAX_CHUNK_TYPE) { - ERR("heap: unknown chunk type"); + ERR_WO_ERRNO("heap: unknown chunk type"); return -1; } if (hdr->flags & ~CHUNK_FLAGS_ALL_VALID) { - ERR("heap: invalid chunk flags"); + ERR_WO_ERRNO("heap: invalid chunk flags"); return -1; } @@ -1843,7 +1845,7 @@ heap_verify_zone(struct zone *zone) return 0; /* not initialized, and that is OK */ if (zone->header.magic != ZONE_HEADER_MAGIC) { - ERR("heap: invalid zone magic"); + ERR_WO_ERRNO("heap: invalid zone magic"); return -1; } @@ -1859,7 +1861,7 @@ heap_verify_zone(struct zone *zone) } if (i != zone->header.size_idx) { - ERR("heap: chunk sizes mismatch"); + ERR_WO_ERRNO("heap: chunk sizes mismatch"); return -1; } @@ -1875,7 +1877,7 @@ int heap_check(void *heap_start, uint64_t heap_size) { if (heap_size < HEAP_MIN_SIZE) { - ERR("heap: invalid heap size"); + ERR_WO_ERRNO("heap: invalid heap size"); return -1; } diff --git a/src/libpmemobj/libpmemobj.c b/src/libpmemobj/libpmemobj.c index 824b9973f76..107254c7159 100644 --- a/src/libpmemobj/libpmemobj.c +++ b/src/libpmemobj/libpmemobj.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * libpmemobj.c -- pmem entry points for libpmemobj @@ -49,13 +49,15 @@ pmemobj_check_versionU(unsigned major_required, unsigned minor_required) major_required, minor_required); if (major_required != PMEMOBJ_MAJOR_VERSION) { - ERR("libpmemobj major version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmemobj major version mismatch (need %u, found %u)", major_required, PMEMOBJ_MAJOR_VERSION); return out_get_errormsg(); } if (minor_required > PMEMOBJ_MINOR_VERSION) { - ERR("libpmemobj minor version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmemobj minor version mismatch (need %u, found %u)", minor_required, PMEMOBJ_MINOR_VERSION); return out_get_errormsg(); } diff --git a/src/libpmemobj/memops.c b/src/libpmemobj/memops.c index c69146db037..a321e83b611 100644 --- a/src/libpmemobj/memops.c +++ b/src/libpmemobj/memops.c @@ -569,7 +569,7 @@ operation_user_buffer_verify_align(struct operation_context *ctx, ssize_t capacity_unaligned = (ssize_t)userbuf->size - size_diff - (ssize_t)sizeof(struct ulog); if (capacity_unaligned < (ssize_t)CACHELINE_SIZE) { - ERR("Capacity insufficient"); + ERR_WO_ERRNO("Capacity insufficient"); return -1; } @@ -580,7 +580,7 @@ operation_user_buffer_verify_align(struct operation_context *ctx, userbuf->size = capacity_aligned + sizeof(struct ulog); if (operation_user_buffer_try_insert(ctx->p_ops->base, userbuf)) { - ERR("Buffer currently used"); + ERR_WO_ERRNO("Buffer currently used"); return -1; } @@ -685,7 +685,7 @@ operation_reserve(struct operation_context *ctx, size_t new_capacity) { if (new_capacity > ctx->ulog_capacity) { if (ctx->extend == NULL) { - ERR("no extend function present"); + ERR_WO_ERRNO("no extend function present"); return -1; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 7caaedaf534..8b9f148be60 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -771,14 +771,14 @@ obj_descr_check(PMEMobjpool *pop, const char *layout, size_t poolsize) void *dscp = (void *)((uintptr_t)pop + sizeof(struct pool_hdr)); if (!util_checksum(dscp, OBJ_DSC_P_SIZE, &pop->checksum, 0, 0)) { - ERR("invalid checksum of pool descriptor"); + ERR_WO_ERRNO("invalid checksum of pool descriptor"); errno = EINVAL; return -1; } if (layout && strncmp(pop->layout, layout, PMEMOBJ_MAX_LAYOUT)) { - ERR("wrong layout (\"%s\"), " + ERR_WO_ERRNO("wrong layout (\"%s\"), " "pool created with layout \"%s\"", layout, pop->layout); errno = EINVAL; @@ -786,7 +786,7 @@ obj_descr_check(PMEMobjpool *pop, const char *layout, size_t poolsize) } if (pop->heap_offset % Pagesize) { - ERR("unaligned heap: off %" PRIu64, pop->heap_offset); + ERR_WO_ERRNO("unaligned heap: off %" PRIu64, pop->heap_offset); errno = EINVAL; return -1; } @@ -1031,8 +1031,8 @@ obj_get_nlanes(void) if (env_nlanes) { int nlanes = atoi(env_nlanes); if (nlanes <= 0) { - ERR("%s variable must be a positive integer", - OBJ_NLANES_ENV_VARIABLE); + ERR_WO_ERRNO("%s variable must be a positive integer", + OBJ_NLANES_ENV_VARIABLE); errno = EINVAL; goto no_valid_env; } @@ -1060,7 +1060,7 @@ pmemobj_createU(const char *path, const char *layout, /* check length of layout */ if (layout && (strlen(layout) >= PMEMOBJ_MAX_LAYOUT)) { - ERR("Layout too long"); + ERR_WO_ERRNO("Layout too long"); errno = EINVAL; return NULL; } @@ -1109,7 +1109,7 @@ pmemobj_createU(const char *path, const char *layout, /* initialize replica runtime - is_pmem, funcs, ... */ if (obj_replica_init(rep, set, r) != 0) { - ERR("initialization of replica #%u failed", r); + ERR_WO_ERRNO("initialization of replica #%u failed", r); goto err; } @@ -1129,7 +1129,7 @@ pmemobj_createU(const char *path, const char *layout, /* initialize runtime parts - lanes, obj stores, ... */ if (obj_runtime_init(pop, 0, 1 /* boot */, runtime_nlanes) != 0) { - ERR("pool initialization failed"); + ERR_WO_ERRNO("pool initialization failed"); goto err; } @@ -1179,7 +1179,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) int consistent = 1; if (pop->run_id % 2) { - ERR("invalid run_id %" PRIu64, pop->run_id); + ERR_WO_ERRNO("invalid run_id %" PRIu64, pop->run_id); consistent = 0; } @@ -1241,7 +1241,7 @@ obj_pool_open(struct pool_set **set, const char *path, unsigned flags, /* read-only mode is not supported in libpmemobj */ if ((*set)->rdonly) { - ERR("read-only mode is not supported"); + ERR_WO_ERRNO("read-only mode is not supported"); errno = EINVAL; goto err_rdonly; } @@ -1274,7 +1274,7 @@ obj_replicas_init(struct pool_set *set) /* initialize replica runtime - is_pmem, funcs, ... */ if (obj_replica_init(rep, set, r) != 0) { - ERR("initialization of replica #%u failed", r); + ERR_WO_ERRNO("initialization of replica #%u failed", r); goto err; } @@ -1314,7 +1314,7 @@ obj_replicas_check_basic(PMEMobjpool *pop) for (unsigned r = 0; r < pop->set->nreplicas; r++) { rep = pop->set->replica[r]->part[0].addr; if (obj_check_basic(rep, pop->set->poolsize) == 0) { - ERR("inconsistent replica #%u", r); + ERR_WO_ERRNO("inconsistent replica #%u", r); return -1; } } @@ -1399,7 +1399,7 @@ obj_open_common(const char *path, const char *layout, unsigned flags, int boot) #endif /* initialize runtime parts - lanes, obj stores, ... */ if (obj_runtime_init(pop, 0, boot, runtime_nlanes) != 0) { - ERR("pool initialization failed"); + ERR_WO_ERRNO("pool initialization failed"); goto err_runtime_init; } @@ -1531,11 +1531,11 @@ pmemobj_close(PMEMobjpool *pop) os_mutex_lock(&pools_mutex); if (critnib_remove(pools_ht, pop->uuid_lo) != pop) { - ERR("critnib_remove for pools_ht"); + ERR_WO_ERRNO("critnib_remove for pools_ht"); } if (critnib_remove(pools_tree, (uint64_t)pop) != pop) - ERR("critnib_remove for pools_tree"); + ERR_WO_ERRNO("critnib_remove for pools_tree"); if (_pobj_cached_pool.pop == pop) { _pobj_cached_pool.pop = NULL; @@ -1718,7 +1718,7 @@ obj_alloc_construct(PMEMobjpool *pop, PMEMoid *oidp, size_t size, pmemobj_constr constructor, void *arg) { if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); errno = ENOMEM; return -1; } @@ -1761,7 +1761,7 @@ pmemobj_alloc(PMEMobjpool *pop, PMEMoid *oidp, size_t size, _POBJ_DEBUG_NOTICE_IN_TX(); if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); errno = EINVAL; return -1; } @@ -1792,13 +1792,13 @@ pmemobj_xalloc(PMEMobjpool *pop, PMEMoid *oidp, size_t size, _POBJ_DEBUG_NOTICE_IN_TX(); if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); errno = EINVAL; return -1; } if (flags & ~POBJ_TX_XALLOC_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_TX_XALLOC_VALID_FLAGS); errno = EINVAL; return -1; @@ -1837,7 +1837,7 @@ pmemobj_zalloc(PMEMobjpool *pop, PMEMoid *oidp, size_t size, _POBJ_DEBUG_NOTICE_IN_TX(); if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); errno = EINVAL; return -1; } @@ -1915,7 +1915,7 @@ obj_realloc_common(PMEMobjpool *pop, } if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); errno = ENOMEM; return -1; } @@ -2292,7 +2292,7 @@ pmemobj_xpersist(PMEMobjpool *pop, const void *addr, size_t len, unsigned flags) if (flags & ~OBJ_X_VALID_FLAGS) { errno = EINVAL; - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); return -1; } @@ -2310,7 +2310,7 @@ pmemobj_xflush(PMEMobjpool *pop, const void *addr, size_t len, unsigned flags) if (flags & ~OBJ_X_VALID_FLAGS) { errno = EINVAL; - ERR("invalid flags 0x%x", flags); + ERR_WO_ERRNO("invalid flags 0x%x", flags); return -1; } @@ -2412,13 +2412,13 @@ pmemobj_root_construct(PMEMobjpool *pop, size_t size, arg); if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); errno = ENOMEM; return OID_NULL; } if (size == 0 && pop->root_offset == 0) { - ERR("requested size cannot equals zero"); + ERR_WO_ERRNO("requested size cannot equals zero"); errno = EINVAL; return OID_NULL; } @@ -2554,7 +2554,7 @@ pmemobj_xreserve(PMEMobjpool *pop, struct pobj_action *act, PMEMoid oid = OID_NULL; if (flags & ~POBJ_ACTION_XRESERVE_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_ACTION_XRESERVE_VALID_FLAGS); errno = EINVAL; return oid; @@ -2663,7 +2663,8 @@ pmemobj_defrag(PMEMobjpool *pop, PMEMoid **oidv, size_t oidcnt, continue; if (oidv[i]->pool_uuid_lo != pop->uuid_lo) { ret = -1; - ERR("Not all PMEMoids belong to the provided pool"); + ERR_WO_ERRNO( + "Not all PMEMoids belong to the provided pool"); goto out; } objv[j++] = &oidv[i]->off; @@ -2732,7 +2733,7 @@ pmemobj_list_insert_new(PMEMobjpool *pop, size_t pe_offset, void *head, ASSERT(pe_offset <= size - sizeof(struct list_entry)); if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); errno = ENOMEM; return OID_NULL; } diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index 9420440277d..e4aa51cddb9 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2022, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * palloc.c -- implementation of pmalloc POSIX-like API @@ -193,7 +193,7 @@ palloc_reservation_create(struct palloc_heap *heap, size_t size, (uint8_t)class_id); if (c == NULL) { - ERR("no allocation class for size %lu bytes", size); + ERR_WO_ERRNO("no allocation class for size %lu bytes", size); errno = EINVAL; return -1; } @@ -208,7 +208,7 @@ palloc_reservation_create(struct palloc_heap *heap, size_t size, */ ssize_t size_idx = alloc_class_calc_size_idx(c, size); if (size_idx < 0) { - ERR("allocation class not suitable for size %lu bytes", + ERR_WO_ERRNO("allocation class not suitable for size %lu bytes", size); errno = EINVAL; return -1; @@ -272,7 +272,7 @@ palloc_heap_action_exec(struct palloc_heap *heap, #ifdef DEBUG enum memblock_state s = act->m.m_ops->get_state(&act->m); if (s == act->new_state || s == MEMBLOCK_STATE_UNKNOWN) { - ERR("invalid operation or heap corruption"); + ERR_WO_ERRNO("invalid operation or heap corruption"); ASSERT(0); } #endif /* DEBUG */ diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 95b49bcc407..41e9a58979d 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2021, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * pmalloc.c -- implementation of pmalloc POSIX-like API @@ -231,13 +231,13 @@ CTL_WRITE_HANDLER(desc)(void *ctx, } if (p->alignment != 0 && p->unit_size % p->alignment != 0) { - ERR("unit size must be evenly divisible by alignment"); + ERR_WO_ERRNO("unit size must be evenly divisible by alignment"); errno = EINVAL; return -1; } if (p->alignment > (MEGABYTE * 2)) { - ERR("alignment cannot be larger than 2 megabytes"); + ERR_WO_ERRNO("alignment cannot be larger than 2 megabytes"); errno = EINVAL; return -1; } @@ -255,14 +255,15 @@ CTL_WRITE_HANDLER(desc)(void *ctx, break; case MAX_POBJ_HEADER_TYPES: default: - ERR("invalid header type"); + ERR_WO_ERRNO("invalid header type"); errno = EINVAL; return -1; } if (PMDK_SLIST_EMPTY(indexes)) { if (alloc_class_find_first_free_slot(ac, &id) != 0) { - ERR("no available free allocation class identifier"); + ERR_WO_ERRNO( + "no available free allocation class identifier"); errno = EINVAL; return -1; } @@ -271,7 +272,7 @@ CTL_WRITE_HANDLER(desc)(void *ctx, ASSERTeq(strcmp(idx->name, "class_id"), 0); if (idx->value < 0 || idx->value >= MAX_ALLOCATION_CLASSES) { - ERR("class id outside of the allowed range"); + ERR_WO_ERRNO("class id outside of the allowed range"); errno = ERANGE; return -1; } @@ -279,7 +280,8 @@ CTL_WRITE_HANDLER(desc)(void *ctx, id = (uint8_t)idx->value; if (alloc_class_reserve(ac, id) != 0) { - ERR("attempted to overwrite an allocation class"); + ERR_WO_ERRNO( + "attempted to overwrite an allocation class"); errno = EEXIST; return -1; } @@ -333,7 +335,7 @@ pmalloc_header_type_parser(const void *arg, void *dest, size_t dest_size) } else if (strcmp(vstr, "legacy") == 0) { *htype = POBJ_HEADER_LEGACY; } else { - ERR("invalid header type"); + ERR_WO_ERRNO("invalid header type"); errno = EINVAL; return -1; } @@ -358,7 +360,7 @@ CTL_READ_HANDLER(desc)(void *ctx, ASSERTeq(strcmp(idx->name, "class_id"), 0); if (idx->value < 0 || idx->value >= MAX_ALLOCATION_CLASSES) { - ERR("class id outside of the allowed range"); + ERR_WO_ERRNO("class id outside of the allowed range"); errno = ERANGE; return -1; } @@ -369,7 +371,7 @@ CTL_READ_HANDLER(desc)(void *ctx, heap_alloc_classes(&pop->heap), id); if (c == NULL) { - ERR("class with the given id does not exist"); + ERR_WO_ERRNO("class with the given id does not exist"); errno = ENOENT; return -1; } @@ -448,7 +450,9 @@ CTL_RUNNABLE_HANDLER(extend)(void *ctx, ssize_t arg_in = *(ssize_t *)arg; if (arg_in < (ssize_t)PMEMOBJ_MIN_PART) { - ERR("incorrect size for extend, must be larger than %" PRIu64, + ERR_WO_ERRNO( + "incorrect size for extend, must be larger than %" \ + PRIu64, PMEMOBJ_MIN_PART); return -1; } @@ -498,7 +502,9 @@ CTL_WRITE_HANDLER(granularity)(void *ctx, ssize_t arg_in = *(int *)arg; if (arg_in != 0 && arg_in < (ssize_t)PMEMOBJ_MIN_PART) { - ERR("incorrect grow size, must be 0 or larger than %" PRIu64, + ERR_WO_ERRNO( + "incorrect grow size, must be 0 or larger than %" \ + PRIu64, PMEMOBJ_MIN_PART); return -1; } @@ -901,7 +907,7 @@ arenas_assignment_type_parser(const void *arg, void *dest, size_t dest_size) } else if (strcmp(vstr, "thread") == 0) { *atype = POBJ_ARENAS_ASSIGNMENT_THREAD_KEY; } else { - ERR("invalid arena assignment type"); + ERR_WO_ERRNO("invalid arena assignment type"); errno = EINVAL; return -1; } diff --git a/src/libpmemobj/stats.c b/src/libpmemobj/stats.c index 8799c4830c6..d1871268c62 100644 --- a/src/libpmemobj/stats.c +++ b/src/libpmemobj/stats.c @@ -67,7 +67,7 @@ stats_enabled_parser(const void *arg, void *dest, size_t dest_size) } else if (strcmp(vstr, "transient") == 0) { *enabled = POBJ_STATS_ENABLED_TRANSIENT; } else { - ERR("invalid enable type"); + ERR_WO_ERRNO("invalid enable type"); errno = EINVAL; return -1; } diff --git a/src/libpmemobj/sync.c b/src/libpmemobj/sync.c index ee7b7198ab3..c8c4428d44e 100644 --- a/src/libpmemobj/sync.c +++ b/src/libpmemobj/sync.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * sync.c -- persistent memory resident synchronization primitives @@ -40,14 +40,14 @@ _get_value(uint64_t pop_runid, volatile uint64_t *runid, void *value, void *arg, initializer = 1; if (init_value(value, arg)) { - ERR("error initializing lock"); + ERR_WO_ERRNO("error initializing lock"); util_fetch_and_and64(runid, 0); return -1; } if (util_bool_compare_and_swap64(runid, pop_runid - 1, pop_runid) == 0) { - ERR("error setting lock runid"); + ERR_WO_ERRNO("error setting lock runid"); return -1; } } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index 3ab1ca2f145..63eac100c33 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -509,7 +509,7 @@ add_to_tx_and_lock(struct tx *tx, enum pobj_tx_param type, void *lock) } break; default: - ERR("Unrecognized lock type"); + ERR_WO_ERRNO("Unrecognized lock type"); ASSERT(0); break; } @@ -546,7 +546,7 @@ release_and_free_tx_locks(struct tx *tx) tx_lock->lock.rwlock); break; default: - ERR("Unrecognized lock type"); + ERR_WO_ERRNO("Unrecognized lock type"); ASSERT(0); break; } @@ -584,7 +584,7 @@ tx_alloc_common(struct tx *tx, size_t size, type_num_t type_num, LOG(3, NULL); if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); return obj_tx_fail_null(ENOMEM, args.flags); } @@ -613,7 +613,7 @@ tx_alloc_common(struct tx *tx, size_t size, type_num_t type_num, err_oom: tx_action_remove(tx); - ERR("out of memory"); + ERR_WO_ERRNO("out of memory"); return obj_tx_fail_null(ENOMEM, args.flags); } @@ -629,7 +629,7 @@ tx_realloc_common(struct tx *tx, PMEMoid oid, size_t size, uint64_t type_num, LOG(3, NULL); if (size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("requested size too large"); + ERR_WO_ERRNO("requested size too large"); return obj_tx_fail_null(ENOMEM, flags); } @@ -643,7 +643,7 @@ tx_realloc_common(struct tx *tx, PMEMoid oid, size_t size, uint64_t type_num, /* if size is 0 just free */ if (size == 0) { if (pmemobj_tx_free(oid)) { - ERR("pmemobj_tx_free failed"); + ERR_WO_ERRNO("pmemobj_tx_free failed"); return oid; } else { return OID_NULL; @@ -661,7 +661,7 @@ tx_realloc_common(struct tx *tx, PMEMoid oid, size_t size, uint64_t type_num, if (!OBJ_OID_IS_NULL(new_obj)) { if (pmemobj_tx_free(oid)) { - ERR("pmemobj_tx_free failed"); + ERR_WO_ERRNO("pmemobj_tx_free failed"); VEC_POP_BACK(&tx->actions); return OID_NULL; } @@ -678,7 +678,7 @@ tx_construct_user_buffer(struct tx *tx, void *addr, size_t size, enum pobj_log_type type, int outer_tx, uint64_t flags) { if (tx->pop != pmemobj_pool_by_ptr(addr)) { - ERR("Buffer from a different pool"); + ERR_WO_ERRNO("Buffer from a different pool"); goto err; } @@ -735,7 +735,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) if (tx->stage == TX_STAGE_WORK) { ASSERTne(tx->lane, NULL); if (tx->pop != pop) { - ERR("nested transaction for different pool"); + ERR_WO_ERRNO("nested transaction for different pool"); return obj_tx_fail_err(EINVAL, 0); } @@ -860,7 +860,7 @@ pmemobj_tx_xlock(enum pobj_tx_param type, void *lockp, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XLOCK_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XLOCK_VALID_FLAGS); return obj_tx_fail_err(EINVAL, flags); } @@ -1229,14 +1229,14 @@ pmemobj_tx_add_common(struct tx *tx, struct tx_range_def *args) LOG(15, NULL); if (args->size > PMEMOBJ_MAX_ALLOC_SIZE) { - ERR("snapshot size too large"); + ERR_WO_ERRNO("snapshot size too large"); return obj_tx_fail_err(EINVAL, args->flags); } if (args->offset < tx->pop->heap_offset || (args->offset + args->size) > (tx->pop->heap_offset + tx->pop->heap_size)) { - ERR("object outside of heap"); + ERR_WO_ERRNO("object outside of heap"); return obj_tx_fail_err(EINVAL, args->flags); } @@ -1376,7 +1376,7 @@ pmemobj_tx_add_common(struct tx *tx, struct tx_range_def *args) } if (ret != 0) { - ERR("out of memory"); + ERR_WO_ERRNO("out of memory"); return obj_tx_fail_err(ENOMEM, args->flags); } @@ -1403,7 +1403,7 @@ pmemobj_tx_add_range_direct(const void *ptr, size_t size) uint64_t flags = tx_abort_on_failure_flag(tx); if (!OBJ_PTR_FROM_POOL(tx->pop, ptr)) { - ERR("object outside of pool"); + ERR_WO_ERRNO("object outside of pool"); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); return ret; @@ -1441,7 +1441,7 @@ pmemobj_tx_xadd_range_direct(const void *ptr, size_t size, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XADD_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, flags + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XADD_VALID_FLAGS); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); @@ -1449,7 +1449,7 @@ pmemobj_tx_xadd_range_direct(const void *ptr, size_t size, uint64_t flags) } if (!OBJ_PTR_FROM_POOL(tx->pop, ptr)) { - ERR("object outside of pool"); + ERR_WO_ERRNO("object outside of pool"); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); return ret; @@ -1486,7 +1486,7 @@ pmemobj_tx_add_range(PMEMoid oid, uint64_t hoff, size_t size) uint64_t flags = tx_abort_on_failure_flag(tx); if (oid.pool_uuid_lo != tx->pop->uuid_lo) { - ERR("invalid pool uuid"); + ERR_WO_ERRNO("invalid pool uuid"); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); return ret; @@ -1524,7 +1524,7 @@ pmemobj_tx_xadd_range(PMEMoid oid, uint64_t hoff, size_t size, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XADD_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, flags + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XADD_VALID_FLAGS); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); @@ -1532,7 +1532,7 @@ pmemobj_tx_xadd_range(PMEMoid oid, uint64_t hoff, size_t size, uint64_t flags) } if (oid.pool_uuid_lo != tx->pop->uuid_lo) { - ERR("invalid pool uuid"); + ERR_WO_ERRNO("invalid pool uuid"); ret = obj_tx_fail_err(EINVAL, flags); PMEMOBJ_API_END(); return ret; @@ -1569,7 +1569,7 @@ pmemobj_tx_alloc(size_t size, uint64_t type_num) PMEMoid oid; if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); return oid; @@ -1600,7 +1600,7 @@ pmemobj_tx_zalloc(size_t size, uint64_t type_num) PMEMOBJ_API_START(); PMEMoid oid; if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); return oid; @@ -1631,14 +1631,14 @@ pmemobj_tx_xalloc(size_t size, uint64_t type_num, uint64_t flags) PMEMoid oid; if (size == 0) { - ERR("allocation with size 0"); + ERR_WO_ERRNO("allocation with size 0"); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); return oid; } if (flags & ~POBJ_TX_XALLOC_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, flags + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~(POBJ_TX_XALLOC_VALID_FLAGS)); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); @@ -1707,7 +1707,7 @@ pmemobj_tx_xstrdup(const char *s, uint64_t type_num, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_TX_XALLOC_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_TX_XALLOC_VALID_FLAGS); return obj_tx_fail_null(EINVAL, flags); } @@ -1715,7 +1715,7 @@ pmemobj_tx_xstrdup(const char *s, uint64_t type_num, uint64_t flags) PMEMOBJ_API_START(); PMEMoid oid; if (NULL == s) { - ERR("cannot duplicate NULL string"); + ERR_WO_ERRNO("cannot duplicate NULL string"); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); return oid; @@ -1765,7 +1765,7 @@ pmemobj_tx_xwcsdup(const wchar_t *s, uint64_t type_num, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_TX_XALLOC_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_TX_XALLOC_VALID_FLAGS); return obj_tx_fail_null(EINVAL, flags); } @@ -1773,7 +1773,7 @@ pmemobj_tx_xwcsdup(const wchar_t *s, uint64_t type_num, uint64_t flags) PMEMOBJ_API_START(); PMEMoid oid; if (NULL == s) { - ERR("cannot duplicate NULL string"); + ERR_WO_ERRNO("cannot duplicate NULL string"); oid = obj_tx_fail_null(EINVAL, flags); PMEMOBJ_API_END(); return oid; @@ -1824,7 +1824,7 @@ pmemobj_tx_xfree(PMEMoid oid, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XFREE_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XFREE_VALID_FLAGS); return obj_tx_fail_err(EINVAL, flags); } @@ -1835,7 +1835,7 @@ pmemobj_tx_xfree(PMEMoid oid, uint64_t flags) PMEMobjpool *pop = tx->pop; if (pop->uuid_lo != oid.pool_uuid_lo) { - ERR("invalid pool uuid"); + ERR_WO_ERRNO("invalid pool uuid"); return obj_tx_fail_err(EINVAL, flags); } @@ -1907,7 +1907,7 @@ pmemobj_tx_xpublish(struct pobj_action *actv, size_t actvcnt, uint64_t flags) flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XPUBLISH_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XPUBLISH_VALID_FLAGS); return obj_tx_fail_err(EINVAL, flags); } @@ -1952,7 +1952,7 @@ pmemobj_tx_xlog_append_buffer(enum pobj_log_type type, void *addr, size_t size, flags |= tx_abort_on_failure_flag(tx); if (flags & ~POBJ_XLOG_APPEND_BUFFER_VALID_FLAGS) { - ERR("unknown flags 0x%" PRIx64, + ERR_WO_ERRNO("unknown flags 0x%" PRIx64, flags & ~POBJ_XLOG_APPEND_BUFFER_VALID_FLAGS); return obj_tx_fail_err(EINVAL, flags); } @@ -2201,7 +2201,8 @@ CTL_WRITE_HANDLER(size)(void *ctx, if (arg_in < 0 || arg_in > (ssize_t)PMEMOBJ_MAX_ALLOC_SIZE) { errno = EINVAL; - ERR("invalid cache size, must be between 0 and max alloc size"); + ERR_WO_ERRNO( + "invalid cache size, must be between 0 and max alloc size"); return -1; } diff --git a/src/libpmempool/check_backup.c b/src/libpmempool/check_backup.c index de1e4dee1a7..01900df0f09 100644 --- a/src/libpmempool/check_backup.c +++ b/src/libpmempool/check_backup.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2021, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * check_backup.c -- pre-check backup @@ -100,7 +100,7 @@ backup_nonpoolset_overwrite(PMEMpoolcheck *ppc, location *loc, loc->step = CHECK_STEP_COMPLETE; return 0; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -265,7 +265,7 @@ backup_poolset_overwrite(PMEMpoolcheck *ppc, location *loc, loc->step = CHECK_STEP_COMPLETE; return 0; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index ca9236726c4..8475dbf8a94 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * check_pool_hdr.c -- pool header check @@ -216,7 +216,7 @@ pool_hdr_default_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, memset(loc->hdr.unused, 0, sizeof(loc->hdr.unused)); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -315,7 +315,7 @@ pool_hdr_nondefault_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, util_convert2le_hdr(&loc->hdr); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -458,7 +458,7 @@ pool_hdr_poolset_uuid_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, check_get_uuid_str(loc->hdr.poolset_uuid)); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -581,7 +581,7 @@ pool_hdr_uuid_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, check_get_uuid_str(loc->hdr.uuid)); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -683,7 +683,7 @@ pool_hdr_uuid_links_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, POOL_HDR_UUID_LEN); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; @@ -736,7 +736,7 @@ pool_hdr_checksum_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, loc->prefix, le64toh(loc->hdr.checksum)); break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; diff --git a/src/libpmempool/check_sds.c b/src/libpmempool/check_sds.c index 1869ee08a9a..7844fcf6cb2 100644 --- a/src/libpmempool/check_sds.c +++ b/src/libpmempool/check_sds.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2022, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * check_shutdown_state.c -- shutdown state check @@ -126,7 +126,7 @@ sds_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, ++loc->healthy_replicas; break; default: - ERR("not implemented question id: %u", question); + ERR_WO_ERRNO("not implemented question id: %u", question); } return 0; } diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 4e39bdd37c5..1d4a8416310 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -262,7 +262,7 @@ status_push(PMEMpoolcheck *ppc, struct check_status *st, uint32_t question) if (CHECK_IS_NOT(ppc, REPAIR)) { /* error status */ if (status_msg_info_only(st->msg)) { - ERR("no error message for the user"); + ERR_WO_ERRNO("no error message for the user"); st->msg[0] = '\0'; } st->status.type = PMEMPOOL_CHECK_MSG_TYPE_ERROR; @@ -620,7 +620,7 @@ check_get_uuid_str(uuid_t uuid) int ret = util_uuid_to_string(uuid, uuid_str); if (ret != 0) { - ERR("failed to convert uuid to string"); + ERR_WO_ERRNO("failed to convert uuid to string"); return ""; } return uuid_str; diff --git a/src/libpmempool/feature.c b/src/libpmempool/feature.c index 83600057e07..f3bfcec6a01 100644 --- a/src/libpmempool/feature.c +++ b/src/libpmempool/feature.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2023, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * feature.c -- implementation of pmempool_feature_(enable|disable|query)() @@ -47,12 +47,12 @@ buff_concat(char *buff, size_t *pos, const char *fmt, ...) va_end(ap); if (ret < 0) { - ERR("vsprintf"); + ERR_WO_ERRNO("vsprintf"); return ret; } if ((size_t)ret >= size) { - ERR("buffer truncated %d >= %zu", ret, size); + ERR_WO_ERRNO("buffer truncated %d >= %zu", ret, size); return -1; } @@ -110,7 +110,7 @@ features_check(features_t *f, struct pool_hdr *hdrp) goto err; if (buff_concat_features(msg, &pos, *f)) goto err; - ERR("features mismatch detected: %s", msg); + ERR_WO_ERRNO("features mismatch detected: %s", msg); return -1; } else { return 0; @@ -130,7 +130,7 @@ features_check(features_t *f, struct pool_hdr *hdrp) size_t pos = 0; if (buff_concat_features(msg, &pos, unknown)) goto err; - ERR("invalid features detected: %s", msg); + ERR_WO_ERRNO("invalid features detected: %s", msg); err: return -1; } @@ -172,7 +172,7 @@ poolset_open(const char *path, int rdonly) /* read poolset */ int ret = util_poolset_create_set(&set, path, 0, 0, true); if (ret < 0) { - ERR("cannot open pool set -- '%s'", path); + ERR_WO_ERRNO("cannot open pool set -- '%s'", path); goto err_poolset; } @@ -196,7 +196,7 @@ poolset_open(const char *path, int rdonly) } if (features_check(&f, HDR(rep, p))) { - ERR( + ERR_WO_ERRNO( "invalid features - replica #%d part #%d", r, p); goto err_open; @@ -301,11 +301,14 @@ require_other_feature_is(struct pool_set *set, features_t other, if (state == req_state) return 1; - const char *msg = (req_state == ENABLED) - ? FEATURE_IS_NOT_ENABLED_PRIOR_STR - : FEATURE_IS_NOT_DISABLED_PRIOR_STR; - ERR(msg, util_feature2str(other, NULL), - cause, util_feature2str(feature, NULL)); + if (req_state == ENABLED) + ERR_WO_ERRNO(FEATURE_IS_NOT_ENABLED_PRIOR_STR, + util_feature2str(other, NULL), cause, + util_feature2str(feature, NULL)); + else + ERR_WO_ERRNO(FEATURE_IS_NOT_DISABLED_PRIOR_STR, + util_feature2str(other, NULL), cause, + util_feature2str(feature, NULL)); return 0; } @@ -354,7 +357,8 @@ query_feature(const char *path, features_t feature) static inline int unsupported_feature(features_t feature) { - ERR("unsupported feature: %s", util_feature2str(feature, NULL)); + ERR_WO_ERRNO("unsupported feature: %s", + util_feature2str(feature, NULL)); errno = EINVAL; return -1; } @@ -600,7 +604,7 @@ static inline int are_flags_valid(unsigned flags) { if (flags != 0) { - ERR("invalid flags: 0x%x", flags); + ERR_WO_ERRNO("invalid flags: 0x%x", flags); errno = EINVAL; return 0; } @@ -614,7 +618,7 @@ static inline int is_feature_valid(uint32_t feature) { if (feature >= FEATURE_FUNCS_MAX) { - ERR("invalid feature: 0x%x", feature); + ERR_WO_ERRNO("invalid feature: 0x%x", feature); errno = EINVAL; return 0; } diff --git a/src/libpmempool/libpmempool.c b/src/libpmempool/libpmempool.c index a842f519e69..b6cbeb8db08 100644 --- a/src/libpmempool/libpmempool.c +++ b/src/libpmempool/libpmempool.c @@ -56,13 +56,15 @@ pmempool_check_versionU(unsigned major_required, unsigned minor_required) major_required, minor_required); if (major_required != PMEMPOOL_MAJOR_VERSION) { - ERR("libpmempool major version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmempool major version mismatch (need %u, found %u)", major_required, PMEMPOOL_MAJOR_VERSION); return out_get_errormsg(); } if (minor_required > PMEMPOOL_MINOR_VERSION) { - ERR("libpmempool minor version mismatch (need %u, found %u)", + ERR_WO_ERRNO( + "libpmempool minor version mismatch (need %u, found %u)", minor_required, PMEMPOOL_MINOR_VERSION); return out_get_errormsg(); } @@ -130,7 +132,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) * args_size. */ if (args_size < sizeof(struct pmempool_check_args)) { - ERR("provided args_size is not supported"); + ERR_WO_ERRNO("provided args_size is not supported"); errno = EINVAL; return NULL; } @@ -144,8 +146,9 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_REPAIR) && util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN | PMEMPOOL_CHECK_ADVANCED | PMEMPOOL_CHECK_ALWAYS_YES)) { - ERR("dry_run, advanced and always_yes are applicable only if " - "repair is set"); + ERR_WO_ERRNO( + "dry_run, advanced and always_yes are applicable " + "only if repair is set"); errno = EINVAL; return NULL; } @@ -155,7 +158,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) */ if (util_flag_isset(args->flags, PMEMPOOL_CHECK_DRY_RUN) && args->backup_path != NULL) { - ERR("dry run does not allow one to perform backup"); + ERR_WO_ERRNO("dry run does not allow one to perform backup"); errno = EINVAL; return NULL; } @@ -164,7 +167,7 @@ pmempool_check_initU(struct pmempool_check_argsU *args, size_t args_size) * libpmempool uses str format of communication so it must be set */ if (util_flag_isclr(args->flags, PMEMPOOL_CHECK_FORMAT_STR)) { - ERR("PMEMPOOL_CHECK_FORMAT_STR flag must be set"); + ERR_WO_ERRNO("PMEMPOOL_CHECK_FORMAT_STR flag must be set"); errno = EINVAL; return NULL; } diff --git a/src/libpmempool/pool.c b/src/libpmempool/pool.c index 68a340565dc..63fb938b5f5 100644 --- a/src/libpmempool/pool.c +++ b/src/libpmempool/pool.c @@ -46,14 +46,14 @@ pool_set_read_header(const char *fname, struct pool_hdr *hdr) const struct pool_set_part *part = PART(REP(set, 0), 0); int fdp = util_file_open(part->path, NULL, 0, O_RDONLY); if (fdp < 0) { - ERR("cannot open poolset part file"); + ERR_WO_ERRNO("cannot open poolset part file"); ret = -1; goto err_pool_set; } /* read the pool header from first pool set file */ if (pread(fdp, hdr, sizeof(*hdr), 0) != sizeof(*hdr)) { - ERR("cannot read pool header from poolset"); + ERR_WO_ERRNO("cannot read pool header from poolset"); ret = -1; goto err_close_part; } @@ -83,7 +83,7 @@ pool_set_map(const char *fname, struct pool_set **poolset, unsigned flags) /* parse pool type from first pool set file */ enum pool_type type = pool_hdr_get_type(&hdr); if (type == POOL_TYPE_UNKNOWN) { - ERR("cannot determine pool type from poolset"); + ERR_WO_ERRNO("cannot determine pool type from poolset"); return -1; } @@ -97,7 +97,7 @@ pool_set_map(const char *fname, struct pool_set **poolset, unsigned flags) if (util_pool_open(poolset, fname, 0 /* minpartsize */, &attr, NULL, NULL, flags | POOL_OPEN_IGNORE_SDS | POOL_OPEN_IGNORE_BAD_BLOCKS)) { - ERR("opening poolset failed"); + ERR_WO_ERRNO("opening poolset failed"); return -1; } @@ -136,7 +136,8 @@ pool_check_type_to_pool_type(enum pmempool_pool_type check_pool_type) case PMEMPOOL_POOL_TYPE_OBJ: return POOL_TYPE_OBJ; default: - ERR("can not convert pmempool_pool_type %u to pool_type", + ERR_WO_ERRNO( + "can not convert pmempool_pool_type %u to pool_type", check_pool_type); return POOL_TYPE_UNKNOWN; } @@ -245,7 +246,7 @@ pool_params_parse(const PMEMpoolcheck *ppc, struct pool_params *params, enum pool_type declared_type = pool_check_type_to_pool_type(ppc->args.pool_type); if ((params->type & ~declared_type) != 0) { - ERR("declared pool type does not match"); + ERR_WO_ERRNO("declared pool type does not match"); errno = EINVAL; ret = 1; goto out_unmap; @@ -311,7 +312,7 @@ pool_set_file_open(const char *fname, int rdonly) os_stat_t buf; if (os_stat(path, &buf)) { - ERR("%s", path); + ERR_WO_ERRNO("%s", path); goto err_close_poolset; } @@ -750,7 +751,7 @@ pool_set_type(struct pool_set *set) if (util_file_pread(part->path, &hdr, sizeof(hdr), 0) != sizeof(hdr)) { - ERR("cannot read pool header from poolset"); + ERR_WO_ERRNO("cannot read pool header from poolset"); return POOL_TYPE_UNKNOWN; } @@ -769,7 +770,7 @@ pool_get_min_size(enum pool_type type) case POOL_TYPE_OBJ: return PMEMOBJ_MIN_POOL; default: - ERR("unknown type of a pool"); + ERR_WO_ERRNO("unknown type of a pool"); return SIZE_MAX; } } diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index 94ab1d38893..a0e9eea7320 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -132,7 +132,7 @@ replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn, /* if the part is a device dax, clear its bad blocks */ if (type == TYPE_DEVDAX && fix_bad_blocks && badblocks_clear_all(part->path)) { - ERR("clearing bad blocks in device dax failed -- '%s'", + ERR_WO_ERRNO("clearing bad blocks in device dax failed -- '%s'", part->path); errno = EIO; return -1; @@ -640,7 +640,7 @@ check_checksums_and_signatures(struct pool_set *set, if (!util_checksum(hdr, sizeof(*hdr), &hdr->checksum, 0, POOL_HDR_CSUM_END_OFF(hdr))) { - ERR("invalid checksum of pool header"); + ERR_WO_ERRNO("invalid checksum of pool header"); rep_hs->part[p].flags |= IS_BROKEN; } else if (util_is_zeroed(hdr, sizeof(*hdr))) { rep_hs->part[p].flags |= IS_BROKEN; @@ -648,7 +648,7 @@ check_checksums_and_signatures(struct pool_set *set, enum pool_type type = pool_hdr_get_type(hdr); if (type == POOL_TYPE_UNKNOWN) { - ERR("invalid signature"); + ERR_WO_ERRNO("invalid signature"); rep_hs->part[p].flags |= IS_BROKEN; } } @@ -781,7 +781,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) /* check if bad blocks build an increasing sequence */ if (bb.offset < min_offset) { - ERR( + ERR_WO_ERRNO( "wrong format of bad block recovery file (bad blocks are not sorted by the offset in ascending order) -- '%s'", path); errno = EINVAL; @@ -1207,13 +1207,13 @@ replica_badblocks_check_or_clear(struct pool_set *set, case RECOVERY_FILES_EXIST_ALL: case RECOVERY_FILES_NOT_ALL_EXIST: if (!called_from_sync) { - ERR( + ERR_WO_ERRNO( "error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' to fix bad blocks first"); return -1; } if (!fix_bad_blocks) { - ERR( + ERR_WO_ERRNO( "error: a bad block recovery file exists, but the '--bad-blocks' option is not set\n" ERR_MSG_BB); return -1; @@ -1318,13 +1318,13 @@ replica_badblocks_check_or_clear(struct pool_set *set, /* bad blocks were found */ if (!called_from_sync) { - ERR( + ERR_WO_ERRNO( "error: bad blocks found, run 'pmempool sync --bad-blocks' to fix bad blocks first"); return -1; } if (!fix_bad_blocks) { - ERR( + ERR_WO_ERRNO( "error: bad blocks found, but the '--bad-blocks' option is not set\n" ERR_MSG_BB); return -1; @@ -1361,7 +1361,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, ret = replica_badblocks_clear(set, set_hs); if (ret < 0) { - ERR("clearing bad blocks failed"); + ERR_WO_ERRNO("clearing bad blocks failed"); return -1; } @@ -1444,7 +1444,7 @@ check_uuids_between_parts(struct pool_set *set, unsigned repn, } if (uuidcmp(HDR(rep, p)->poolset_uuid, poolset_uuid)) { - ERR( + ERR_WO_ERRNO( "different poolset uuids in parts from the same replica (repn %u, parts %u and %u) - cannot synchronize", repn, part_stored, p); errno = EINVAL; @@ -1473,7 +1473,7 @@ check_uuids_between_parts(struct pool_set *set, unsigned repn, hdrp->next_repl_uuid); if (prev_differ || next_differ) { - ERR( + ERR_WO_ERRNO( "different adjacent replica UUID between parts (repn %u, parts %u and %u) - cannot synchronize", repn, unbroken_p, p); errno = EINVAL; @@ -1499,7 +1499,7 @@ check_uuids_between_parts(struct pool_set *set, unsigned repn, hdrp->uuid) || uuidcmp(hdrp->next_part_uuid, next_hdrp->uuid); if (next_decoupled) { - ERR( + ERR_WO_ERRNO( "two consecutive unbroken parts are not linked to each other (repn %u, parts %u and %u) - cannot synchronize", repn, p, p + 1); errno = EINVAL; @@ -1616,7 +1616,7 @@ check_poolset_uuids(struct pool_set *set, /* find a replica with healthy header */ unsigned r_h = replica_find_replica_healthy_header(set_hs); if (r_h == UNDEF_REPLICA) { - ERR("no healthy replica found"); + ERR_WO_ERRNO("no healthy replica found"); return -1; } @@ -1630,7 +1630,7 @@ check_poolset_uuids(struct pool_set *set, continue; if (check_replica_poolset_uuids(set, r, poolset_uuid, set_hs)) { - ERR( + ERR_WO_ERRNO( "inconsistent poolset uuids between replicas %u and %u - cannot synchronize", r_h, r); return -1; @@ -1702,7 +1702,7 @@ check_uuids_between_replicas(struct pool_set *set, if (p_n != UNDEF_PART && rep_uuidp != NULL && uuidcmp(*rep_uuidp, HDR(rep_n, p_n)->prev_repl_uuid)) { - ERR( + ERR_WO_ERRNO( "inconsistent replica uuids between replicas %u and %u", r, r_n); return -1; @@ -1710,7 +1710,7 @@ check_uuids_between_replicas(struct pool_set *set, if (p != UNDEF_PART && rep_n_uuidp != NULL && uuidcmp(*rep_n_uuidp, HDR(rep, p)->next_repl_uuid)) { - ERR( + ERR_WO_ERRNO( "inconsistent replica uuids between replicas %u and %u", r, r_n); return -1; @@ -1735,7 +1735,7 @@ check_uuids_between_replicas(struct pool_set *set, struct pool_replica *rep_nn = REP(set, r_nn); if (uuidcmp(HDR(rep, p)->next_repl_uuid, HDR(rep_nn, p_nn)->prev_repl_uuid)) { - ERR( + ERR_WO_ERRNO( "inconsistent replica uuids on borders of replica %u", r); return -1; @@ -1776,7 +1776,7 @@ check_replica_cycles(struct pool_set *set, * the number of all replicas; for the user it * means that: */ - ERR( + ERR_WO_ERRNO( "alien replica found (probably coming from a different poolset)"); return -1; } @@ -1820,7 +1820,7 @@ check_replica_sizes(struct pool_set *set, struct poolset_health_status *set_hs) /* check if each replica is big enough to hold the pool data */ if (set->poolsize < (size_t)replica_pool_size) { - ERR( + ERR_WO_ERRNO( "some replicas are too small to hold synchronized data"); return -1; } @@ -1832,7 +1832,8 @@ check_replica_sizes(struct pool_set *set, struct poolset_health_status *set_hs) /* check if pools in all healthy replicas are of equal size */ if (pool_size != replica_pool_size) { - ERR("pool sizes from different replicas differ"); + ERR_WO_ERRNO( + "pool sizes from different replicas differ"); return -1; } } @@ -2061,8 +2062,9 @@ replica_check_part_sizes(struct pool_set *set, size_t min_size) for (unsigned p = 0; p < rep->nparts; ++p) { if (PART(rep, p)->filesize < min_size) { - ERR("replica %u, part %u: file is too small", - r, p); + ERR_WO_ERRNO( + "replica %u, part %u: file is too small", + r, p); errno = EINVAL; return -1; } @@ -2084,7 +2086,7 @@ replica_check_local_part_dir(struct pool_set *set, unsigned repn, const char *dir = dirname(path); os_stat_t sb; if (os_stat(dir, &sb) != 0 || !(sb.st_mode & S_IFDIR)) { - ERR( + ERR_WO_ERRNO( "directory %s for part %u in replica %u does not exist or is not accessible", path, partn, repn); Free(path); @@ -2173,13 +2175,13 @@ pmempool_syncU(const char *poolset, unsigned flags) /* check if poolset has correct signature */ if (util_is_poolset_file(poolset) != 1) { - ERR("file is not a poolset file"); + ERR_WO_ERRNO("file is not a poolset file"); goto err; } /* check if flags are supported */ if (check_flags_sync(flags)) { - ERR("unsupported flags"); + ERR_WO_ERRNO("unsupported flags"); errno = EINVAL; goto err; } @@ -2187,19 +2189,19 @@ pmempool_syncU(const char *poolset, unsigned flags) /* open poolset file */ int fd = util_file_open(poolset, NULL, 0, O_RDONLY); if (fd < 0) { - ERR("cannot open a poolset file"); + ERR_WO_ERRNO("cannot open a poolset file"); goto err; } /* fill up pool_set structure */ struct pool_set *set = NULL; if (util_poolset_parse(&set, poolset, fd)) { - ERR("parsing input poolset failed"); + ERR_WO_ERRNO("parsing input poolset failed"); goto err_close_file; } if (set->nreplicas == 1) { - ERR("no replica(s) found in the pool set"); + ERR_WO_ERRNO("no replica(s) found in the pool set"); errno = EINVAL; goto err_close_all; } @@ -2251,19 +2253,19 @@ pmempool_transformU(const char *poolset_src, /* check if the source poolset has correct signature */ if (util_is_poolset_file(poolset_src) != 1) { - ERR("source file is not a poolset file"); + ERR_WO_ERRNO("source file is not a poolset file"); goto err; } /* check if the destination poolset has correct signature */ if (util_is_poolset_file(poolset_dst) != 1) { - ERR("destination file is not a poolset file"); + ERR_WO_ERRNO("destination file is not a poolset file"); goto err; } /* check if flags are supported */ if (check_flags_transform(flags)) { - ERR("unsupported flags"); + ERR_WO_ERRNO("unsupported flags"); errno = EINVAL; goto err; } @@ -2271,14 +2273,14 @@ pmempool_transformU(const char *poolset_src, /* open the source poolset file */ int fd_in = util_file_open(poolset_src, NULL, 0, O_RDONLY); if (fd_in < 0) { - ERR("cannot open source poolset file"); + ERR_WO_ERRNO("cannot open source poolset file"); goto err; } /* parse the source poolset file */ struct pool_set *set_in = NULL; if (util_poolset_parse(&set_in, poolset_src, fd_in)) { - ERR("parsing source poolset failed"); + ERR_WO_ERRNO("parsing source poolset failed"); os_close(fd_in); goto err; } @@ -2287,7 +2289,7 @@ pmempool_transformU(const char *poolset_src, /* open the destination poolset file */ int fd_out = util_file_open(poolset_dst, NULL, 0, O_RDONLY); if (fd_out < 0) { - ERR("cannot open destination poolset file"); + ERR_WO_ERRNO("cannot open destination poolset file"); goto err_free_poolin; } @@ -2296,7 +2298,7 @@ pmempool_transformU(const char *poolset_src, /* parse the destination poolset file */ struct pool_set *set_out = NULL; if (util_poolset_parse(&set_out, poolset_dst, fd_out)) { - ERR("parsing destination poolset failed"); + ERR_WO_ERRNO("parsing destination poolset failed"); os_close(fd_out); goto err_free_poolin; } @@ -2306,8 +2308,9 @@ pmempool_transformU(const char *poolset_src, enum pool_type ptype = pool_set_type(set_in); if (ptype != POOL_TYPE_OBJ) { errno = EINVAL; - ERR("transform is not supported for given pool type: %s", - pool_get_pool_type_str(ptype)); + ERR_WO_ERRNO( + "transform is not supported for given pool type: %s", + pool_get_pool_type_str(ptype)); goto err_free_poolout; } diff --git a/src/libpmempool/rm.c b/src/libpmempool/rm.c index 2978ae15cb1..b8faabcba29 100644 --- a/src/libpmempool/rm.c +++ b/src/libpmempool/rm.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2023, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * rm.c -- implementation of pmempool_rm() function @@ -22,7 +22,7 @@ if (CHECK_FLAG((f), FORCE))\ LOG(2, "!(ignored) " __VA_ARGS__);\ else\ - ERR(__VA_ARGS__);\ + ERR_WO_ERRNO(__VA_ARGS__);\ } while (0) #define CHECK_FLAG(f, i) ((f) & PMEMPOOL_RM_##i) @@ -51,9 +51,9 @@ rm_local(const char *path, unsigned flags, int is_part_file) if (S_ISDIR(buff.st_mode)) { errno = EISDIR; if (is_part_file) - ERR("%s: removing file failed", path); + ERR_WO_ERRNO("%s: removing file failed", path); else - ERR("removing file failed"); + ERR_WO_ERRNO("removing file failed"); return -1; } } @@ -98,7 +98,7 @@ pmempool_rmU(const char *path, unsigned flags) int ret; if (flags & ~PMEMPOOL_RM_ALL_FLAGS) { - ERR("invalid flags specified"); + ERR_WO_ERRNO("invalid flags specified"); errno = EINVAL; return -1; } @@ -110,7 +110,7 @@ pmempool_rmU(const char *path, unsigned flags) if (!ret) { if (S_ISDIR(buff.st_mode)) { errno = EISDIR; - ERR("removing file failed"); + ERR_WO_ERRNO("removing file failed"); return -1; } } diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index 3f04f74e984..bc22068f244 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2022, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * sync.c -- a module for poolset synchronizing @@ -921,7 +921,8 @@ fill_struct_broken_part_uuids(struct pool_set *set, unsigned repn, if (replica_is_poolset_transformed(flags)) { /* generate new uuid for this part */ if (util_uuid_generate(rep->part[p].uuid) < 0) { - ERR("cannot generate pool set part UUID"); + ERR_WO_ERRNO( + "cannot generate pool set part UUID"); errno = EINVAL; return -1; } @@ -946,7 +947,7 @@ fill_struct_broken_part_uuids(struct pool_set *set, unsigned repn, hdrp = HDR(REPP(set, repn), 0); if (is_uuid_already_used(hdrp->next_repl_uuid, set, repn)) { - ERR( + ERR_WO_ERRNO( "repeated uuid - some replicas were created with a different poolset file"); errno = EINVAL; return -1; @@ -959,7 +960,7 @@ fill_struct_broken_part_uuids(struct pool_set *set, unsigned repn, hdrp = HDR(REPN(set, repn), 0); if (is_uuid_already_used(hdrp->prev_repl_uuid, set, repn)) { - ERR( + ERR_WO_ERRNO( "repeated uuid - some replicas were created with a different poolset file"); errno = EINVAL; return -1; @@ -969,7 +970,8 @@ fill_struct_broken_part_uuids(struct pool_set *set, unsigned repn, } else { /* generate new uuid for this part */ if (util_uuid_generate(rep->part[p].uuid) < 0) { - ERR("cannot generate pool set part UUID"); + ERR_WO_ERRNO( + "cannot generate pool set part UUID"); errno = EINVAL; return -1; } @@ -1110,7 +1112,8 @@ grant_created_parts_perm(struct pool_set *set, unsigned src_repn, mode_t src_mode; os_stat_t sb; if (os_stat(PART(REP(set, src_repn), 0)->path, &sb) != 0) { - ERR("cannot check file permissions of %s (replica %u, part %u)", + ERR_WO_ERRNO( + "cannot check file permissions of %s (replica %u, part %u)", PART(REP(set, src_repn), 0)->path, src_repn, 0); src_mode = def_mode; } else { @@ -1133,7 +1136,7 @@ grant_created_parts_perm(struct pool_set *set, unsigned src_repn, /* set rights to those of existing part files */ if (os_chmod(PART(REP(set, r), p)->path, src_mode)) { - ERR( + ERR_WO_ERRNO( "cannot set permission rights for created parts: replica %u, part %u", r, p); errno = EPERM; @@ -1333,7 +1336,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, if (healthy_header == UNDEF_REPLICA) { healthy_header = replica_find_replica_healthy_header(set_hs); if (healthy_header == UNDEF_REPLICA) { - ERR("no healthy replica found"); + ERR_WO_ERRNO("no healthy replica found"); errno = EINVAL; ret = -1; goto out; @@ -1348,21 +1351,21 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* recreate broken parts */ if (recreate_broken_parts(set, set_hs, fix_bad_blocks(flags))) { - ERR("recreating broken parts failed"); + ERR_WO_ERRNO("recreating broken parts failed"); ret = -1; goto out; } /* open all part files */ if (replica_open_poolset_part_files(set)) { - ERR("opening poolset part files failed"); + ERR_WO_ERRNO("opening poolset part files failed"); ret = -1; goto out; } /* map all replicas */ if (util_poolset_open(set)) { - ERR("opening poolset failed"); + ERR_WO_ERRNO("opening poolset failed"); ret = -1; goto out; } @@ -1390,7 +1393,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, } if (status == 1) { - ERR( + ERR_WO_ERRNO( "a part of the pool has uncorrectable errors in all replicas"); errno = EINVAL; ret = -1; @@ -1409,7 +1412,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* find one good replica; it will be the source of data */ healthy_replica = replica_find_healthy_replica(set_hs); if (healthy_replica == UNDEF_REPLICA) { - ERR("no healthy replica found"); + ERR_WO_ERRNO("no healthy replica found"); errno = EINVAL; ret = -1; goto out; @@ -1417,14 +1420,14 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* update uuid fields in the set structure with part headers */ if (fill_struct_uuids(set, healthy_replica, set_hs, flags)) { - ERR("gathering uuids failed"); + ERR_WO_ERRNO("gathering uuids failed"); ret = -1; goto out; } /* create headers for broken parts */ if (create_headers_for_broken_parts(set, healthy_replica, set_hs)) { - ERR("creating headers for broken parts failed"); + ERR_WO_ERRNO("creating headers for broken parts failed"); ret = -1; goto out; } @@ -1432,21 +1435,21 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* check and copy data if possible */ if (copy_data_to_broken_parts(set, healthy_replica, flags, set_hs)) { - ERR("copying data to broken parts failed"); + ERR_WO_ERRNO("copying data to broken parts failed"); ret = -1; goto out; } /* update uuids of replicas and parts */ if (update_uuids(set, set_hs)) { - ERR("updating uuids failed"); + ERR_WO_ERRNO("updating uuids failed"); ret = -1; goto out; } /* grant permissions to all created parts */ if (grant_created_parts_perm(set, healthy_replica, set_hs)) { - ERR("granting permissions to created parts failed"); + ERR_WO_ERRNO("granting permissions to created parts failed"); ret = -1; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index cb5a8b45ad3..151a064e436 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -74,30 +74,31 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) char *pathp = util_part_realpath(PART(repr, p)->path); if (pathp == NULL) { if (errno != ENOENT) { - ERR("realpath failed for %s, errno %d", + ERR_WO_ERRNO( + "realpath failed for %s, errno %d", PART(repr, p)->path, errno); ret = -1; goto out; } - LOG(1, "cannot get absolute path for %s," - " replica %u, part %u", - PART(rep, partn)->path, repn, - partn); + LOG(1, + "cannot get absolute path for %s, replica %u, part %u", + PART(rep, partn)->path, repn, partn); pathp = strdup(PART(repr, p)->path); errno = 0; } int result = util_compare_file_inodes(path, pathp); if (result == 0) { /* same file used multiple times */ - ERR("some part file's path is" - " used multiple times"); + ERR_WO_ERRNO( + "some part file's path is used multiple times"); ret = -1; errno = EINVAL; free(pathp); goto out; } else if (result < 0) { - ERR("comparing file inodes failed for %s and" - " %s", path, pathp); + ERR_WO_ERRNO( + "comparing file inodes failed for %s and %s", + path, pathp); ret = -1; free(pathp); goto out; @@ -140,7 +141,8 @@ validate_args(struct pool_set *set_in, struct pool_set *set_out) LOG(3, "set_in %p, set_out %p", set_in, set_out); if (set_in->directory_based) { - ERR("transform of directory poolsets is not supported"); + ERR_WO_ERRNO( + "transform of directory poolsets is not supported"); errno = EINVAL; return -1; } @@ -150,7 +152,7 @@ validate_args(struct pool_set *set_in, struct pool_set *set_out) * (now replication works only for pmemobj pools) */ if (replica_check_part_sizes(set_out, PMEMOBJ_MIN_POOL)) { - ERR("part sizes check failed"); + ERR_WO_ERRNO("part sizes check failed"); return -1; } @@ -168,12 +170,12 @@ validate_args(struct pool_set *set_in, struct pool_set *set_out) */ ssize_t master_pool_size = replica_get_pool_size(set_in, 0); if (master_pool_size < 0) { - ERR("getting pool size from master replica failed"); + ERR_WO_ERRNO("getting pool size from master replica failed"); return -1; } if (set_out->poolsize < (size_t)master_pool_size) { - ERR("target poolset is too small"); + ERR_WO_ERRNO("target poolset is too small"); errno = EINVAL; return -1; } @@ -265,8 +267,8 @@ check_compare_poolsets_status(struct pool_set *set_in, set_out_s->replica[ro] != UNDEF_REPLICA) { /* there are more than one counterparts */ - ERR("there are more then one corresponding" - " replicas; cannot transform"); + ERR_WO_ERRNO( + "there are more then one corresponding replicas; cannot transform"); errno = EINVAL; return -1; } @@ -296,8 +298,8 @@ check_compare_poolsets_options(struct pool_set *set_in, if ((set_in->options & OPTION_NOHDRS) || (set_out->options & OPTION_NOHDRS)) { errno = EINVAL; - ERR( - "the NOHDRS poolset option is not supported in local poolset files"); + ERR_WO_ERRNO( + "the NOHDRS poolset option is not supported in local poolset files"); return -1; } @@ -383,7 +385,7 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, /* make sure we have at least one replica to keep */ if (!has_replica_to_keep) { - ERR("there must be at least one replica left"); + ERR_WO_ERRNO("there must be at least one replica left"); return NOT_TRANSFORMABLE; } @@ -393,7 +395,7 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, LOG(2, "Replica %u from output set has no counterpart", r); if (is_removing_replicas) { - ERR( + ERR_WO_ERRNO( "adding and removing replicas at the same time is not allowed"); return NOT_TRANSFORMABLE; } @@ -407,7 +409,7 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, if (!is_removing_replicas && !is_adding_replicas && (set_in_s->flags & OPTION_SINGLEHDR) == (set_out_s->flags & OPTION_SINGLEHDR)) { - ERR("both poolsets are equal"); + ERR_WO_ERRNO("both poolsets are equal"); return NOT_TRANSFORMABLE; } @@ -415,7 +417,7 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, if ((is_removing_replicas || is_adding_replicas) && (set_in_s->flags & OPTION_SINGLEHDR) != (set_out_s->flags & OPTION_SINGLEHDR)) { - ERR( + ERR_WO_ERRNO( "cannot add/remove replicas and change the SINGLEHDR option at the same time"); return NOT_TRANSFORMABLE; } @@ -602,7 +604,7 @@ fill_replica_struct_uuids(struct pool_set *set, unsigned repn) memcpy(PART(rep, 0)->uuid, HDR(rep, 0)->uuid, POOL_HDR_UUID_LEN); for (unsigned p = 1; p < rep->nhdrs; ++p) { if (util_uuid_generate(rep->part[p].uuid) < 0) { - ERR("cannot generate part UUID"); + ERR_WO_ERRNO("cannot generate part UUID"); errno = EINVAL; return -1; } @@ -852,12 +854,12 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, struct poolset_health_status *set_in_hs = NULL; if (replica_check_poolset_health(set_in, &set_in_hs, 0 /* called from transform */, flags)) { - ERR("source poolset health check failed"); + ERR_WO_ERRNO("source poolset health check failed"); return -1; } if (!replica_is_poolset_healthy(set_in_hs)) { - ERR("source poolset is broken"); + ERR_WO_ERRNO("source poolset is broken"); ret = -1; errno = EINVAL; goto free_hs_in; @@ -868,7 +870,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, struct poolset_health_status *set_out_hs = NULL; if (replica_create_poolset_health_status(set_out, &set_out_hs)) { - ERR("creating poolset health status failed"); + ERR_WO_ERRNO("creating poolset health status failed"); ret = -1; goto free_hs_in; } @@ -877,7 +879,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, struct poolset_compare_status *set_in_cs = NULL; struct poolset_compare_status *set_out_cs = NULL; if (compare_poolsets(set_in, set_out, &set_in_cs, &set_out_cs)) { - ERR("comparing poolsets failed"); + ERR_WO_ERRNO("comparing poolsets failed"); ret = -1; goto free_hs_out; } @@ -896,15 +898,15 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, if (!is_dry_run(flags) && remove_hdrs(set_in, set_out, set_in_hs, flags)) { - ERR("removing headers failed; falling back to the " - "input poolset"); + ERR_WO_ERRNO( + "removing headers failed; falling back to the input poolset"); if (replica_sync(set_in, set_in_hs, flags | IS_TRANSFORMED)) { - LOG(1, "falling back to the input poolset " - "failed"); + LOG(1, + "falling back to the input poolset failed"); } else { - LOG(1, "falling back to the input poolset " - "succeeded"); + LOG(1, + "falling back to the input poolset succeeded"); } ret = -1; } @@ -914,15 +916,15 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, if (operation == ADD_HDRS) { if (!is_dry_run(flags) && add_hdrs(set_in, set_out, set_in_hs, flags)) { - ERR("adding headers failed; falling back to the " - "input poolset"); + ERR_WO_ERRNO( + "adding headers failed; falling back to the input poolset"); if (replica_sync(set_in, set_in_hs, flags | IS_TRANSFORMED)) { - LOG(1, "falling back to the input poolset " - "failed"); + LOG(1, + "falling back to the input poolset failed"); } else { - LOG(1, "falling back to the input poolset " - "succeeded"); + LOG(1, + "falling back to the input poolset succeeded"); } ret = -1; } @@ -934,7 +936,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, * check if any of the parts that are to be added already exists */ if (do_added_parts_exist(set_out, set_out_hs)) { - ERR("some parts being added already exist"); + ERR_WO_ERRNO("some parts being added already exist"); ret = -1; errno = EINVAL; goto free_cs; diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index 31230b197a9..a3b6552487c 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -28,7 +28,7 @@ main(int argc, char *argv[]) MAJOR_VERSION, MINOR_VERSION); errno = 0; - ERR("ERR #%d", 1); + ERR_WO_ERRNO("ERR #%d", 1); UT_OUT("%s", out_get_errormsg()); errno = 0; From 7576c09efd6b689cd7e80feb8afcd93f4005ba53 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 14:30:39 +0100 Subject: [PATCH 028/182] common: exclude error messages in examples tests Signed-off-by: Tomasz Gromadzki --- src/test/ex_libpmemobj/TEST0 | 12 +++++++++--- src/test/ex_libpmemobj/TEST1 | 20 +++++++++++++------- src/test/ex_libpmemobj/TEST17 | 24 +++++++++++++++--------- src/test/ex_libpmemobj/TEST18 | 2 +- src/test/ex_libpmemobj/TEST7 | 12 +++++++++--- src/test/ex_libpmemobj/TEST8 | 12 +++++++++--- src/test/ex_libpmemobj/TEST9 | 11 ++++++++--- src/test/ex_libpmemobj/common.sh | 13 +++++++++++++ 8 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 src/test/ex_libpmemobj/common.sh diff --git a/src/test/ex_libpmemobj/TEST0 b/src/test/ex_libpmemobj/TEST0 index f3cd5149176..a3ac967685a 100755 --- a/src/test/ex_libpmemobj/TEST0 +++ b/src/test/ex_libpmemobj/TEST0 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST0 -- unit test for libpmemobj examples @@ -17,8 +17,14 @@ setup EX_PATH=../../examples/libpmemobj -expect_normal_exit $EX_PATH/pi $DIR/testfile1 c 2 20 > out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/pi $DIR/testfile1 p >> out$UNITTEST_NUM.log 2>&1 +. ./common.sh + +expect_normal_exit $EX_PATH/pi $DIR/testfile1 c 2 20 > $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/pi $DIR/testfile1 p >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/TEST1 b/src/test/ex_libpmemobj/TEST1 index 86f751c47f3..bb6256c31a6 100755 --- a/src/test/ex_libpmemobj/TEST1 +++ b/src/test/ex_libpmemobj/TEST1 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST1 -- unit test for libpmemobj examples @@ -14,14 +14,20 @@ require_build_type debug nondebug setup +. ./common.sh + EX_PATH=../../examples/libpmemobj -expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 1234 foo > out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 4321 bar >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 1 Hello >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 2 World! >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/btree $DIR/testfile1 p >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/btree $DIR/testfile1 f 4321 >> out$UNITTEST_NUM.log 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 1234 foo > $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 4321 bar >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 1 Hello >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 2 World! >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 p >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/btree $DIR/testfile1 f 4321 >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/TEST17 b/src/test/ex_libpmemobj/TEST17 index ccbca8f96cd..91b6e79de22 100755 --- a/src/test/ex_libpmemobj/TEST17 +++ b/src/test/ex_libpmemobj/TEST17 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST17 -- unit test for libpmemobj examples @@ -13,16 +13,22 @@ require_test_type medium setup +. ./common.sh + EX_PATH=../../examples/libpmemobj -expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 foo 100 > out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 2 bar 200 >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 3 foo 300 >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 bar 400 >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 foo print >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 2 bar print >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 3 foo print >> out$UNITTEST_NUM.log 2>&1 -expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 bar print >> out$UNITTEST_NUM.log 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 foo 100 > $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 2 bar 200 >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 3 foo 300 >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 bar 400 >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 foo print >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 2 bar print >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 3 foo print >> $LOG_TEMP 2>&1 +expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 bar print >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/TEST18 b/src/test/ex_libpmemobj/TEST18 index cbda68729a8..44f36924a38 100755 --- a/src/test/ex_libpmemobj/TEST18 +++ b/src/test/ex_libpmemobj/TEST18 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST18 -- unit test for libpmemobj examples diff --git a/src/test/ex_libpmemobj/TEST7 b/src/test/ex_libpmemobj/TEST7 index 6f58a41172f..39582372ebe 100755 --- a/src/test/ex_libpmemobj/TEST7 +++ b/src/test/ex_libpmemobj/TEST7 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST7 -- unit test for libpmemobj examples @@ -14,13 +14,19 @@ require_build_type debug nondebug setup +. ./common.sh + EX_PATH=../../examples/libpmemobj/string_store -expect_normal_exit $EX_PATH/writer $DIR/testfile1 > out$UNITTEST_NUM.log 2>&1 << EOF +expect_normal_exit $EX_PATH/writer $DIR/testfile1 > $LOG_TEMP 2>&1 << EOF Hello! EOF -expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> out$UNITTEST_NUM.log 2>&1 +expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/TEST8 b/src/test/ex_libpmemobj/TEST8 index a8f949c9657..e084c188e92 100755 --- a/src/test/ex_libpmemobj/TEST8 +++ b/src/test/ex_libpmemobj/TEST8 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST8 -- unit test for libpmemobj examples @@ -14,13 +14,19 @@ require_build_type debug nondebug setup +. ./common.sh + EX_PATH=../../examples/libpmemobj/string_store_tx -expect_normal_exit $EX_PATH/writer $DIR/testfile1 > out$UNITTEST_NUM.log 2>&1 << EOF +expect_normal_exit $EX_PATH/writer $DIR/testfile1 > $LOG_TEMP 2>&1 << EOF Hello! EOF -expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> out$UNITTEST_NUM.log 2>&1 +expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/TEST9 b/src/test/ex_libpmemobj/TEST9 index 5f109791b2d..266b8cfbb93 100755 --- a/src/test/ex_libpmemobj/TEST9 +++ b/src/test/ex_libpmemobj/TEST9 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/ex_libpmemobj/TEST9 -- unit test for libpmemobj examples @@ -14,13 +14,18 @@ require_build_type debug nondebug setup +. ./common.sh EX_PATH=../../examples/libpmemobj/string_store_tx_type -expect_normal_exit $EX_PATH/writer $DIR/testfile1 > out$UNITTEST_NUM.log 2>&1 << EOF +expect_normal_exit $EX_PATH/writer $DIR/testfile1 > $LOG_TEMP 2>&1 << EOF Hello! EOF -expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> out$UNITTEST_NUM.log 2>&1 +expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 + +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP check diff --git a/src/test/ex_libpmemobj/common.sh b/src/test/ex_libpmemobj/common.sh new file mode 100644 index 00000000000..262a90d362c --- /dev/null +++ b/src/test/ex_libpmemobj/common.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +# +# src/test/ex_libpmemobj/common.sh -- common setup of unit test +# for libpmemobj examples +# + +LOG=out$UNITTEST_NUM.log + +LOG_TEMP=out${UNITTEST_NUM}_part.log +rm -f $LOG_TEMP && touch $LOG_TEMP From 65ad2bd1aad05447b3598113b4ec504ad9fefd87 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 16:04:43 +0100 Subject: [PATCH 029/182] common: include new ERROR messages in match files Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_feature/grep0.log.match | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/pmempool_feature/grep0.log.match b/src/test/pmempool_feature/grep0.log.match index 2d1f606a373..8db2004f0e0 100644 --- a/src/test/pmempool_feature/grep0.log.match +++ b/src/test/pmempool_feature/grep0.log.match @@ -1 +1,3 @@ +$(OPT)$(*)*ERROR* feature.c: $(N): unsupported_feature: unsupported feature: SINGLEHDR +$(OPT)$(*)*ERROR* feature.c: $(N): unsupported_feature: unsupported feature: SINGLEHDR query SINGLEHDR result is 0 From a2d9fcd50627ab043528c372b02e2c326193a2d0 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 16:33:08 +0100 Subject: [PATCH 030/182] common: exclude error messages in pmempool_sync tests until #5983 fixed https://github.com/pmem/pmdk/issues/5983 Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_sync/TEST11 | 7 +++++-- src/test/pmempool_sync/TEST12 | 7 +++++-- src/test/pmempool_sync/TEST25 | 7 +++++-- src/test/pmempool_sync/TEST26 | 7 +++++-- src/test/pmempool_sync/TEST29 | 7 ++++++- src/test/pmempool_sync/TEST32 | 7 ++++++- src/test/pmempool_sync/TEST33 | 7 ++++++- src/test/pmempool_sync/TEST34 | 7 ++++++- src/test/pmempool_sync/TEST35 | 7 ++++++- src/test/pmempool_sync/TEST36 | 7 ++++++- src/test/pmempool_sync/TEST37 | 7 ++++++- src/test/pmempool_sync/TEST42 | 7 ++++++- src/test/pmempool_sync/TEST43 | 7 ++++++- src/test/pmempool_sync/TEST44 | 7 ++++++- src/test/pmempool_sync/TEST45 | 7 ++++++- src/test/pmempool_sync/TEST46 | 7 ++++++- src/test/pmempool_sync/TEST47 | 7 ++++++- src/test/pmempool_sync/TEST48 | 7 ++++++- src/test/pmempool_sync/TEST49 | 7 ++++++- src/test/pmempool_sync/TEST50 | 7 ++++++- src/test/pmempool_sync/TEST51 | 7 ++++++- src/test/pmempool_sync/TEST52 | 7 ++++++- src/test/pmempool_sync/TEST53 | 7 ++++++- src/test/pmempool_sync/TEST8 | 7 +++++-- 24 files changed, 139 insertions(+), 29 deletions(-) diff --git a/src/test/pmempool_sync/TEST11 b/src/test/pmempool_sync/TEST11 index aaa6f6e9787..a4003f1d619 100755 --- a/src/test/pmempool_sync/TEST11 +++ b/src/test/pmempool_sync/TEST11 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_sync/TEST11 -- test for checking pmempool sync @@ -61,7 +61,10 @@ expect_normal_exit $DDMAP$EXESUFFIX -o $DIR/part20 -n 10 -b 1 # Try to synchronize replicas using the third poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET3 &>> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST12 b/src/test/pmempool_sync/TEST12 index ab0e177442b..de0a8a6a91b 100755 --- a/src/test/pmempool_sync/TEST12 +++ b/src/test/pmempool_sync/TEST12 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2017-2019, Intel Corporation +# Copyright 2017-2024, Intel Corporation # # # pmempool_sync/TEST12 -- test for checking pmempool sync; @@ -44,7 +44,10 @@ expect_normal_exit $PMEMSPOIL $DIR/testfile1 pool_hdr.uuid=0000000000000000\ # Try to synchronize replicas expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET &>> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST25 b/src/test/pmempool_sync/TEST25 index e6d4d99aa53..a84e7cfa75f 100755 --- a/src/test/pmempool_sync/TEST25 +++ b/src/test/pmempool_sync/TEST25 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST25 -- test for checking pmempool sync @@ -62,7 +62,10 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST26 b/src/test/pmempool_sync/TEST26 index ebd4b88e26c..6457a20b2e9 100755 --- a/src/test/pmempool_sync/TEST26 +++ b/src/test/pmempool_sync/TEST26 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2023, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST26 -- test for checking pmempool sync; @@ -47,7 +47,10 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET >> $LOG_TEMP 2>&1 # Remove poolset expect_normal_exit $PMEMPOOL$EXESUFFIX rm $POOLSET -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_sync/TEST29 b/src/test/pmempool_sync/TEST29 index b2c25a46bcf..e2adb8b9c9c 100755 --- a/src/test/pmempool_sync/TEST29 +++ b/src/test/pmempool_sync/TEST29 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST29 -- test for sync using the 'obj_verify' tool @@ -40,6 +40,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST32 b/src/test/pmempool_sync/TEST32 index ef47a4fb40f..c8e0836a754 100755 --- a/src/test/pmempool_sync/TEST32 +++ b/src/test/pmempool_sync/TEST32 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST32 -- test for sync command @@ -50,6 +50,11 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST33 b/src/test/pmempool_sync/TEST33 index 6367f92bec5..46048b4fd31 100755 --- a/src/test/pmempool_sync/TEST33 +++ b/src/test/pmempool_sync/TEST33 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST33 -- test for sync command @@ -50,6 +50,11 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST34 b/src/test/pmempool_sync/TEST34 index d0ff494588e..8a522a8b80a 100755 --- a/src/test/pmempool_sync/TEST34 +++ b/src/test/pmempool_sync/TEST34 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST34 -- test for sync command @@ -59,6 +59,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST35 b/src/test/pmempool_sync/TEST35 index 2aa32823043..fc334b4ffee 100755 --- a/src/test/pmempool_sync/TEST35 +++ b/src/test/pmempool_sync/TEST35 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST35 -- test for sync command @@ -59,6 +59,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST36 b/src/test/pmempool_sync/TEST36 index 20e5e8ad151..f3899ede7de 100755 --- a/src/test/pmempool_sync/TEST36 +++ b/src/test/pmempool_sync/TEST36 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST36 -- test for sync command @@ -63,6 +63,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST37 b/src/test/pmempool_sync/TEST37 index aecdac74063..e12a5c86262 100755 --- a/src/test/pmempool_sync/TEST37 +++ b/src/test/pmempool_sync/TEST37 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST37 -- test for sync command @@ -63,6 +63,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST42 b/src/test/pmempool_sync/TEST42 index 943fdfccac7..aa4d6cf12b9 100755 --- a/src/test/pmempool_sync/TEST42 +++ b/src/test/pmempool_sync/TEST42 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST42 -- test for sync command with badblocks @@ -62,6 +62,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST43 b/src/test/pmempool_sync/TEST43 index cf095a22cf7..e456acbb989 100755 --- a/src/test/pmempool_sync/TEST43 +++ b/src/test/pmempool_sync/TEST43 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST43 -- test for sync command with badblocks @@ -63,6 +63,11 @@ expect_abnormal_exit "$PMEMPOOL$EXESUFFIX sync -v -b $POOLSET &>> $LOG" # pool verification should fail expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST44 b/src/test/pmempool_sync/TEST44 index b3993498094..5b2e1465ddd 100755 --- a/src/test/pmempool_sync/TEST44 +++ b/src/test/pmempool_sync/TEST44 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST44 -- test for sync command with badblocks @@ -82,6 +82,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST45 b/src/test/pmempool_sync/TEST45 index 16060d83fd6..9a48af2c01b 100755 --- a/src/test/pmempool_sync/TEST45 +++ b/src/test/pmempool_sync/TEST45 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST45 -- test for sync command with badblocks @@ -80,6 +80,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST46 b/src/test/pmempool_sync/TEST46 index 09f4026d4d8..de57afa19ac 100755 --- a/src/test/pmempool_sync/TEST46 +++ b/src/test/pmempool_sync/TEST46 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST46 -- test for sync command with badblocks @@ -80,6 +80,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST47 b/src/test/pmempool_sync/TEST47 index 05406ee4725..62ad2a7048a 100755 --- a/src/test/pmempool_sync/TEST47 +++ b/src/test/pmempool_sync/TEST47 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST47 -- test for sync command with badblocks @@ -83,6 +83,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST48 b/src/test/pmempool_sync/TEST48 index a65ae25abef..31c22d6e69a 100755 --- a/src/test/pmempool_sync/TEST48 +++ b/src/test/pmempool_sync/TEST48 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST48 -- test for sync command with badblocks @@ -86,6 +86,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST49 b/src/test/pmempool_sync/TEST49 index d00e4b4693f..c643f0a22c6 100755 --- a/src/test/pmempool_sync/TEST49 +++ b/src/test/pmempool_sync/TEST49 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2011-2019, Intel Corporation +# Copyright 2011-2024, Intel Corporation # # # pmempool_sync/TEST49 -- test for sync command with badblocks @@ -85,6 +85,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST50 b/src/test/pmempool_sync/TEST50 index 6735f1bc90e..9d9a5e05b67 100755 --- a/src/test/pmempool_sync/TEST50 +++ b/src/test/pmempool_sync/TEST50 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST50 -- test for sync command with badblocks @@ -85,6 +85,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST51 b/src/test/pmempool_sync/TEST51 index 86d4225a061..33c8f45dbcf 100755 --- a/src/test/pmempool_sync/TEST51 +++ b/src/test/pmempool_sync/TEST51 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST51 -- test for sync command with badblocks @@ -86,6 +86,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST52 b/src/test/pmempool_sync/TEST52 index 50cb9f48325..fa608e1940a 100755 --- a/src/test/pmempool_sync/TEST52 +++ b/src/test/pmempool_sync/TEST52 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # # pmempool_sync/TEST52 -- test for sync command with badblocks @@ -83,6 +83,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST53 b/src/test/pmempool_sync/TEST53 index e3e87f6acad..5c09150ea50 100755 --- a/src/test/pmempool_sync/TEST53 +++ b/src/test/pmempool_sync/TEST53 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2011-2019, Intel Corporation +# Copyright 2011-2024, Intel Corporation # # # pmempool_sync/TEST53 -- test for sync command with badblocks @@ -85,6 +85,11 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" +# Exclude error messages printed out on the stderr by PMDK in debug +LOG_TEMP=$LOG.log +fgrep -v "*ERROR*" $LOG > $LOG_TEMP +mv $LOG_TEMP $LOG + check pass diff --git a/src/test/pmempool_sync/TEST8 b/src/test/pmempool_sync/TEST8 index 7ca05a9ed87..77897f32b91 100755 --- a/src/test/pmempool_sync/TEST8 +++ b/src/test/pmempool_sync/TEST8 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_sync/TEST8 -- test for checking pmempool sync; @@ -55,7 +55,10 @@ rm -f $DIR/part11 # Synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass From dd220a9d6eb5f2d0af40aca9210466477a991d49 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 17:53:59 +0100 Subject: [PATCH 031/182] common: disable pmempool_transform tests unitl issue #5982 is fixed https://github.com/pmem/pmdk/issues/5982 Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_transform/TEST12 | 5 ++++- src/test/pmempool_transform/TEST9 | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/pmempool_transform/TEST12 b/src/test/pmempool_transform/TEST12 index 679924ad0dd..7bc7fdf4280 100755 --- a/src/test/pmempool_transform/TEST12 +++ b/src/test/pmempool_transform/TEST12 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2019, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST12 -- test for transform with SINGLEHDR option @@ -10,6 +10,9 @@ # . ../unittest/unittest.sh +# disabled due to crash until #5982 is fixed +# https://github.com/pmem/pmdk/issues/5982 +DISABLED require_test_type medium require_fs_type any diff --git a/src/test/pmempool_transform/TEST9 b/src/test/pmempool_transform/TEST9 index 2e1bd178305..9c074344af6 100755 --- a/src/test/pmempool_transform/TEST9 +++ b/src/test/pmempool_transform/TEST9 @@ -9,6 +9,9 @@ # . ../unittest/unittest.sh +# disabled due to crash until #5982 is fixed +# https://github.com/pmem/pmdk/issues/5982 +DISABLED require_test_type medium require_dax_devices 2 @@ -86,6 +89,7 @@ dump_pool_info ${DEVICE_DAX_PATH[1]} >> $LOG_TEMP expect_normal_exit $CMPMAP$EXESUFFIX -z -l $HDR_LEN ${DEVICE_DAX_PATH[0]} mv $LOG_TEMP $LOG + check pass From ac7b315a8fc0182102db50bc99efd528882f5a57 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 17:54:34 +0100 Subject: [PATCH 032/182] common: exclude error messages in pmempool_transform tests Signed-off-by: Tomasz Gromadzki --- src/test/ex_libpmemobj/TEST18 | 2 +- src/test/pmempool_transform/TEST3 | 7 +++++-- src/test/pmempool_transform/TEST5 | 7 +++++-- src/test/pmempool_transform/TEST6 | 7 +++++-- src/test/pmempool_transform/TEST9 | 2 +- src/test/pmempool_transform/out10.log.match | 1 + 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/test/ex_libpmemobj/TEST18 b/src/test/ex_libpmemobj/TEST18 index 44f36924a38..cbda68729a8 100755 --- a/src/test/ex_libpmemobj/TEST18 +++ b/src/test/ex_libpmemobj/TEST18 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2024, Intel Corporation +# Copyright 2015-2019, Intel Corporation # # src/test/ex_libpmemobj/TEST18 -- unit test for libpmemobj examples diff --git a/src/test/pmempool_transform/TEST3 b/src/test/pmempool_transform/TEST3 index 4eb59fa3ab5..259ababaa1c 100755 --- a/src/test/pmempool_transform/TEST3 +++ b/src/test/pmempool_transform/TEST3 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST3 -- test for checking pmempool transform; @@ -83,7 +83,10 @@ dump_pool_info $DIR/testfile00 >> $LOG_TEMP # Make sure no other parts were created check_no_files $DIR/testfile10 $DIR/testfile11 -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_transform/TEST5 b/src/test/pmempool_transform/TEST5 index 6cbc430e4a3..929bd3838b5 100755 --- a/src/test/pmempool_transform/TEST5 +++ b/src/test/pmempool_transform/TEST5 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST5 -- test for checking pmempool transform; @@ -92,7 +92,10 @@ dump_pool_info $DIR/testfile01 >> $LOG_TEMP dump_pool_info $DIR/testfile02 >> $LOG_TEMP dump_pool_info $DIR/testfile10 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_transform/TEST6 b/src/test/pmempool_transform/TEST6 index 2639d8e9fe2..91bde3c12a8 100755 --- a/src/test/pmempool_transform/TEST6 +++ b/src/test/pmempool_transform/TEST6 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST6 -- test for checking pmempool transform; @@ -71,7 +71,10 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_OUT1 >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude error messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_transform/TEST9 b/src/test/pmempool_transform/TEST9 index 9c074344af6..e778b5e5a32 100755 --- a/src/test/pmempool_transform/TEST9 +++ b/src/test/pmempool_transform/TEST9 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST9 -- test for checking pmempool transform; diff --git a/src/test/pmempool_transform/out10.log.match b/src/test/pmempool_transform/out10.log.match index 1476db59f19..41b64d5dc4d 100644 --- a/src/test/pmempool_transform/out10.log.match +++ b/src/test/pmempool_transform/out10.log.match @@ -11,6 +11,7 @@ REPLICA 20M $(nW)testfile01 20M $(nW)testfile21 +$(OPT)$(*) *ERROR* transform.c: $(N): check_if_part_used_once: some part file's path is used multiple times error: Invalid argument error: failed to transform $(nW)poolset.in -> $(nW)poolset.out: some part file's path is used multiple times Poolset structure: From 35f64bc8867d956b2690dbeed065c9080f455a12 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 25 Jan 2024 17:58:54 +0100 Subject: [PATCH 033/182] common: fartially disable libpmempool_featuretests unitl #5981 is fixed https://github.com/pmem/pmdk/issues/5981 Signed-off-by: Tomasz Gromadzki --- src/test/libpmempool_feature/common.sh | 17 ++++++++++++++++- src/test/libpmempool_feature/grep3.log.match | 15 ++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/test/libpmempool_feature/common.sh b/src/test/libpmempool_feature/common.sh index ce9992a880e..1b438a672f2 100644 --- a/src/test/libpmempool_feature/common.sh +++ b/src/test/libpmempool_feature/common.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2019, Intel Corporation +# Copyright 2018-2024, Intel Corporation # # src/test/libpmempool_feature/common.sh -- common part of libpmempool_feature tests @@ -24,9 +24,14 @@ sds_enabled=$(is_ndctl_enabled ./libpmempool_feature$EXESUFFIX; echo $?) function libpmempool_feature_query_abnormal() { # query feature expect_abnormal_exit ./libpmempool_feature$EXESUFFIX $POOL q $1 + +# XXX disable log file verification until #5981 is resolved +# https://github.com/pmem/pmdk/issues/5981 +if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi +fi } # libpmempool_feature_query -- query feature @@ -57,13 +62,19 @@ function libpmempool_feature_query() { function libpmempool_feature_enable() { $exit_func ./libpmempool_feature$EXESUFFIX $POOL e $1 if [ "$exit_func" == "expect_abnormal_exit" ]; then + +# XXX disable log file verification until #5981 is resolved +# https://github.com/pmem/pmdk/issues/5981 +if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi +fi fi if [ "x$2" != "xno-query" ]; then libpmempool_feature_query $1 fi + echo normal end } # libpmempool_feature_disable -- disable feature @@ -72,9 +83,13 @@ function libpmempool_feature_enable() { function libpmempool_feature_disable() { $exit_func ./libpmempool_feature$EXESUFFIX $POOL d $1 if [ "$exit_func" == "expect_abnormal_exit" ]; then +# XXX disable log file verification until #5981 is resolved +# https://github.com/pmem/pmdk/issues/5981 +if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi +fi fi if [ "x$2" != "xno-query" ]; then libpmempool_feature_query $1 diff --git a/src/test/libpmempool_feature/grep3.log.match b/src/test/libpmempool_feature/grep3.log.match index bf37883bdc5..dd007438b30 100644 --- a/src/test/libpmempool_feature/grep3.log.match +++ b/src/test/libpmempool_feature/grep3.log.match @@ -1,13 +1,18 @@ $(*)pool.obj: spoil: pool_hdr.features.compat=0xfe $(*)pool.obj: spoil: pool_hdr.f:checksum_gen -: <1> [feature.c:$(N) features_check] invalid features detected: {compat 0xfe, incompat 0x0, ro_compat 0x0} -: <1> [feature.c:$(N) poolset_open] invalid features - replica #0 part #0 +$(OPT)XXX Next line to be restored (no OPT) when #5981 is fixed +$(OPT): <1> [feature.c:$(N) features_check] invalid features detected: {compat 0xfe, incompat 0x0, ro_compat 0x0} +$(OPT)XXX Next line to be restored (no OPT) when #5981 is fixed +$(OPT): <1> [feature.c:$(N) poolset_open] invalid features - replica #0 part #0 $(*)testfile23: spoil: pool_hdr.features.incompat=0xfe $(*)testfile23: spoil: pool_hdr.f:checksum_gen $(OPT): <1> [feature.c:$(N) features_check] features mismatch detected: {compat 0x0, incompat 0xfe, ro_compat 0x0} != {compat 0x0, incompat 0x$(N), ro_compat 0x0} $(OPT): <1> [feature.c:$(N) features_check] features mismatch detected: {compat 0x1, incompat 0xfe, ro_compat 0x0} != {compat 0x1, incompat 0x$(N), ro_compat 0x0} -: <1> [feature.c:$(N) poolset_open] invalid features - replica #1 part #2 +$(OPT)XXX Next line to be restored (no OPT) when #5981 is fixed +$(OPT): <1> [feature.c:$(N) poolset_open] invalid features - replica #1 part #2 $(*)testfile11: spoil: pool_hdr.features.ro_compat=0xfe $(*)testfile11: spoil: pool_hdr.f:checksum_gen -: <1> [feature.c:$(N) features_check] invalid features detected: {compat 0x0, incompat 0x0, ro_compat 0xfe} -: <1> [feature.c:$(N) poolset_open] invalid features - replica #0 part #0 +$(OPT)XXX Next line to be restored (no OPT) when #5981 is fixed +$(OPT): <1> [feature.c:$(N) features_check] invalid features detected: {compat 0x0, incompat 0x0, ro_compat 0xfe} +$(OPT)XXX Next line to be restored (no OPT) when #5981 is fixed +$(OPT): <1> [feature.c:$(N) poolset_open] invalid features - replica #0 part #0 From a465cfc8385fe4709e463e6eedd98d6dcffaef7c Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 29 Jan 2024 10:40:44 +0100 Subject: [PATCH 034/182] common: add out_log_va to white list Add out_log_va to the white list as it is no longer used in the release version. Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/white_list.json | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 35bb4133ba6..9031d208c59 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -127,6 +127,7 @@ "os_writev", "out_fatal", "out_log", + "out_log_va", "out_nonl", "pmalloc_operation_hold_no_start", "pmalloc", From 6d09ac239a472f76bdcd8b20e8ee04722b9fa03e Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 18:37:54 +0100 Subject: [PATCH 035/182] common: include ERROR message in pmempool_feature tests Signed-off-by: Tomasz Gromadzki --- src/libpmem2/deep_flush.c | 5 +++-- src/libpmem2/pmem2_utils_ndctl.c | 4 ++-- src/libpmemobj/obj.c | 4 ++-- src/libpmemobj/pmalloc.c | 2 +- src/test/pmempool_feature/grep1.log.match | 1 + src/test/pmempool_feature/grep2.log.match | 1 + 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libpmem2/deep_flush.c b/src/libpmem2/deep_flush.c index 1882ab7fca9..cb26dee8ff6 100644 --- a/src/libpmem2/deep_flush.c +++ b/src/libpmem2/deep_flush.c @@ -27,8 +27,9 @@ pmem2_deep_flush(struct pmem2_map *map, void *ptr, size_t size) uintptr_t flush_end = flush_addr + size; if (flush_addr < map_addr || flush_end > map_end) { - ERR_WO_ERRNO("requested deep flush rage ptr %p size %zu" - "exceeds map range %p", ptr, size, map); + ERR_WO_ERRNO( + "requested deep flush rage ptr %p size %zu exceeds map range %p", + ptr, size, map); return PMEM2_E_DEEP_FLUSH_RANGE; } diff --git a/src/libpmem2/pmem2_utils_ndctl.c b/src/libpmem2/pmem2_utils_ndctl.c index 0de3c774129..68d3284ff6e 100644 --- a/src/libpmem2/pmem2_utils_ndctl.c +++ b/src/libpmem2/pmem2_utils_ndctl.c @@ -79,8 +79,8 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) *size = ndctl_dax_get_size(dax); } else { ret = PMEM2_E_DAX_REGION_NOT_FOUND; - ERR_WO_ERRNO("Issue while reading Device Dax size - cannot " - "find dax region"); + ERR_WO_ERRNO( + "Issue while reading Device Dax size - cannot find dax region"); } end: diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 8b9f148be60..fe9747bc04a 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -778,8 +778,8 @@ obj_descr_check(PMEMobjpool *pop, const char *layout, size_t poolsize) if (layout && strncmp(pop->layout, layout, PMEMOBJ_MAX_LAYOUT)) { - ERR_WO_ERRNO("wrong layout (\"%s\"), " - "pool created with layout \"%s\"", + ERR_WO_ERRNO( + "wrong layout (\"%s\"), pool created with layout \"%s\"", layout, pop->layout); errno = EINVAL; return -1; diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 41e9a58979d..7d119d50efe 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -503,7 +503,7 @@ CTL_WRITE_HANDLER(granularity)(void *ctx, ssize_t arg_in = *(int *)arg; if (arg_in != 0 && arg_in < (ssize_t)PMEMOBJ_MIN_PART) { ERR_WO_ERRNO( - "incorrect grow size, must be 0 or larger than %" \ + "incorrect grow size, must be 0 or larger than %" PRIu64, PMEMOBJ_MIN_PART); return -1; diff --git a/src/test/pmempool_feature/grep1.log.match b/src/test/pmempool_feature/grep1.log.match index 7a755266bd1..9f10940c5b3 100644 --- a/src/test/pmempool_feature/grep1.log.match +++ b/src/test/pmempool_feature/grep1.log.match @@ -1,4 +1,5 @@ query CKSUM_2K result is 1 +$(OPT)$(*) *ERROR* feature.c: $(N): require_other_feature_is: disable SHUTDOWN_STATE prior to disabling CKSUM_2K query CKSUM_2K result is 1 query SHUTDOWN_STATE result is 0 query CKSUM_2K result is 0 diff --git a/src/test/pmempool_feature/grep2.log.match b/src/test/pmempool_feature/grep2.log.match index 9a6fc81ec1a..b8a8a1d489a 100644 --- a/src/test/pmempool_feature/grep2.log.match +++ b/src/test/pmempool_feature/grep2.log.match @@ -1,6 +1,7 @@ $(OPT)query SHUTDOWN_STATE result is 1 query SHUTDOWN_STATE result is 0 query CKSUM_2K result is 0 +$(OPT)$(*) *ERROR* feature.c: $(N): require_other_feature_is: enable CKSUM_2K prior to enabling SHUTDOWN_STATE query SHUTDOWN_STATE result is 0 query CKSUM_2K result is 1 query SHUTDOWN_STATE result is 1 From 6a9fea9ec2a8d8c9e7c67bab32fafc2850562ce2 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 22 Jan 2024 09:13:13 +0100 Subject: [PATCH 036/182] common: errno explicitly provided to ERR() macro. Remove "!..." logic from error message format string. Use separate argument to either use or not use errno in error message. Remove non-posix version of util_strerror. Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 38 +++++++++++-------------------------- src/core/out.h | 12 ++++++------ src/core/util.h | 3 +-- src/core/util_posix.c | 11 ----------- src/test/out_err/out_err.c | 4 ++-- src/tools/pmempool/output.c | 4 ++-- src/tools/pmempool/output.h | 6 +++--- 7 files changed, 25 insertions(+), 53 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index 4d220a64358..4b5ea1ccc94 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -311,8 +311,6 @@ out_common(const char *file, int line, const char *func, int level, const char *sep = ""; char errstr[UTIL_MAX_ERR_MSG] = ""; - unsigned long olast_error = 0; - if (file) { char *f = strrchr(file, OS_DIR_SEPARATOR); if (f) @@ -335,15 +333,7 @@ out_common(const char *file, int line, const char *func, int level, if (*fmt == '!') { sep = ": "; fmt++; - if (*fmt == '!') { - fmt++; - /* it will abort on non Windows OS */ - util_strwinerror(olast_error, errstr, - UTIL_MAX_ERR_MSG); - } else { - util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); - } - + util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); } ret = vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap); if (ret < 0) { @@ -365,11 +355,12 @@ out_common(const char *file, int line, const char *func, int level, * out_error -- common error output code, all error messages go through here */ static void -out_error(const char *file, int line, const char *func, +out_error(int use_errno, const char *file, int line, const char *func, const char *suffix, const char *fmt, va_list ap) { - int oerrno = errno; - unsigned long olast_error = 0; + int oerrno = 0; + if (use_errno) + oerrno = errno; unsigned cc = 0; unsigned print_msg = 1; int ret; @@ -392,17 +383,9 @@ out_error(const char *file, int line, const char *func, fmt++; } - if (*fmt == '!') { + if (use_errno) { sep = ": "; - fmt++; - if (*fmt == '!') { - fmt++; - /* it will abort on non Windows OS */ - util_strwinerror(olast_error, errstr, - UTIL_MAX_ERR_MSG); - } else { - util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); - } + util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); } ret = vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap); @@ -449,7 +432,8 @@ out_error(const char *file, int line, const char *func, #endif end: - errno = oerrno; + if (use_errno) + errno = oerrno; } /* @@ -528,13 +512,13 @@ out_fatal(const char *file, int line, const char *func, * out_err -- output an error message */ void -out_err(const char *file, int line, const char *func, +out_err(int use_errno, const char *file, int line, const char *func, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - out_error(file, line, func, "\n", fmt, ap); + out_error(use_errno, file, line, func, "\n", fmt, ap); va_end(ap); } diff --git a/src/core/out.h b/src/core/out.h index 22d9b520a2f..c0914ac2c1c 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -184,18 +184,18 @@ out_fatal_abort(const char *file, int line, const char *func, ASSERTne_rt(lhs, rhs);\ } while (0) -#define ERR(...)\ - out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define ERR(use_errno, ...)\ + out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ do {\ - ERR("*!" f, ##__VA_ARGS__);\ + ERR(1, "*" f, ##__VA_ARGS__);\ CORE_LOG_ERROR_WITH_ERRNO(f, ##__VA_ARGS__);\ } while (0) #define ERR_WO_ERRNO(f, ...)\ do {\ - ERR("*" f, ##__VA_ARGS__);\ + ERR(0, "*" f, ##__VA_ARGS__);\ CORE_LOG_ERROR(f, ##__VA_ARGS__);\ } while (0) @@ -209,8 +209,8 @@ void out_log_va(const char *file, int line, const char *func, int level, const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); -void out_err(const char *file, int line, const char *func, - const char *fmt, ...) FORMAT_PRINTF(4, 5); +void out_err(int use_errno, const char *file, int line, const char *func, + const char *fmt, ...) FORMAT_PRINTF(5, 6); void NORETURN out_fatal(const char *file, int line, const char *func, const char *fmt, ...) FORMAT_PRINTF(4, 5); const char *out_get_errormsg(void); diff --git a/src/core/util.h b/src/core/util.h index 0224aaa774d..003a48da1b9 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * Copyright (c) 2016-2020, Microsoft Corporation. All rights reserved. * @@ -101,7 +101,6 @@ int util_snprintf(char *str, size_t size, #define UTIL_MAX_ERR_MSG 128 void util_strerror(int errnum, char *buff, size_t bufflen); -void util_strwinerror(unsigned long err, char *buff, size_t bufflen); void util_set_alloc_funcs( void *(*malloc_func)(size_t size), diff --git a/src/core/util_posix.c b/src/core/util_posix.c index b3bd924f34a..2d7558e48c8 100644 --- a/src/core/util_posix.c +++ b/src/core/util_posix.c @@ -23,17 +23,6 @@ util_strerror(int errnum, char *buff, size_t bufflen) strerror_r(errnum, buff, bufflen); } -/* - * util_strwinerror -- should never be called on posix OS - abort() - */ -void -util_strwinerror(unsigned long err, char *buff, size_t bufflen) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(err, buff, bufflen); - abort(); -} - /* * util_part_realpath -- get canonicalized absolute pathname * diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index a3b6552487c..fca1809a9b9 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -41,13 +41,13 @@ main(int argc, char *argv[]) errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); - out_err(__FILE__, 100, __func__, + out_err(0, __FILE__, 100, __func__, "ERR1: %s:%d", buff, 1234); UT_OUT("%s", out_get_errormsg()); errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); - out_err(NULL, 0, NULL, + out_err(0, NULL, 0, NULL, "ERR2: %s:%d", buff, 1234); UT_OUT("%s", out_get_errormsg()); diff --git a/src/tools/pmempool/output.c b/src/tools/pmempool/output.c index 63df4f5244b..19b2527464a 100644 --- a/src/tools/pmempool/output.c +++ b/src/tools/pmempool/output.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * output.c -- definitions of output printing related functions @@ -774,7 +774,7 @@ out_get_incompat_features_str(uint32_t incompat) /* print the value and the left square bracket */ ret = util_snprintf(str_buff, STR_MAX, "0x%x [", incompat); if (ret < 0) { - ERR("snprintf for incompat features: %d", ret); + ERR(0, "snprintf for incompat features: %d", ret); return ""; } diff --git a/src/tools/pmempool/output.h b/src/tools/pmempool/output.h index 80922f2ec0a..0b86ac1f759 100644 --- a/src/tools/pmempool/output.h +++ b/src/tools/pmempool/output.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * output.h -- declarations of output printing related functions @@ -14,8 +14,8 @@ void out_set_stream(FILE *stream); void out_set_prefix(const char *prefix); void out_set_col_width(unsigned col_width); void outv_err(const char *fmt, ...) FORMAT_PRINTF(1, 2); -void out_err(const char *file, int line, const char *func, - const char *fmt, ...) FORMAT_PRINTF(4, 5); +void out_err(int use_errno, const char *file, int line, const char *func, + const char *fmt, ...) FORMAT_PRINTF(5, 6); void outv_err_vargs(const char *fmt, va_list ap); void outv_indent(int vlevel, int i); void outv(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3); From 4f3473f6d2be3911fbc6390ecf893ed08f490c81 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 19 Jan 2024 13:51:26 +0100 Subject: [PATCH 037/182] obj: all errorl logs via ERR_WO_ERRNO() Signed-off-by: Tomasz Gromadzki --- src/libpmemobj/pmalloc.c | 14 +++++++------- src/libpmemobj/tx.c | 8 ++++---- src/libpmemobj/ulog.c | 7 ++++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 7d119d50efe..1678710eb5e 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -567,7 +567,7 @@ CTL_WRITE_HANDLER(max)(void *ctx, int ret = heap_set_narenas_max(&pop->heap, size); if (ret) { - LOG(1, "cannot change max arena number"); + ERR_WO_ERRNO("cannot change max arena number"); return -1; } @@ -633,7 +633,7 @@ CTL_WRITE_HANDLER(arena_id)(void *ctx, * or if it is not equal zero */ if (arena_id < 1 || arena_id > narenas) { - LOG(1, "arena id outside of the allowed range: <1,%u>", + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", narenas); errno = ERANGE; return -1; @@ -671,14 +671,14 @@ CTL_WRITE_HANDLER(automatic)(void *ctx, enum ctl_query_source source, * or if it is not equal zero */ if (arena_id < 1 || arena_id > narenas) { - LOG(1, "arena id outside of the allowed range: <1,%u>", + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", narenas); errno = ERANGE; return -1; } if (arg_in != 0 && arg_in != 1) { - LOG(1, "incorrect arena state, must be 0 or 1"); + ERR_WO_ERRNO("incorrect arena state, must be 0 or 1"); return -1; } @@ -710,7 +710,7 @@ CTL_READ_HANDLER(automatic)(void *ctx, * or if it is not equal zero */ if (arena_id < 1 || arena_id > narenas) { - LOG(1, "arena id outside of the allowed range: <1,%u>", + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", narenas); errno = ERANGE; return -1; @@ -758,7 +758,7 @@ CTL_READ_HANDLER(size)(void *ctx, * or if it is not equal zero */ if (arena_id < 1 || arena_id > narenas) { - LOG(1, "arena id outside of the allowed range: <1,%u>", + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", narenas); errno = ERANGE; return -1; @@ -957,7 +957,7 @@ CTL_WRITE_HANDLER(arenas_default_max)(void *ctx, unsigned size = *(unsigned *)arg; if (size == 0) { - LOG(1, "number of default arenas can't be 0"); + ERR_WO_ERRNO("number of default arenas can't be 0"); return -1; } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index 63eac100c33..6e4f25a230e 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -2225,9 +2225,9 @@ CTL_READ_HANDLER(threshold)(void *ctx, /* suppress unused-parameter errors */ SUPPRESS_UNUSED(ctx, source, arg, indexes); - LOG(1, "tx.cache.threshold parameter is deprecated"); + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - return 0; + return -1; } /* @@ -2240,9 +2240,9 @@ CTL_WRITE_HANDLER(threshold)(void *ctx, /* suppress unused-parameter errors */ SUPPRESS_UNUSED(ctx, source, arg, indexes); - LOG(1, "tx.cache.threshold parameter is deprecated"); + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - return 0; + return -1; } static const struct ctl_argument CTL_ARG(threshold) = CTL_ARG_LONG_LONG; diff --git a/src/libpmemobj/ulog.c b/src/libpmemobj/ulog.c index 80569373d85..54b7f316f42 100644 --- a/src/libpmemobj/ulog.c +++ b/src/libpmemobj/ulog.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2021, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * ulog.c -- unified log implementation @@ -240,7 +240,7 @@ ulog_reserve(struct ulog *ulog, const struct pmem_ops *p_ops) { if (!auto_reserve) { - LOG(1, "cannot auto reserve next ulog"); + ERR_WO_ERRNO("cannot auto reserve next ulog"); return -1; } @@ -669,7 +669,8 @@ ulog_free_next(struct ulog *u, const struct pmem_ops *p_ops, if (VEC_PUSH_BACK(&ulogs_internal_except_first, &u->next) != 0) { /* this is fine, it will just use more pmem */ - LOG(1, "unable to free transaction logs memory"); + CORE_LOG_NOTICE( + "unable to free transaction logs memory"); goto out; } u = ulog_by_offset(u->next, p_ops); From 496812b85ce5fee5345c46198a5fa057e2aa5501 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 25 Jan 2024 13:09:59 -0500 Subject: [PATCH 038/182] common: final touch for the default logging function - put the primary destination first and the auxiliary second Signed-off-by: Jan Michalski --- src/core/log_default.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/core/log_default.c b/src/core/log_default.c index 353fc2dc76e..81018b7688d 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "log_internal.h" #include "log_default.h" @@ -106,10 +107,16 @@ core_log_default_function(void *context, enum core_log_level level, const char *file_info = file_info_buffer; char message[1024] = ""; const char file_info_error[] = "[file info error]: "; + bool is_always = false; if (CORE_LOG_DISABLED == level) return; + if (level == CORE_LOG_LEVEL_ALWAYS) { + is_always = true; + level = CORE_LOG_LEVEL_NOTICE; + } + va_list arg; va_start(arg, message_format); if (vsnprintf(message, sizeof(message), message_format, arg) < 0) { @@ -134,21 +141,28 @@ core_log_default_function(void *context, enum core_log_level level, } } - if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX] && - level != CORE_LOG_LEVEL_ALWAYS) { + /* primary logging destination (CORE_LOG_THRESHOLD) */ + syslog(log_level_syslog_severity[level], "%s%s%s", + log_level_names[level], file_info, message); + + /* + * Since the CORE_LOG_LEVEL_ALWAYS level messages convey pretty mundane + * information regarding the libraries versions etc. it has been decided + * to print them out to the syslog and under no circumstances to stderr + * to keep it clean for potentially more critical information. + */ + if (is_always) { + return; + } + + /* secondary logging destination (CORE_LOG_THRESHOLD_AUX) */ + if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX]) { char times_tamp[45] = ""; get_timestamp_prefix(times_tamp, sizeof(times_tamp)); (void) fprintf(stderr, "%s[%ld] %s%s%s\n", times_tamp, syscall(SYS_gettid), log_level_names[level], file_info, message); } - - level = (level == CORE_LOG_LEVEL_ALWAYS)? CORE_LOG_LEVEL_NOTICE: level; - /* assumed: level <= Core_log_threshold[CORE_LOG_THRESHOLD] */ - syslog(log_level_syslog_severity[level], - "%s%s%s", - log_level_names[level], - file_info, message); } /* From 3a71c49be9887e9c8f92c40b7d533fb29c8a9e99 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 10:31:35 +0100 Subject: [PATCH 039/182] common: introduce a separate FATAL macro with errno Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 5 ++- src/common/util_pmem.h | 4 +- src/core/alloc.c | 4 +- src/core/out.c | 4 +- src/core/out.h | 5 ++- src/core/sys_util.h | 40 +++++++++---------- src/libpmem/pmem.c | 4 +- src/libpmem2/aarch64/init.c | 4 +- src/libpmem2/map_posix.c | 2 +- src/libpmem2/pmem2_utils.c | 2 +- src/libpmem2/source_posix.c | 4 +- src/libpmem2/x86_64/init.c | 4 +- src/libpmemobj/lane.c | 14 +++---- src/libpmemobj/memblock.c | 9 +++-- src/libpmemobj/obj.c | 8 ++-- src/libpmemobj/palloc.c | 2 +- src/libpmemobj/sync.h | 6 +-- src/libpmemobj/tx.c | 26 +++++++----- src/libpmempool/check_pool_hdr.c | 2 +- src/libpmempool/check_sds.c | 2 +- src/libpmempool/check_util.c | 4 +- .../pmem_is_pmem_posix/pmem_is_pmem_posix.c | 6 +-- 22 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index 487e755c65d..be2415aaaad 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -217,7 +217,7 @@ util_unmap_hdr(struct pool_set_part *part) VALGRIND_REMOVE_PMEM_MAPPING(part->hdr, part->hdrsize); if (munmap(part->hdr, part->hdrsize) != 0) /* this means there's a bug on the caller side */ - FATAL("!munmap: %s", part->path); + FATAL_W_ERRNO("munmap: %s", part->path); part->hdr = NULL; part->hdrsize = 0; } @@ -2209,7 +2209,8 @@ util_poolset_append_new_part(struct pool_set *set, size_t size) d->path, PMEM_FILE_PADDING, set->next_id, PMEM_EXT); if (util_replica_add_part(&set->replica[r], path, size) != 0) - FATAL("cannot add a new part to the replica info"); + FATAL_WO_ERRNO( + "cannot add a new part to the replica info"); } set->next_directory_id += 1; diff --git a/src/common/util_pmem.h b/src/common/util_pmem.h index a31b6b8f7e9..76dd0d279a3 100644 --- a/src/common/util_pmem.h +++ b/src/common/util_pmem.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2020, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * util_pmem.h -- internal definitions for pmem utils @@ -26,7 +26,7 @@ util_persist(int is_pmem, const void *addr, size_t len) if (is_pmem) pmem_persist(addr, len); else if (pmem_msync(addr, len)) - FATAL("!pmem_msync"); + FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/core/alloc.c b/src/core/alloc.c index e267e4e6291..6c3d7e16bdb 100644 --- a/src/core/alloc.c +++ b/src/core/alloc.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2020, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ #include @@ -58,7 +58,7 @@ core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at) fail_realloc_from = at; break; default: - FATAL("unknown allocation type"); + FATAL_WO_ERRNO("unknown allocation type"); } } diff --git a/src/core/out.c b/src/core/out.c index 4b5ea1ccc94..ad51b320c61 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -48,7 +48,7 @@ _Last_errormsg_key_alloc(void) { int pth_ret = os_tls_key_create(&Last_errormsg_key, free); if (pth_ret) - FATAL("!os_thread_key_create"); + FATAL_W_ERRNO("os_thread_key_create"); VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); } @@ -89,7 +89,7 @@ Last_errormsg_get(void) errormsg->msg[0] = '\0'; int ret = os_tls_set(Last_errormsg_key, errormsg); if (ret) - FATAL("!os_tls_set"); + FATAL_W_ERRNO("os_tls_set"); } return errormsg; } diff --git a/src/core/out.h b/src/core/out.h index c0914ac2c1c..f5227991ba9 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -117,9 +117,12 @@ out_fatal_abort(const char *file, int line, const char *func, } while (0) /* produce output and exit */ -#define FATAL(...)\ +#define FATAL_WO_ERRNO(...)\ OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define FATAL_W_ERRNO(...)\ + OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, "!" __VA_ARGS__) + /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ diff --git a/src/core/sys_util.h b/src/core/sys_util.h index 58a4fb0208e..80d880e90a5 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -28,7 +28,7 @@ util_mutex_init(os_mutex_t *m) int tmp = os_mutex_init(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_init"); + FATAL_W_ERRNO("os_mutex_init"); } } @@ -43,7 +43,7 @@ util_mutex_destroy(os_mutex_t *m) int tmp = os_mutex_destroy(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_destroy"); + FATAL_W_ERRNO("os_mutex_destroy"); } } @@ -58,7 +58,7 @@ util_mutex_lock(os_mutex_t *m) int tmp = os_mutex_lock(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_lock"); + FATAL_W_ERRNO("os_mutex_lock"); } } @@ -74,7 +74,7 @@ util_mutex_trylock(os_mutex_t *m) int tmp = os_mutex_trylock(m); if (tmp && tmp != EBUSY) { errno = tmp; - FATAL("!os_mutex_trylock"); + FATAL_W_ERRNO("os_mutex_trylock"); } return tmp; } @@ -90,7 +90,7 @@ util_mutex_unlock(os_mutex_t *m) int tmp = os_mutex_unlock(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_unlock"); + FATAL_W_ERRNO("os_mutex_unlock"); } } @@ -105,7 +105,7 @@ util_rwlock_init(os_rwlock_t *m) int tmp = os_rwlock_init(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_init"); + FATAL_W_ERRNO("os_rwlock_init"); } } @@ -120,7 +120,7 @@ util_rwlock_rdlock(os_rwlock_t *m) int tmp = os_rwlock_rdlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_rdlock"); + FATAL_W_ERRNO("os_rwlock_rdlock"); } } @@ -135,7 +135,7 @@ util_rwlock_wrlock(os_rwlock_t *m) int tmp = os_rwlock_wrlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_wrlock"); + FATAL_W_ERRNO("os_rwlock_wrlock"); } } @@ -150,7 +150,7 @@ util_rwlock_unlock(os_rwlock_t *m) int tmp = os_rwlock_unlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_unlock"); + FATAL_W_ERRNO("os_rwlock_unlock"); } } @@ -165,7 +165,7 @@ util_rwlock_destroy(os_rwlock_t *m) int tmp = os_rwlock_destroy(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_destroy"); + FATAL_W_ERRNO("os_rwlock_destroy"); } } @@ -194,7 +194,7 @@ util_spin_destroy(os_spinlock_t *lock) int tmp = os_spin_destroy(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_destroy"); + FATAL_W_ERRNO("os_spin_destroy"); } } @@ -208,7 +208,7 @@ util_spin_lock(os_spinlock_t *lock) int tmp = os_spin_lock(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_lock"); + FATAL_W_ERRNO("os_spin_lock"); } } @@ -223,7 +223,7 @@ util_spin_unlock(os_spinlock_t *lock) int tmp = os_spin_unlock(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_unlock"); + FATAL_W_ERRNO("os_spin_unlock"); } } @@ -236,7 +236,7 @@ static inline void util_semaphore_init(os_semaphore_t *sem, unsigned value) { if (os_semaphore_init(sem, value)) - FATAL("!os_semaphore_init"); + FATAL_W_ERRNO("os_semaphore_init"); } /* @@ -246,7 +246,7 @@ static inline void util_semaphore_destroy(os_semaphore_t *sem) { if (os_semaphore_destroy(sem) != 0) - FATAL("!os_semaphore_destroy"); + FATAL_W_ERRNO("os_semaphore_destroy"); } /* @@ -263,7 +263,7 @@ util_semaphore_wait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0) - FATAL("!os_semaphore_wait"); + FATAL_W_ERRNO("os_semaphore_wait"); } /* @@ -279,7 +279,7 @@ util_semaphore_trywait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0 && errno != EAGAIN) - FATAL("!os_semaphore_trywait"); + FATAL_W_ERRNO("os_semaphore_trywait"); return ret; } @@ -291,21 +291,21 @@ static inline void util_semaphore_post(os_semaphore_t *sem) { if (os_semaphore_post(sem) != 0) - FATAL("!os_semaphore_post"); + FATAL_W_ERRNO("os_semaphore_post"); } static inline void util_cond_init(os_cond_t *__restrict cond) { if (os_cond_init(cond)) - FATAL("!os_cond_init"); + FATAL_W_ERRNO("os_cond_init"); } static inline void util_cond_destroy(os_cond_t *__restrict cond) { if (os_cond_destroy(cond)) - FATAL("!os_cond_destroy"); + FATAL_W_ERRNO("os_cond_destroy"); } #ifdef __cplusplus diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 5b4241ba2c7..49ae318facb 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -359,7 +359,7 @@ pmem_is_pmem_init(void) Is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) - FATAL("util_bool_compare_and_swap32"); + FATAL_WO_ERRNO("util_bool_compare_and_swap32"); } } @@ -911,7 +911,7 @@ pmem_init(void) if (Funcs.flush == flush_empty) LOG(3, "not flushing CPU cache"); else if (Funcs.flush != Funcs.deep_flush) - FATAL("invalid flush function address"); + FATAL_WO_ERRNO("invalid flush function address"); pmem_os_init(&Is_pmem); } diff --git a/src/libpmem2/aarch64/init.c b/src/libpmem2/aarch64/init.c index 6540b0bf70e..21cf6c0bfdd 100644 --- a/src/libpmem2/aarch64/init.c +++ b/src/libpmem2/aarch64/init.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2021, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -85,5 +85,5 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_pop) LOG(3, "Synchronize VA to pop for ARM"); else - FATAL("invalid deep flush function address"); + FATAL_WO_ERRNO("invalid deep flush function address"); } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 9fe3ec616e6..fa886a58e20 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -484,7 +484,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, [cfg->requested_max_granularity] [available_min_granularity]; if (strcmp(err, GRAN_IMPOSSIBLE) == 0) - FATAL( + FATAL_WO_ERRNO( "unhandled granularity error: available_min_granularity: %d" \ "requested_max_granularity: %d", available_min_granularity, diff --git a/src/libpmem2/pmem2_utils.c b/src/libpmem2/pmem2_utils.c index 3daf76929a1..b9c0b3bd9c3 100644 --- a/src/libpmem2/pmem2_utils.c +++ b/src/libpmem2/pmem2_utils.c @@ -67,7 +67,7 @@ int pmem2_err_to_errno(int err) { if (err > 0) - FATAL("positive error code is a bug in libpmem2"); + FATAL_WO_ERRNO("positive error code is a bug in libpmem2"); if (err == PMEM2_E_NOSUPP) return ENOTSUP; diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 6f811170f59..4f36c1cef18 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -126,7 +126,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) *size = (size_t)st.st_size; break; default: - FATAL( + FATAL_WO_ERRNO( "BUG: unhandled file type in pmem2_source_size"); } @@ -162,7 +162,7 @@ pmem2_source_alignment(const struct pmem2_source *src, size_t *alignment) *alignment = Pagesize; break; default: - FATAL( + FATAL_WO_ERRNO( "BUG: unhandled file type in pmem2_source_alignment"); } diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index bc21183301c..95b9e84b705 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2022, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -585,7 +585,7 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_clflush) LOG(3, "using clflush"); else - FATAL("invalid deep flush function address"); + FATAL_WO_ERRNO("invalid deep flush function address"); if (impl == MEMCPY_MOVDIR64B) LOG(3, "using movnt MOVDIR64B"); diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 26350bea714..6210b27ddd1 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -40,7 +40,7 @@ lane_info_create(void) { Lane_info_ht = critnib_new(); if (Lane_info_ht == NULL) - FATAL("critnib_new"); + FATAL_WO_ERRNO("critnib_new"); } /* @@ -77,7 +77,7 @@ lane_info_ht_boot(void) int result = os_tls_set(Lane_info_key, Lane_info_ht); if (result != 0) { errno = result; - FATAL("!os_tls_set"); + FATAL_W_ERRNO("os_tls_set"); } } @@ -102,7 +102,7 @@ lane_info_boot(void) int result = os_tls_key_create(&Lane_info_key, lane_info_ht_destroy); if (result != 0) { errno = result; - FATAL("!os_tls_key_create"); + FATAL_W_ERRNO("os_tls_key_create"); } } @@ -479,7 +479,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(info == NULL)) { info = Malloc(sizeof(struct lane_info)); if (unlikely(info == NULL)) { - FATAL("Malloc"); + FATAL_WO_ERRNO("Malloc"); } info->pop_uuid_lo = pop->uuid_lo; info->lane_idx = UINT64_MAX; @@ -495,7 +495,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(critnib_insert( Lane_info_ht, pop->uuid_lo, info) != 0)) { - FATAL("critnib_insert"); + FATAL_WO_ERRNO("critnib_insert"); } } @@ -551,12 +551,12 @@ lane_release(PMEMobjpool *pop) ASSERTne(lane->lane_idx, UINT64_MAX); if (unlikely(lane->nest_count == 0)) { - FATAL("lane_release"); + FATAL_WO_ERRNO("lane_release"); } else if (--(lane->nest_count) == 0) { if (unlikely(!util_bool_compare_and_swap64( &pop->lanes_desc.lane_locks[lane->lane_idx], 1, 0))) { - FATAL("util_bool_compare_and_swap64"); + FATAL_WO_ERRNO("util_bool_compare_and_swap64"); } } } diff --git a/src/libpmemobj/memblock.c b/src/libpmemobj/memblock.c index 9ad6c2dc063..e3c68bd5650 100644 --- a/src/libpmemobj/memblock.c +++ b/src/libpmemobj/memblock.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2021, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * memblock.c -- implementation of memory block @@ -1103,7 +1103,7 @@ huge_vg_init(const struct memory_block *m, int objects, if (objects && huge_get_state(m) == MEMBLOCK_ALLOCATED) { if (cb(m, arg) != 0) - FATAL("failed to initialize valgrind state"); + FATAL_WO_ERRNO("failed to initialize valgrind state"); } } @@ -1143,7 +1143,7 @@ run_vg_init(const struct memory_block *m, int objects, if (objects) { if (run_iterate_used(m, cb, arg) != 0) - FATAL("failed to initialize valgrind state"); + FATAL_WO_ERRNO("failed to initialize valgrind state"); } } @@ -1463,7 +1463,8 @@ memblock_detect_type(struct palloc_heap *heap, const struct memory_block *m) break; default: /* unreachable */ - FATAL("possible zone chunks metadata corruption"); + FATAL_WO_ERRNO( + "possible zone chunks metadata corruption"); } return ret; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index fe9747bc04a..4ebce90182f 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -146,7 +146,7 @@ obj_pool_init(void) if (pools_ht == NULL) { c = critnib_new(); if (c == NULL) - FATAL("!critnib_new for pools_ht"); + FATAL_W_ERRNO("critnib_new for pools_ht"); if (!util_bool_compare_and_swap64(&pools_ht, NULL, c)) critnib_delete(c); } @@ -154,7 +154,7 @@ obj_pool_init(void) if (pools_tree == NULL) { c = critnib_new(); if (c == NULL) - FATAL("!critnib_new for pools_tree"); + FATAL_W_ERRNO("critnib_new for pools_tree"); if (!util_bool_compare_and_swap64(&pools_tree, NULL, c)) critnib_delete(c); } @@ -209,7 +209,7 @@ obj_init(void) pmalloc_global_ctl_register(); if (obj_ctl_init_and_load(NULL)) - FATAL("error: %s", pmemobj_errormsg()); + FATAL_WO_ERRNO("error: %s", pmemobj_errormsg()); lane_info_boot(); } @@ -250,7 +250,7 @@ static void obj_msync_nofail(const void *addr, size_t size) { if (pmem_msync(addr, size)) - FATAL("!pmem_msync"); + FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index e4aa51cddb9..ee98af180c5 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -301,7 +301,7 @@ palloc_restore_free_chunk_state(struct palloc_heap *heap, HEAP_ARENA_PER_THREAD); if (heap_free_chunk_reuse(heap, b, m) != 0) { if (errno == EEXIST) { - FATAL( + FATAL_WO_ERRNO( "duplicate runtime chunk state, possible double free"); } else { LOG(2, "unable to track runtime chunk state"); diff --git a/src/libpmemobj/sync.h b/src/libpmemobj/sync.h index 46aa1bb221c..3ba37b9f89b 100644 --- a/src/libpmemobj/sync.h +++ b/src/libpmemobj/sync.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2016-2020, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * sync.h -- internal to obj synchronization API @@ -84,7 +84,7 @@ pmemobj_mutex_lock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_lock(pop, mutexp); if (ret) { errno = ret; - FATAL("!pmemobj_mutex_lock"); + FATAL_W_ERRNO("pmemobj_mutex_lock"); } } @@ -99,7 +99,7 @@ pmemobj_mutex_unlock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_unlock(pop, mutexp); if (ret) { errno = ret; - FATAL("!pmemobj_mutex_unlock"); + FATAL_W_ERRNO("pmemobj_mutex_unlock"); } } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index 6e4f25a230e..f95d7569bd4 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -158,13 +158,14 @@ obj_tx_fail_null(int errnum, uint64_t flags) /* ASSERT_IN_TX -- checks whether there's open transaction */ #define ASSERT_IN_TX(tx) do {\ if ((tx)->stage == TX_STAGE_NONE)\ - FATAL("%s called outside of transaction", __func__);\ + FATAL_WO_ERRNO("%s called outside of transaction", __func__);\ } while (0) /* ASSERT_TX_STAGE_WORK -- checks whether current transaction stage is WORK */ #define ASSERT_TX_STAGE_WORK(tx) do {\ if ((tx)->stage != TX_STAGE_WORK)\ - FATAL("%s called in invalid stage %d", __func__, (tx)->stage);\ + FATAL_WO_ERRNO("%s called in invalid stage %d",\ + __func__, (tx)->stage);\ } while (0) /* @@ -268,7 +269,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); txrn->begin = txr->begin; txrn->end = begin; @@ -280,7 +281,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); txrn->begin = end; txrn->end = txr->end; @@ -317,7 +318,7 @@ tx_restore_range(PMEMobjpool *pop, struct tx *tx, struct ulog_entry_buf *range) txr = Malloc(sizeof(*txr)); if (txr == NULL) { /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); } uint64_t range_offset = ulog_entry_offset(&range->base); @@ -570,7 +571,7 @@ tx_lane_ranges_insert_def(PMEMobjpool *pop, struct tx *tx, int ret = ravl_emplace_copy(tx->ranges, rdef); if (ret && errno == EEXIST) - FATAL("invalid state of ranges tree"); + FATAL_WO_ERRNO("invalid state of ranges tree"); return ret; } @@ -765,7 +766,8 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) tx->user_data = NULL; } else { - FATAL("Invalid stage %d to begin new transaction", tx->stage); + FATAL_WO_ERRNO("Invalid stage %d to begin new transaction", + tx->stage); } struct tx_data *txd = Malloc(sizeof(*txd)); @@ -802,8 +804,8 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) if (tx->stage_callback && (tx->stage_callback != cb || tx->stage_callback_arg != arg)) { - FATAL("transaction callback is already set, " - "old %p new %p old_arg %p new_arg %p", + FATAL_WO_ERRNO( + "transaction callback is already set, old %p new %p old_arg %p new_arg %p", tx->stage_callback, cb, tx->stage_callback_arg, arg); } @@ -1044,10 +1046,12 @@ pmemobj_tx_end(void) struct tx *tx = get_tx(); if (tx->stage == TX_STAGE_WORK) - FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); + FATAL_WO_ERRNO( + "pmemobj_tx_end called without pmemobj_tx_commit"); if (tx->pop == NULL) - FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); + FATAL_WO_ERRNO( + "pmemobj_tx_end called without pmemobj_tx_begin"); if (tx->stage_callback && (tx->stage == TX_STAGE_ONCOMMIT || diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index 8475dbf8a94..d6a645cb4be 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -852,7 +852,7 @@ init_location_data(PMEMpoolcheck *ppc, location *loc) "replica %u part %u: ", loc->replica, loc->part); if (ret < 0) - FATAL("!snprintf"); + FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_sds.c b/src/libpmempool/check_sds.c index 7844fcf6cb2..a67da1697a1 100644 --- a/src/libpmempool/check_sds.c +++ b/src/libpmempool/check_sds.c @@ -187,7 +187,7 @@ init_prefix(location *loc) "replica %u: ", loc->replica); if (ret < 0) - FATAL("!snprintf"); + FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 1d4a8416310..b57962991b8 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -181,11 +181,11 @@ status_alloc(void) { struct check_status *status = malloc(sizeof(*status)); if (!status) - FATAL("!malloc"); + FATAL_W_ERRNO("malloc"); status->msg = malloc(sizeof(char) * MAX_MSG_STR_SIZE); if (!status->msg) { free(status); - FATAL("!malloc"); + FATAL_W_ERRNO("malloc"); } status->status.str.msg = status->msg; status->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; diff --git a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c index ffef2686eb7..22757e1bfcf 100644 --- a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c +++ b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2020, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * pmem_is_pmem_posix.c -- Posix specific unit test for pmem_is_pmem() @@ -24,7 +24,7 @@ str2type(char *str) if (strcmp(str, "MAP_SYNC") == 0) return PMEM_MAP_SYNC; - FATAL("unknown type '%s'", str); + FATAL_WO_ERRNO("unknown type '%s'", str); } static int @@ -145,7 +145,7 @@ main(int argc, char *argv[]) i += do_fault_injection_split(addr, len); break; default: - FATAL("invalid op '%c'", argv[i][0]); + FATAL_WO_ERRNO("invalid op '%c'", argv[i][0]); } } From c64c0c96162eafa836834951ed23dd12907a36d5 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 12:53:05 +0100 Subject: [PATCH 040/182] common: replace FATAL* by CORE_LOG_FATAL* Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 4 +- src/common/util_pmem.h | 2 +- src/core/alloc.c | 2 +- src/core/log_default.c | 1 - src/core/log_internal.h | 18 ++++++++- src/core/out.c | 4 +- src/core/out.h | 7 ---- src/core/sys_util.h | 40 +++++++++---------- src/libpmem/pmem.c | 4 +- src/libpmem2/aarch64/init.c | 2 +- src/libpmem2/map_posix.c | 2 +- src/libpmem2/pmem2_utils.c | 2 +- src/libpmem2/source_posix.c | 4 +- src/libpmem2/x86_64/init.c | 2 +- src/libpmemobj/lane.c | 14 +++---- src/libpmemobj/memblock.c | 6 +-- src/libpmemobj/obj.c | 8 ++-- src/libpmemobj/palloc.c | 2 +- src/libpmemobj/sync.h | 4 +- src/libpmemobj/tx.c | 20 +++++----- src/libpmempool/check_pool_hdr.c | 2 +- src/libpmempool/check_sds.c | 2 +- src/libpmempool/check_util.c | 4 +- .../pmem_is_pmem_posix/pmem_is_pmem_posix.c | 4 +- 24 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index be2415aaaad..621d6e5e2d1 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -217,7 +217,7 @@ util_unmap_hdr(struct pool_set_part *part) VALGRIND_REMOVE_PMEM_MAPPING(part->hdr, part->hdrsize); if (munmap(part->hdr, part->hdrsize) != 0) /* this means there's a bug on the caller side */ - FATAL_W_ERRNO("munmap: %s", part->path); + CORE_LOG_FATAL_W_ERRNO("munmap: %s", part->path); part->hdr = NULL; part->hdrsize = 0; } @@ -2209,7 +2209,7 @@ util_poolset_append_new_part(struct pool_set *set, size_t size) d->path, PMEM_FILE_PADDING, set->next_id, PMEM_EXT); if (util_replica_add_part(&set->replica[r], path, size) != 0) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "cannot add a new part to the replica info"); } diff --git a/src/common/util_pmem.h b/src/common/util_pmem.h index 76dd0d279a3..743fbc31cc9 100644 --- a/src/common/util_pmem.h +++ b/src/common/util_pmem.h @@ -26,7 +26,7 @@ util_persist(int is_pmem, const void *addr, size_t len) if (is_pmem) pmem_persist(addr, len); else if (pmem_msync(addr, len)) - FATAL_W_ERRNO("pmem_msync"); + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/core/alloc.c b/src/core/alloc.c index 6c3d7e16bdb..7d508d8cbf7 100644 --- a/src/core/alloc.c +++ b/src/core/alloc.c @@ -58,7 +58,7 @@ core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at) fail_realloc_from = at; break; default: - FATAL_WO_ERRNO("unknown allocation type"); + CORE_LOG_FATAL("unknown allocation type"); } } diff --git a/src/core/log_default.c b/src/core/log_default.c index 353fc2dc76e..a0715da3b92 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -6,7 +6,6 @@ * to syslog or to stderr */ -#define _GNU_SOURCE #include #include #include diff --git a/src/core/log_internal.h b/src/core/log_internal.h index b8b01b8f8c0..3117b0d9d7e 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -8,6 +8,10 @@ #ifndef CORE_LOG_INTERNAL_H #define CORE_LOG_INTERNAL_H +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + #include #include #include @@ -137,7 +141,19 @@ void core_log_default_function(void *context, enum core_log_level level, CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) + do { \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__); \ + abort(); \ + } while (0) + +#define CORE_LOG_MAX_ERR_MSG 128 +#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ + strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ + abort(); \ + } while (0) #define CORE_LOG_ALWAYS(format, ...) \ CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) diff --git a/src/core/out.c b/src/core/out.c index ad51b320c61..dc80e53ccae 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -48,7 +48,7 @@ _Last_errormsg_key_alloc(void) { int pth_ret = os_tls_key_create(&Last_errormsg_key, free); if (pth_ret) - FATAL_W_ERRNO("os_thread_key_create"); + CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); } @@ -89,7 +89,7 @@ Last_errormsg_get(void) errormsg->msg[0] = '\0'; int ret = os_tls_set(Last_errormsg_key, errormsg); if (ret) - FATAL_W_ERRNO("os_tls_set"); + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); } return errormsg; } diff --git a/src/core/out.h b/src/core/out.h index f5227991ba9..33d30315e50 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -116,13 +116,6 @@ out_fatal_abort(const char *file, int line, const char *func, OUT_NONL(level, __VA_ARGS__); \ } while (0) -/* produce output and exit */ -#define FATAL_WO_ERRNO(...)\ - OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__) - -#define FATAL_W_ERRNO(...)\ - OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, "!" __VA_ARGS__) - /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ diff --git a/src/core/sys_util.h b/src/core/sys_util.h index 80d880e90a5..931c73e4cdb 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -28,7 +28,7 @@ util_mutex_init(os_mutex_t *m) int tmp = os_mutex_init(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_init"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); } } @@ -43,7 +43,7 @@ util_mutex_destroy(os_mutex_t *m) int tmp = os_mutex_destroy(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); } } @@ -58,7 +58,7 @@ util_mutex_lock(os_mutex_t *m) int tmp = os_mutex_lock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_lock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); } } @@ -74,7 +74,7 @@ util_mutex_trylock(os_mutex_t *m) int tmp = os_mutex_trylock(m); if (tmp && tmp != EBUSY) { errno = tmp; - FATAL_W_ERRNO("os_mutex_trylock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); } return tmp; } @@ -90,7 +90,7 @@ util_mutex_unlock(os_mutex_t *m) int tmp = os_mutex_unlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); } } @@ -105,7 +105,7 @@ util_rwlock_init(os_rwlock_t *m) int tmp = os_rwlock_init(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_init"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_init"); } } @@ -120,7 +120,7 @@ util_rwlock_rdlock(os_rwlock_t *m) int tmp = os_rwlock_rdlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_rdlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_rdlock"); } } @@ -135,7 +135,7 @@ util_rwlock_wrlock(os_rwlock_t *m) int tmp = os_rwlock_wrlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_wrlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_wrlock"); } } @@ -150,7 +150,7 @@ util_rwlock_unlock(os_rwlock_t *m) int tmp = os_rwlock_unlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_unlock"); } } @@ -165,7 +165,7 @@ util_rwlock_destroy(os_rwlock_t *m) int tmp = os_rwlock_destroy(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_destroy"); } } @@ -194,7 +194,7 @@ util_spin_destroy(os_spinlock_t *lock) int tmp = os_spin_destroy(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_spin_destroy"); } } @@ -208,7 +208,7 @@ util_spin_lock(os_spinlock_t *lock) int tmp = os_spin_lock(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_lock"); + CORE_LOG_FATAL_W_ERRNO("os_spin_lock"); } } @@ -223,7 +223,7 @@ util_spin_unlock(os_spinlock_t *lock) int tmp = os_spin_unlock(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_spin_unlock"); } } @@ -236,7 +236,7 @@ static inline void util_semaphore_init(os_semaphore_t *sem, unsigned value) { if (os_semaphore_init(sem, value)) - FATAL_W_ERRNO("os_semaphore_init"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_init"); } /* @@ -246,7 +246,7 @@ static inline void util_semaphore_destroy(os_semaphore_t *sem) { if (os_semaphore_destroy(sem) != 0) - FATAL_W_ERRNO("os_semaphore_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_destroy"); } /* @@ -263,7 +263,7 @@ util_semaphore_wait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0) - FATAL_W_ERRNO("os_semaphore_wait"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_wait"); } /* @@ -279,7 +279,7 @@ util_semaphore_trywait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0 && errno != EAGAIN) - FATAL_W_ERRNO("os_semaphore_trywait"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_trywait"); return ret; } @@ -291,21 +291,21 @@ static inline void util_semaphore_post(os_semaphore_t *sem) { if (os_semaphore_post(sem) != 0) - FATAL_W_ERRNO("os_semaphore_post"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_post"); } static inline void util_cond_init(os_cond_t *__restrict cond) { if (os_cond_init(cond)) - FATAL_W_ERRNO("os_cond_init"); + CORE_LOG_FATAL_W_ERRNO("os_cond_init"); } static inline void util_cond_destroy(os_cond_t *__restrict cond) { if (os_cond_destroy(cond)) - FATAL_W_ERRNO("os_cond_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_cond_destroy"); } #ifdef __cplusplus diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 49ae318facb..931ae63b550 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -359,7 +359,7 @@ pmem_is_pmem_init(void) Is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) - FATAL_WO_ERRNO("util_bool_compare_and_swap32"); + CORE_LOG_FATAL("util_bool_compare_and_swap32"); } } @@ -911,7 +911,7 @@ pmem_init(void) if (Funcs.flush == flush_empty) LOG(3, "not flushing CPU cache"); else if (Funcs.flush != Funcs.deep_flush) - FATAL_WO_ERRNO("invalid flush function address"); + CORE_LOG_FATAL("invalid flush function address"); pmem_os_init(&Is_pmem); } diff --git a/src/libpmem2/aarch64/init.c b/src/libpmem2/aarch64/init.c index 21cf6c0bfdd..d4dd8812b21 100644 --- a/src/libpmem2/aarch64/init.c +++ b/src/libpmem2/aarch64/init.c @@ -85,5 +85,5 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_pop) LOG(3, "Synchronize VA to pop for ARM"); else - FATAL_WO_ERRNO("invalid deep flush function address"); + CORE_LOG_FATAL("invalid deep flush function address"); } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index fa886a58e20..cab0d705e4a 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -484,7 +484,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, [cfg->requested_max_granularity] [available_min_granularity]; if (strcmp(err, GRAN_IMPOSSIBLE) == 0) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "unhandled granularity error: available_min_granularity: %d" \ "requested_max_granularity: %d", available_min_granularity, diff --git a/src/libpmem2/pmem2_utils.c b/src/libpmem2/pmem2_utils.c index b9c0b3bd9c3..19cfc5c9c56 100644 --- a/src/libpmem2/pmem2_utils.c +++ b/src/libpmem2/pmem2_utils.c @@ -67,7 +67,7 @@ int pmem2_err_to_errno(int err) { if (err > 0) - FATAL_WO_ERRNO("positive error code is a bug in libpmem2"); + CORE_LOG_FATAL("positive error code is a bug in libpmem2"); if (err == PMEM2_E_NOSUPP) return ENOTSUP; diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 4f36c1cef18..346623d770d 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -126,7 +126,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) *size = (size_t)st.st_size; break; default: - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "BUG: unhandled file type in pmem2_source_size"); } @@ -162,7 +162,7 @@ pmem2_source_alignment(const struct pmem2_source *src, size_t *alignment) *alignment = Pagesize; break; default: - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "BUG: unhandled file type in pmem2_source_alignment"); } diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index 95b9e84b705..66867f2e84d 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -585,7 +585,7 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_clflush) LOG(3, "using clflush"); else - FATAL_WO_ERRNO("invalid deep flush function address"); + CORE_LOG_FATAL("invalid deep flush function address"); if (impl == MEMCPY_MOVDIR64B) LOG(3, "using movnt MOVDIR64B"); diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 6210b27ddd1..0dcdbe59ccd 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -40,7 +40,7 @@ lane_info_create(void) { Lane_info_ht = critnib_new(); if (Lane_info_ht == NULL) - FATAL_WO_ERRNO("critnib_new"); + CORE_LOG_FATAL("critnib_new"); } /* @@ -77,7 +77,7 @@ lane_info_ht_boot(void) int result = os_tls_set(Lane_info_key, Lane_info_ht); if (result != 0) { errno = result; - FATAL_W_ERRNO("os_tls_set"); + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); } } @@ -102,7 +102,7 @@ lane_info_boot(void) int result = os_tls_key_create(&Lane_info_key, lane_info_ht_destroy); if (result != 0) { errno = result; - FATAL_W_ERRNO("os_tls_key_create"); + CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); } } @@ -479,7 +479,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(info == NULL)) { info = Malloc(sizeof(struct lane_info)); if (unlikely(info == NULL)) { - FATAL_WO_ERRNO("Malloc"); + CORE_LOG_FATAL("Malloc"); } info->pop_uuid_lo = pop->uuid_lo; info->lane_idx = UINT64_MAX; @@ -495,7 +495,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(critnib_insert( Lane_info_ht, pop->uuid_lo, info) != 0)) { - FATAL_WO_ERRNO("critnib_insert"); + CORE_LOG_FATAL("critnib_insert"); } } @@ -551,12 +551,12 @@ lane_release(PMEMobjpool *pop) ASSERTne(lane->lane_idx, UINT64_MAX); if (unlikely(lane->nest_count == 0)) { - FATAL_WO_ERRNO("lane_release"); + CORE_LOG_FATAL("lane_release"); } else if (--(lane->nest_count) == 0) { if (unlikely(!util_bool_compare_and_swap64( &pop->lanes_desc.lane_locks[lane->lane_idx], 1, 0))) { - FATAL_WO_ERRNO("util_bool_compare_and_swap64"); + CORE_LOG_FATAL("util_bool_compare_and_swap64"); } } } diff --git a/src/libpmemobj/memblock.c b/src/libpmemobj/memblock.c index e3c68bd5650..ee5dc7141c5 100644 --- a/src/libpmemobj/memblock.c +++ b/src/libpmemobj/memblock.c @@ -1103,7 +1103,7 @@ huge_vg_init(const struct memory_block *m, int objects, if (objects && huge_get_state(m) == MEMBLOCK_ALLOCATED) { if (cb(m, arg) != 0) - FATAL_WO_ERRNO("failed to initialize valgrind state"); + CORE_LOG_FATAL("failed to initialize valgrind state"); } } @@ -1143,7 +1143,7 @@ run_vg_init(const struct memory_block *m, int objects, if (objects) { if (run_iterate_used(m, cb, arg) != 0) - FATAL_WO_ERRNO("failed to initialize valgrind state"); + CORE_LOG_FATAL("failed to initialize valgrind state"); } } @@ -1463,7 +1463,7 @@ memblock_detect_type(struct palloc_heap *heap, const struct memory_block *m) break; default: /* unreachable */ - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "possible zone chunks metadata corruption"); } return ret; diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 4ebce90182f..ef8a2c2298d 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -146,7 +146,7 @@ obj_pool_init(void) if (pools_ht == NULL) { c = critnib_new(); if (c == NULL) - FATAL_W_ERRNO("critnib_new for pools_ht"); + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); if (!util_bool_compare_and_swap64(&pools_ht, NULL, c)) critnib_delete(c); } @@ -154,7 +154,7 @@ obj_pool_init(void) if (pools_tree == NULL) { c = critnib_new(); if (c == NULL) - FATAL_W_ERRNO("critnib_new for pools_tree"); + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); if (!util_bool_compare_and_swap64(&pools_tree, NULL, c)) critnib_delete(c); } @@ -209,7 +209,7 @@ obj_init(void) pmalloc_global_ctl_register(); if (obj_ctl_init_and_load(NULL)) - FATAL_WO_ERRNO("error: %s", pmemobj_errormsg()); + CORE_LOG_FATAL("error: %s", pmemobj_errormsg()); lane_info_boot(); } @@ -250,7 +250,7 @@ static void obj_msync_nofail(const void *addr, size_t size) { if (pmem_msync(addr, size)) - FATAL_W_ERRNO("pmem_msync"); + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index ee98af180c5..bbce59dff68 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -301,7 +301,7 @@ palloc_restore_free_chunk_state(struct palloc_heap *heap, HEAP_ARENA_PER_THREAD); if (heap_free_chunk_reuse(heap, b, m) != 0) { if (errno == EEXIST) { - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "duplicate runtime chunk state, possible double free"); } else { LOG(2, "unable to track runtime chunk state"); diff --git a/src/libpmemobj/sync.h b/src/libpmemobj/sync.h index 3ba37b9f89b..bc206826c16 100644 --- a/src/libpmemobj/sync.h +++ b/src/libpmemobj/sync.h @@ -84,7 +84,7 @@ pmemobj_mutex_lock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_lock(pop, mutexp); if (ret) { errno = ret; - FATAL_W_ERRNO("pmemobj_mutex_lock"); + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); } } @@ -99,7 +99,7 @@ pmemobj_mutex_unlock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_unlock(pop, mutexp); if (ret) { errno = ret; - FATAL_W_ERRNO("pmemobj_mutex_unlock"); + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); } } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index f95d7569bd4..f9fe29de58d 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -158,13 +158,13 @@ obj_tx_fail_null(int errnum, uint64_t flags) /* ASSERT_IN_TX -- checks whether there's open transaction */ #define ASSERT_IN_TX(tx) do {\ if ((tx)->stage == TX_STAGE_NONE)\ - FATAL_WO_ERRNO("%s called outside of transaction", __func__);\ + CORE_LOG_FATAL("%s called outside of transaction", __func__);\ } while (0) /* ASSERT_TX_STAGE_WORK -- checks whether current transaction stage is WORK */ #define ASSERT_TX_STAGE_WORK(tx) do {\ if ((tx)->stage != TX_STAGE_WORK)\ - FATAL_WO_ERRNO("%s called in invalid stage %d",\ + CORE_LOG_FATAL("%s called in invalid stage %d",\ __func__, (tx)->stage);\ } while (0) @@ -269,7 +269,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); txrn->begin = txr->begin; txrn->end = begin; @@ -281,7 +281,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); txrn->begin = end; txrn->end = txr->end; @@ -318,7 +318,7 @@ tx_restore_range(PMEMobjpool *pop, struct tx *tx, struct ulog_entry_buf *range) txr = Malloc(sizeof(*txr)); if (txr == NULL) { /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); } uint64_t range_offset = ulog_entry_offset(&range->base); @@ -571,7 +571,7 @@ tx_lane_ranges_insert_def(PMEMobjpool *pop, struct tx *tx, int ret = ravl_emplace_copy(tx->ranges, rdef); if (ret && errno == EEXIST) - FATAL_WO_ERRNO("invalid state of ranges tree"); + CORE_LOG_FATAL("invalid state of ranges tree"); return ret; } @@ -766,7 +766,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) tx->user_data = NULL; } else { - FATAL_WO_ERRNO("Invalid stage %d to begin new transaction", + CORE_LOG_FATAL("Invalid stage %d to begin new transaction", tx->stage); } @@ -804,7 +804,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) if (tx->stage_callback && (tx->stage_callback != cb || tx->stage_callback_arg != arg)) { - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "transaction callback is already set, old %p new %p old_arg %p new_arg %p", tx->stage_callback, cb, tx->stage_callback_arg, arg); @@ -1046,11 +1046,11 @@ pmemobj_tx_end(void) struct tx *tx = get_tx(); if (tx->stage == TX_STAGE_WORK) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "pmemobj_tx_end called without pmemobj_tx_commit"); if (tx->pop == NULL) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "pmemobj_tx_end called without pmemobj_tx_begin"); if (tx->stage_callback && diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index d6a645cb4be..7a5500570d9 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -852,7 +852,7 @@ init_location_data(PMEMpoolcheck *ppc, location *loc) "replica %u part %u: ", loc->replica, loc->part); if (ret < 0) - FATAL_W_ERRNO("snprintf"); + CORE_LOG_FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_sds.c b/src/libpmempool/check_sds.c index a67da1697a1..3ffc87bb985 100644 --- a/src/libpmempool/check_sds.c +++ b/src/libpmempool/check_sds.c @@ -187,7 +187,7 @@ init_prefix(location *loc) "replica %u: ", loc->replica); if (ret < 0) - FATAL_W_ERRNO("snprintf"); + CORE_LOG_FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index b57962991b8..5611fc51308 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -181,11 +181,11 @@ status_alloc(void) { struct check_status *status = malloc(sizeof(*status)); if (!status) - FATAL_W_ERRNO("malloc"); + CORE_LOG_FATAL_W_ERRNO("malloc"); status->msg = malloc(sizeof(char) * MAX_MSG_STR_SIZE); if (!status->msg) { free(status); - FATAL_W_ERRNO("malloc"); + CORE_LOG_FATAL_W_ERRNO("malloc"); } status->status.str.msg = status->msg; status->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; diff --git a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c index 22757e1bfcf..fae84bbc5cb 100644 --- a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c +++ b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c @@ -24,7 +24,7 @@ str2type(char *str) if (strcmp(str, "MAP_SYNC") == 0) return PMEM_MAP_SYNC; - FATAL_WO_ERRNO("unknown type '%s'", str); + CORE_LOG_FATAL("unknown type '%s'", str); } static int @@ -145,7 +145,7 @@ main(int argc, char *argv[]) i += do_fault_injection_split(addr, len); break; default: - FATAL_WO_ERRNO("invalid op '%c'", argv[i][0]); + CORE_LOG_FATAL("invalid op '%c'", argv[i][0]); } } From f9df2013e36a386a3edb160fb4bddef98f074297 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 13:02:14 +0100 Subject: [PATCH 041/182] common: remove old FATAL implementation Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 17 ----------------- src/core/out.h | 10 ++++------ utils/call_stacks_analysis/white_list.json | 1 - 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index dc80e53ccae..ff8c9db027b 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -491,23 +491,6 @@ out_log(const char *file, int line, const char *func, int level, va_end(ap); } -/* - * out_fatal -- output a fatal error & die (i.e. assertion failure) - */ -void -out_fatal(const char *file, int line, const char *func, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - out_common(file, line, func, 1, "\n", fmt, ap); - - va_end(ap); - - abort(); -} - /* * out_err -- output an error message */ diff --git a/src/core/out.h b/src/core/out.h index 33d30315e50..99ff4353d61 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -43,8 +43,6 @@ extern "C" { #define OUT_LOG out_log #define OUT_NONL out_nonl -#define OUT_FATAL out_fatal -#define OUT_FATAL_ABORT out_fatal #else @@ -119,20 +117,20 @@ out_fatal_abort(const char *file, int line, const char *func, /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__, "assertion failure: %s", #cnd);\ + CORE_LOG_FATAL("assertion failure: %s", #cnd);\ } while (0) /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__, \ + CORE_LOG_FATAL( \ "assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__,\ + CORE_LOG_FATAL(\ "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) @@ -140,7 +138,7 @@ out_fatal_abort(const char *file, int line, const char *func, /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__,\ + CORE_LOG_FATAL(\ "assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 9031d208c59..89c7cacd11a 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -125,7 +125,6 @@ "os_thread_setaffinity_np", "os_unsetenv", "os_writev", - "out_fatal", "out_log", "out_log_va", "out_nonl", From 5eb4adc74d93772f1c01f8d62af539fd01ba1580 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 13:12:52 +0100 Subject: [PATCH 042/182] common: assert macros redefinition Signed-off-by: Tomasz Gromadzki --- src/core/out.h | 53 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/core/out.h b/src/core/out.h index 99ff4353d61..bc48cffe9a8 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -23,12 +23,6 @@ extern "C" { * Suppress errors which are after appropriate ASSERT* macro for nondebug * builds. */ -#if !defined(DEBUG) && (defined(__clang_analyzer__) || defined(__COVERITY__)) -#define OUT_FATAL_DISCARD_NORETURN __attribute__((noreturn)) -#else -#define OUT_FATAL_DISCARD_NORETURN -#endif - #ifndef EVALUATE_DBG_EXPRESSIONS #if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ defined(__KLOCWORK__) @@ -61,28 +55,8 @@ out_nonl_discard(int level, const char *fmt, ...) SUPPRESS_UNUSED(level, fmt); } -static __attribute__((always_inline)) OUT_FATAL_DISCARD_NORETURN inline void -out_fatal_discard(const char *file, int line, const char *func, - const char *fmt, ...) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, fmt); -} - -static __attribute__((always_inline)) NORETURN inline void -out_fatal_abort(const char *file, int line, const char *func, - const char *fmt, ...) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, fmt); - - abort(); -} - #define OUT_LOG out_log_discard #define OUT_NONL out_nonl_discard -#define OUT_FATAL out_fatal_discard -#define OUT_FATAL_ABORT out_fatal_abort #endif @@ -115,6 +89,7 @@ out_fatal_abort(const char *file, int line, const char *func, } while (0) /* assert a condition is true at runtime */ +#if defined(DEBUG) #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s", #cnd);\ @@ -123,23 +98,20 @@ out_fatal_abort(const char *file, int line, const char *func, /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - CORE_LOG_FATAL( \ - "assertion failure: %s (%s = %s)", #cnd, #info, info);\ + CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - CORE_LOG_FATAL(\ - "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + CORE_LOG_FATAL("assertion failure: %s (0x%llx) == %s (0x%llx)", \ + #lhs, (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ - CORE_LOG_FATAL(\ - "assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ + CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) @@ -177,9 +149,18 @@ out_fatal_abort(const char *file, int line, const char *func, TEST_ALWAYS_NE_EXPR(lhs, rhs);\ ASSERTne_rt(lhs, rhs);\ } while (0) - -#define ERR(use_errno, ...)\ - out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) +#else +#define ASSERT_rt(cnd) +#define ASSERTinfo_rt(cnd, info) +#define ASSERTeq_rt(lhs, rhs) +#define ASSERTne_rt(lhs, rhs) +#define ASSERT(cnd) +#define ASSERTinfo(cnd, info) +#define ASSERTeq(lhs, rhs) +#define ASSERTne(lhs, rhs) +#endif // #if defined(DEBUG) +#define ERR(...)\ + out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ do {\ From b8f11e952f61f61b75941ec488306468344e28ce Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 15:02:17 +0100 Subject: [PATCH 043/182] common: adjust code for null ASSERT definition in debug Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 2 ++ src/core/log_internal.h | 2 +- src/core/out.h | 27 +++++++++++++----------- src/libpmem2/map_posix.c | 5 ++++- src/libpmem2/mcsafe_ops_posix.c | 18 +++++++++------- src/libpmemobj/alloc_class.c | 6 ++++-- src/libpmemobj/heap.c | 4 ++++ src/libpmemobj/list.c | 2 ++ src/libpmemobj/memops.c | 5 ++++- src/libpmemobj/obj.c | 5 ++++- src/libpmemobj/pmalloc.c | 11 +++++++++- src/libpmemobj/stats.c | 3 +++ src/libpmemobj/ulog.c | 2 ++ src/libpmempool/check_util.c | 2 ++ src/libpmempool/sync.c | 2 ++ src/test/obj_ctl_arenas/obj_ctl_arenas.c | 8 +++---- src/test/pmem2_perror/pmem2_perror.c | 10 +++++++-- 17 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index 621d6e5e2d1..944d6be97f5 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -3263,8 +3263,10 @@ util_replica_deep_common(const void *addr, size_t len, struct pool_set *set, addr, len, set, replica_id, flush); struct pool_replica *rep = set->replica[replica_id]; +#ifdef DEBUG /* variables required for ASSERTs below */ uintptr_t rep_start = (uintptr_t)rep->part[0].addr; uintptr_t rep_end = rep_start + rep->repsize; +#endif uintptr_t start = (uintptr_t)addr; uintptr_t end = start + len; diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 3117b0d9d7e..bd6bb124feb 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -8,7 +8,7 @@ #ifndef CORE_LOG_INTERNAL_H #define CORE_LOG_INTERNAL_H -#if !defined(_GNU_SOURCE) +#ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/src/core/out.h b/src/core/out.h index bc48cffe9a8..42f15032878 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -20,7 +20,7 @@ extern "C" { #endif /* - * Suppress errors which are after appropriate ASSERT* macro for nondebug + * Suppress errors messages (LOG()) in non-debug version * builds. */ #ifndef EVALUATE_DBG_EXPRESSIONS @@ -89,30 +89,32 @@ out_nonl_discard(int level, const char *fmt, ...) } while (0) /* assert a condition is true at runtime */ -#if defined(DEBUG) +#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ + defined(__KLOCWORK__) #define ASSERT_rt(cnd) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ + if ((cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s", #cnd);\ } while (0) /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ + if ((cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - CORE_LOG_FATAL("assertion failure: %s (0x%llx) == %s (0x%llx)", \ - #lhs, (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + if ((lhs) == (rhs)) break; \ + CORE_LOG_FATAL( \ + "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs, \ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ + if ((lhs) != (rhs)) break; \ CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert a condition is true */ @@ -158,9 +160,10 @@ out_nonl_discard(int level, const char *fmt, ...) #define ASSERTinfo(cnd, info) #define ASSERTeq(lhs, rhs) #define ASSERTne(lhs, rhs) -#endif // #if defined(DEBUG) -#define ERR(...)\ - out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) +#endif /* DEBUG */ + +#define ERR(use_errno, ...)\ + out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ do {\ diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index cab0d705e4a..44ffbc130fc 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -266,9 +266,12 @@ unmap(void *addr, size_t len) static int vm_reservation_mend(struct pmem2_vm_reservation *rsv, void *addr, size_t size) { +#ifdef DEBUG /* variables required for ASSERTs below */ void *rsv_addr = pmem2_vm_reservation_get_address(rsv); size_t rsv_size = pmem2_vm_reservation_get_size(rsv); - +#else + SUPPRESS_UNUSED(rsv); +#endif ASSERT((char *)addr >= (char *)rsv_addr && (char *)addr + size <= (char *)rsv_addr + rsv_size); diff --git a/src/libpmem2/mcsafe_ops_posix.c b/src/libpmem2/mcsafe_ops_posix.c index 1da8c1c9200..72a913ba3e8 100644 --- a/src/libpmem2/mcsafe_ops_posix.c +++ b/src/libpmem2/mcsafe_ops_posix.c @@ -163,7 +163,6 @@ static int devdax_read(struct pmem2_source *src, void *buf, size_t size, size_t offset) { int ret; - int clnup_ret; struct pmem2_config *cfg; struct pmem2_map *map; @@ -186,11 +185,13 @@ devdax_read(struct pmem2_source *src, void *buf, size_t size, size_t offset) memcpy_fn(buf, ADDR_SUM(addr, offset), size, 0); - clnup_ret = pmem2_map_delete(&map); +#ifdef DEBUG /* variables required for ASSERTs below */ + int clnup_ret = +#endif + pmem2_map_delete(&map); ASSERTeq(clnup_ret, 0); clnup_cfg_delete: - clnup_ret = pmem2_config_delete(&cfg); - ASSERTeq(clnup_ret, 0); + pmem2_config_delete(&cfg); return ret; } @@ -202,7 +203,6 @@ static int devdax_write(struct pmem2_source *src, void *buf, size_t size, size_t offset) { int ret; - int clnup_ret; struct pmem2_config *cfg; struct pmem2_map *map; @@ -225,11 +225,13 @@ devdax_write(struct pmem2_source *src, void *buf, size_t size, size_t offset) memcpy_fn(ADDR_SUM(addr, offset), buf, size, 0); - clnup_ret = pmem2_map_delete(&map); +#ifdef DEBUG /* variables required for ASSERTs below */ + int clnup_ret = +#endif + pmem2_map_delete(&map); ASSERTeq(clnup_ret, 0); clnup_cfg_delete: - clnup_ret = pmem2_config_delete(&cfg); - ASSERTeq(clnup_ret, 0); + pmem2_config_delete(&cfg); return ret; } diff --git a/src/libpmemobj/alloc_class.c b/src/libpmemobj/alloc_class.c index af261412d46..6b807d64f6d 100644 --- a/src/libpmemobj/alloc_class.c +++ b/src/libpmemobj/alloc_class.c @@ -167,8 +167,10 @@ alloc_class_reservation_clear(struct alloc_class_collection *ac, int id) { LOG(10, NULL); - int ret = util_bool_compare_and_swap64(&ac->aclasses[id], - ACLASS_RESERVED, NULL); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + util_bool_compare_and_swap64(&ac->aclasses[id], ACLASS_RESERVED, NULL); ASSERT(ret); } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 1090e607ad6..e71c5513735 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -741,7 +741,9 @@ heap_reclaim_run(struct palloc_heap *heap, struct memory_block *m, int startup) struct recycler_element e = recycler_element_new(heap, m); if (c == NULL) { +#ifdef DEBUG uint32_t size_idx = m->size_idx; +#endif struct run_bitmap b; m->m_ops->get_bitmap(m, &b); @@ -827,7 +829,9 @@ heap_ensure_zone_reclaimed(struct palloc_heap *heap, uint32_t zone_id) DEFAULT_ALLOC_CLASS_ID, HEAP_ARENA_PER_THREAD); +#ifdef DEBUG /* variables required for ASSERTs below */ struct zone *z = ZID_TO_ZONE(heap->layout, zone_id); +#endif ASSERTeq(z->header.magic, ZONE_HEADER_MAGIC); /* check a second time just to make sure no other thread was first */ diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index bb93f004fb1..af2cfbbd2a0 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -202,7 +202,9 @@ list_update_head(PMEMobjpool *pop, static void u64_add_offset(uint64_t *value, ssize_t off) { +#ifdef DEBUG /* variables required for ASSERTs below */ uint64_t prev = *value; +#endif if (off >= 0) { *value += (size_t)off; ASSERT(*value >= prev); /* detect overflow */ diff --git a/src/libpmemobj/memops.c b/src/libpmemobj/memops.c index a321e83b611..f9c630b4f19 100644 --- a/src/libpmemobj/memops.c +++ b/src/libpmemobj/memops.c @@ -466,7 +466,10 @@ operation_add_buffer(struct operation_context *ctx, ulog_clobber_entry(next_entry, ctx->p_ops); /* create a persistent log entry */ - struct ulog_entry_buf *e = ulog_entry_buf_create(ctx->ulog_curr, +#ifdef DEBUG /* variables required for ASSERTs below */ + struct ulog_entry_buf *e = +#endif + ulog_entry_buf_create(ctx->ulog_curr, ctx->ulog_curr_offset, ctx->ulog_curr_gen_num, dest, src, data_size, diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index ef8a2c2298d..6849ff47102 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -1001,7 +1001,10 @@ obj_runtime_init(PMEMobjpool *pop, int rdonly, int boot, unsigned nlanes) util_mutex_destroy(&pop->ulog_user_buffers.lock); ctl_delete(pop->ctl); err_ctl:; - void *n = critnib_remove(pools_tree, (uint64_t)pop); +#ifdef DEBUG /* variables required for ASSERTs below */ + void *n = +#endif + critnib_remove(pools_tree, (uint64_t)pop); ASSERTne(n, NULL); err_tree_insert: critnib_remove(pools_ht, pop->uuid_lo); diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 1678710eb5e..9956538b3ce 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -166,7 +166,10 @@ pfree(PMEMobjpool *pop, uint64_t *off) struct operation_context *ctx = pmalloc_operation_hold_type(pop, OPERATION_INTERNAL, 1); - int ret = palloc_operation(&pop->heap, *off, off, 0, NULL, NULL, +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + palloc_operation(&pop->heap, *off, off, 0, NULL, NULL, 0, 0, 0, 0, ctx); ASSERTeq(ret, 0); @@ -326,6 +329,9 @@ pmalloc_header_type_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_header_type *htype = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_header_type)); if (strcmp(vstr, "none") == 0) { @@ -900,6 +906,9 @@ arenas_assignment_type_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_arenas_assignment_type *atype = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_header_type)); if (strcmp(vstr, "global") == 0) { diff --git a/src/libpmemobj/stats.c b/src/libpmemobj/stats.c index d1871268c62..1e17b3e3539 100644 --- a/src/libpmemobj/stats.c +++ b/src/libpmemobj/stats.c @@ -49,6 +49,9 @@ stats_enabled_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_stats_enabled *enabled = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_stats_enabled)); int bool_out; diff --git a/src/libpmemobj/ulog.c b/src/libpmemobj/ulog.c index 54b7f316f42..6d7ab9153d1 100644 --- a/src/libpmemobj/ulog.c +++ b/src/libpmemobj/ulog.c @@ -26,8 +26,10 @@ #define ULOG_OFFSET_MASK (~(ULOG_OPERATION_MASK)) #define CACHELINE_ALIGN(size) ALIGN_UP(size, CACHELINE_SIZE) +#ifdef DEBUG /* variables required for ASSERTs below */ #define IS_CACHELINE_ALIGNED(ptr)\ (((uintptr_t)(ptr) & (CACHELINE_SIZE - 1)) == 0) +#endif /* * ulog_by_offset -- calculates the ulog pointer diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 5611fc51308..d1afc6c44fd 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -20,7 +20,9 @@ #define MSG_SEPARATOR '|' /* error part of message must have '.' at the end */ +#ifdef DEBUG /* variables required for ASSERTs below */ #define MSG_PLACE_OF_SEPARATION '.' +#endif #define MAX_MSG_STR_SIZE 8192 #define CHECK_ANSWER_YES "yes" diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index bc22068f244..17199a70423 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -532,7 +532,9 @@ sync_badblocks_assign_healthy_replica(struct part_health_status *phs, struct bb_vec bbv_new = VEC_INITIALIZER; +#ifdef DEBUG /* variables required for ASSERTs below */ size_t size_all = VEC_SIZE(pbbv_all); +#endif pbb_all = VEC_GET(pbbv_all, *i_all); for (unsigned i = 0; i < phs->bbs.bb_cnt; i++) { diff --git a/src/test/obj_ctl_arenas/obj_ctl_arenas.c b/src/test/obj_ctl_arenas/obj_ctl_arenas.c index ff11bf975bc..7f5cff2d0b8 100644 --- a/src/test/obj_ctl_arenas/obj_ctl_arenas.c +++ b/src/test/obj_ctl_arenas/obj_ctl_arenas.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2021, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * obj_ctl_arenas.c -- tests for the ctl entry points @@ -215,7 +215,6 @@ worker_arena_threads(void *arg) UT_ASSERTeq(ret, 0); PMEMoid oid[NOBJECT_THREAD]; - unsigned d; for (int i = 0; i < NOBJECT_THREAD; i++) { ret = pmemobj_xalloc(pop, &oid[i], @@ -224,10 +223,9 @@ worker_arena_threads(void *arg) NULL, NULL); UT_ASSERTeq(ret, 0); - d = labs((long)ref->oid.off - (long)oid[i].off); - /* objects are in the same block as the first one */ - ASSERT(d <= alloc_class[ALLOC_CLASS_ARENA].unit_size * + ASSERT(labs((long)ref->oid.off - (long)oid[i].off) <= + alloc_class[ALLOC_CLASS_ARENA].unit_size * (alloc_class[ALLOC_CLASS_ARENA].units_per_block - 1)); } diff --git a/src/test/pmem2_perror/pmem2_perror.c b/src/test/pmem2_perror/pmem2_perror.c index 65de96605d6..45cb08b3a9d 100644 --- a/src/test/pmem2_perror/pmem2_perror.c +++ b/src/test/pmem2_perror/pmem2_perror.c @@ -98,7 +98,10 @@ test_fail_pmem2_syscall_simple(const struct test_case *tc, src.value.fd = -1; /* "randomly" chosen function to be failed */ - int ret = pmem2_source_size(&src, &size); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + pmem2_source_size(&src, &size); ASSERTne(ret, 0); pmem2_perror("test"); @@ -121,7 +124,10 @@ test_fail_pmem2_syscall_format(const struct test_case *tc, src.value.fd = -1; /* "randomly" chosen function to be failed */ - int ret = pmem2_source_size(&src, &size); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + pmem2_source_size(&src, &size); ASSERTne(ret, 0); pmem2_perror("test %d", 123); From 08c059b6cc016643f4c49e1cb5550d2fe4d93ef6 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 29 Jan 2024 11:07:05 +0100 Subject: [PATCH 044/182] common: convert LOG(1,...) into CORE_LOG_ERROR() Signed-off-by: Tomasz Gromadzki --- src/common/bad_blocks.c | 13 ++-- src/common/ctl.c | 2 +- src/common/file_posix.c | 2 +- src/common/mmap.c | 2 +- src/common/os_deep_linux.c | 17 +++-- src/common/set.c | 38 ++++++---- src/common/set_badblocks.c | 5 +- src/core/log_internal.h | 7 +- src/core/util_posix.c | 4 +- src/libpmem/pmem_posix.c | 4 +- src/libpmem2/auto_flush_linux.c | 3 +- src/libpmem2/badblocks_ndctl.c | 8 +- src/libpmem2/deep_flush.c | 3 +- src/libpmem2/deep_flush_linux.c | 17 +++-- src/libpmem2/deep_flush_other.c | 3 +- src/libpmem2/map.c | 5 +- src/libpmem2/map_posix.c | 4 +- src/libpmem2/numa_ndctl.c | 2 +- src/libpmem2/persist.c | 6 +- src/libpmem2/pmem2_utils_ndctl.c | 4 +- src/libpmem2/region_namespace_ndctl.c | 2 +- src/libpmempool/pool.c | 3 +- src/libpmempool/replica.c | 104 ++++++++++++++------------ src/libpmempool/sync.c | 21 +++--- src/libpmempool/transform.c | 66 +++++++++------- src/test/traces/traces.c | 4 +- 26 files changed, 199 insertions(+), 150 deletions(-) diff --git a/src/common/bad_blocks.c b/src/common/bad_blocks.c index 8657060bfdc..f44ec4848e3 100644 --- a/src/common/bad_blocks.c +++ b/src/common/bad_blocks.c @@ -148,7 +148,7 @@ badblocks_clear(const char *file, struct badblocks *bbs) ret = pmem2_badblock_context_new(&bbctx, src); if (ret) { - LOG(1, "pmem2_badblock_context_new failed -- %s", file); + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", file); goto exit_delete_source; } @@ -157,7 +157,7 @@ badblocks_clear(const char *file, struct badblocks *bbs) bb.length = bbs->bbv[b].length; ret = pmem2_badblock_clear(bbctx, &bb); if (ret) { - LOG(1, "pmem2_badblock_clear -- %s", file); + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file); goto exit_delete_ctx; } } @@ -206,14 +206,14 @@ badblocks_clear_all(const char *file) ret = pmem2_badblock_context_new(&bbctx, src); if (ret) { - LOG(1, "pmem2_badblock_context_new failed -- %s", file); + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", file); goto exit_delete_source; } while ((pmem2_badblock_next(bbctx, &bb)) == 0) { ret = pmem2_badblock_clear(bbctx, &bb); if (ret) { - LOG(1, "pmem2_badblock_clear -- %s", file); + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file); goto exit_delete_ctx; } }; @@ -251,12 +251,13 @@ badblocks_check_file(const char *file) long bbsc = badblocks_count(file); if (bbsc < 0) { - LOG(1, "counting bad blocks failed -- '%s'", file); + CORE_LOG_ERROR("counting bad blocks failed -- '%s'", file); return -1; } if (bbsc > 0) { - LOG(1, "pool file '%s' contains %li bad block(s)", file, bbsc); + CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", file, + bbsc); return 1; } diff --git a/src/common/ctl.c b/src/common/ctl.c index 99d2ece7dc0..fa721dbeda3 100644 --- a/src/common/ctl.c +++ b/src/common/ctl.c @@ -234,7 +234,7 @@ ctl_exec_query_write(void *ctx, const struct ctl_node *n, void *real_arg = ctl_query_get_real_args(n, arg, source); if (real_arg == NULL) { - LOG(1, "Invalid arguments"); + CORE_LOG_ERROR("Invalid arguments"); return -1; } diff --git a/src/common/file_posix.c b/src/common/file_posix.c index 2a1dc19870d..938722130e9 100644 --- a/src/common/file_posix.c +++ b/src/common/file_posix.c @@ -112,7 +112,7 @@ device_dax_alignment(const char *path) int fd = os_open(path, O_RDONLY); if (fd == -1) { - LOG(1, "Cannot open file %s", path); + CORE_LOG_ERROR("Cannot open file %s", path); return size; } diff --git a/src/common/mmap.c b/src/common/mmap.c index 546f11a08e7..aaf4b3deddb 100644 --- a/src/common/mmap.c +++ b/src/common/mmap.c @@ -91,7 +91,7 @@ util_map(int fd, os_off_t off, size_t len, int flags, int rdonly, void *base; void *addr = util_map_hint(len, req_align); if (addr == MAP_FAILED) { - LOG(1, "cannot find a contiguous region of given size"); + CORE_LOG_ERROR("cannot find a contiguous region of given size"); return NULL; } diff --git a/src/common/os_deep_linux.c b/src/common/os_deep_linux.c index eec0a3a5ce1..f74cf64a8d0 100644 --- a/src/common/os_deep_linux.c +++ b/src/common/os_deep_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2017-2023, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * os_deep_linux.c -- Linux abstraction layer @@ -35,7 +35,7 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len) if (ret < 0) { if (ret == PMEM2_E_NOSUPP) { errno = ENOTSUP; - LOG(1, "!deep_flush not supported"); + CORE_LOG_ERROR("!deep_flush not supported"); } else { errno = pmem2_err_to_errno(ret); LOG(2, "cannot write to deep_flush" @@ -122,7 +122,7 @@ os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr, return 0; if (pmem_msync(addr, len)) { - LOG(1, "pmem_msync(%p, %lu)", addr, len); + CORE_LOG_ERROR("pmem_msync(%p, %lu)", addr, len); return -1; } return 0; @@ -151,16 +151,17 @@ os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr, if (ret < 0) { if (errno == ENOENT) { errno = ENOTSUP; - LOG(1, "!deep_flush not supported"); + CORE_LOG_ERROR_WITH_ERRNO( + "deep_flush not supported"); } else { - LOG(1, "invalid dax_region id %u", region_id); + CORE_LOG_ERROR("invalid dax_region id %u", + region_id); } return -1; } if (pmem2_deep_flush_write(region_id)) { - LOG(1, "pmem2_deep_flush_write(%u)", - region_id); + CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", region_id); return -1; } } else { @@ -169,7 +170,7 @@ os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr, * call msync on one page. */ if (pmem_msync(addr, MIN(Pagesize, len))) { - LOG(1, "pmem_msync(%p, %lu)", addr, len); + CORE_LOG_ERROR("pmem_msync(%p, %lu)", addr, len); return -1; } } diff --git a/src/common/set.c b/src/common/set.c index 944d6be97f5..fda06829a9c 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -180,7 +180,8 @@ util_map_hdr(struct pool_set_part *part, int flags, int rdonly) /* this is required only for Device DAX & memcheck */ addr = util_map_hint(hdrsize, hdrsize); if (addr == MAP_FAILED) { - LOG(1, "cannot find a contiguous region of given size"); + CORE_LOG_ERROR( + "cannot find a contiguous region of given size"); /* there's nothing we can do */ return -1; } @@ -424,8 +425,8 @@ util_poolset_chmod(struct pool_set *set, mode_t mode) } if (stbuf.st_mode & ~(unsigned)S_IFMT) { - LOG(1, "file permissions changed during pool " - "initialization, file: %s (%o)", + CORE_LOG_ERROR( + "file permissions changed during pool initialization, file: %s (%o)", part->path, stbuf.st_mode & ~(unsigned)S_IFMT); } @@ -1959,7 +1960,8 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) /* determine a hint address for mmap() */ addr = util_map_hint(rep->resvsize, 0); if (addr == MAP_FAILED) { - LOG(1, "cannot find a contiguous region of given size"); + CORE_LOG_ERROR( + "cannot find a contiguous region of given size"); return -1; } @@ -2434,7 +2436,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, (attr->features.compat & POOL_FEAT_CHECK_BAD_BLOCKS)) { int bbs = badblocks_check_poolset(set, 1 /* create */); if (bbs < 0) { - LOG(1, + CORE_LOG_ERROR( "failed to check pool set for bad blocks -- '%s'", path); goto err_poolset_free; @@ -2579,7 +2581,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) if (addr == NULL) addr = util_map_hint(rep->resvsize, 0); if (addr == MAP_FAILED) { - LOG(1, "cannot find a contiguous region of given size"); + CORE_LOG_ERROR( + "cannot find a contiguous region of given size"); return -1; } @@ -2865,20 +2868,21 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) return -1; } if (bfe < 0) { - LOG(1, + CORE_LOG_ERROR( "an error occurred when checking whether recovery file exists."); return -1; } int bbs = badblocks_check_poolset(set, 0 /* not create */); if (bbs < 0) { - LOG(1, "failed to check pool set for bad blocks"); + CORE_LOG_ERROR( + "failed to check pool set for bad blocks"); return -1; } if (bbs > 0) { if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) { - LOG(1, + CORE_LOG_ERROR( "WARNING: pool set contains bad blocks, ignoring"); } else { ERR_WO_ERRNO( @@ -2936,14 +2940,16 @@ util_read_compat_features(struct pool_set *set, uint32_t *compat_features) struct pool_set_part *part = &rep->part[p]; if (util_part_open(part, 0, 0 /* create */)) { - LOG(1, "!cannot open the part -- \"%s\"", + CORE_LOG_ERROR( + "!cannot open the part -- \"%s\"", part->path); /* try to open the next part */ continue; } if (util_map_hdr(part, MAP_SHARED, 0) != 0) { - LOG(1, "header mapping failed -- \"%s\"", + CORE_LOG_ERROR( + "header mapping failed -- \"%s\"", part->path); util_part_fdclose(part); return -1; @@ -3009,7 +3015,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, uint32_t compat_features; if (util_read_compat_features(set, &compat_features)) { - LOG(1, "reading compat features failed"); + CORE_LOG_ERROR("reading compat features failed"); goto err_poolset_free; } @@ -3024,14 +3030,14 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, } if (bfe < 0) { - LOG(1, + CORE_LOG_ERROR( "an error occurred when checking whether recovery file exists."); goto err_poolset_free; } int bbs = badblocks_check_poolset(set, 0 /* not create */); if (bbs < 0) { - LOG(1, + CORE_LOG_ERROR( "failed to check pool set for bad blocks -- '%s'", path); goto err_poolset_free; @@ -3039,7 +3045,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, if (bbs > 0) { if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) { - LOG(1, + CORE_LOG_ERROR( "WARNING: pool set contains bad blocks, ignoring -- '%s'", path); } else { @@ -3295,7 +3301,7 @@ util_replica_deep_common(const void *addr, size_t len, struct pool_set *set, replica_id, part, (void *)range_start, range_len); if (os_part_deep_common(rep, p, (void *)range_start, range_len, flush)) { - LOG(1, "os_part_deep_common(%p, %p, %lu)", + CORE_LOG_ERROR("os_part_deep_common(%p, %p, %lu)", part, (void *)range_start, range_len); return -1; } diff --git a/src/common/set_badblocks.c b/src/common/set_badblocks.c index e12d73bf323..f39ac85966f 100644 --- a/src/common/set_badblocks.c +++ b/src/common/set_badblocks.c @@ -83,7 +83,8 @@ badblocks_check_poolset(struct pool_set *set, int create) } if (cfcb.n_files_bbs) { - LOG(1, "%i pool file(s) contain bad blocks", cfcb.n_files_bbs); + CORE_LOG_ERROR("%i pool file(s) contain bad blocks", + cfcb.n_files_bbs); set->has_bad_blocks = 1; } @@ -209,7 +210,7 @@ badblocks_recovery_file_exists(struct pool_set *set) char *rec_file = badblocks_recovery_file_alloc(set->path, r, p); if (rec_file == NULL) { - LOG(1, + CORE_LOG_ERROR( "allocating name of bad block recovery file failed"); return -1; } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index bd6bb124feb..1fe0119da1a 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -164,7 +164,12 @@ void core_log_default_function(void *context, enum core_log_level level, * additional arguments. */ #define CORE_LOG_ERROR_WITH_ERRNO(f, ...) \ - CORE_LOG_ERROR(f ": %s", ##__VA_ARGS__, strerror(errno)) + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ + strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ + abort(); \ + } while (0) static inline int core_log_error_translate(int ret) diff --git a/src/core/util_posix.c b/src/core/util_posix.c index 2d7558e48c8..d55e0c89f52 100644 --- a/src/core/util_posix.c +++ b/src/core/util_posix.c @@ -48,7 +48,7 @@ util_compare_file_inodes(const char *path1, const char *path2) ERR_W_ERRNO("stat failed for %s", path1); return -1; } - LOG(1, "stat failed for %s", path1); + CORE_LOG_ERROR("stat failed for %s", path1); errno = 0; return strcmp(path1, path2) != 0; } @@ -58,7 +58,7 @@ util_compare_file_inodes(const char *path1, const char *path2) ERR_W_ERRNO("stat failed for %s", path2); return -1; } - LOG(1, "stat failed for %s", path2); + CORE_LOG_ERROR("stat failed for %s", path2); errno = 0; return strcmp(path1, path2) != 0; } diff --git a/src/libpmem/pmem_posix.c b/src/libpmem/pmem_posix.c index d295b13c732..c06308ffcdd 100644 --- a/src/libpmem/pmem_posix.c +++ b/src/libpmem/pmem_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2019, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * pmem_posix.c -- pmem utilities with Posix implementation @@ -58,7 +58,7 @@ pmem_map_register(int fd, size_t len, const char *path, int is_dev_dax) if (type != MAX_PMEM_TYPE) { if (util_range_register(addr, len, path, type)) { - LOG(1, "can't track mapped region"); + CORE_LOG_ERROR("can't track mapped region"); goto err_unmap; } } diff --git a/src/libpmem2/auto_flush_linux.c b/src/libpmem2/auto_flush_linux.c index 951dc791833..ebe0fe84323 100644 --- a/src/libpmem2/auto_flush_linux.c +++ b/src/libpmem2/auto_flush_linux.c @@ -34,7 +34,8 @@ check_cpu_cache(const char *domain_path) int cpu_cache = 0; if ((domain_fd = os_open(domain_path, O_RDONLY)) < 0) { - LOG(1, "!open(\"%s\", O_RDONLY)", domain_path); + CORE_LOG_ERROR_WITH_ERRNO("open(\"%s\", O_RDONLY)", + domain_path); goto end; } ssize_t len = read(domain_fd, domain_value, diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index c2205d8c61d..35a914e9566 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -284,7 +284,7 @@ pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, ret = pmem2_region_namespace(ctx, src, ®ion, &ndns); if (ret) { - LOG(1, "getting region and namespace failed"); + CORE_LOG_ERROR("getting region and namespace failed"); goto exit_ndctl_unref; } @@ -314,7 +314,7 @@ pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, region, ndns, &ns_beg, &ns_size); if (ret) { - LOG(1, "cannot read namespace's bounds"); + CORE_LOG_ERROR("cannot read namespace's bounds"); goto error_free_all; } @@ -339,7 +339,7 @@ pmem2_badblock_context_new(struct pmem2_badblock_context **bbctx, /* only regular files have extents */ ret = pmem2_extents_create_get(src->value.fd, &tbbctx->exts); if (ret) { - LOG(1, "getting extents of fd %i failed", + CORE_LOG_ERROR("getting extents of fd %i failed", src->value.fd); goto error_free_all; } @@ -744,7 +744,7 @@ pmem2_badblock_clear_devdax(const struct pmem2_badblock_context *bbctx, bb->offset + bbctx->rgn.ns_res, bb->length); if (ret) { - LOG(1, + CORE_LOG_ERROR( "failed to clear a bad block: offset %zu length %zu (in 512B sectors)", B2SEC(bb->offset), B2SEC(bb->length)); diff --git a/src/libpmem2/deep_flush.c b/src/libpmem2/deep_flush.c index cb26dee8ff6..f31aa7b8ec1 100644 --- a/src/libpmem2/deep_flush.c +++ b/src/libpmem2/deep_flush.c @@ -35,7 +35,8 @@ pmem2_deep_flush(struct pmem2_map *map, void *ptr, size_t size) int ret = map->deep_flush_fn(map, ptr, size); if (ret) { - LOG(1, "cannot perform deep flush operation for map %p", map); + CORE_LOG_ERROR( + "cannot perform deep flush operation for map %p", map); return ret; } diff --git a/src/libpmem2/deep_flush_linux.c b/src/libpmem2/deep_flush_linux.c index ff4d547bcb9..44b98ada5dc 100644 --- a/src/libpmem2/deep_flush_linux.c +++ b/src/libpmem2/deep_flush_linux.c @@ -39,12 +39,13 @@ pmem2_deep_flush_write(unsigned region_id) } if ((deep_flush_fd = os_open(deep_flush_path, O_RDONLY)) < 0) { - LOG(1, "!os_open(\"%s\", O_RDONLY)", deep_flush_path); + CORE_LOG_ERROR_WITH_ERRNO("os_open(\"%s\", O_RDONLY)", + deep_flush_path); return 0; } if (read(deep_flush_fd, rbuf, sizeof(rbuf)) != 2) { - LOG(1, "!read(%d)", deep_flush_fd); + CORE_LOG_ERROR_WITH_ERRNO("read(%d)", deep_flush_fd); goto end; } @@ -56,13 +57,14 @@ pmem2_deep_flush_write(unsigned region_id) os_close(deep_flush_fd); if ((deep_flush_fd = os_open(deep_flush_path, O_WRONLY)) < 0) { - LOG(1, "Cannot open deep_flush file %s to write", + CORE_LOG_ERROR("Cannot open deep_flush file %s to write", deep_flush_path); return 0; } if (write(deep_flush_fd, "1", 1) != 1) { - LOG(1, "Cannot write to deep_flush file %d", deep_flush_fd); + CORE_LOG_ERROR("Cannot write to deep_flush file %d", + deep_flush_fd); goto end; } @@ -98,7 +100,7 @@ pmem2_deep_flush_dax(struct pmem2_map *map, void *ptr, size_t size) ret = pmem2_flush_file_buffers_os(map, ptr, size, 0); if (ret) { - LOG(1, "cannot flush buffers addr %p len %zu", + CORE_LOG_ERROR("cannot flush buffers addr %p len %zu", ptr, size); return ret; } @@ -106,13 +108,14 @@ pmem2_deep_flush_dax(struct pmem2_map *map, void *ptr, size_t size) unsigned region_id; int ret = pmem2_get_region_id(&map->source, ®ion_id); if (ret < 0) { - LOG(1, "cannot find region id for dev %lu", + CORE_LOG_ERROR("cannot find region id for dev %lu", map->source.value.st_rdev); return ret; } ret = pmem2_deep_flush_write(region_id); if (ret) { - LOG(1, "cannot write to deep_flush file for region %d", + CORE_LOG_ERROR( + "cannot write to deep_flush file for region %d", region_id); return ret; } diff --git a/src/libpmem2/deep_flush_other.c b/src/libpmem2/deep_flush_other.c index 4b4b8ebb394..b1aaa5a2ee5 100644 --- a/src/libpmem2/deep_flush_other.c +++ b/src/libpmem2/deep_flush_other.c @@ -23,7 +23,8 @@ pmem2_deep_flush_dax(struct pmem2_map *map, void *ptr, size_t size) { int ret = pmem2_flush_file_buffers_os(map, ptr, size, 0); if (ret) { - LOG(1, "cannot flush buffers addr %p len %zu", ptr, size); + CORE_LOG_ERROR("cannot flush buffers addr %p len %zu", ptr, + size); return ret; } diff --git a/src/libpmem2/map.c b/src/libpmem2/map.c index ea78bec1309..de729b58a9c 100644 --- a/src/libpmem2/map.c +++ b/src/libpmem2/map.c @@ -70,7 +70,8 @@ parse_force_granularity() char str[11]; /* strlen("CACHE_LINE") + 1 */ if (util_safe_strcpy(str, ptr, sizeof(str))) { - LOG(1, "Invalid value of PMEM2_FORCE_GRANULARITY"); + CORE_LOG_ERROR( + "Invalid value of PMEM2_FORCE_GRANULARITY"); return PMEM2_GRANULARITY_INVALID; } @@ -90,7 +91,7 @@ parse_force_granularity() return PMEM2_GRANULARITY_PAGE; } - LOG(1, "Invalid value of PMEM2_FORCE_GRANULARITY"); + CORE_LOG_ERROR("Invalid value of PMEM2_FORCE_GRANULARITY"); } return PMEM2_GRANULARITY_INVALID; } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 44ffbc130fc..afaf1c1f549 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -432,10 +432,10 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, &reserved_length, cfg); if (ret != 0) { if (ret == PMEM2_E_MAPPING_EXISTS) - LOG(1, + CORE_LOG_ERROR( "given mapping region is already occupied"); else - LOG(1, + CORE_LOG_ERROR( "cannot find a contiguous region of given size"); return ret; } diff --git a/src/libpmem2/numa_ndctl.c b/src/libpmem2/numa_ndctl.c index 15e1e700e3c..9359a531342 100644 --- a/src/libpmem2/numa_ndctl.c +++ b/src/libpmem2/numa_ndctl.c @@ -39,7 +39,7 @@ pmem2_source_numa_node(const struct pmem2_source *src, int *numa_node) int ret = pmem2_region_namespace(ctx, src, ®ion, NULL); if (ret < 0) { - LOG(1, "getting region failed"); + CORE_LOG_ERROR("getting region failed"); goto end; } diff --git a/src/libpmem2/persist.c b/src/libpmem2/persist.c index defe99d8a4f..b9281089958 100644 --- a/src/libpmem2/persist.c +++ b/src/libpmem2/persist.c @@ -322,7 +322,8 @@ pmem2_deep_flush_cache(struct pmem2_map *map, void *ptr, size_t size) int ret = pmem2_deep_flush_dax(map, ptr, size); if (ret < 0) { - LOG(1, "cannot perform deep flush cache for map %p", map); + CORE_LOG_ERROR( + "cannot perform deep flush cache for map %p", map); return ret; } @@ -356,7 +357,8 @@ pmem2_deep_flush_byte(struct pmem2_map *map, void *ptr, size_t size) int ret = pmem2_deep_flush_dax(map, ptr, size); if (ret < 0) { - LOG(1, "cannot perform deep flush byte for map %p", map); + CORE_LOG_ERROR("cannot perform deep flush byte for map %p", + map); return ret; } diff --git a/src/libpmem2/pmem2_utils_ndctl.c b/src/libpmem2/pmem2_utils_ndctl.c index 68d3284ff6e..b51aeedff95 100644 --- a/src/libpmem2/pmem2_utils_ndctl.c +++ b/src/libpmem2/pmem2_utils_ndctl.c @@ -30,7 +30,7 @@ pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment) ret = pmem2_region_namespace(ctx, src, NULL, &ndns); if (ret) { - LOG(1, "getting region and namespace failed"); + CORE_LOG_ERROR("getting region and namespace failed"); goto end; } @@ -69,7 +69,7 @@ pmem2_device_dax_size(const struct pmem2_source *src, size_t *size) ret = pmem2_region_namespace(ctx, src, NULL, &ndns); if (ret) { - LOG(1, "getting region and namespace failed"); + CORE_LOG_ERROR("getting region and namespace failed"); goto end; } diff --git a/src/libpmem2/region_namespace_ndctl.c b/src/libpmem2/region_namespace_ndctl.c index f9893d4c897..03aa85a214b 100644 --- a/src/libpmem2/region_namespace_ndctl.c +++ b/src/libpmem2/region_namespace_ndctl.c @@ -245,7 +245,7 @@ pmem2_get_region_id(const struct pmem2_source *src, unsigned *region_id) int rv = pmem2_region_namespace(ctx, src, ®ion, &ndns); if (rv) { - LOG(1, "getting region and namespace failed"); + CORE_LOG_ERROR("getting region and namespace failed"); goto end; } diff --git a/src/libpmempool/pool.c b/src/libpmempool/pool.c index 63fb938b5f5..f6d6866e487 100644 --- a/src/libpmempool/pool.c +++ b/src/libpmempool/pool.c @@ -597,7 +597,8 @@ pool_set_part_copy(struct pool_set_part *dpart, struct pool_set_part *spart, #ifdef DEBUG /* provide extra logging in case of wrong dmapped/smapped value */ if (dmapped < smapped) { - LOG(1, "dmapped < smapped: dmapped = %lu, smapped = %lu", + CORE_LOG_ERROR( + "dmapped < smapped: dmapped = %lu, smapped = %lu", dmapped, smapped); ASSERT(0); } diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index a0e9eea7320..b58ae9a253d 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -546,7 +546,8 @@ check_and_open_poolset_part_files(struct pool_set *set, enum file_type type = util_file_get_type(path); if (type < 0 || os_access(path, R_OK|W_OK) != 0) { - LOG(1, "part file %s is not accessible", path); + CORE_LOG_ERROR("part file %s is not accessible", + path); errno = 0; rep_hs->part[p].flags |= IS_BROKEN; if (is_dry_run(flags)) @@ -555,12 +556,12 @@ check_and_open_poolset_part_files(struct pool_set *set, if (util_part_open(&rep->part[p], 0, 0)) { if (type == TYPE_DEVDAX) { - LOG(1, + CORE_LOG_ERROR( "opening part on Device DAX %s failed", path); return -1; } - LOG(1, "opening part %s failed", path); + CORE_LOG_ERROR("opening part %s failed", path); errno = 0; rep_hs->part[p].flags |= IS_BROKEN; } @@ -590,7 +591,8 @@ map_all_unbroken_headers(struct pool_set *set, LOG(4, "mapping header for part %u, replica %u", p, r); if (util_map_hdr(&rep->part[p], MAP_SHARED, 0) != 0) { - LOG(1, "header mapping failed - part #%d", p); + CORE_LOG_ERROR( + "header mapping failed - part #%d", p); rep_hs->part[p].flags |= IS_BROKEN; } } @@ -767,7 +769,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) do { if (fscanf(recovery_file, "%zu %zu\n", &bb.offset, &bb.length) < 2) { - LOG(1, + CORE_LOG_ERROR( "incomplete bad block recovery file -- '%s'", path); ret = 1; @@ -804,7 +806,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) os_fclose(recovery_file); - LOG(1, "bad blocks read from the recovery file -- '%s'", path); + CORE_LOG_ERROR("bad blocks read from the recovery file -- '%s'", path); return 0; @@ -856,7 +858,7 @@ replica_badblocks_recovery_files_check(struct pool_set *set, badblocks_recovery_file_alloc(set->path, r, p); if (part_hs->recovery_file_name == NULL) { - LOG(1, + CORE_LOG_ERROR( "allocating name of bad block recovery file failed"); return RECOVERY_FILES_ERROR; } @@ -926,21 +928,21 @@ replica_badblocks_recovery_files_read(struct pool_set *set, continue; } - LOG(1, + CORE_LOG_ERROR( "reading bad blocks from the recovery file -- '%s'", part_hs->recovery_file_name); ret = replica_part_badblocks_recovery_file_read( part_hs); if (ret < 0) { - LOG(1, + CORE_LOG_ERROR( "reading bad blocks from the recovery file failed -- '%s'", part_hs->recovery_file_name); return -1; } if (ret > 0) { - LOG(1, + CORE_LOG_ERROR( "incomplete bad block recovery file detected -- '%s'", part_hs->recovery_file_name); return 1; @@ -1042,7 +1044,7 @@ replica_badblocks_recovery_files_save(struct pool_set *set, int ret = replica_badblocks_recovery_file_save(part_hs); if (ret < 0) { - LOG(1, + CORE_LOG_ERROR( "opening bad block recovery file failed -- '%s'", part_hs->recovery_file_name); return -1; @@ -1160,7 +1162,7 @@ replica_badblocks_clear(struct pool_set *set, ret = badblocks_clear(path, &part_hs->bbs); if (ret < 0) { - LOG(1, + CORE_LOG_ERROR( "clearing bad blocks in replica failed -- '%s'", path); return -1; @@ -1201,7 +1203,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, /* phase #1 - error handling */ switch (status) { case RECOVERY_FILES_ERROR: - LOG(1, "checking bad block recovery files failed"); + CORE_LOG_ERROR("checking bad block recovery files failed"); return -1; case RECOVERY_FILES_EXIST_ALL: @@ -1244,14 +1246,15 @@ replica_badblocks_check_or_clear(struct pool_set *set, /* read all bad block recovery files */ ret = replica_badblocks_recovery_files_read(set, set_hs); if (ret < 0) { - LOG(1, "checking bad block recovery files failed"); + CORE_LOG_ERROR( + "checking bad block recovery files failed"); return -1; } if (ret > 0) { /* incomplete bad block recovery file was detected */ - LOG(1, + CORE_LOG_ERROR( "warning: incomplete bad block recovery file detected\n" " - all recovery files will be removed"); @@ -1261,7 +1264,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, break; case RECOVERY_FILES_NOT_ALL_EXIST: - LOG(1, + CORE_LOG_ERROR( "warning: one of bad block recovery files does not exist\n" " - all recovery files will be removed"); break; @@ -1278,15 +1281,17 @@ replica_badblocks_check_or_clear(struct pool_set *set, */ if (!dry_run) { - LOG(1, "removing all bad block recovery files..."); + CORE_LOG_ERROR( + "removing all bad block recovery files..."); ret = replica_remove_all_recovery_files(set_hs); if (ret < 0) { - LOG(1, + CORE_LOG_ERROR( "removing bad block recovery files failed"); return -1; } } else { - LOG(1, "all bad block recovery files would be removed"); + CORE_LOG_ERROR( + "all bad block recovery files would be removed"); } /* changing status to RECOVERY_FILES_DO_NOT_EXIST */ @@ -1302,11 +1307,11 @@ replica_badblocks_check_or_clear(struct pool_set *set, int bad_blocks_found = replica_badblocks_get(set, set_hs); if (bad_blocks_found < 0) { if (errno == ENOTSUP) { - LOG(1, BB_NOT_SUPP); + CORE_LOG_ERROR(BB_NOT_SUPP); return -1; } - LOG(1, "checking bad blocks failed"); + CORE_LOG_ERROR("checking bad blocks failed"); return -1; } @@ -1332,7 +1337,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, if (dry_run) { /* dry-run - do nothing */ - LOG(1, "warning: bad blocks were found"); + CORE_LOG_ERROR("warning: bad blocks were found"); return 0; } @@ -1340,7 +1345,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, ret = replica_badblocks_recovery_files_create_empty(set, set_hs); if (ret < 0) { - LOG(1, + CORE_LOG_ERROR( "creating empty bad block recovery files failed"); return -1; } @@ -1348,14 +1353,15 @@ replica_badblocks_check_or_clear(struct pool_set *set, /* save bad blocks in recovery files */ ret = replica_badblocks_recovery_files_save(set, set_hs); if (ret < 0) { - LOG(1, "saving bad block recovery files failed"); + CORE_LOG_ERROR( + "saving bad block recovery files failed"); return -1; } } if (dry_run) { /* dry-run - do nothing */ - LOG(1, "bad blocks would be cleared"); + CORE_LOG_ERROR("bad blocks would be cleared"); return 0; } @@ -1545,7 +1551,7 @@ check_replica_options(struct pool_set *set, unsigned repn, struct pool_hdr *hdr = HDR(rep, p); if (((hdr->features.incompat & POOL_FEAT_SINGLEHDR) == 0) != ((set->options & OPTION_SINGLEHDR) == 0)) { - LOG(1, + CORE_LOG_ERROR( "improper options are set in part %u's header in replica %u", p, repn); rep_hs->part[p].flags |= IS_BROKEN; @@ -1803,7 +1809,9 @@ check_replica_sizes(struct pool_set *set, struct poolset_health_status *set_hs) replica_pool_size = replica_get_pool_size(set, r); if (replica_pool_size < 0) { - LOG(1, "getting pool size from replica %u failed", r); + CORE_LOG_ERROR( + "getting pool size from replica %u failed", + r); set_hs->replica[r]->flags |= IS_BROKEN; continue; } @@ -1811,7 +1819,7 @@ check_replica_sizes(struct pool_set *set, struct poolset_health_status *set_hs) /* check if the pool is bigger than minimum size */ enum pool_type type = pool_hdr_get_type(HDR(REP(set, r), 0)); if ((size_t)replica_pool_size < pool_get_min_size(type)) { - LOG(1, + CORE_LOG_ERROR( "pool size from replica %u is smaller than the minimum size allowed for the pool", r); set_hs->replica[r]->flags |= IS_BROKEN; @@ -1862,7 +1870,7 @@ replica_read_features(struct pool_set *set, continue; if (util_map_hdr(part, MAP_SHARED, 0) != 0) { - LOG(1, "header mapping failed"); + CORE_LOG_ERROR("header mapping failed"); return -1; } @@ -1892,7 +1900,7 @@ replica_check_poolset_health(struct pool_set *set, set, set_hsp, called_from_sync, flags); if (replica_create_poolset_health_status(set, set_hsp)) { - LOG(1, "creating poolset health status failed"); + CORE_LOG_ERROR("creating poolset health status failed"); return -1; } @@ -1900,7 +1908,7 @@ replica_check_poolset_health(struct pool_set *set, /* check if part files exist and are accessible */ if (check_and_open_poolset_part_files(set, set_hs, flags)) { - LOG(1, "poolset part files check failed"); + CORE_LOG_ERROR("poolset part files check failed"); goto err; } @@ -1922,7 +1930,7 @@ replica_check_poolset_health(struct pool_set *set, * We will not fix bad blocks, so we have to read features here. */ if (replica_read_features(set, set_hs, &features)) { - LOG(1, "reading features failed"); + CORE_LOG_ERROR("reading features failed"); goto err; } check_bad_blks = features.compat & POOL_FEAT_CHECK_BAD_BLOCKS; @@ -1931,13 +1939,13 @@ replica_check_poolset_health(struct pool_set *set, /* check for bad blocks when in dry run or clear them otherwise */ if (replica_badblocks_check_or_clear(set, set_hs, is_dry_run(flags), called_from_sync, check_bad_blks, fix_bad_blks)) { - LOG(1, "replica bad_blocks check failed"); + CORE_LOG_ERROR("replica bad_blocks check failed"); goto err; } /* read features after fixing bad blocks */ if (fix_bad_blks && replica_read_features(set, set_hs, &features)) { - LOG(1, "reading features failed"); + CORE_LOG_ERROR("reading features failed"); goto err; } @@ -1955,47 +1963,47 @@ replica_check_poolset_health(struct pool_set *set, /* check if option flags are consistent */ if (check_options(set, set_hs)) { - LOG(1, "flags check failed"); + CORE_LOG_ERROR("flags check failed"); goto err; } if (!set->ignore_sds && check_shutdown_state(set, set_hs)) { - LOG(1, "replica shutdown_state check failed"); + CORE_LOG_ERROR("replica shutdown_state check failed"); goto err; } /* check if uuids in parts across each replica are consistent */ if (check_replicas_consistency(set, set_hs)) { - LOG(1, "replica consistency check failed"); + CORE_LOG_ERROR("replica consistency check failed"); goto err; } /* check poolset_uuid values between replicas */ if (check_poolset_uuids(set, set_hs)) { - LOG(1, "poolset uuids check failed"); + CORE_LOG_ERROR("poolset uuids check failed"); goto err; } /* check if uuids for adjacent replicas are consistent */ if (check_uuids_between_replicas(set, set_hs)) { - LOG(1, "replica uuids check failed"); + CORE_LOG_ERROR("replica uuids check failed"); goto err; } /* check if healthy replicas make up another poolset */ if (check_replica_cycles(set, set_hs)) { - LOG(1, "replica cycles check failed"); + CORE_LOG_ERROR("replica cycles check failed"); goto err; } /* check if replicas are large enough */ if (check_replica_sizes(set, set_hs)) { - LOG(1, "replica sizes check failed"); + CORE_LOG_ERROR("replica sizes check failed"); goto err; } if (check_store_all_sizes(set, set_hs)) { - LOG(1, "reading pool sizes failed"); + CORE_LOG_ERROR("reading pool sizes failed"); goto err; } @@ -2129,8 +2137,9 @@ replica_open_replica_part_files(struct pool_set *set, unsigned repn) continue; if (util_part_open(&rep->part[p], 0, 0)) { - LOG(1, "part files open failed for replica %u, part %u", - repn, p); + CORE_LOG_ERROR( + "part files open failed for replica %u, part %u", + repn, p); errno = EINVAL; goto err; } @@ -2151,7 +2160,8 @@ replica_open_poolset_part_files(struct pool_set *set) LOG(3, "set %p", set); for (unsigned r = 0; r < set->nreplicas; ++r) { if (replica_open_replica_part_files(set, r)) { - LOG(1, "opening replica %u, part files failed", r); + CORE_LOG_ERROR("opening replica %u, part files failed", + r); goto err; } } @@ -2208,7 +2218,7 @@ pmempool_syncU(const char *poolset, unsigned flags) /* sync all replicas */ if (replica_sync(set, NULL, flags)) { - LOG(1, "synchronization failed"); + CORE_LOG_ERROR("synchronization failed"); goto err_close_all; } @@ -2318,7 +2328,7 @@ pmempool_transformU(const char *poolset_src, /* transform poolset */ if (replica_transform(set_in, set_out, flags)) { - LOG(1, "transformation failed"); + CORE_LOG_ERROR("transformation failed"); goto err_free_poolout; } diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index 17199a70423..e01f1343699 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -98,7 +98,8 @@ sync_recreate_header(struct pool_set *set, unsigned r, unsigned p, util_pool_hdr2attr(&attr, src_hdr); if (util_header_create(set, r, p, &attr, 1) != 0) { - LOG(1, "part headers create failed for replica %u part %u", + CORE_LOG_ERROR( + "part headers create failed for replica %u part %u", r, p); errno = EINVAL; return -1; @@ -713,7 +714,7 @@ sync_check_bad_blocks_overlap(struct pool_set *set, if (pbb_all->nhealthy == NO_HEALTHY_REPLICA) { ret = 1; /* this bad block cannot be fixed */ - LOG(1, + CORE_LOG_ERROR( "uncorrectable bad block found: offset 0x%zx, length 0x%zx", pbb_all->offset, pbb_all->length); @@ -818,10 +819,10 @@ sync_badblocks_data(struct pool_set *set, struct poolset_health_status *set_hs) sync_mark_replica_no_badblocks(r, set_hs); } - LOG(1, "all bad blocks have been fixed"); + CORE_LOG_ERROR("all bad blocks have been fixed"); if (replica_remove_all_recovery_files(set_hs)) { - LOG(1, "removing bad block recovery files failed"); + CORE_LOG_ERROR("removing bad block recovery files failed"); return -1; } @@ -1319,13 +1320,13 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, if (replica_check_poolset_health(set, &set_hs, 1 /* called from sync */, flags)) { - LOG(1, "poolset health check failed"); + CORE_LOG_ERROR("poolset health check failed"); return -1; } /* check if poolset is broken; if not, nothing to do */ if (replica_is_poolset_healthy(set_hs)) { - LOG(1, "poolset is healthy"); + CORE_LOG_ERROR("poolset is healthy"); goto out; } } else { @@ -1347,7 +1348,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* in dry-run mode we can stop here */ if (is_dry_run(flags)) { - LOG(1, "Sync in dry-run mode finished successfully"); + CORE_LOG_ERROR("Sync in dry-run mode finished successfully"); goto out; } @@ -1378,7 +1379,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* recalculate offset and length of bad blocks */ if (sync_recalc_badblocks(set, set_hs)) { - LOG(1, "syncing bad blocks data failed"); + CORE_LOG_ERROR("syncing bad blocks data failed"); ret = -1; goto out; } @@ -1389,7 +1390,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, */ int status = sync_check_bad_blocks_overlap(set, set_hs); if (status == -1) { - LOG(1, "checking bad blocks failed"); + CORE_LOG_ERROR("checking bad blocks failed"); ret = -1; goto out; } @@ -1406,7 +1407,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* sync data in bad blocks */ if (sync_badblocks_data(set, set_hs)) { - LOG(1, "syncing bad blocks data failed"); + CORE_LOG_ERROR("syncing bad blocks data failed"); ret = -1; goto out; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index 151a064e436..f130e14764d 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -55,8 +55,9 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) struct pool_replica *rep = REP(set, repn); char *path = util_part_realpath(PART(rep, partn)->path); if (path == NULL) { - LOG(1, "cannot get absolute path for %s, replica %u, part %u", - PART(rep, partn)->path, repn, partn); + CORE_LOG_ERROR( + "cannot get absolute path for %s, replica %u, part %u", + PART(rep, partn)->path, repn, partn); errno = 0; path = strdup(PART(rep, partn)->path); if (path == NULL) { @@ -80,7 +81,7 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) ret = -1; goto out; } - LOG(1, + CORE_LOG_ERROR( "cannot get absolute path for %s, replica %u, part %u", PART(rep, partn)->path, repn, partn); pathp = strdup(PART(repr, p)->path); @@ -258,7 +259,8 @@ check_compare_poolsets_status(struct pool_set *set_in, struct pool_replica *rep_in = REP(set_in, ri); for (unsigned ro = 0; ro < set_out->nreplicas; ++ro) { struct pool_replica *rep_out = REP(set_out, ro); - LOG(1, "comparing rep_in %u with rep_out %u", ri, ro); + CORE_LOG_ERROR("comparing rep_in %u with rep_out %u", + ri, ro); /* skip different replicas */ if (compare_replicas(rep_in, rep_out)) continue; @@ -461,8 +463,8 @@ do_added_parts_exist(struct pool_set *set, return -1; if (exists && !rep->part[p].is_dev_dax) { - LOG(1, "part file %s exists", - rep->part[p].path); + CORE_LOG_ERROR("part file %s exists", + rep->part[p].path); return 1; } errno = oerrno; @@ -502,7 +504,8 @@ copy_replica_data_fw(struct pool_set *set_dst, struct pool_set *set_src, LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn); ssize_t pool_size = replica_get_pool_size(set_src, repn); if (pool_size < 0) { - LOG(1, "getting pool size from replica %u failed", repn); + CORE_LOG_ERROR("getting pool size from replica %u failed", + repn); pool_size = (ssize_t)set_src->poolsize; } @@ -529,7 +532,8 @@ copy_replica_data_bw(struct pool_set *set_dst, struct pool_set *set_src, LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn); ssize_t pool_size = replica_get_pool_size(set_src, repn); if (pool_size < 0) { - LOG(1, "getting pool size from replica %u failed", repn); + CORE_LOG_ERROR("getting pool size from replica %u failed", + repn); pool_size = (ssize_t)set_src->poolsize; } @@ -559,8 +563,9 @@ create_missing_headers(struct pool_set *set, unsigned repn) util_pool_hdr2attr(&attr, src_hdr); attr.features.incompat &= (uint32_t)(~POOL_FEAT_SINGLEHDR); if (util_header_create(set, repn, p, &attr, 1) != 0) { - LOG(1, "part headers create failed for" - " replica %u part %u", repn, p); + CORE_LOG_ERROR( + "part headers create failed for replica %u part %u", + repn, p); errno = EINVAL; return -1; } @@ -674,7 +679,7 @@ remove_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out, /* open all part files of the input replica */ if (replica_open_replica_part_files(set_in, repn)) { - LOG(1, "opening replica %u, part files failed", repn); + CORE_LOG_ERROR("opening replica %u, part files failed", repn); ret = -1; goto out; } @@ -684,14 +689,16 @@ remove_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out, /* map the whole input replica */ if (util_replica_open(set_in, repn, MAP_SHARED)) { - LOG(1, "opening input replica failed: replica %u", repn); + CORE_LOG_ERROR("opening input replica failed: replica %u", + repn); ret = -1; goto out_close; } /* map the whole output replica */ if (util_replica_open(set_out, repn, MAP_SHARED)) { - LOG(1, "opening output replica failed: replica %u", repn); + CORE_LOG_ERROR("opening output replica failed: replica %u", + repn); ret = -1; goto out_unmap_in; } @@ -726,7 +733,8 @@ add_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out, /* open all part files of the input replica */ if (replica_open_replica_part_files(set_in, repn)) { - LOG(1, "opening replica %u, part files failed", repn); + CORE_LOG_ERROR("opening replica %u, part files failed", + repn); ret = -1; goto out; } @@ -736,22 +744,25 @@ add_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out, /* map the whole input replica */ if (util_replica_open(set_in, repn, MAP_SHARED)) { - LOG(1, "opening input replica failed: replica %u", repn); + CORE_LOG_ERROR("opening input replica failed: replica %u", + repn); ret = -1; goto out_close; } /* map the whole output replica */ if (util_replica_open(set_out, repn, MAP_SHARED)) { - LOG(1, "opening output replica failed: replica %u", repn); + CORE_LOG_ERROR("opening output replica failed: replica %u", + repn); ret = -1; goto out_unmap_in; } /* generate new uuids for lacking headers */ if (fill_replica_struct_uuids(set_out, repn)) { - LOG(1, "generating lacking uuids for parts failed: replica %u", - repn); + CORE_LOG_ERROR( + "generating lacking uuids for parts failed: replica %u", + repn); ret = -1; goto out_unmap_out; } @@ -762,7 +773,8 @@ add_hdrs_replica(struct pool_set *set_in, struct pool_set *set_out, /* create the missing headers */ if (create_missing_headers(set_out, repn)) { - LOG(1, "creating lacking headers failed: replica %u", repn); + CORE_LOG_ERROR("creating lacking headers failed: replica %u", + repn); /* * copy the data back, so we could fall back to the original * state @@ -802,7 +814,8 @@ remove_hdrs(struct pool_set *set_in, struct pool_set *set_out, set_in, set_out, set_in_hs, flags); for (unsigned r = 0; r < set_in->nreplicas; ++r) { if (remove_hdrs_replica(set_in, set_out, r)) { - LOG(1, "removing headers from replica %u failed", r); + CORE_LOG_ERROR( + "removing headers from replica %u failed", r); /* mark all previous replicas as damaged */ while (--r < set_in->nreplicas) REP_HEALTH(set_in_hs, r)->flags |= IS_BROKEN; @@ -826,7 +839,8 @@ add_hdrs(struct pool_set *set_in, struct pool_set *set_out, set_in, set_out, set_in_hs, flags); for (unsigned r = 0; r < set_in->nreplicas; ++r) { if (add_hdrs_replica(set_in, set_out, r)) { - LOG(1, "adding headers to replica %u failed", r); + CORE_LOG_ERROR("adding headers to replica %u failed", + r); /* mark all previous replicas as damaged */ while (--r < set_in->nreplicas) REP_HEALTH(set_in_hs, r)->flags |= IS_BROKEN; @@ -888,7 +902,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, set_out_cs, set_in_hs, set_out_hs); if (operation == NOT_TRANSFORMABLE) { - LOG(1, "poolsets are not transformable"); + CORE_LOG_ERROR("poolsets are not transformable"); ret = -1; errno = EINVAL; goto free_cs; @@ -902,10 +916,10 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, "removing headers failed; falling back to the input poolset"); if (replica_sync(set_in, set_in_hs, flags | IS_TRANSFORMED)) { - LOG(1, + CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - LOG(1, + CORE_LOG_ERROR( "falling back to the input poolset succeeded"); } ret = -1; @@ -920,10 +934,10 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, "adding headers failed; falling back to the input poolset"); if (replica_sync(set_in, set_in_hs, flags | IS_TRANSFORMED)) { - LOG(1, + CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - LOG(1, + CORE_LOG_ERROR( "falling back to the input poolset succeeded"); } ret = -1; diff --git a/src/test/traces/traces.c b/src/test/traces/traces.c index 317ceb53f9a..f465729d640 100644 --- a/src/test/traces/traces.c +++ b/src/test/traces/traces.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2017, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * traces.c -- unit test for traces @@ -25,7 +25,7 @@ main(int argc, char *argv[]) common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); LOG(0, "Log level NONE"); - LOG(1, "Log level ERROR"); + CORE_LOG_ERROR("Log level ERROR"); LOG(2, "Log level WARNING"); LOG(3, "Log level INFO"); LOG(4, "Log level DEBUG"); From fdf8a78669f89238a760e63461eadb5a7d06ff88 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 29 Jan 2024 11:42:36 +0100 Subject: [PATCH 045/182] common: extend error messages in match file pmempool_transform/TEST10. Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_transform/out10.log.match | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/pmempool_transform/out10.log.match b/src/test/pmempool_transform/out10.log.match index 41b64d5dc4d..5152de98020 100644 --- a/src/test/pmempool_transform/out10.log.match +++ b/src/test/pmempool_transform/out10.log.match @@ -11,7 +11,10 @@ REPLICA 20M $(nW)testfile01 20M $(nW)testfile21 +$(OPT)$(*) *ERROR* transform.c: $(N): check_if_part_used_once: cannot get absolute path for $(*)/test_pmempool_transform10/testfile00, replica 0, part 0 +$(OPT)$(*) *ERROR* util_posix.c: $(N): util_compare_file_inodes: stat failed for $(*)/test_pmempool_transform10/testfile21 $(OPT)$(*) *ERROR* transform.c: $(N): check_if_part_used_once: some part file's path is used multiple times +$(OPT)$(*) *ERROR* replica.c: $(N): pmempool_transformU: transformation failed error: Invalid argument error: failed to transform $(nW)poolset.in -> $(nW)poolset.out: some part file's path is used multiple times Poolset structure: From 591fdf45cf1d61502e0ef2c271970e03f8d8dc7b Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 17:00:55 +0100 Subject: [PATCH 046/182] common: addjust loging levels Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 12 ++++++------ src/libpmempool/replica.c | 25 ++++++++++++------------- src/libpmempool/sync.c | 6 +++--- src/libpmempool/transform.c | 14 +++++++------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index fda06829a9c..9612f0c9a46 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -425,7 +425,7 @@ util_poolset_chmod(struct pool_set *set, mode_t mode) } if (stbuf.st_mode & ~(unsigned)S_IFMT) { - CORE_LOG_ERROR( + CORE_LOG_WARNING( "file permissions changed during pool initialization, file: %s (%o)", part->path, stbuf.st_mode & ~(unsigned)S_IFMT); @@ -2882,8 +2882,8 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) if (bbs > 0) { if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) { - CORE_LOG_ERROR( - "WARNING: pool set contains bad blocks, ignoring"); + CORE_LOG_WARNING( + "pool set contains bad blocks, ignoring"); } else { ERR_WO_ERRNO( "pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); @@ -2940,7 +2940,7 @@ util_read_compat_features(struct pool_set *set, uint32_t *compat_features) struct pool_set_part *part = &rep->part[p]; if (util_part_open(part, 0, 0 /* create */)) { - CORE_LOG_ERROR( + CORE_LOG_WARNING( "!cannot open the part -- \"%s\"", part->path); /* try to open the next part */ @@ -3045,8 +3045,8 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, if (bbs > 0) { if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) { - CORE_LOG_ERROR( - "WARNING: pool set contains bad blocks, ignoring -- '%s'", + CORE_LOG_WARNING( + "pool set contains bad blocks, ignoring -- '%s'", path); } else { ERR_WO_ERRNO( diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index b58ae9a253d..6dc1c08b9b8 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -806,7 +806,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) os_fclose(recovery_file); - CORE_LOG_ERROR("bad blocks read from the recovery file -- '%s'", path); + CORE_LOG_ALWAYS("bad blocks read from the recovery file -- '%s'", path); return 0; @@ -928,7 +928,7 @@ replica_badblocks_recovery_files_read(struct pool_set *set, continue; } - CORE_LOG_ERROR( + CORE_LOG_ALWAYS( "reading bad blocks from the recovery file -- '%s'", part_hs->recovery_file_name); @@ -942,7 +942,7 @@ replica_badblocks_recovery_files_read(struct pool_set *set, } if (ret > 0) { - CORE_LOG_ERROR( + CORE_LOG_WARNING( "incomplete bad block recovery file detected -- '%s'", part_hs->recovery_file_name); return 1; @@ -1254,9 +1254,9 @@ replica_badblocks_check_or_clear(struct pool_set *set, if (ret > 0) { /* incomplete bad block recovery file was detected */ - CORE_LOG_ERROR( - "warning: incomplete bad block recovery file detected\n" - " - all recovery files will be removed"); + CORE_LOG_WARNING( + "incomplete bad block recovery file detected\n" + "- all recovery files will be removed"); /* changing status to RECOVERY_FILES_NOT_ALL_EXIST */ status = RECOVERY_FILES_NOT_ALL_EXIST; @@ -1264,9 +1264,8 @@ replica_badblocks_check_or_clear(struct pool_set *set, break; case RECOVERY_FILES_NOT_ALL_EXIST: - CORE_LOG_ERROR( - "warning: one of bad block recovery files does not exist\n" - " - all recovery files will be removed"); + CORE_LOG_WARNING( + "one of bad block recovery files does not exist - all recovery files will be removed"); break; default: @@ -1281,7 +1280,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, */ if (!dry_run) { - CORE_LOG_ERROR( + CORE_LOG_ALWAYS( "removing all bad block recovery files..."); ret = replica_remove_all_recovery_files(set_hs); if (ret < 0) { @@ -1290,7 +1289,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, return -1; } } else { - CORE_LOG_ERROR( + CORE_LOG_ALWAYS( "all bad block recovery files would be removed"); } @@ -1337,7 +1336,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, if (dry_run) { /* dry-run - do nothing */ - CORE_LOG_ERROR("warning: bad blocks were found"); + CORE_LOG_WARNING("bad blocks were found"); return 0; } @@ -1361,7 +1360,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, if (dry_run) { /* dry-run - do nothing */ - CORE_LOG_ERROR("bad blocks would be cleared"); + CORE_LOG_ALWAYS("bad blocks would be cleared"); return 0; } diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index e01f1343699..7e61b7108a6 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -819,7 +819,7 @@ sync_badblocks_data(struct pool_set *set, struct poolset_health_status *set_hs) sync_mark_replica_no_badblocks(r, set_hs); } - CORE_LOG_ERROR("all bad blocks have been fixed"); + CORE_LOG_ALWAYS("all bad blocks have been fixed"); if (replica_remove_all_recovery_files(set_hs)) { CORE_LOG_ERROR("removing bad block recovery files failed"); @@ -1326,7 +1326,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* check if poolset is broken; if not, nothing to do */ if (replica_is_poolset_healthy(set_hs)) { - CORE_LOG_ERROR("poolset is healthy"); + CORE_LOG_ALWAYS("poolset is healthy"); goto out; } } else { @@ -1348,7 +1348,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* in dry-run mode we can stop here */ if (is_dry_run(flags)) { - CORE_LOG_ERROR("Sync in dry-run mode finished successfully"); + CORE_LOG_ALWAYS("Sync in dry-run mode finished successfully"); goto out; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index f130e14764d..8b927fa35b5 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -55,7 +55,7 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) struct pool_replica *rep = REP(set, repn); char *path = util_part_realpath(PART(rep, partn)->path); if (path == NULL) { - CORE_LOG_ERROR( + CORE_LOG_WARNING( "cannot get absolute path for %s, replica %u, part %u", PART(rep, partn)->path, repn, partn); errno = 0; @@ -81,7 +81,7 @@ check_if_part_used_once(struct pool_set *set, unsigned repn, unsigned partn) ret = -1; goto out; } - CORE_LOG_ERROR( + CORE_LOG_WARNING( "cannot get absolute path for %s, replica %u, part %u", PART(rep, partn)->path, repn, partn); pathp = strdup(PART(repr, p)->path); @@ -259,7 +259,7 @@ check_compare_poolsets_status(struct pool_set *set_in, struct pool_replica *rep_in = REP(set_in, ri); for (unsigned ro = 0; ro < set_out->nreplicas; ++ro) { struct pool_replica *rep_out = REP(set_out, ro); - CORE_LOG_ERROR("comparing rep_in %u with rep_out %u", + CORE_LOG_DEBUG("comparing rep_in %u with rep_out %u", ri, ro); /* skip different replicas */ if (compare_replicas(rep_in, rep_out)) @@ -504,7 +504,7 @@ copy_replica_data_fw(struct pool_set *set_dst, struct pool_set *set_src, LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn); ssize_t pool_size = replica_get_pool_size(set_src, repn); if (pool_size < 0) { - CORE_LOG_ERROR("getting pool size from replica %u failed", + CORE_LOG_WARNING("getting pool size from replica %u failed", repn); pool_size = (ssize_t)set_src->poolsize; } @@ -532,7 +532,7 @@ copy_replica_data_bw(struct pool_set *set_dst, struct pool_set *set_src, LOG(3, "set_in %p, set_out %p, repn %u", set_src, set_dst, repn); ssize_t pool_size = replica_get_pool_size(set_src, repn); if (pool_size < 0) { - CORE_LOG_ERROR("getting pool size from replica %u failed", + CORE_LOG_WARNING("getting pool size from replica %u failed", repn); pool_size = (ssize_t)set_src->poolsize; } @@ -919,7 +919,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - CORE_LOG_ERROR( + CORE_LOG_ALWAYS( "falling back to the input poolset succeeded"); } ret = -1; @@ -937,7 +937,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - CORE_LOG_ERROR( + CORE_LOG_ALWAYS( "falling back to the input poolset succeeded"); } ret = -1; From ee731fa5663353298ea25287d1bd7facf000d09a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 17:34:42 +0100 Subject: [PATCH 047/182] common: CORE_LOG_WARNING_W_ERRNO implementation Signed-off-by: Tomasz Gromadzki --- src/common/os_deep_linux.c | 3 ++- src/common/set.c | 4 ++-- src/core/log_internal.h | 10 ++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/common/os_deep_linux.c b/src/common/os_deep_linux.c index f74cf64a8d0..d4fe2065541 100644 --- a/src/common/os_deep_linux.c +++ b/src/common/os_deep_linux.c @@ -35,7 +35,8 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len) if (ret < 0) { if (ret == PMEM2_E_NOSUPP) { errno = ENOTSUP; - CORE_LOG_ERROR("!deep_flush not supported"); + CORE_LOG_ERROR_WITH_ERRNO( + "deep_flush not supported"); } else { errno = pmem2_err_to_errno(ret); LOG(2, "cannot write to deep_flush" diff --git a/src/common/set.c b/src/common/set.c index 9612f0c9a46..cb930c42105 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -2940,8 +2940,8 @@ util_read_compat_features(struct pool_set *set, uint32_t *compat_features) struct pool_set_part *part = &rep->part[p]; if (util_part_open(part, 0, 0 /* create */)) { - CORE_LOG_WARNING( - "!cannot open the part -- \"%s\"", + CORE_LOG_WARNING_W_ERRNO( + "cannot open the part -- \"%s\"", part->path); /* try to open the next part */ continue; diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 1fe0119da1a..ca52b0320ab 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -163,12 +163,18 @@ void core_log_default_function(void *context, enum core_log_level level, * 'f' stands here for 'function' or 'format' where the latter may accept * additional arguments. */ -#define CORE_LOG_ERROR_WITH_ERRNO(f, ...) \ +#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ + strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ + } while (0) + +#define CORE_LOG_WARNING_W_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ - abort(); \ } while (0) static inline int From 5e26b9f54e860c84cb2c2646f6cad72da2c00bdb Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 19:20:25 +0100 Subject: [PATCH 048/182] common: workaround of unpredictable strerror_r version strerror_r() has different return type depends on compliation settings. It is included from string.h and version depends on #define _GNU_SOURCE. Signed-off-by: Tomasz Gromadzki --- src/core/log_internal.h | 44 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/core/log_internal.h b/src/core/log_internal.h index ca52b0320ab..33804af712d 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -8,14 +8,11 @@ #ifndef CORE_LOG_INTERNAL_H #define CORE_LOG_INTERNAL_H -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include #include #include #include + #ifdef ATOMIC_OPERATIONS_SUPPORTED #include #endif /* ATOMIC_OPERATIONS_SUPPORTED */ @@ -147,6 +144,7 @@ void core_log_default_function(void *context, enum core_log_level level, } while (0) #define CORE_LOG_MAX_ERR_MSG 128 +#ifdef _GNU_SOURCE #define CORE_LOG_FATAL_W_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ @@ -154,6 +152,18 @@ void core_log_default_function(void *context, enum core_log_level level, strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ abort(); \ } while (0) +#else +#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + uint64_t ret = (uint64_t)strerror_r(errno, buff, \ + CORE_LOG_MAX_ERR_MSG); \ + ret = ret; \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ + buff); \ + abort(); \ + } while (0) +#endif #define CORE_LOG_ALWAYS(format, ...) \ CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) @@ -163,19 +173,43 @@ void core_log_default_function(void *context, enum core_log_level level, * 'f' stands here for 'function' or 'format' where the latter may accept * additional arguments. */ +#ifdef _GNU_SOURCE #define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ } while (0) +#else +#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + uint64_t ret = (uint64_t)strerror_r(errno, buff, \ + CORE_LOG_MAX_ERR_MSG); \ + ret = ret; \ + CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ + buff); \ + } while (0) +#endif +#ifdef _GNU_SOURCE #define CORE_LOG_WARNING_W_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ - CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ + CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ } while (0) +#else +#define CORE_LOG_WARNING_W_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + uint64_t ret = (uint64_t)strerror_r(errno, buff, \ + CORE_LOG_MAX_ERR_MSG); \ + ret = ret; \ + CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ + buff); \ + } while (0) +#endif static inline int core_log_error_translate(int ret) From 7d3e525ba9d4fc9d3367e419bd6a052632333c5e Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 23:00:48 +0100 Subject: [PATCH 049/182] common: addjust tests match file for util_poolset tests Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_transform/TEST10 | 7 +++++-- src/test/pmempool_transform/TEST5 | 4 ++-- src/test/pmempool_transform/TEST6 | 4 ++-- src/test/util_poolset/grep1.log.match | 2 -- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/pmempool_transform/TEST10 b/src/test/pmempool_transform/TEST10 index 23791430713..06d897c85b5 100755 --- a/src/test/pmempool_transform/TEST10 +++ b/src/test/pmempool_transform/TEST10 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2018, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # # pmempool_transform/TEST10 -- test for checking pmempool transform; @@ -56,7 +56,10 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_IN >> $LOG_TEMP -mv $LOG_TEMP $LOG +# Exclude warning messages printed out on the stderr by PMDK in debug +grep -v "*WARN*" $LOG_TEMP > $LOG +rm $LOG_TEMP + check pass diff --git a/src/test/pmempool_transform/TEST5 b/src/test/pmempool_transform/TEST5 index 929bd3838b5..8cbf7e86b42 100755 --- a/src/test/pmempool_transform/TEST5 +++ b/src/test/pmempool_transform/TEST5 @@ -92,8 +92,8 @@ dump_pool_info $DIR/testfile01 >> $LOG_TEMP dump_pool_info $DIR/testfile02 >> $LOG_TEMP dump_pool_info $DIR/testfile10 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warning messages printed out on the stderr by PMDK in debug +grep -v -E "\*ERROR\*|\*WARN\*" $LOG_TEMP > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_transform/TEST6 b/src/test/pmempool_transform/TEST6 index 91bde3c12a8..a09722b3e0d 100755 --- a/src/test/pmempool_transform/TEST6 +++ b/src/test/pmempool_transform/TEST6 @@ -71,8 +71,8 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_OUT1 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warning messages printed out on the stderr by PMDK in debug +grep -v -E "\*ERROR\*|\*WARN\*" $LOG_TEMP > $LOG rm $LOG_TEMP check diff --git a/src/test/util_poolset/grep1.log.match b/src/test/util_poolset/grep1.log.match index 20a69f0e9c7..388f7f6909f 100644 --- a/src/test/util_poolset/grep1.log.match +++ b/src/test/util_poolset/grep1.log.match @@ -11,9 +11,7 @@ open "$(nW)/testset0": No such file or directory invalid major version (0) open "$(nW)/testset2": Permission denied open "$(nW)/testfile31": No such file or directory -cannot open the part -- "$(nW)/testfile31": No such file or directory open "$(nW)/testfile32": No such file or directory -cannot open the part -- "$(nW)/testfile32": No such file or directory open "$(nW)/testfile31": No such file or directory open "$(nW)/testfile42": No such file or directory size 1048576 smaller than 2097152 From 2883cf1286eaa7dcf5275a9b66cf07b18888ad2d Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 23:34:10 +0100 Subject: [PATCH 050/182] common: avoid badblock error msg when used internally Signed-off-by: Tomasz Gromadzki --- src/common/bad_blocks.c | 4 ++-- src/common/badblocks.h | 4 ++++ src/common/set_badblocks.c | 1 + src/libpmem2/badblocks.c | 1 + src/libpmem2/badblocks_ndctl.c | 17 +++++++++++++++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/common/bad_blocks.c b/src/common/bad_blocks.c index f44ec4848e3..a9c0c4d720b 100644 --- a/src/common/bad_blocks.c +++ b/src/common/bad_blocks.c @@ -72,7 +72,7 @@ badblocks_get(const char *file, struct badblocks *bbs) goto exit_delete_source; bb_found = 0; - while ((pmem2_badblock_next(bbctx, &bb)) == 0) { + while ((pmem2_badblock_next_internal(bbctx, &bb)) == 0) { bb_found++; /* * Form a new bad block structure with offset and length @@ -210,7 +210,7 @@ badblocks_clear_all(const char *file) goto exit_delete_source; } - while ((pmem2_badblock_next(bbctx, &bb)) == 0) { + while ((pmem2_badblock_next_internal(bbctx, &bb)) == 0) { ret = pmem2_badblock_clear(bbctx, &bb); if (ret) { CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file); diff --git a/src/common/badblocks.h b/src/common/badblocks.h index d06e81adb28..18ebd8493af 100644 --- a/src/common/badblocks.h +++ b/src/common/badblocks.h @@ -11,6 +11,7 @@ #include #include #include +#include "libpmem2.h" #ifdef __cplusplus extern "C" { @@ -70,6 +71,9 @@ int badblocks_clear_all(const char *file); int badblocks_check_file(const char *path); +int pmem2_badblock_next_internal(struct pmem2_badblock_context *bbctx, + struct pmem2_badblock *bb); + #ifdef __cplusplus } #endif diff --git a/src/common/set_badblocks.c b/src/common/set_badblocks.c index f39ac85966f..542c40a765b 100644 --- a/src/common/set_badblocks.c +++ b/src/common/set_badblocks.c @@ -14,6 +14,7 @@ #include "os.h" #include "out.h" #include "set_badblocks.h" +#include "libpmem2.h" #include "badblocks.h" /* helper structure for badblocks_check_file_cb() */ diff --git a/src/libpmem2/badblocks.c b/src/libpmem2/badblocks.c index c702d4f65cd..af21869c352 100644 --- a/src/libpmem2/badblocks.c +++ b/src/libpmem2/badblocks.c @@ -5,6 +5,7 @@ * badblocks.c -- implementation of common bad blocks API */ +#include "libpmem2.h" #include "badblocks.h" #include "alloc.h" #include "out.h" diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index 35a914e9566..16c352c23dd 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -528,10 +528,10 @@ pmem2_badblock_next_region(struct pmem2_badblock_context *bbctx, } /* - * pmem2_badblock_next -- get the next bad block + * pmem2_badblock_next_internal -- get the next bad block */ int -pmem2_badblock_next(struct pmem2_badblock_context *bbctx, +pmem2_badblock_next_internal(struct pmem2_badblock_context *bbctx, struct pmem2_badblock *bb) { LOG(3, "bbctx %p bb %p", bbctx, bb); @@ -674,6 +674,19 @@ pmem2_badblock_next(struct pmem2_badblock_context *bbctx, return 0; } +int +pmem2_badblock_next(struct pmem2_badblock_context *bbctx, + struct pmem2_badblock *bb) +{ + int ret = pmem2_badblock_next_internal(bbctx, bb); + + if (ret == PMEM2_E_NO_BAD_BLOCK_FOUND) { + ERR_WO_ERRNO( + "Cannot find any matching device, no bad blocks found"); + } + return ret; +} + /* * pmem2_badblock_clear_fsdax -- (internal) clear one bad block * in a FSDAX device From a201bbd8e22fac28206aec4852958c35e7532300 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 23:40:14 +0100 Subject: [PATCH 051/182] Revert "common: avoid badblock error msg when used internally" This reverts commit 8b87e93dea34e6ae7d627b3d68809ed8b2b634b0. --- src/common/bad_blocks.c | 4 ++-- src/common/badblocks.h | 4 ---- src/common/set_badblocks.c | 1 - src/libpmem2/badblocks.c | 1 - src/libpmem2/badblocks_ndctl.c | 17 ++--------------- 5 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/common/bad_blocks.c b/src/common/bad_blocks.c index a9c0c4d720b..f44ec4848e3 100644 --- a/src/common/bad_blocks.c +++ b/src/common/bad_blocks.c @@ -72,7 +72,7 @@ badblocks_get(const char *file, struct badblocks *bbs) goto exit_delete_source; bb_found = 0; - while ((pmem2_badblock_next_internal(bbctx, &bb)) == 0) { + while ((pmem2_badblock_next(bbctx, &bb)) == 0) { bb_found++; /* * Form a new bad block structure with offset and length @@ -210,7 +210,7 @@ badblocks_clear_all(const char *file) goto exit_delete_source; } - while ((pmem2_badblock_next_internal(bbctx, &bb)) == 0) { + while ((pmem2_badblock_next(bbctx, &bb)) == 0) { ret = pmem2_badblock_clear(bbctx, &bb); if (ret) { CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file); diff --git a/src/common/badblocks.h b/src/common/badblocks.h index 18ebd8493af..d06e81adb28 100644 --- a/src/common/badblocks.h +++ b/src/common/badblocks.h @@ -11,7 +11,6 @@ #include #include #include -#include "libpmem2.h" #ifdef __cplusplus extern "C" { @@ -71,9 +70,6 @@ int badblocks_clear_all(const char *file); int badblocks_check_file(const char *path); -int pmem2_badblock_next_internal(struct pmem2_badblock_context *bbctx, - struct pmem2_badblock *bb); - #ifdef __cplusplus } #endif diff --git a/src/common/set_badblocks.c b/src/common/set_badblocks.c index 542c40a765b..f39ac85966f 100644 --- a/src/common/set_badblocks.c +++ b/src/common/set_badblocks.c @@ -14,7 +14,6 @@ #include "os.h" #include "out.h" #include "set_badblocks.h" -#include "libpmem2.h" #include "badblocks.h" /* helper structure for badblocks_check_file_cb() */ diff --git a/src/libpmem2/badblocks.c b/src/libpmem2/badblocks.c index af21869c352..c702d4f65cd 100644 --- a/src/libpmem2/badblocks.c +++ b/src/libpmem2/badblocks.c @@ -5,7 +5,6 @@ * badblocks.c -- implementation of common bad blocks API */ -#include "libpmem2.h" #include "badblocks.h" #include "alloc.h" #include "out.h" diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index 16c352c23dd..35a914e9566 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -528,10 +528,10 @@ pmem2_badblock_next_region(struct pmem2_badblock_context *bbctx, } /* - * pmem2_badblock_next_internal -- get the next bad block + * pmem2_badblock_next -- get the next bad block */ int -pmem2_badblock_next_internal(struct pmem2_badblock_context *bbctx, +pmem2_badblock_next(struct pmem2_badblock_context *bbctx, struct pmem2_badblock *bb) { LOG(3, "bbctx %p bb %p", bbctx, bb); @@ -674,19 +674,6 @@ pmem2_badblock_next_internal(struct pmem2_badblock_context *bbctx, return 0; } -int -pmem2_badblock_next(struct pmem2_badblock_context *bbctx, - struct pmem2_badblock *bb) -{ - int ret = pmem2_badblock_next_internal(bbctx, bb); - - if (ret == PMEM2_E_NO_BAD_BLOCK_FOUND) { - ERR_WO_ERRNO( - "Cannot find any matching device, no bad blocks found"); - } - return ret; -} - /* * pmem2_badblock_clear_fsdax -- (internal) clear one bad block * in a FSDAX device From 9b2a884f96850eea198aef01898b788162ed82a0 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 29 Jan 2024 11:36:27 +0100 Subject: [PATCH 052/182] common: convert LOG(2,...) into CORE_LOG_WARNING() Signed-off-by: Tomasz Gromadzki --- src/common/file.c | 40 ++++++++++++---------- src/common/mmap.c | 4 +-- src/common/os_deep_linux.c | 5 +-- src/common/set.c | 68 ++++++++++++++++++++++--------------- src/common/shutdown_state.c | 10 +++--- src/common/uuid.c | 14 ++++---- src/common/uuid_linux.c | 6 ++-- src/libpmem/pmem.c | 3 +- src/libpmemobj/heap.c | 6 ++-- src/libpmemobj/lane.c | 3 +- src/libpmemobj/list.c | 10 +++--- src/libpmemobj/memops.c | 2 +- src/libpmemobj/obj.c | 28 +++++++-------- src/libpmemobj/palloc.c | 3 +- src/libpmempool/pool.c | 4 +-- src/libpmempool/replica.c | 8 +++-- src/libpmempool/rm.c | 6 ++-- src/libpmempool/sync.c | 8 ++--- src/libpmempool/transform.c | 7 ++-- src/test/traces/traces.c | 2 +- src/tools/pmempool/common.c | 4 +-- 21 files changed, 133 insertions(+), 108 deletions(-) diff --git a/src/common/file.c b/src/common/file.c index 9d4574f470e..b79cab02f44 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -209,13 +209,13 @@ util_file_map_whole(const char *path) ssize_t size = util_fd_get_size(fd); if (size < 0) { - LOG(2, "cannot determine file length \"%s\"", path); + CORE_LOG_WARNING("cannot determine file length \"%s\"", path); goto out; } addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL); if (addr == NULL) { - LOG(2, "failed to map entire file \"%s\"", path); + CORE_LOG_WARNING("failed to map entire file \"%s\"", path); goto out; } @@ -247,27 +247,29 @@ util_file_zero(const char *path, os_off_t off, size_t len) ssize_t size = util_fd_get_size(fd); if (size < 0) { - LOG(2, "cannot determine file length \"%s\"", path); + CORE_LOG_WARNING("cannot determine file length \"%s\"", path); ret = -1; goto out; } if (off > size) { - LOG(2, "offset beyond file length, %ju > %ju", off, size); + CORE_LOG_WARNING("offset beyond file length, %ju > %ju", off, + size); ret = -1; goto out; } if ((size_t)off + len > (size_t)size) { - LOG(2, "requested size of write goes beyond the file length, " - "%zu > %zu", (size_t)off + len, size); + CORE_LOG_WARNING( + "requested size of write goes beyond the file length, %zu > %zu", + (size_t)off + len, size); LOG(4, "adjusting len to %zu", size - off); len = (size_t)(size - off); } void *addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL); if (addr == NULL) { - LOG(2, "failed to map entire file \"%s\"", path); + CORE_LOG_WARNING("failed to map entire file \"%s\"", path); ret = -1; goto out; } @@ -302,7 +304,7 @@ util_file_pwrite(const char *path, const void *buffer, size_t size, if (type == TYPE_NORMAL) { int fd = util_file_open(path, NULL, 0, O_RDWR); if (fd < 0) { - LOG(2, "failed to open file \"%s\"", path); + CORE_LOG_WARNING("failed to open file \"%s\"", path); return -1; } @@ -315,21 +317,22 @@ util_file_pwrite(const char *path, const void *buffer, size_t size, ssize_t file_size = util_file_get_size(path); if (file_size < 0) { - LOG(2, "cannot determine file length \"%s\"", path); + CORE_LOG_WARNING("cannot determine file length \"%s\"", path); return -1; } size_t max_size = (size_t)(file_size - offset); if (size > max_size) { - LOG(2, "requested size of write goes beyond the file length, " - "%zu > %zu", size, max_size); + CORE_LOG_WARNING( + "requested size of write goes beyond the file length, %zu > %zu", + size, max_size); LOG(4, "adjusting size to %zu", max_size); size = max_size; } void *addr = util_file_map_whole(path); if (addr == NULL) { - LOG(2, "failed to map entire file \"%s\"", path); + CORE_LOG_WARNING("failed to map entire file \"%s\"", path); return -1; } @@ -355,7 +358,7 @@ util_file_pread(const char *path, void *buffer, size_t size, if (type == TYPE_NORMAL) { int fd = util_file_open(path, NULL, 0, O_RDONLY); if (fd < 0) { - LOG(2, "failed to open file \"%s\"", path); + CORE_LOG_WARNING("failed to open file \"%s\"", path); return -1; } @@ -368,21 +371,22 @@ util_file_pread(const char *path, void *buffer, size_t size, ssize_t file_size = util_file_get_size(path); if (file_size < 0) { - LOG(2, "cannot determine file length \"%s\"", path); + CORE_LOG_WARNING("cannot determine file length \"%s\"", path); return -1; } size_t max_size = (size_t)(file_size - offset); if (size > max_size) { - LOG(2, "requested size of read goes beyond the file length, " - "%zu > %zu", size, max_size); + CORE_LOG_WARNING( + "requested size of read goes beyond the file length, %zu > %zu", + size, max_size); LOG(4, "adjusting size to %zu", max_size); size = max_size; } void *addr = util_file_map_whole(path); if (addr == NULL) { - LOG(2, "failed to map entire file \"%s\"", path); + CORE_LOG_WARNING("failed to map entire file \"%s\"", path); return -1; } @@ -540,7 +544,7 @@ util_unlink_flock(const char *path) int fd = util_file_open(path, NULL, 0, O_RDONLY); if (fd < 0) { - LOG(2, "failed to open file \"%s\"", path); + CORE_LOG_WARNING("failed to open file \"%s\"", path); return -1; } diff --git a/src/common/mmap.c b/src/common/mmap.c index aaf4b3deddb..48bb01d1233 100644 --- a/src/common/mmap.c +++ b/src/common/mmap.c @@ -51,9 +51,9 @@ util_mmap_init(void) unsigned long long val = strtoull(e, &endp, 16); if (errno || endp == e) { - LOG(2, "Invalid PMEM_MMAP_HINT"); + CORE_LOG_WARNING("Invalid PMEM_MMAP_HINT"); } else if (os_access(OS_MAPFILE, R_OK)) { - LOG(2, "No /proc, PMEM_MMAP_HINT ignored"); + CORE_LOG_WARNING("No /proc, PMEM_MMAP_HINT ignored"); } else { Mmap_hint = (void *)val; Mmap_no_random = 1; diff --git a/src/common/os_deep_linux.c b/src/common/os_deep_linux.c index d4fe2065541..4460832bc52 100644 --- a/src/common/os_deep_linux.c +++ b/src/common/os_deep_linux.c @@ -39,8 +39,9 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len) "deep_flush not supported"); } else { errno = pmem2_err_to_errno(ret); - LOG(2, "cannot write to deep_flush" - "in region %u", mt->region_id); + CORE_LOG_WARNING( + "cannot write to deep_flush in region %u", + mt->region_id); } return -1; } diff --git a/src/common/set.c b/src/common/set.c index cb930c42105..ed5a7521912 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -340,7 +340,7 @@ util_poolset_open(struct pool_set *set) { for (unsigned r = 0; r < set->nreplicas; ++r) { if (util_replica_open(set, r, MAP_SHARED)) { - LOG(2, "replica open failed: replica %u", r); + CORE_LOG_WARNING("replica open failed: replica %u", r); errno = EINVAL; return -1; } @@ -1050,9 +1050,9 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory) ssize_t size = util_file_get_size(entry->path); if (size < 0) { - LOG(2, - "cannot read size of file (%s) in a poolset directory", - entry->path); + CORE_LOG_WARNING( + "cannot read size of file (%s) in a poolset directory", + entry->path); goto err; } @@ -1481,7 +1481,8 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) part->fd = util_file_create(part->path, part->filesize, minsize); if (part->fd == -1) { - LOG(2, "failed to create file: %s", part->path); + CORE_LOG_WARNING("failed to create file: %s", + part->path); return -1; } part->created = 1; @@ -1490,7 +1491,7 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) int flags = O_RDWR; part->fd = util_file_open(part->path, &size, minsize, flags); if (part->fd == -1) { - LOG(2, "failed to open file: %s", part->path); + CORE_LOG_WARNING("failed to open file: %s", part->path); return -1; } @@ -1968,7 +1969,8 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) /* map the first part and reserve space for remaining parts */ if (util_map_part(&rep->part[0], addr, rep->resvsize, 0, flags, 0) != 0) { - LOG(2, "pool mapping failed - replica #%u part #0", + CORE_LOG_WARNING( + "pool mapping failed - replica #%u part #0", repidx); return -1; } @@ -1997,8 +1999,9 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) */ if ((errno == EINVAL) && (remaining_retries > 0)) { - LOG(2, "usable space mapping failed - " - "part #%d - retrying", p); + CORE_LOG_WARNING( + "usable space mapping failed - part #%d - retrying", + p); retry_for_contiguous_addr = 1; remaining_retries--; @@ -2010,7 +2013,8 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) munmap(addr, rep->resvsize - mapsize); break; } - LOG(2, "usable space mapping failed - part #%d", + CORE_LOG_WARNING( + "usable space mapping failed - part #%d", p); goto err; } @@ -2078,7 +2082,7 @@ util_replica_init_headers_local(struct pool_set *set, unsigned repidx, /* map all headers - don't care about the address */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_map_hdr(&rep->part[p], flags, 0) != 0) { - LOG(2, "header mapping failed - part #%d", p); + CORE_LOG_WARNING("header mapping failed - part #%d", p); goto err; } } @@ -2086,7 +2090,8 @@ util_replica_init_headers_local(struct pool_set *set, unsigned repidx, /* create headers, set UUID's */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_header_create(set, repidx, p, attr, 0) != 0) { - LOG(2, "header creation failed - part #%d", p); + CORE_LOG_WARNING("header creation failed - part #%d", + p); goto err; } } @@ -2122,7 +2127,7 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags, */ if (PART(REP(set, repidx), 0)->addr == NULL) { if (util_replica_map_local(set, repidx, flags) != 0) { - LOG(2, "replica #%u map failed", repidx); + CORE_LOG_WARNING("replica #%u map failed", repidx); return -1; } } @@ -2131,7 +2136,8 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags, return 0; if (util_replica_init_headers_local(set, repidx, flags, attr) != 0) { - LOG(2, "replica #%u headers initialization failed", repidx); + CORE_LOG_WARNING("replica #%u headers initialization failed", + repidx); return -1; } return 0; @@ -2389,7 +2395,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, int ret = util_poolset_create_set(setp, path, poolsize, minsize, IGNORE_SDS(attr)); if (ret < 0) { - LOG(2, "cannot create pool set -- '%s'", path); + CORE_LOG_WARNING("cannot create pool set -- '%s'", path); return -1; } @@ -2476,7 +2482,8 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, /* generate pool set UUID */ ret = util_uuid_generate(set->uuid); if (ret < 0) { - LOG(2, "cannot generate pool set UUID"); + CORE_LOG_WARNING( + "cannot generate pool set UUID"); goto err_poolset; } } @@ -2487,7 +2494,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, for (unsigned i = 0; i < rep->nhdrs; i++) { ret = util_uuid_generate(rep->part[i].uuid); if (ret < 0) { - LOG(2, + CORE_LOG_WARNING( "cannot generate pool set part UUID"); goto err_poolset; } @@ -2514,7 +2521,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_create_local(set, r, flags, attr) != 0) { - LOG(2, "replica #%u creation failed", r); + CORE_LOG_WARNING("replica #%u creation failed", r); goto err_create; } } @@ -2591,7 +2598,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) /* map the first part and reserve space for remaining parts */ if (util_map_part(&rep->part[0], addr, rep->resvsize, 0, flags, 0) != 0) { - LOG(2, "pool mapping failed - replica #%u part #0", + CORE_LOG_WARNING( + "pool mapping failed - replica #%u part #0", repidx); return -1; } @@ -2604,7 +2612,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) /* map all headers - don't care about the address */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_map_hdr(&rep->part[p], flags, 0) != 0) { - LOG(2, "header mapping failed - part #%d", p); + CORE_LOG_WARNING( + "header mapping failed - part #%d", p); goto err; } } @@ -2637,8 +2646,9 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) */ if ((errno == EINVAL) && (remaining_retries > 0)) { - LOG(2, "usable space mapping failed - " - "part #%d - retrying", p); + CORE_LOG_WARNING( + "usable space mapping failed - part #%d - retrying", + p); retry_for_contiguous_addr = 1; remaining_retries--; @@ -2649,7 +2659,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) rep->resvsize); break; } - LOG(2, "usable space mapping failed - part #%d", + CORE_LOG_WARNING( + "usable space mapping failed - part #%d", p); goto err; } @@ -2779,7 +2790,8 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) struct pool_replica *rep = set->replica[r]; for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_header_check(set, r, p, attr) != 0) { - LOG(2, "header check failed - part #%d", p); + CORE_LOG_WARNING( + "header check failed - part #%d", p); return -1; } set->rdonly |= rep->part[p].rdonly; @@ -2808,7 +2820,7 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) ASSERTne(rep->nparts, 0); if (shutdown_state_check(&sds, &HDR(rep, 0)->sds, rep)) { - LOG(2, "ADR failure detected"); + CORE_LOG_WARNING("ADR failure detected"); errno = EINVAL; return -1; } @@ -2901,7 +2913,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_open(set, r, mmap_flags) != 0) { - LOG(2, "replica #%u open failed", r); + CORE_LOG_WARNING("replica #%u open failed", r); goto err_replica; } } @@ -2992,7 +3004,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, int ret = util_poolset_create_set(setp, path, 0, 0, flags & POOL_OPEN_IGNORE_SDS); if (ret < 0) { - LOG(2, "cannot open pool set -- '%s'", path); + CORE_LOG_WARNING("cannot open pool set -- '%s'", path); return -1; } @@ -3064,7 +3076,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_open(set, r, mmap_flags) != 0) { - LOG(2, "replica #%u open failed", r); + CORE_LOG_WARNING("replica #%u open failed", r); goto err_replica; } } diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index 919bc29c528..66d20e5dd52 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -77,7 +77,8 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, ERR_WO_ERRNO( "Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); } - LOG(2, "cannot read unsafe shutdown count for %d", fd); + CORE_LOG_WARNING("cannot read unsafe shutdown count for %d", + fd); goto err; } @@ -202,7 +203,8 @@ shutdown_state_check(struct shutdown_state *curr_sds, if (!is_checksum_correct) { /* the program was killed during opening or closing the pool */ - LOG(2, "incorrect checksum - SDS will be reinitialized"); + CORE_LOG_WARNING( + "incorrect checksum - SDS will be reinitialized"); shutdown_state_reinit(curr_sds, pool_sds, rep); return 0; } @@ -214,14 +216,14 @@ shutdown_state_check(struct shutdown_state *curr_sds, * the program was killed when the pool was opened * but there wasn't an ADR failure */ - LOG(2, + CORE_LOG_WARNING( "the pool was not closed - SDS will be reinitialized"); shutdown_state_reinit(curr_sds, pool_sds, rep); return 0; } if (dirty == 0) { /* an ADR failure but the pool was closed */ - LOG(2, + CORE_LOG_WARNING( "an ADR failure was detected but the pool was closed - SDS will be reinitialized"); shutdown_state_reinit(curr_sds, pool_sds, rep); return 0; diff --git a/src/common/uuid.c b/src/common/uuid.c index 0b16d7f7c58..c1c084c82e3 100644 --- a/src/common/uuid.c +++ b/src/common/uuid.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2021, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * uuid.c -- uuid utilities @@ -20,12 +20,12 @@ util_uuid_to_string(const uuid_t u, char *buf) int len; /* size that is returned from sprintf call */ if (buf == NULL) { - LOG(2, "invalid buffer for uuid string"); + CORE_LOG_WARNING("invalid buffer for uuid string"); return -1; } if (u == NULL) { - LOG(2, "invalid uuid structure"); + CORE_LOG_WARNING("invalid uuid structure"); return -1; } @@ -38,7 +38,7 @@ util_uuid_to_string(const uuid_t u, char *buf) uuid->node[5]); if (len != POOL_HDR_UUID_STR_LEN - 1) { - LOG(2, "snprintf(uuid): %d", len); + CORE_LOG_WARNING("snprintf(uuid): %d", len); return -1; } @@ -56,13 +56,13 @@ int util_uuid_from_string(const char uuid[POOL_HDR_UUID_STR_LEN], struct uuid *ud) { if (strlen(uuid) != 36) { - LOG(2, "invalid uuid string"); + CORE_LOG_WARNING("invalid uuid string"); return -1; } if (uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-') { - LOG(2, "invalid uuid string"); + CORE_LOG_WARNING("invalid uuid string"); return -1; } @@ -75,7 +75,7 @@ util_uuid_from_string(const char uuid[POOL_HDR_UUID_STR_LEN], struct uuid *ud) &ud->node[5]); if (n != 11) { - LOG(2, "sscanf(uuid)"); + CORE_LOG_WARNING("sscanf(uuid)"); return -1; } diff --git a/src/common/uuid_linux.c b/src/common/uuid_linux.c index 979e0ad52ba..16ee2dae531 100644 --- a/src/common/uuid_linux.c +++ b/src/common/uuid_linux.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2017, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * uuid_linux.c -- pool set utilities with OS-specific implementation @@ -28,13 +28,13 @@ util_uuid_generate(uuid_t uuid) int fd = os_open(POOL_HDR_UUID_GEN_FILE, O_RDONLY); if (fd < 0) { /* Fatal error */ - LOG(2, "!open(uuid)"); + CORE_LOG_WARNING("!open(uuid)"); return -1; } ssize_t num = read(fd, uu, POOL_HDR_UUID_STR_LEN); if (num < POOL_HDR_UUID_STR_LEN) { /* Fatal error */ - LOG(2, "!read(uuid)"); + CORE_LOG_WARNING("!read(uuid)"); os_close(fd); return -1; } diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 931ae63b550..c552a246f67 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -477,7 +477,8 @@ pmem_map_fileU(const char *path, size_t len, int flags, if ((fd = util_tmpfile(path, OS_DIR_SEP_STR"pmem.XXXXXX", open_flags & O_EXCL)) < 0) { - LOG(2, "failed to create temporary file at \"%s\"", + CORE_LOG_WARNING( + "failed to create temporary file at \"%s\"", path); return NULL; } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index e71c5513735..78900137dfc 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -1189,7 +1189,7 @@ heap_split_block(struct palloc_heap *heap, struct bucket *b, NULL, NULL, 0, 0, NULL}; memblock_rebuild_state(heap, &r); if (bucket_insert_block(b, &r) != 0) - LOG(2, + CORE_LOG_WARNING( "failed to allocate memory block runtime tracking info"); } else { uint32_t new_chunk_id = m->chunk_id + units; @@ -1201,7 +1201,7 @@ heap_split_block(struct palloc_heap *heap, struct bucket *b, *m = memblock_huge_init(heap, m->chunk_id, m->zone_id, units); if (bucket_insert_block(b, &n) != 0) - LOG(2, + CORE_LOG_WARNING( "failed to allocate memory block runtime tracking info"); } @@ -1324,7 +1324,7 @@ heap_set_narenas_max(struct palloc_heap *heap, unsigned size) util_mutex_lock(&h->arenas.lock); unsigned capacity = (unsigned)VEC_CAPACITY(&h->arenas.vec); if (size < capacity) { - LOG(2, "cannot decrease max number of arenas"); + CORE_LOG_WARNING("cannot decrease max number of arenas"); goto out; } else if (size == capacity) { ret = 0; diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 0dcdbe59ccd..00ab7f3820d 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -414,7 +414,8 @@ lane_check(PMEMobjpool *pop) layout = lane_get_layout(pop, j); if (ulog_check((struct ulog *)&layout->internal, OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops) != 0) { - LOG(2, "lane %" PRIu64 " internal redo failed: %d", + CORE_LOG_WARNING( + "lane %" PRIu64 " internal redo failed: %d", j, err); return err; } diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index af2cfbbd2a0..01185130833 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -561,7 +561,7 @@ list_insert_new_user(PMEMobjpool *pop, int ret; if ((ret = pmemobj_mutex_lock(pop, &user_head->lock))) { errno = ret; - LOG(2, "pmemobj_mutex_lock failed"); + CORE_LOG_WARNING("pmemobj_mutex_lock failed"); return -1; } @@ -600,7 +600,7 @@ list_insert(PMEMobjpool *pop, if ((ret = pmemobj_mutex_lock(pop, &head->lock))) { errno = ret; - LOG(2, "pmemobj_mutex_lock failed"); + CORE_LOG_WARNING("pmemobj_mutex_lock failed"); ret = -1; goto err; } @@ -728,7 +728,7 @@ list_remove_free_user(PMEMobjpool *pop, size_t pe_offset, int ret; if ((ret = pmemobj_mutex_lock(pop, &user_head->lock))) { errno = ret; - LOG(2, "pmemobj_mutex_lock failed"); + CORE_LOG_WARNING("pmemobj_mutex_lock failed"); return -1; } @@ -762,7 +762,7 @@ list_remove(PMEMobjpool *pop, if ((ret = pmemobj_mutex_lock(pop, &head->lock))) { errno = ret; - LOG(2, "pmemobj_mutex_lock failed"); + CORE_LOG_WARNING("pmemobj_mutex_lock failed"); ret = -1; goto err; } @@ -839,7 +839,7 @@ list_move(PMEMobjpool *pop, */ if ((ret = list_mutexes_lock(pop, head_new, head_old))) { errno = ret; - LOG(2, "list_mutexes_lock failed"); + CORE_LOG_WARNING("list_mutexes_lock failed"); ret = -1; goto err; } diff --git a/src/libpmemobj/memops.c b/src/libpmemobj/memops.c index f9c630b4f19..7d86c41a32f 100644 --- a/src/libpmemobj/memops.c +++ b/src/libpmemobj/memops.c @@ -349,7 +349,7 @@ operation_merge_entry_add(struct operation_context *ctx, if (VECQ_ENQUEUE(&ctx->merge_entries, entry) != 0) { /* this is fine, only runtime perf will get slower */ - LOG(2, "out of memory - unable to track entries"); + CORE_LOG_WARNING("out of memory - unable to track entries"); } } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 6849ff47102..a1eda31b54e 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -87,7 +87,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) LOG(3, "pop %p", pop); if (pop != NULL && (pop->ctl = ctl_new()) == NULL) { - LOG(2, "!ctl_new"); + CORE_LOG_WARNING("!ctl_new"); return -1; } @@ -102,8 +102,8 @@ obj_ctl_init_and_load(PMEMobjpool *pop) if (env_config != NULL) { if (ctl_load_config_from_string(pop ? pop->ctl : NULL, pop, env_config) != 0) { - LOG(2, "unable to parse config stored in %s " - "environment variable", + CORE_LOG_WARNING( + "unable to parse config stored in %s environment variable", OBJ_CONFIG_ENV_VARIABLE); goto err; } @@ -113,10 +113,9 @@ obj_ctl_init_and_load(PMEMobjpool *pop) if (env_config_file != NULL && env_config_file[0] != '\0') { if (ctl_load_config_from_file(pop ? pop->ctl : NULL, pop, env_config_file) != 0) { - LOG(2, "unable to parse config stored in %s " - "file (from %s environment variable)", - env_config_file, - OBJ_CONFIG_FILE_ENV_VARIABLE); + CORE_LOG_WARNING( + "unable to parse config stored in %s file (from %s environment variable)", + env_config_file, OBJ_CONFIG_FILE_ENV_VARIABLE); goto err; } } @@ -1088,7 +1087,7 @@ pmemobj_createU(const char *path, const char *layout, if (util_pool_create(&set, path, poolsize, PMEMOBJ_MIN_POOL, PMEMOBJ_MIN_PART, &adj_pool_attr, &runtime_nlanes, REPLICAS_ENABLED) != 0) { - LOG(2, "cannot create pool or pool set"); + CORE_LOG_WARNING("cannot create pool or pool set"); os_mutex_unlock(&pools_mutex); return NULL; } @@ -1125,7 +1124,7 @@ pmemobj_createU(const char *path, const char *layout, /* create pool descriptor */ if (obj_descr_create(pop, layout, set->poolsize) != 0) { - LOG(2, "creation of pool descriptor failed"); + CORE_LOG_WARNING("creation of pool descriptor failed"); goto err; } @@ -1187,7 +1186,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) } if ((errno = lane_check(pop)) != 0) { - LOG(2, "!lane_check"); + CORE_LOG_WARNING("!lane_check"); consistent = 0; } @@ -1196,7 +1195,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) errno = palloc_heap_check((char *)pop + pop->heap_offset, heap_size); if (errno != 0) { - LOG(2, "!heap_check"); + CORE_LOG_WARNING("!heap_check"); consistent = 0; } @@ -1236,7 +1235,7 @@ obj_pool_open(struct pool_set **set, const char *path, unsigned flags, { if (util_pool_open(set, path, PMEMOBJ_MIN_PART, &Obj_open_attr, nlanes, NULL, flags) != 0) { - LOG(2, "cannot open pool or pool set"); + CORE_LOG_WARNING("cannot open pool or pool set"); return -1; } @@ -1373,7 +1372,8 @@ obj_open_common(const char *path, const char *layout, unsigned flags, int boot) PMEMobjpool *rep = repset->part[0].addr; /* check descriptor */ if (obj_descr_check(rep, layout, set->poolsize) != 0) { - LOG(2, "descriptor check of replica #%u failed", r); + CORE_LOG_WARNING( + "descriptor check of replica #%u failed", r); goto err_descr_check; } } @@ -2435,7 +2435,7 @@ pmemobj_root_construct(PMEMobjpool *pop, size_t size, if (size > pop->root_size && obj_alloc_root(pop, size, constructor, arg)) { pmemobj_mutex_unlock_nofail(pop, &pop->rootlock); - LOG(2, "obj_realloc_root failed"); + CORE_LOG_WARNING("obj_realloc_root failed"); PMEMOBJ_API_END(); return OID_NULL; } diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index bbce59dff68..7b2f7c8b3ff 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -304,7 +304,8 @@ palloc_restore_free_chunk_state(struct palloc_heap *heap, CORE_LOG_FATAL( "duplicate runtime chunk state, possible double free"); } else { - LOG(2, "unable to track runtime chunk state"); + CORE_LOG_WARNING( + "unable to track runtime chunk state"); } } heap_bucket_release(b); diff --git a/src/libpmempool/pool.c b/src/libpmempool/pool.c index f6d6866e487..d4b734d2619 100644 --- a/src/libpmempool/pool.c +++ b/src/libpmempool/pool.c @@ -187,7 +187,7 @@ pool_params_parse(const PMEMpoolcheck *ppc, struct pool_params *params, ret = util_poolset_create_set(&set, ppc->path, 0, 0, true); if (ret < 0) { - LOG(2, "cannot open pool set -- '%s'", + CORE_LOG_WARNING("cannot open pool set -- '%s'", ppc->path); return -1; } @@ -296,7 +296,7 @@ pool_set_file_open(const char *fname, int rdonly) int ret = util_poolset_create_set(&file->poolset, path, 0, 0, true); if (ret < 0) { - LOG(2, "cannot open pool set -- '%s'", path); + CORE_LOG_WARNING("cannot open pool set -- '%s'", path); goto err_free_fname; } unsigned flags = (rdonly ? POOL_OPEN_COW : 0) | diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index 6dc1c08b9b8..1cfb00473cd 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -1694,9 +1694,11 @@ check_uuids_between_replicas(struct pool_set *set, uuid_t *rep_n_uuidp = NULL; unsigned r_n = REPN_HEALTHidx(set_hs, r); if (get_replica_uuid(rep, r, set_hs, &rep_uuidp)) - LOG(2, "cannot get replica uuid, replica %u", r); + CORE_LOG_WARNING("cannot get replica uuid, replica %u", + r); if (get_replica_uuid(rep_n, r_n, set_hs, &rep_n_uuidp)) - LOG(2, "cannot get replica uuid, replica %u", r_n); + CORE_LOG_WARNING("cannot get replica uuid, replica %u", + r_n); /* * check if replica uuids are consistent between two adjacent @@ -1732,7 +1734,7 @@ check_uuids_between_replicas(struct pool_set *set, unsigned p_nn = replica_find_unbroken_part(r_nn, set_hs); if (p_nn == UNDEF_PART) { - LOG(2, + CORE_LOG_WARNING( "cannot compare uuids on borders of replica %u", r); continue; diff --git a/src/libpmempool/rm.c b/src/libpmempool/rm.c index b8faabcba29..cbb540249a0 100644 --- a/src/libpmempool/rm.c +++ b/src/libpmempool/rm.c @@ -20,7 +20,7 @@ #define ERR_F(f, ...) do {\ if (CHECK_FLAG((f), FORCE))\ - LOG(2, "!(ignored) " __VA_ARGS__);\ + CORE_LOG_WARNING("!(ignored) " __VA_ARGS__);\ else\ ERR_WO_ERRNO(__VA_ARGS__);\ } while (0) @@ -122,11 +122,11 @@ pmempool_rmU(const char *path, unsigned flags) } if (!is_poolset) { - LOG(2, "%s: not a poolset file", path); + CORE_LOG_WARNING("%s: not a poolset file", path); return rm_local(path, flags, 0); } - LOG(2, "%s: poolset file", path); + CORE_LOG_WARNING("%s: poolset file", path); /* fill up pool_set structure */ struct pool_set *set = NULL; diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index 7e61b7108a6..2f9b7672480 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -41,7 +41,7 @@ validate_args(struct pool_set *set) * (now replication works only for pmemobj pools) */ if (replica_check_part_sizes(set, PMEMOBJ_MIN_POOL)) { - LOG(2, "part sizes check failed"); + CORE_LOG_WARNING("part sizes check failed"); goto err; } @@ -49,7 +49,7 @@ validate_args(struct pool_set *set) * check if all directories for part files exist */ if (replica_check_part_dirs(set)) { - LOG(2, "part directories check failed"); + CORE_LOG_WARNING("part directories check failed"); goto err; } @@ -851,14 +851,14 @@ recreate_broken_parts(struct pool_set *set, /* remove parts from broken replica */ if (replica_remove_part(set, r, p, fix_bad_blocks)) { - LOG(2, "cannot remove part"); + CORE_LOG_WARNING("cannot remove part"); return -1; } /* create removed part and open it */ if (util_part_open(&broken_r->part[p], 0, 1 /* create */)) { - LOG(2, "cannot open/create parts"); + CORE_LOG_WARNING("cannot open/create parts"); return -1; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index 8b927fa35b5..3a671dc14f6 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -374,13 +374,13 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, for (unsigned r = 0; r < set_in_s->nreplicas; ++r) { unsigned c = replica_counterpart(r, set_in_s); if (c != UNDEF_REPLICA) { - LOG(2, "replica %u has a counterpart %u", r, + CORE_LOG_WARNING("replica %u has a counterpart %u", r, set_in_s->replica[r]); has_replica_to_keep = 1; REP_HEALTH(set_out_hs, c)->pool_size = REP_HEALTH(set_in_hs, r)->pool_size; } else { - LOG(2, "replica %u has no counterpart", r); + CORE_LOG_WARNING("replica %u has no counterpart", r); is_removing_replicas = 1; } } @@ -394,7 +394,8 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, /* check if there are replicas to be added */ for (unsigned r = 0; r < set_out_s->nreplicas; ++r) { if (replica_counterpart(r, set_out_s) == UNDEF_REPLICA) { - LOG(2, "Replica %u from output set has no counterpart", + CORE_LOG_WARNING( + "Replica %u from output set has no counterpart", r); if (is_removing_replicas) { ERR_WO_ERRNO( diff --git a/src/test/traces/traces.c b/src/test/traces/traces.c index f465729d640..e61046bcebf 100644 --- a/src/test/traces/traces.c +++ b/src/test/traces/traces.c @@ -26,7 +26,7 @@ main(int argc, char *argv[]) MAJOR_VERSION, MINOR_VERSION); LOG(0, "Log level NONE"); CORE_LOG_ERROR("Log level ERROR"); - LOG(2, "Log level WARNING"); + CORE_LOG_WARNING("Log level WARNING"); LOG(3, "Log level INFO"); LOG(4, "Log level DEBUG"); diff --git a/src/tools/pmempool/common.c b/src/tools/pmempool/common.c index 4fac0ca94a4..88ebc8419ca 100644 --- a/src/tools/pmempool/common.c +++ b/src/tools/pmempool/common.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * common.c -- definitions of common functions @@ -1304,7 +1304,7 @@ util_pool_clear_badblocks(const char *path, int create) int ret = util_poolset_create_set(&setp, path, 0, 0, POOL_OPEN_IGNORE_SDS); if (ret < 0) { - LOG(2, "cannot open pool set -- '%s'", path); + CORE_LOG_WARNING("cannot open pool set -- '%s'", path); return -1; } From 2fae65a014fa316b14aa529123e252cf2cbe8f1e Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 29 Jan 2024 14:09:14 +0100 Subject: [PATCH 053/182] common: exclude warn messages in pmempool_sync tests until #5983 fixed Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_sync/TEST10 | 4 ++-- src/test/pmempool_sync/TEST11 | 4 ++-- src/test/pmempool_sync/TEST23 | 4 ++-- src/test/pmempool_sync/TEST24 | 4 ++-- src/test/pmempool_sync/TEST29 | 4 ++-- src/test/pmempool_sync/TEST32 | 4 ++-- src/test/pmempool_sync/TEST33 | 4 ++-- src/test/pmempool_sync/TEST34 | 4 ++-- src/test/pmempool_sync/TEST35 | 4 ++-- src/test/pmempool_sync/TEST36 | 4 ++-- src/test/pmempool_sync/TEST37 | 4 ++-- src/test/pmempool_sync/TEST42 | 4 ++-- src/test/pmempool_sync/TEST43 | 4 ++-- src/test/pmempool_sync/TEST44 | 4 ++-- src/test/pmempool_sync/TEST45 | 4 ++-- src/test/pmempool_sync/TEST46 | 4 ++-- src/test/pmempool_sync/TEST47 | 4 ++-- src/test/pmempool_sync/TEST48 | 4 ++-- src/test/pmempool_sync/TEST49 | 4 ++-- src/test/pmempool_sync/TEST50 | 4 ++-- src/test/pmempool_sync/TEST51 | 4 ++-- src/test/pmempool_sync/TEST52 | 4 ++-- src/test/pmempool_sync/TEST53 | 4 ++-- src/test/pmempool_sync/TEST8 | 4 ++-- src/test/pmempool_sync/TEST9 | 4 ++-- 25 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/test/pmempool_sync/TEST10 b/src/test/pmempool_sync/TEST10 index 14556f9b60f..13c78b73e0e 100755 --- a/src/test/pmempool_sync/TEST10 +++ b/src/test/pmempool_sync/TEST10 @@ -51,8 +51,8 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_sync/TEST11 b/src/test/pmempool_sync/TEST11 index a4003f1d619..22ed47b9afd 100755 --- a/src/test/pmempool_sync/TEST11 +++ b/src/test/pmempool_sync/TEST11 @@ -61,8 +61,8 @@ expect_normal_exit $DDMAP$EXESUFFIX -o $DIR/part20 -n 10 -b 1 # Try to synchronize replicas using the third poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET3 &>> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_sync/TEST23 b/src/test/pmempool_sync/TEST23 index a37ed0af7cd..923fccd3220 100755 --- a/src/test/pmempool_sync/TEST23 +++ b/src/test/pmempool_sync/TEST23 @@ -63,8 +63,8 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_sync/TEST24 b/src/test/pmempool_sync/TEST24 index 8784b2e31d5..dbbfecc5798 100755 --- a/src/test/pmempool_sync/TEST24 +++ b/src/test/pmempool_sync/TEST24 @@ -60,8 +60,8 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_sync/TEST29 b/src/test/pmempool_sync/TEST29 index e2adb8b9c9c..a73aa3b8f17 100755 --- a/src/test/pmempool_sync/TEST29 +++ b/src/test/pmempool_sync/TEST29 @@ -40,9 +40,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST32 b/src/test/pmempool_sync/TEST32 index c8e0836a754..fadb39e2271 100755 --- a/src/test/pmempool_sync/TEST32 +++ b/src/test/pmempool_sync/TEST32 @@ -50,9 +50,9 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST33 b/src/test/pmempool_sync/TEST33 index 46048b4fd31..2ada861d978 100755 --- a/src/test/pmempool_sync/TEST33 +++ b/src/test/pmempool_sync/TEST33 @@ -50,9 +50,9 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST34 b/src/test/pmempool_sync/TEST34 index 8a522a8b80a..d0d7d92571c 100755 --- a/src/test/pmempool_sync/TEST34 +++ b/src/test/pmempool_sync/TEST34 @@ -59,9 +59,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST35 b/src/test/pmempool_sync/TEST35 index fc334b4ffee..856837f5182 100755 --- a/src/test/pmempool_sync/TEST35 +++ b/src/test/pmempool_sync/TEST35 @@ -59,9 +59,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST36 b/src/test/pmempool_sync/TEST36 index f3899ede7de..827b588f75c 100755 --- a/src/test/pmempool_sync/TEST36 +++ b/src/test/pmempool_sync/TEST36 @@ -63,9 +63,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST37 b/src/test/pmempool_sync/TEST37 index e12a5c86262..1e2dd7fd87a 100755 --- a/src/test/pmempool_sync/TEST37 +++ b/src/test/pmempool_sync/TEST37 @@ -63,9 +63,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST42 b/src/test/pmempool_sync/TEST42 index aa4d6cf12b9..bbdf8eee097 100755 --- a/src/test/pmempool_sync/TEST42 +++ b/src/test/pmempool_sync/TEST42 @@ -62,9 +62,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST43 b/src/test/pmempool_sync/TEST43 index e456acbb989..d6c9cba7e3a 100755 --- a/src/test/pmempool_sync/TEST43 +++ b/src/test/pmempool_sync/TEST43 @@ -63,9 +63,9 @@ expect_abnormal_exit "$PMEMPOOL$EXESUFFIX sync -v -b $POOLSET &>> $LOG" # pool verification should fail expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST44 b/src/test/pmempool_sync/TEST44 index 5b2e1465ddd..534794c2144 100755 --- a/src/test/pmempool_sync/TEST44 +++ b/src/test/pmempool_sync/TEST44 @@ -82,9 +82,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST45 b/src/test/pmempool_sync/TEST45 index 9a48af2c01b..a3101b33425 100755 --- a/src/test/pmempool_sync/TEST45 +++ b/src/test/pmempool_sync/TEST45 @@ -80,9 +80,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST46 b/src/test/pmempool_sync/TEST46 index de57afa19ac..7268fbe034c 100755 --- a/src/test/pmempool_sync/TEST46 +++ b/src/test/pmempool_sync/TEST46 @@ -80,9 +80,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST47 b/src/test/pmempool_sync/TEST47 index 62ad2a7048a..d4eb0f2e589 100755 --- a/src/test/pmempool_sync/TEST47 +++ b/src/test/pmempool_sync/TEST47 @@ -83,9 +83,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST48 b/src/test/pmempool_sync/TEST48 index 31c22d6e69a..244e96f21ae 100755 --- a/src/test/pmempool_sync/TEST48 +++ b/src/test/pmempool_sync/TEST48 @@ -86,9 +86,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST49 b/src/test/pmempool_sync/TEST49 index c643f0a22c6..604dd765c24 100755 --- a/src/test/pmempool_sync/TEST49 +++ b/src/test/pmempool_sync/TEST49 @@ -85,9 +85,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST50 b/src/test/pmempool_sync/TEST50 index 9d9a5e05b67..f26241efb05 100755 --- a/src/test/pmempool_sync/TEST50 +++ b/src/test/pmempool_sync/TEST50 @@ -85,9 +85,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST51 b/src/test/pmempool_sync/TEST51 index 33c8f45dbcf..5bcf8548032 100755 --- a/src/test/pmempool_sync/TEST51 +++ b/src/test/pmempool_sync/TEST51 @@ -86,9 +86,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST52 b/src/test/pmempool_sync/TEST52 index fa608e1940a..5fee861d20f 100755 --- a/src/test/pmempool_sync/TEST52 +++ b/src/test/pmempool_sync/TEST52 @@ -83,9 +83,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST53 b/src/test/pmempool_sync/TEST53 index 5c09150ea50..2de6af42801 100755 --- a/src/test/pmempool_sync/TEST53 +++ b/src/test/pmempool_sync/TEST53 @@ -85,9 +85,9 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error messages printed out on the stderr by PMDK in debug +# Exclude error and warn messages printed out on the stderr by PMDK in debug LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG > $LOG_TEMP +fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST8 b/src/test/pmempool_sync/TEST8 index 77897f32b91..6a0c54ca2c6 100755 --- a/src/test/pmempool_sync/TEST8 +++ b/src/test/pmempool_sync/TEST8 @@ -55,8 +55,8 @@ rm -f $DIR/part11 # Synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_sync/TEST9 b/src/test/pmempool_sync/TEST9 index 9bb26f4d8fe..699acb4a692 100755 --- a/src/test/pmempool_sync/TEST9 +++ b/src/test/pmempool_sync/TEST9 @@ -58,8 +58,8 @@ rm -f $DIR/part01 # Try to synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check From 564b836b01c7689fcd99a64e1d37fdb9b98f83f1 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 30 Jan 2024 17:46:24 +0100 Subject: [PATCH 054/182] common: CORE_LOG_WARNING_W_ERRNO integration Signed-off-by: Tomasz Gromadzki --- src/common/uuid_linux.c | 4 ++-- src/libpmemobj/obj.c | 6 +++--- src/libpmempool/rm.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/uuid_linux.c b/src/common/uuid_linux.c index 16ee2dae531..5755a0d4718 100644 --- a/src/common/uuid_linux.c +++ b/src/common/uuid_linux.c @@ -28,13 +28,13 @@ util_uuid_generate(uuid_t uuid) int fd = os_open(POOL_HDR_UUID_GEN_FILE, O_RDONLY); if (fd < 0) { /* Fatal error */ - CORE_LOG_WARNING("!open(uuid)"); + CORE_LOG_WARNING_W_ERRNO("open(uuid)"); return -1; } ssize_t num = read(fd, uu, POOL_HDR_UUID_STR_LEN); if (num < POOL_HDR_UUID_STR_LEN) { /* Fatal error */ - CORE_LOG_WARNING("!read(uuid)"); + CORE_LOG_WARNING_W_ERRNO("read(uuid)"); os_close(fd); return -1; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index a1eda31b54e..3025224b4ce 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -87,7 +87,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) LOG(3, "pop %p", pop); if (pop != NULL && (pop->ctl = ctl_new()) == NULL) { - CORE_LOG_WARNING("!ctl_new"); + CORE_LOG_WARNING_W_ERRNO("ctl_new"); return -1; } @@ -1186,7 +1186,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) } if ((errno = lane_check(pop)) != 0) { - CORE_LOG_WARNING("!lane_check"); + CORE_LOG_WARNING_W_ERRNO("lane_check"); consistent = 0; } @@ -1195,7 +1195,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) errno = palloc_heap_check((char *)pop + pop->heap_offset, heap_size); if (errno != 0) { - CORE_LOG_WARNING("!heap_check"); + CORE_LOG_WARNING_W_ERRNO("heap_check"); consistent = 0; } diff --git a/src/libpmempool/rm.c b/src/libpmempool/rm.c index cbb540249a0..425858c4970 100644 --- a/src/libpmempool/rm.c +++ b/src/libpmempool/rm.c @@ -20,7 +20,7 @@ #define ERR_F(f, ...) do {\ if (CHECK_FLAG((f), FORCE))\ - CORE_LOG_WARNING("!(ignored) " __VA_ARGS__);\ + CORE_LOG_WARNING_W_ERRNO("(ignored) " __VA_ARGS__);\ else\ ERR_WO_ERRNO(__VA_ARGS__);\ } while (0) From d9ca2f670131117b2b62ba1633aa520f9291357d Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 31 Jan 2024 13:00:11 +0100 Subject: [PATCH 055/182] common: addjust logging levels Signed-off-by: Tomasz Gromadzki --- src/common/file.c | 24 +++++++++---------- src/common/os_deep_linux.c | 2 +- src/common/set.c | 46 ++++++++++++++++++------------------- src/common/shutdown_state.c | 2 +- src/common/uuid.c | 12 +++++----- src/common/uuid_linux.c | 4 ++-- src/libpmem/pmem.c | 2 +- src/libpmemobj/heap.c | 2 +- src/libpmemobj/lane.c | 2 +- src/libpmemobj/list.c | 10 ++++---- src/libpmemobj/obj.c | 20 ++++++++-------- src/libpmempool/pool.c | 4 ++-- src/libpmempool/rm.c | 4 ++-- src/libpmempool/sync.c | 8 +++---- src/libpmempool/transform.c | 6 ++--- src/tools/pmempool/common.c | 2 +- 16 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/common/file.c b/src/common/file.c index b79cab02f44..b77c49c9bd2 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -209,13 +209,13 @@ util_file_map_whole(const char *path) ssize_t size = util_fd_get_size(fd); if (size < 0) { - CORE_LOG_WARNING("cannot determine file length \"%s\"", path); + CORE_LOG_ERROR("cannot determine file length \"%s\"", path); goto out; } addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL); if (addr == NULL) { - CORE_LOG_WARNING("failed to map entire file \"%s\"", path); + CORE_LOG_ERROR("failed to map entire file \"%s\"", path); goto out; } @@ -247,13 +247,13 @@ util_file_zero(const char *path, os_off_t off, size_t len) ssize_t size = util_fd_get_size(fd); if (size < 0) { - CORE_LOG_WARNING("cannot determine file length \"%s\"", path); + CORE_LOG_ERROR("cannot determine file length \"%s\"", path); ret = -1; goto out; } if (off > size) { - CORE_LOG_WARNING("offset beyond file length, %ju > %ju", off, + CORE_LOG_ERROR("offset beyond file length, %ju > %ju", off, size); ret = -1; goto out; @@ -269,7 +269,7 @@ util_file_zero(const char *path, os_off_t off, size_t len) void *addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL); if (addr == NULL) { - CORE_LOG_WARNING("failed to map entire file \"%s\"", path); + CORE_LOG_ERROR("failed to map entire file \"%s\"", path); ret = -1; goto out; } @@ -304,7 +304,7 @@ util_file_pwrite(const char *path, const void *buffer, size_t size, if (type == TYPE_NORMAL) { int fd = util_file_open(path, NULL, 0, O_RDWR); if (fd < 0) { - CORE_LOG_WARNING("failed to open file \"%s\"", path); + CORE_LOG_ERROR("failed to open file \"%s\"", path); return -1; } @@ -317,7 +317,7 @@ util_file_pwrite(const char *path, const void *buffer, size_t size, ssize_t file_size = util_file_get_size(path); if (file_size < 0) { - CORE_LOG_WARNING("cannot determine file length \"%s\"", path); + CORE_LOG_ERROR("cannot determine file length \"%s\"", path); return -1; } @@ -332,7 +332,7 @@ util_file_pwrite(const char *path, const void *buffer, size_t size, void *addr = util_file_map_whole(path); if (addr == NULL) { - CORE_LOG_WARNING("failed to map entire file \"%s\"", path); + CORE_LOG_ERROR("failed to map entire file \"%s\"", path); return -1; } @@ -358,7 +358,7 @@ util_file_pread(const char *path, void *buffer, size_t size, if (type == TYPE_NORMAL) { int fd = util_file_open(path, NULL, 0, O_RDONLY); if (fd < 0) { - CORE_LOG_WARNING("failed to open file \"%s\"", path); + CORE_LOG_ERROR("failed to open file \"%s\"", path); return -1; } @@ -371,7 +371,7 @@ util_file_pread(const char *path, void *buffer, size_t size, ssize_t file_size = util_file_get_size(path); if (file_size < 0) { - CORE_LOG_WARNING("cannot determine file length \"%s\"", path); + CORE_LOG_ERROR("cannot determine file length \"%s\"", path); return -1; } @@ -386,7 +386,7 @@ util_file_pread(const char *path, void *buffer, size_t size, void *addr = util_file_map_whole(path); if (addr == NULL) { - CORE_LOG_WARNING("failed to map entire file \"%s\"", path); + CORE_LOG_ERROR("failed to map entire file \"%s\"", path); return -1; } @@ -544,7 +544,7 @@ util_unlink_flock(const char *path) int fd = util_file_open(path, NULL, 0, O_RDONLY); if (fd < 0) { - CORE_LOG_WARNING("failed to open file \"%s\"", path); + CORE_LOG_ERROR("failed to open file \"%s\"", path); return -1; } diff --git a/src/common/os_deep_linux.c b/src/common/os_deep_linux.c index 4460832bc52..ce5dc011d04 100644 --- a/src/common/os_deep_linux.c +++ b/src/common/os_deep_linux.c @@ -39,7 +39,7 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len) "deep_flush not supported"); } else { errno = pmem2_err_to_errno(ret); - CORE_LOG_WARNING( + CORE_LOG_ERROR( "cannot write to deep_flush in region %u", mt->region_id); } diff --git a/src/common/set.c b/src/common/set.c index ed5a7521912..57b78bc7723 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -340,7 +340,7 @@ util_poolset_open(struct pool_set *set) { for (unsigned r = 0; r < set->nreplicas; ++r) { if (util_replica_open(set, r, MAP_SHARED)) { - CORE_LOG_WARNING("replica open failed: replica %u", r); + CORE_LOG_ERROR("replica open failed: replica %u", r); errno = EINVAL; return -1; } @@ -1050,7 +1050,7 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory) ssize_t size = util_file_get_size(entry->path); if (size < 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "cannot read size of file (%s) in a poolset directory", entry->path); goto err; @@ -1481,7 +1481,7 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) part->fd = util_file_create(part->path, part->filesize, minsize); if (part->fd == -1) { - CORE_LOG_WARNING("failed to create file: %s", + CORE_LOG_ERROR("failed to create file: %s", part->path); return -1; } @@ -1491,7 +1491,7 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part) int flags = O_RDWR; part->fd = util_file_open(part->path, &size, minsize, flags); if (part->fd == -1) { - CORE_LOG_WARNING("failed to open file: %s", part->path); + CORE_LOG_ERROR("failed to open file: %s", part->path); return -1; } @@ -1969,7 +1969,7 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) /* map the first part and reserve space for remaining parts */ if (util_map_part(&rep->part[0], addr, rep->resvsize, 0, flags, 0) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "pool mapping failed - replica #%u part #0", repidx); return -1; @@ -2013,7 +2013,7 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags) munmap(addr, rep->resvsize - mapsize); break; } - CORE_LOG_WARNING( + CORE_LOG_ERROR( "usable space mapping failed - part #%d", p); goto err; @@ -2082,7 +2082,7 @@ util_replica_init_headers_local(struct pool_set *set, unsigned repidx, /* map all headers - don't care about the address */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_map_hdr(&rep->part[p], flags, 0) != 0) { - CORE_LOG_WARNING("header mapping failed - part #%d", p); + CORE_LOG_ERROR("header mapping failed - part #%d", p); goto err; } } @@ -2090,7 +2090,7 @@ util_replica_init_headers_local(struct pool_set *set, unsigned repidx, /* create headers, set UUID's */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_header_create(set, repidx, p, attr, 0) != 0) { - CORE_LOG_WARNING("header creation failed - part #%d", + CORE_LOG_ERROR("header creation failed - part #%d", p); goto err; } @@ -2127,7 +2127,7 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags, */ if (PART(REP(set, repidx), 0)->addr == NULL) { if (util_replica_map_local(set, repidx, flags) != 0) { - CORE_LOG_WARNING("replica #%u map failed", repidx); + CORE_LOG_ERROR("replica #%u map failed", repidx); return -1; } } @@ -2136,7 +2136,7 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags, return 0; if (util_replica_init_headers_local(set, repidx, flags, attr) != 0) { - CORE_LOG_WARNING("replica #%u headers initialization failed", + CORE_LOG_ERROR("replica #%u headers initialization failed", repidx); return -1; } @@ -2395,7 +2395,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, int ret = util_poolset_create_set(setp, path, poolsize, minsize, IGNORE_SDS(attr)); if (ret < 0) { - CORE_LOG_WARNING("cannot create pool set -- '%s'", path); + CORE_LOG_ERROR("cannot create pool set -- '%s'", path); return -1; } @@ -2482,7 +2482,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, /* generate pool set UUID */ ret = util_uuid_generate(set->uuid); if (ret < 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "cannot generate pool set UUID"); goto err_poolset; } @@ -2494,8 +2494,8 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, for (unsigned i = 0; i < rep->nhdrs; i++) { ret = util_uuid_generate(rep->part[i].uuid); if (ret < 0) { - CORE_LOG_WARNING( - "cannot generate pool set part UUID"); + CORE_LOG_ERROR( + "cannot generate pool set part UUID"); goto err_poolset; } } @@ -2521,7 +2521,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path, for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_create_local(set, r, flags, attr) != 0) { - CORE_LOG_WARNING("replica #%u creation failed", r); + CORE_LOG_ERROR("replica #%u creation failed", r); goto err_create; } } @@ -2598,7 +2598,7 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) /* map the first part and reserve space for remaining parts */ if (util_map_part(&rep->part[0], addr, rep->resvsize, 0, flags, 0) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "pool mapping failed - replica #%u part #0", repidx); return -1; @@ -2612,7 +2612,7 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) /* map all headers - don't care about the address */ for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_map_hdr(&rep->part[p], flags, 0) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "header mapping failed - part #%d", p); goto err; } @@ -2659,7 +2659,7 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags) rep->resvsize); break; } - CORE_LOG_WARNING( + CORE_LOG_ERROR( "usable space mapping failed - part #%d", p); goto err; @@ -2790,7 +2790,7 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) struct pool_replica *rep = set->replica[r]; for (unsigned p = 0; p < rep->nhdrs; p++) { if (util_header_check(set, r, p, attr) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "header check failed - part #%d", p); return -1; } @@ -2820,7 +2820,7 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) ASSERTne(rep->nparts, 0); if (shutdown_state_check(&sds, &HDR(rep, 0)->sds, rep)) { - CORE_LOG_WARNING("ADR failure detected"); + CORE_LOG_ERROR("ADR failure detected"); errno = EINVAL; return -1; } @@ -2913,7 +2913,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags) for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_open(set, r, mmap_flags) != 0) { - CORE_LOG_WARNING("replica #%u open failed", r); + CORE_LOG_ERROR("replica #%u open failed", r); goto err_replica; } } @@ -3004,7 +3004,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, int ret = util_poolset_create_set(setp, path, 0, 0, flags & POOL_OPEN_IGNORE_SDS); if (ret < 0) { - CORE_LOG_WARNING("cannot open pool set -- '%s'", path); + CORE_LOG_ERROR("cannot open pool set -- '%s'", path); return -1; } @@ -3076,7 +3076,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize, for (unsigned r = 0; r < set->nreplicas; r++) { if (util_replica_open(set, r, mmap_flags) != 0) { - CORE_LOG_WARNING("replica #%u open failed", r); + CORE_LOG_ERROR("replica #%u open failed", r); goto err_replica; } } diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index 66d20e5dd52..fb101d38e56 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -77,7 +77,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, ERR_WO_ERRNO( "Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); } - CORE_LOG_WARNING("cannot read unsafe shutdown count for %d", + CORE_LOG_ERROR("cannot read unsafe shutdown count for %d", fd); goto err; } diff --git a/src/common/uuid.c b/src/common/uuid.c index c1c084c82e3..c92de54c8c6 100644 --- a/src/common/uuid.c +++ b/src/common/uuid.c @@ -20,12 +20,12 @@ util_uuid_to_string(const uuid_t u, char *buf) int len; /* size that is returned from sprintf call */ if (buf == NULL) { - CORE_LOG_WARNING("invalid buffer for uuid string"); + CORE_LOG_ERROR("invalid buffer for uuid string"); return -1; } if (u == NULL) { - CORE_LOG_WARNING("invalid uuid structure"); + CORE_LOG_ERROR("invalid uuid structure"); return -1; } @@ -38,7 +38,7 @@ util_uuid_to_string(const uuid_t u, char *buf) uuid->node[5]); if (len != POOL_HDR_UUID_STR_LEN - 1) { - CORE_LOG_WARNING("snprintf(uuid): %d", len); + CORE_LOG_ERROR("snprintf(uuid): %d", len); return -1; } @@ -56,13 +56,13 @@ int util_uuid_from_string(const char uuid[POOL_HDR_UUID_STR_LEN], struct uuid *ud) { if (strlen(uuid) != 36) { - CORE_LOG_WARNING("invalid uuid string"); + CORE_LOG_ERROR("invalid uuid string"); return -1; } if (uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-') { - CORE_LOG_WARNING("invalid uuid string"); + CORE_LOG_ERROR("invalid uuid string"); return -1; } @@ -75,7 +75,7 @@ util_uuid_from_string(const char uuid[POOL_HDR_UUID_STR_LEN], struct uuid *ud) &ud->node[5]); if (n != 11) { - CORE_LOG_WARNING("sscanf(uuid)"); + CORE_LOG_ERROR("sscanf(uuid)"); return -1; } diff --git a/src/common/uuid_linux.c b/src/common/uuid_linux.c index 5755a0d4718..82d0a8dbcb7 100644 --- a/src/common/uuid_linux.c +++ b/src/common/uuid_linux.c @@ -28,13 +28,13 @@ util_uuid_generate(uuid_t uuid) int fd = os_open(POOL_HDR_UUID_GEN_FILE, O_RDONLY); if (fd < 0) { /* Fatal error */ - CORE_LOG_WARNING_W_ERRNO("open(uuid)"); + CORE_LOG_ERROR_WITH_ERRNO("open(uuid)"); return -1; } ssize_t num = read(fd, uu, POOL_HDR_UUID_STR_LEN); if (num < POOL_HDR_UUID_STR_LEN) { /* Fatal error */ - CORE_LOG_WARNING_W_ERRNO("read(uuid)"); + CORE_LOG_ERROR_WITH_ERRNO("read(uuid)"); os_close(fd); return -1; } diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index c552a246f67..1078d14eec1 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -477,7 +477,7 @@ pmem_map_fileU(const char *path, size_t len, int flags, if ((fd = util_tmpfile(path, OS_DIR_SEP_STR"pmem.XXXXXX", open_flags & O_EXCL)) < 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "failed to create temporary file at \"%s\"", path); return NULL; diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 78900137dfc..d0b02f6fa18 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -1324,7 +1324,7 @@ heap_set_narenas_max(struct palloc_heap *heap, unsigned size) util_mutex_lock(&h->arenas.lock); unsigned capacity = (unsigned)VEC_CAPACITY(&h->arenas.vec); if (size < capacity) { - CORE_LOG_WARNING("cannot decrease max number of arenas"); + CORE_LOG_ERROR("cannot decrease max number of arenas"); goto out; } else if (size == capacity) { ret = 0; diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 00ab7f3820d..fee0bfed92b 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -414,7 +414,7 @@ lane_check(PMEMobjpool *pop) layout = lane_get_layout(pop, j); if (ulog_check((struct ulog *)&layout->internal, OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "lane %" PRIu64 " internal redo failed: %d", j, err); return err; diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index 01185130833..614d38fbd4c 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -561,7 +561,7 @@ list_insert_new_user(PMEMobjpool *pop, int ret; if ((ret = pmemobj_mutex_lock(pop, &user_head->lock))) { errno = ret; - CORE_LOG_WARNING("pmemobj_mutex_lock failed"); + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); return -1; } @@ -600,7 +600,7 @@ list_insert(PMEMobjpool *pop, if ((ret = pmemobj_mutex_lock(pop, &head->lock))) { errno = ret; - CORE_LOG_WARNING("pmemobj_mutex_lock failed"); + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); ret = -1; goto err; } @@ -728,7 +728,7 @@ list_remove_free_user(PMEMobjpool *pop, size_t pe_offset, int ret; if ((ret = pmemobj_mutex_lock(pop, &user_head->lock))) { errno = ret; - CORE_LOG_WARNING("pmemobj_mutex_lock failed"); + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); return -1; } @@ -762,7 +762,7 @@ list_remove(PMEMobjpool *pop, if ((ret = pmemobj_mutex_lock(pop, &head->lock))) { errno = ret; - CORE_LOG_WARNING("pmemobj_mutex_lock failed"); + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); ret = -1; goto err; } @@ -839,7 +839,7 @@ list_move(PMEMobjpool *pop, */ if ((ret = list_mutexes_lock(pop, head_new, head_old))) { errno = ret; - CORE_LOG_WARNING("list_mutexes_lock failed"); + CORE_LOG_ERROR("list_mutexes_lock failed"); ret = -1; goto err; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 3025224b4ce..077a6f581ba 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -87,7 +87,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) LOG(3, "pop %p", pop); if (pop != NULL && (pop->ctl = ctl_new()) == NULL) { - CORE_LOG_WARNING_W_ERRNO("ctl_new"); + CORE_LOG_ERROR_WITH_ERRNO("ctl_new"); return -1; } @@ -102,7 +102,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) if (env_config != NULL) { if (ctl_load_config_from_string(pop ? pop->ctl : NULL, pop, env_config) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "unable to parse config stored in %s environment variable", OBJ_CONFIG_ENV_VARIABLE); goto err; @@ -113,7 +113,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) if (env_config_file != NULL && env_config_file[0] != '\0') { if (ctl_load_config_from_file(pop ? pop->ctl : NULL, pop, env_config_file) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "unable to parse config stored in %s file (from %s environment variable)", env_config_file, OBJ_CONFIG_FILE_ENV_VARIABLE); goto err; @@ -1087,7 +1087,7 @@ pmemobj_createU(const char *path, const char *layout, if (util_pool_create(&set, path, poolsize, PMEMOBJ_MIN_POOL, PMEMOBJ_MIN_PART, &adj_pool_attr, &runtime_nlanes, REPLICAS_ENABLED) != 0) { - CORE_LOG_WARNING("cannot create pool or pool set"); + CORE_LOG_ERROR("cannot create pool or pool set"); os_mutex_unlock(&pools_mutex); return NULL; } @@ -1124,7 +1124,7 @@ pmemobj_createU(const char *path, const char *layout, /* create pool descriptor */ if (obj_descr_create(pop, layout, set->poolsize) != 0) { - CORE_LOG_WARNING("creation of pool descriptor failed"); + CORE_LOG_ERROR("creation of pool descriptor failed"); goto err; } @@ -1186,7 +1186,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) } if ((errno = lane_check(pop)) != 0) { - CORE_LOG_WARNING_W_ERRNO("lane_check"); + CORE_LOG_ERROR_WITH_ERRNO("lane_check"); consistent = 0; } @@ -1195,7 +1195,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) errno = palloc_heap_check((char *)pop + pop->heap_offset, heap_size); if (errno != 0) { - CORE_LOG_WARNING_W_ERRNO("heap_check"); + CORE_LOG_ERROR_WITH_ERRNO("heap_check"); consistent = 0; } @@ -1235,7 +1235,7 @@ obj_pool_open(struct pool_set **set, const char *path, unsigned flags, { if (util_pool_open(set, path, PMEMOBJ_MIN_PART, &Obj_open_attr, nlanes, NULL, flags) != 0) { - CORE_LOG_WARNING("cannot open pool or pool set"); + CORE_LOG_ERROR("cannot open pool or pool set"); return -1; } @@ -1372,7 +1372,7 @@ obj_open_common(const char *path, const char *layout, unsigned flags, int boot) PMEMobjpool *rep = repset->part[0].addr; /* check descriptor */ if (obj_descr_check(rep, layout, set->poolsize) != 0) { - CORE_LOG_WARNING( + CORE_LOG_ERROR( "descriptor check of replica #%u failed", r); goto err_descr_check; } @@ -2435,7 +2435,7 @@ pmemobj_root_construct(PMEMobjpool *pop, size_t size, if (size > pop->root_size && obj_alloc_root(pop, size, constructor, arg)) { pmemobj_mutex_unlock_nofail(pop, &pop->rootlock); - CORE_LOG_WARNING("obj_realloc_root failed"); + CORE_LOG_ERROR("obj_realloc_root failed"); PMEMOBJ_API_END(); return OID_NULL; } diff --git a/src/libpmempool/pool.c b/src/libpmempool/pool.c index d4b734d2619..9ccc432ee86 100644 --- a/src/libpmempool/pool.c +++ b/src/libpmempool/pool.c @@ -187,7 +187,7 @@ pool_params_parse(const PMEMpoolcheck *ppc, struct pool_params *params, ret = util_poolset_create_set(&set, ppc->path, 0, 0, true); if (ret < 0) { - CORE_LOG_WARNING("cannot open pool set -- '%s'", + CORE_LOG_ERROR("cannot open pool set -- '%s'", ppc->path); return -1; } @@ -296,7 +296,7 @@ pool_set_file_open(const char *fname, int rdonly) int ret = util_poolset_create_set(&file->poolset, path, 0, 0, true); if (ret < 0) { - CORE_LOG_WARNING("cannot open pool set -- '%s'", path); + CORE_LOG_ERROR("cannot open pool set -- '%s'", path); goto err_free_fname; } unsigned flags = (rdonly ? POOL_OPEN_COW : 0) | diff --git a/src/libpmempool/rm.c b/src/libpmempool/rm.c index 425858c4970..480b3fa79cb 100644 --- a/src/libpmempool/rm.c +++ b/src/libpmempool/rm.c @@ -122,11 +122,11 @@ pmempool_rmU(const char *path, unsigned flags) } if (!is_poolset) { - CORE_LOG_WARNING("%s: not a poolset file", path); + CORE_LOG_ERROR("%s: not a poolset file", path); return rm_local(path, flags, 0); } - CORE_LOG_WARNING("%s: poolset file", path); + CORE_LOG_ERROR("%s: poolset file", path); /* fill up pool_set structure */ struct pool_set *set = NULL; diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index 2f9b7672480..ad1bedd2bb8 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -41,7 +41,7 @@ validate_args(struct pool_set *set) * (now replication works only for pmemobj pools) */ if (replica_check_part_sizes(set, PMEMOBJ_MIN_POOL)) { - CORE_LOG_WARNING("part sizes check failed"); + CORE_LOG_ERROR("part sizes check failed"); goto err; } @@ -49,7 +49,7 @@ validate_args(struct pool_set *set) * check if all directories for part files exist */ if (replica_check_part_dirs(set)) { - CORE_LOG_WARNING("part directories check failed"); + CORE_LOG_ERROR("part directories check failed"); goto err; } @@ -851,14 +851,14 @@ recreate_broken_parts(struct pool_set *set, /* remove parts from broken replica */ if (replica_remove_part(set, r, p, fix_bad_blocks)) { - CORE_LOG_WARNING("cannot remove part"); + CORE_LOG_ERROR("cannot remove part"); return -1; } /* create removed part and open it */ if (util_part_open(&broken_r->part[p], 0, 1 /* create */)) { - CORE_LOG_WARNING("cannot open/create parts"); + CORE_LOG_ERROR("cannot open/create parts"); return -1; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index 3a671dc14f6..b0785b02c7f 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -374,13 +374,13 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, for (unsigned r = 0; r < set_in_s->nreplicas; ++r) { unsigned c = replica_counterpart(r, set_in_s); if (c != UNDEF_REPLICA) { - CORE_LOG_WARNING("replica %u has a counterpart %u", r, + CORE_LOG_DEBUG("replica %u has a counterpart %u", r, set_in_s->replica[r]); has_replica_to_keep = 1; REP_HEALTH(set_out_hs, c)->pool_size = REP_HEALTH(set_in_hs, r)->pool_size; } else { - CORE_LOG_WARNING("replica %u has no counterpart", r); + CORE_LOG_NOTICE("replica %u has no counterpart", r); is_removing_replicas = 1; } } @@ -394,7 +394,7 @@ identify_transform_operation(struct poolset_compare_status *set_in_s, /* check if there are replicas to be added */ for (unsigned r = 0; r < set_out_s->nreplicas; ++r) { if (replica_counterpart(r, set_out_s) == UNDEF_REPLICA) { - CORE_LOG_WARNING( + CORE_LOG_NOTICE( "Replica %u from output set has no counterpart", r); if (is_removing_replicas) { diff --git a/src/tools/pmempool/common.c b/src/tools/pmempool/common.c index 88ebc8419ca..c814380599f 100644 --- a/src/tools/pmempool/common.c +++ b/src/tools/pmempool/common.c @@ -1304,7 +1304,7 @@ util_pool_clear_badblocks(const char *path, int create) int ret = util_poolset_create_set(&setp, path, 0, 0, POOL_OPEN_IGNORE_SDS); if (ret < 0) { - CORE_LOG_WARNING("cannot open pool set -- '%s'", path); + CORE_LOG_ERROR("cannot open pool set -- '%s'", path); return -1; } From f7a0fb58b77fd7c8254c76b0534be3274f06b2fa Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 31 Jan 2024 13:09:39 +0100 Subject: [PATCH 056/182] common: adjust tests --- src/test/pmempool_sync/TEST24 | 2 +- src/test/pmempool_transform/TEST5 | 4 ++-- src/test/pmempool_transform/TEST6 | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/pmempool_sync/TEST24 b/src/test/pmempool_sync/TEST24 index dbbfecc5798..e70d3e2ef00 100755 --- a/src/test/pmempool_sync/TEST24 +++ b/src/test/pmempool_sync/TEST24 @@ -61,7 +61,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP dump_pool_info $POOLSET1 >> $LOG_TEMP # Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" | fgrep -v "*WARN*" > $LOG +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_transform/TEST5 b/src/test/pmempool_transform/TEST5 index 8cbf7e86b42..47541d1a92c 100755 --- a/src/test/pmempool_transform/TEST5 +++ b/src/test/pmempool_transform/TEST5 @@ -92,8 +92,8 @@ dump_pool_info $DIR/testfile01 >> $LOG_TEMP dump_pool_info $DIR/testfile02 >> $LOG_TEMP dump_pool_info $DIR/testfile10 >> $LOG_TEMP -# Exclude error and warning messages printed out on the stderr by PMDK in debug -grep -v -E "\*ERROR\*|\*WARN\*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check diff --git a/src/test/pmempool_transform/TEST6 b/src/test/pmempool_transform/TEST6 index a09722b3e0d..420a5f03ab8 100755 --- a/src/test/pmempool_transform/TEST6 +++ b/src/test/pmempool_transform/TEST6 @@ -71,8 +71,8 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_OUT1 >> $LOG_TEMP -# Exclude error and warning messages printed out on the stderr by PMDK in debug -grep -v -E "\*ERROR\*|\*WARN\*" $LOG_TEMP > $LOG +# Exclude error and warn messages printed out on the stderr by PMDK in debug +fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG rm $LOG_TEMP check From 506a7ffde9c7e45bcdf73e15108a451e2d88781e Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 5 Feb 2024 18:49:10 -0500 Subject: [PATCH 057/182] test: adjust tests (part 2) Signed-off-by: Jan Michalski --- src/test/util_poolset/grep0.log.match | 16 ++++++++++++++++ src/test/util_poolset/grep1.log.match | 12 ++++++++++++ src/test/util_poolset/grep2.log.match | 10 ++++++++++ src/test/util_poolset/grep6.log.match | 7 +++++++ 4 files changed, 45 insertions(+) diff --git a/src/test/util_poolset/grep0.log.match b/src/test/util_poolset/grep0.log.match index 65444a345ac..6790b813cff 100644 --- a/src/test/util_poolset/grep0.log.match +++ b/src/test/util_poolset/grep0.log.match @@ -8,6 +8,7 @@ $(OPT)compiled with support for Valgrind drd $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ open "$(nW)/testset0": No such file or directory +cannot create pool set -- '$(nW)/testset0' $(OPT)Cannot read device usc - ndctl is not available $(OPT)Unsafe shutdown count is not supported for this source $(OPT)Cannot read device usc - ndctl is not available @@ -19,17 +20,32 @@ $(OPT)Unsafe shutdown count is not supported for this source $(OPT)Cannot read device usc - ndctl is not available $(OPT)Unsafe shutdown count is not supported for this source size 1000000 smaller than 2097152 +failed to create file: $(nW)/testfile41 size 1000000 smaller than 2097152 +failed to create file: $(nW)/testfile52 open "$(nW)/nodir/testfile62": No such file or directory +failed to create file: $(nW)/testfile62 open "/proc/testfile72": Permission denied +failed to create file: /proc/testfile72 posix_fallocate "$(nW)/testfile82", 1073741824: No space left on device +failed to create file: $(nW)/testfile82 open "$(nW)/testfile102": Permission denied +failed to open file: $(nW)/testfile102 file size does not match config: $(nW)testfile113, 4194304 != 1048576 size 12288 smaller than 2097152 +failed to open file: $(nW)/testfile122 size 12288 smaller than 2097152 +failed to open file: $(nW)/testfile131 file size does not match config: $(nW)testfile142, 4194304 != 8388608 file size does not match config: $(nW)testfile152, 3145728 != 4194304 Non-empty file detected +header creation failed - part #1 +replica #0 headers initialization failed +replica #0 creation failed Non-empty file detected +header creation failed - part #0 +replica #0 headers initialization failed +replica #0 creation failed open "$(nW)/testset23": Permission denied +cannot create pool set -- '$(nW)/testset23' reservation pool size 1048576 smaller than 4194304 diff --git a/src/test/util_poolset/grep1.log.match b/src/test/util_poolset/grep1.log.match index 388f7f6909f..7dcf42462b5 100644 --- a/src/test/util_poolset/grep1.log.match +++ b/src/test/util_poolset/grep1.log.match @@ -8,16 +8,28 @@ $(OPT)compiled with support for Valgrind drd $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ open "$(nW)/testset0": No such file or directory +cannot open pool set -- '$(nW)/testset0' invalid major version (0) +header check failed - part #0 open "$(nW)/testset2": Permission denied +cannot open pool set -- '$(nW)/testset2' open "$(nW)/testfile31": No such file or directory +failed to open file: $(nW)/testfile31 open "$(nW)/testfile32": No such file or directory +failed to open file: $(nW)/testfile32 open "$(nW)/testfile31": No such file or directory +failed to open file: $(nW)/testfile31 open "$(nW)/testfile42": No such file or directory +failed to open file: $(nW)/testfile42 size 1048576 smaller than 2097152 +failed to open file: $(nW)/testfile51 size 1048576 smaller than 2097152 +failed to open file: $(nW)/testfile62 size 2097151 smaller than 2097152 +failed to open file: $(nW)/testfile71 open "$(nW)/testfile82": Permission denied +failed to open file: $(nW)/testfile82 file size does not match config: $(nW)testfile92, 4194304 != 65536 file size does not match config: $(nW)testfile102, 4194303 != 4194304 invalid major version (0) +header check failed - part #0 diff --git a/src/test/util_poolset/grep2.log.match b/src/test/util_poolset/grep2.log.match index f7d99cc936f..6d25e56c110 100644 --- a/src/test/util_poolset/grep2.log.match +++ b/src/test/util_poolset/grep2.log.match @@ -8,18 +8,28 @@ $(OPT)compiled with support for Valgrind drd $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ invalid checksum of pool header +header check failed - part #1 wrong pool type: "ERRORXX" +header check failed - part #1 pool version 99 (library expects 1) +header check failed - part #1 invalid reserved values invalid machine value invalid data value invalid machine_class value invalid alignment_desc value wrong architecture flags +header check failed - part #1 incompatible feature flags +header check failed - part #1 incompatible feature flags +header check failed - part #1 incompatible feature flags +header check failed - part #1 wrong pool set UUID +header check failed - part #1 wrong part UUID +header check failed - part #0 wrong part UUID +header check failed - part #0 wrong replica UUID diff --git a/src/test/util_poolset/grep6.log.match b/src/test/util_poolset/grep6.log.match index 08bd647a7e5..536bfdc581b 100644 --- a/src/test/util_poolset/grep6.log.match +++ b/src/test/util_poolset/grep6.log.match @@ -8,9 +8,16 @@ $(OPT)compiled with support for Valgrind drd $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset2' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset3' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset4' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset6' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset7' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset8' cannot mix directories and files in a set +cannot create pool set -- '$(nW)/testset9' From 042456bd13bd30cefa686dca390f62de186d5001 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 5 Feb 2024 19:35:31 -0500 Subject: [PATCH 058/182] common: extract the error_msg module Signed-off-by: Jan Michalski --- src/core/error_msg.c | 120 ++++++++++++++++++++++++++++++++++ src/core/error_msg.h | 30 +++++++++ src/core/out.c | 118 ++------------------------------- src/core/out.h | 1 - src/core/pmemcore.h | 2 + src/core/pmemcore.inc | 3 +- src/libpmem/Makefile | 1 + src/libpmem/libpmem.c | 6 +- src/libpmem2/errormsg.c | 4 +- src/libpmem2/pmem2_utils.h | 3 +- src/libpmemobj/libpmemobj.c | 6 +- src/libpmempool/libpmempool.c | 6 +- src/test/Makefile.inc | 3 + src/test/out_err/out_err.c | 10 +-- src/tools/pmempool/rm.c | 5 +- 15 files changed, 184 insertions(+), 134 deletions(-) create mode 100644 src/core/error_msg.c create mode 100644 src/core/error_msg.h diff --git a/src/core/error_msg.c b/src/core/error_msg.c new file mode 100644 index 00000000000..a73141b7066 --- /dev/null +++ b/src/core/error_msg.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2014-2024, Intel Corporation */ + +/* + * error_msg.c -- maintain TLS buffers to store the last error message + */ + +#include +#include +#include +#include +#include +#include + +#include "error_msg.h" +#include "os_thread.h" +#include "out.h" +#include "valgrind_internal.h" + +struct errormsg +{ + char msg[CORE_ERROR_MSG_MAXPRINT]; +}; + +#ifndef NO_LIBPTHREAD + +static os_once_t Last_errormsg_key_once = OS_ONCE_INIT; +static os_tls_key_t Last_errormsg_key; + +static void +error_msg_key_alloc(void) +{ + int pth_ret = os_tls_key_create(&Last_errormsg_key, free); + if (pth_ret) + CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); + + VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); +} + +void +error_msg_init(void) +{ + os_once(&Last_errormsg_key_once, error_msg_key_alloc); + /* + * Workaround Helgrind's bug: + * https://bugs.kde.org/show_bug.cgi?id=337735 + */ + VALGRIND_ANNOTATE_HAPPENS_AFTER(&Last_errormsg_key_once); +} + +void +error_msg_fini(void) +{ + void *p = os_tls_get(Last_errormsg_key); + if (p) { + free(p); + (void) os_tls_set(Last_errormsg_key, NULL); + } + (void) os_tls_key_delete(Last_errormsg_key); +} + +static inline struct errormsg * +error_msg_get_internal(void) +{ + error_msg_init(); + + struct errormsg *errormsg = os_tls_get(Last_errormsg_key); + if (errormsg == NULL) { + errormsg = malloc(sizeof(struct errormsg)); + if (errormsg == NULL) + return NULL; + /* make sure it contains empty string initially */ + errormsg->msg[0] = '\0'; + int ret = os_tls_set(Last_errormsg_key, errormsg); + if (ret) + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); + } + return errormsg; +} + +#else + +/* + * We don't want libpmem to depend on libpthread. Instead of using pthread + * API to dynamically allocate thread-specific error message buffer, we put + * it into TLS. However, keeping a pretty large static buffer (8K) in TLS + * may lead to some issues, so the maximum message length is reduced. + * Fortunately, it looks like the longest error message in libpmem should + * not be longer than about 90 chars (in case of pmem_check_version()). + */ + +static __thread struct errormsg Last_errormsg; + +static inline void +error_msg_init(void) +{ +} + +static inline void +error_msg_fini(void) +{ +} + +static inline const struct errormsg * +error_msg_get_internal(void) +{ + return &Last_errormsg; +} + +#endif /* NO_LIBPTHREAD */ + +/* + * error_msg_get -- get the last error message + */ +const char * +error_msg_get(void) +{ + const struct errormsg *errormsg = error_msg_get_internal(); + return &errormsg->msg[0]; +} diff --git a/src/core/error_msg.h b/src/core/error_msg.h new file mode 100644 index 00000000000..35aac1b7668 --- /dev/null +++ b/src/core/error_msg.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2014-2024, Intel Corporation */ + +/* + * error_msg.h -- definitions for the "error_msg" module + */ + +#ifndef CORE_ERROR_MSG_H +#define CORE_ERROR_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NO_LIBPTHREAD +#define CORE_ERROR_MSG_MAXPRINT 8192 /* maximum expected log line */ +#else +#define CORE_ERROR_MSG_MAXPRINT 256 /* maximum expected log line for libpmem */ +#endif + +void error_msg_init(void); +void error_msg_fini(void); + +const char *error_msg_get(void); + +#ifdef __cplusplus +} +#endif + +#endif /* CORE_ERROR_MSG_H */ diff --git a/src/core/out.c b/src/core/out.c index ff8c9db027b..18ce25b78b7 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -17,114 +17,18 @@ #include "out.h" #include "os.h" -#include "os_thread.h" #include "valgrind_internal.h" #include "util.h" #include "log_internal.h" +#include "error_msg.h" + +#define MAXPRINT CORE_ERROR_MSG_MAXPRINT static const char *Log_prefix; static int Log_level; static FILE *Out_fp; static unsigned Log_alignment; -#ifndef NO_LIBPTHREAD -#define MAXPRINT 8192 /* maximum expected log line */ -#else -#define MAXPRINT 256 /* maximum expected log line for libpmem */ -#endif - -struct errormsg -{ - char msg[MAXPRINT]; -}; - -#ifndef NO_LIBPTHREAD - -static os_once_t Last_errormsg_key_once = OS_ONCE_INIT; -static os_tls_key_t Last_errormsg_key; - -static void -_Last_errormsg_key_alloc(void) -{ - int pth_ret = os_tls_key_create(&Last_errormsg_key, free); - if (pth_ret) - CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); - - VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); -} - -static void -Last_errormsg_key_alloc(void) -{ - os_once(&Last_errormsg_key_once, _Last_errormsg_key_alloc); - /* - * Workaround Helgrind's bug: - * https://bugs.kde.org/show_bug.cgi?id=337735 - */ - VALGRIND_ANNOTATE_HAPPENS_AFTER(&Last_errormsg_key_once); -} - -static inline void -Last_errormsg_fini(void) -{ - void *p = os_tls_get(Last_errormsg_key); - if (p) { - free(p); - (void) os_tls_set(Last_errormsg_key, NULL); - } - (void) os_tls_key_delete(Last_errormsg_key); -} - -static inline struct errormsg * -Last_errormsg_get(void) -{ - Last_errormsg_key_alloc(); - - struct errormsg *errormsg = os_tls_get(Last_errormsg_key); - if (errormsg == NULL) { - errormsg = malloc(sizeof(struct errormsg)); - if (errormsg == NULL) - return NULL; - /* make sure it contains empty string initially */ - errormsg->msg[0] = '\0'; - int ret = os_tls_set(Last_errormsg_key, errormsg); - if (ret) - CORE_LOG_FATAL_W_ERRNO("os_tls_set"); - } - return errormsg; -} - -#else - -/* - * We don't want libpmem to depend on libpthread. Instead of using pthread - * API to dynamically allocate thread-specific error message buffer, we put - * it into TLS. However, keeping a pretty large static buffer (8K) in TLS - * may lead to some issues, so the maximum message length is reduced. - * Fortunately, it looks like the longest error message in libpmem should - * not be longer than about 90 chars (in case of pmem_check_version()). - */ - -static __thread struct errormsg Last_errormsg; - -static inline void -Last_errormsg_key_alloc(void) -{ -} - -static inline void -Last_errormsg_fini(void) -{ -} - -static inline const struct errormsg * -Last_errormsg_get(void) -{ - return &Last_errormsg; -} - -#endif /* NO_LIBPTHREAD */ - /* * out_init -- initialize the log * @@ -242,7 +146,7 @@ out_init(const char *log_prefix, const char *log_level_var, CORE_LOG_ALWAYS("%s", ndctl_ge_63_msg); #endif - Last_errormsg_key_alloc(); + error_msg_init(); } /* @@ -257,8 +161,6 @@ out_fini(void) fclose(Out_fp); Out_fp = stderr; } - - Last_errormsg_fini(); } /* @@ -367,7 +269,7 @@ out_error(int use_errno, const char *file, int line, const char *func, const char *sep = ""; char errstr[UTIL_MAX_ERR_MSG] = ""; - char *errormsg = (char *)out_get_errormsg(); + char *errormsg = (char *)error_msg_get(); if (errormsg == NULL) { out_print_func("No memory to properly format error strings."); @@ -505,13 +407,3 @@ out_err(int use_errno, const char *file, int line, const char *func, va_end(ap); } - -/* - * out_get_errormsg -- get the last error message - */ -const char * -out_get_errormsg(void) -{ - const struct errormsg *errormsg = Last_errormsg_get(); - return &errormsg->msg[0]; -} diff --git a/src/core/out.h b/src/core/out.h index 42f15032878..eba7ec2598f 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -191,7 +191,6 @@ void out_err(int use_errno, const char *file, int line, const char *func, const char *fmt, ...) FORMAT_PRINTF(5, 6); void NORETURN out_fatal(const char *file, int line, const char *func, const char *fmt, ...) FORMAT_PRINTF(4, 5); -const char *out_get_errormsg(void); #ifdef __cplusplus } diff --git a/src/core/pmemcore.h b/src/core/pmemcore.h index 4eb7f7dffe0..4e25a53a7b2 100644 --- a/src/core/pmemcore.h +++ b/src/core/pmemcore.h @@ -10,6 +10,7 @@ #include "util.h" #include "out.h" +#include "error_msg.h" #include "log_internal.h" #ifdef __cplusplus @@ -38,6 +39,7 @@ core_fini(void) { out_fini(); core_log_fini(); + error_msg_fini(); } #ifdef __cplusplus diff --git a/src/core/pmemcore.inc b/src/core/pmemcore.inc index e07f5a8f7e1..920cd398b48 100644 --- a/src/core/pmemcore.inc +++ b/src/core/pmemcore.inc @@ -1,4 +1,4 @@ -# Copyright 2020, Intel Corporation +# Copyright 2020-2024, Intel Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,6 +33,7 @@ SOURCE +=\ $(CORE)/alloc.c\ + $(CORE)/error_msg.c\ $(CORE)/fs_posix.c\ $(CORE)/os_posix.c\ $(CORE)/os_thread_posix.c\ diff --git a/src/libpmem/Makefile b/src/libpmem/Makefile index a3f8a70e064..5ad7173e780 100644 --- a/src/libpmem/Makefile +++ b/src/libpmem/Makefile @@ -12,6 +12,7 @@ LIBRARY_SO_VERSION = 1 LIBRARY_VERSION = 0.0 SOURCE =\ $(CORE)/alloc.c\ + $(CORE)/error_msg.c\ $(CORE)/fs_posix.c\ $(CORE)/os_posix.c\ $(CORE)/os_thread_posix.c\ diff --git a/src/libpmem/libpmem.c b/src/libpmem/libpmem.c index c2e999e3fab..f10ac6647ce 100644 --- a/src/libpmem/libpmem.c +++ b/src/libpmem/libpmem.c @@ -56,14 +56,14 @@ pmem_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmem major version mismatch (need %u, found %u)", major_required, PMEM_MAJOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } if (minor_required > PMEM_MINOR_VERSION) { ERR_WO_ERRNO( "libpmem minor version mismatch (need %u, found %u)", minor_required, PMEM_MINOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } return NULL; @@ -85,7 +85,7 @@ static inline const char * pmem_errormsgU(void) { - return out_get_errormsg(); + return error_msg_get(); } /* diff --git a/src/libpmem2/errormsg.c b/src/libpmem2/errormsg.c index ba1ac8f9136..b14d22d6713 100644 --- a/src/libpmem2/errormsg.c +++ b/src/libpmem2/errormsg.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2023, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * errormsg.c -- pmem2_errormsg* implementation @@ -16,7 +16,7 @@ static inline const char * pmem2_errormsgU(void) { - return out_get_errormsg(); + return error_msg_get(); } /* diff --git a/src/libpmem2/pmem2_utils.h b/src/libpmem2/pmem2_utils.h index be113eb7f14..193bcde05a1 100644 --- a/src/libpmem2/pmem2_utils.h +++ b/src/libpmem2/pmem2_utils.h @@ -12,6 +12,7 @@ #include "os.h" #include "out.h" +#include "error_msg.h" #include "source.h" static inline int @@ -32,7 +33,7 @@ pmem2_assert_errno(void) #define PMEM2_ERR_CLR() \ {\ errno = 0;\ - char *errormsg = (char *)out_get_errormsg();\ + char *errormsg = (char *)error_msg_get();\ strcpy(errormsg, "\0");\ } #else diff --git a/src/libpmemobj/libpmemobj.c b/src/libpmemobj/libpmemobj.c index 107254c7159..8d09adc305c 100644 --- a/src/libpmemobj/libpmemobj.c +++ b/src/libpmemobj/libpmemobj.c @@ -52,14 +52,14 @@ pmemobj_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmemobj major version mismatch (need %u, found %u)", major_required, PMEMOBJ_MAJOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } if (minor_required > PMEMOBJ_MINOR_VERSION) { ERR_WO_ERRNO( "libpmemobj minor version mismatch (need %u, found %u)", minor_required, PMEMOBJ_MINOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } return NULL; @@ -96,7 +96,7 @@ static inline const char * pmemobj_errormsgU(void) { - return out_get_errormsg(); + return error_msg_get(); } /* diff --git a/src/libpmempool/libpmempool.c b/src/libpmempool/libpmempool.c index b6cbeb8db08..bbbd9c350ad 100644 --- a/src/libpmempool/libpmempool.c +++ b/src/libpmempool/libpmempool.c @@ -59,14 +59,14 @@ pmempool_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmempool major version mismatch (need %u, found %u)", major_required, PMEMPOOL_MAJOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } if (minor_required > PMEMPOOL_MINOR_VERSION) { ERR_WO_ERRNO( "libpmempool minor version mismatch (need %u, found %u)", minor_required, PMEMPOOL_MINOR_VERSION); - return out_get_errormsg(); + return error_msg_get(); } return NULL; @@ -88,7 +88,7 @@ static inline const char * pmempool_errormsgU(void) { - return out_get_errormsg(); + return error_msg_get(); } /* diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index e143aa7eb65..d3a3f50256b 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -394,6 +394,7 @@ ifeq ($(LIBPMEMCORE), internal-nondebug) USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/nondebug/core/alloc.o\ + $(TOP)/src/nondebug/core/error_msg.o\ $(TOP)/src/nondebug/core/fs_posix.o\ $(TOP)/src/nondebug/core/log.o\ $(TOP)/src/nondebug/core/log_default.o\ @@ -412,6 +413,7 @@ ifeq ($(LIBPMEMCORE), internal-debug) USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/debug/core/alloc.o\ + $(TOP)/src/debug/core/error_msg.o\ $(TOP)/src/debug/core/fs_posix.o\ $(TOP)/src/debug/core/log.o\ $(TOP)/src/debug/core/log_default.o\ @@ -542,6 +544,7 @@ endif # In case the binary is built with directly linking with core units it is # assumed the following are among them already. ifneq ($(USE_LOG_PMEMCORE),y) +OBJS += $(TOP)/src/debug/core/error_msg.o OBJS += $(TOP)/src/debug/core/out.o OBJS += $(TOP)/src/debug/core/log.o OBJS += $(TOP)/src/debug/core/log_default.o diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index fca1809a9b9..d652663108e 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -29,27 +29,27 @@ main(int argc, char *argv[]) errno = 0; ERR_WO_ERRNO("ERR #%d", 1); - UT_OUT("%s", out_get_errormsg()); + UT_OUT("%s", error_msg_get()); errno = 0; ERR_W_ERRNO("ERR #%d", 2); - UT_OUT("%s", out_get_errormsg()); + UT_OUT("%s", error_msg_get()); errno = EINVAL; ERR_W_ERRNO("ERR #%d", 3); - UT_OUT("%s", out_get_errormsg()); + UT_OUT("%s", error_msg_get()); errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); out_err(0, __FILE__, 100, __func__, "ERR1: %s:%d", buff, 1234); - UT_OUT("%s", out_get_errormsg()); + UT_OUT("%s", error_msg_get()); errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); out_err(0, NULL, 0, NULL, "ERR2: %s:%d", buff, 1234); - UT_OUT("%s", out_get_errormsg()); + UT_OUT("%s", error_msg_get()); /* Cleanup */ common_fini(); diff --git a/src/tools/pmempool/rm.c b/src/tools/pmempool/rm.c index d142da15dc1..361c72b2976 100644 --- a/src/tools/pmempool/rm.c +++ b/src/tools/pmempool/rm.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2022, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * rm.c -- pmempool rm command main source file @@ -14,6 +14,7 @@ #include "os.h" #include "out.h" +#include "error_msg.h" #include "common.h" #include "output.h" #include "file.h" @@ -169,7 +170,7 @@ rm_poolset(const char *file) int ret = util_poolset_foreach_part(file, rm_poolset_cb, &error); if (ret == -1) { outv_err("parsing poolset failed: %s\n", - out_get_errormsg()); + error_msg_get()); return ret; } From e8fe057c416dc8b5fa6e28b0feeae944c593fdba Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 7 Feb 2024 10:26:57 -0500 Subject: [PATCH 059/182] common: rename error_msg -> last_error_msg The last error message is a hand-picked error message believed to convey the critical piece of information which will be available to the user via the *_errormsg() API calls. Signed-off-by: Jan Michalski --- src/core/error_msg.h | 30 ------------ src/core/{error_msg.c => last_error_msg.c} | 54 ++++++++++++---------- src/core/last_error_msg.h | 30 ++++++++++++ src/core/out.c | 18 ++++---- src/core/pmemcore.h | 4 +- src/core/pmemcore.inc | 2 +- src/libpmem/Makefile | 2 +- src/libpmem/libpmem.c | 10 ++-- src/libpmem2/errormsg.c | 6 +-- src/libpmem2/pmem2_utils.h | 4 +- src/libpmemobj/libpmemobj.c | 10 ++-- src/libpmempool/libpmempool.c | 10 ++-- src/test/Makefile.inc | 6 +-- src/test/out_err/out_err.c | 10 ++-- src/tools/pmempool/rm.c | 4 +- 15 files changed, 102 insertions(+), 98 deletions(-) delete mode 100644 src/core/error_msg.h rename src/core/{error_msg.c => last_error_msg.c} (61%) create mode 100644 src/core/last_error_msg.h diff --git a/src/core/error_msg.h b/src/core/error_msg.h deleted file mode 100644 index 35aac1b7668..00000000000 --- a/src/core/error_msg.h +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2024, Intel Corporation */ - -/* - * error_msg.h -- definitions for the "error_msg" module - */ - -#ifndef CORE_ERROR_MSG_H -#define CORE_ERROR_MSG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef NO_LIBPTHREAD -#define CORE_ERROR_MSG_MAXPRINT 8192 /* maximum expected log line */ -#else -#define CORE_ERROR_MSG_MAXPRINT 256 /* maximum expected log line for libpmem */ -#endif - -void error_msg_init(void); -void error_msg_fini(void); - -const char *error_msg_get(void); - -#ifdef __cplusplus -} -#endif - -#endif /* CORE_ERROR_MSG_H */ diff --git a/src/core/error_msg.c b/src/core/last_error_msg.c similarity index 61% rename from src/core/error_msg.c rename to src/core/last_error_msg.c index a73141b7066..83a86a94984 100644 --- a/src/core/error_msg.c +++ b/src/core/last_error_msg.c @@ -2,7 +2,11 @@ /* Copyright 2014-2024, Intel Corporation */ /* - * error_msg.c -- maintain TLS buffers to store the last error message + * last_error_msg.c -- maintain TLS buffers to store the last error message + * + * The last error message is a hand-picked error message believed to convey + * the critical piece of information which will be available to the user via + * the *_errormsg() API calls. */ #include @@ -12,14 +16,14 @@ #include #include -#include "error_msg.h" +#include "last_error_msg.h" #include "os_thread.h" #include "out.h" #include "valgrind_internal.h" -struct errormsg +struct lasterrormsg { - char msg[CORE_ERROR_MSG_MAXPRINT]; + char msg[CORE_LAST_ERROR_MSG_MAXPRINT]; }; #ifndef NO_LIBPTHREAD @@ -28,7 +32,7 @@ static os_once_t Last_errormsg_key_once = OS_ONCE_INIT; static os_tls_key_t Last_errormsg_key; static void -error_msg_key_alloc(void) +last_error_msg_key_alloc(void) { int pth_ret = os_tls_key_create(&Last_errormsg_key, free); if (pth_ret) @@ -38,9 +42,9 @@ error_msg_key_alloc(void) } void -error_msg_init(void) +last_error_msg_init(void) { - os_once(&Last_errormsg_key_once, error_msg_key_alloc); + os_once(&Last_errormsg_key_once, last_error_msg_key_alloc); /* * Workaround Helgrind's bug: * https://bugs.kde.org/show_bug.cgi?id=337735 @@ -49,7 +53,7 @@ error_msg_init(void) } void -error_msg_fini(void) +last_error_msg_fini(void) { void *p = os_tls_get(Last_errormsg_key); if (p) { @@ -59,23 +63,23 @@ error_msg_fini(void) (void) os_tls_key_delete(Last_errormsg_key); } -static inline struct errormsg * -error_msg_get_internal(void) +static inline struct lasterrormsg * +last_error_msg_get_internal(void) { - error_msg_init(); + last_error_msg_init(); - struct errormsg *errormsg = os_tls_get(Last_errormsg_key); - if (errormsg == NULL) { - errormsg = malloc(sizeof(struct errormsg)); - if (errormsg == NULL) + struct lasterrormsg *last = os_tls_get(Last_errormsg_key); + if (last == NULL) { + last = malloc(sizeof(struct lasterrormsg)); + if (last == NULL) return NULL; /* make sure it contains empty string initially */ - errormsg->msg[0] = '\0'; - int ret = os_tls_set(Last_errormsg_key, errormsg); + last->msg[0] = '\0'; + int ret = os_tls_set(Last_errormsg_key, last); if (ret) CORE_LOG_FATAL_W_ERRNO("os_tls_set"); } - return errormsg; + return last; } #else @@ -92,17 +96,17 @@ error_msg_get_internal(void) static __thread struct errormsg Last_errormsg; static inline void -error_msg_init(void) +last_error_msg_init(void) { } static inline void -error_msg_fini(void) +last_error_msg_fini(void) { } static inline const struct errormsg * -error_msg_get_internal(void) +last_error_msg_get_internal(void) { return &Last_errormsg; } @@ -110,11 +114,11 @@ error_msg_get_internal(void) #endif /* NO_LIBPTHREAD */ /* - * error_msg_get -- get the last error message + * last_error_msg_get -- get the last error message */ const char * -error_msg_get(void) +last_error_msg_get(void) { - const struct errormsg *errormsg = error_msg_get_internal(); - return &errormsg->msg[0]; + const struct lasterrormsg *last = last_error_msg_get_internal(); + return &last->msg[0]; } diff --git a/src/core/last_error_msg.h b/src/core/last_error_msg.h new file mode 100644 index 00000000000..be66ac8dcc9 --- /dev/null +++ b/src/core/last_error_msg.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2014-2024, Intel Corporation */ + +/* + * last_error_msg.h -- definitions for the "last_error_msg" module + */ + +#ifndef CORE_LAST_ERROR_MSG_H +#define CORE_LAST_ERROR_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NO_LIBPTHREAD +#define CORE_LAST_ERROR_MSG_MAXPRINT 8192 /* maximum expected log line */ +#else +#define CORE_LAST_ERROR_MSG_MAXPRINT 256 /* ... for libpmem */ +#endif + +void last_error_msg_init(void); +void last_error_msg_fini(void); + +const char *last_error_msg_get(void); + +#ifdef __cplusplus +} +#endif + +#endif /* CORE_LAST_ERROR_MSG_H */ diff --git a/src/core/out.c b/src/core/out.c index 18ce25b78b7..b1276cb2166 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -20,9 +20,9 @@ #include "valgrind_internal.h" #include "util.h" #include "log_internal.h" -#include "error_msg.h" +#include "last_error_msg.h" -#define MAXPRINT CORE_ERROR_MSG_MAXPRINT +#define MAXPRINT CORE_LAST_ERROR_MSG_MAXPRINT static const char *Log_prefix; static int Log_level; @@ -146,7 +146,7 @@ out_init(const char *log_prefix, const char *log_level_var, CORE_LOG_ALWAYS("%s", ndctl_ge_63_msg); #endif - error_msg_init(); + last_error_msg_init(); } /* @@ -269,9 +269,9 @@ out_error(int use_errno, const char *file, int line, const char *func, const char *sep = ""; char errstr[UTIL_MAX_ERR_MSG] = ""; - char *errormsg = (char *)error_msg_get(); + char *last_error = (char *)last_error_msg_get(); - if (errormsg == NULL) { + if (last_error == NULL) { out_print_func("No memory to properly format error strings."); return; } @@ -290,13 +290,13 @@ out_error(int use_errno, const char *file, int line, const char *func, util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); } - ret = vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap); + ret = vsnprintf(&last_error[cc], MAXPRINT, fmt, ap); if (ret < 0) { - strcpy(errormsg, "vsnprintf failed"); + strcpy(last_error, "vsnprintf failed"); goto end; } cc += (unsigned)ret; - out_snprintf(&errormsg[cc], MAXPRINT - cc, "%s%s", + out_snprintf(&last_error[cc], MAXPRINT - cc, "%s%s", sep, errstr); } @@ -323,7 +323,7 @@ out_error(int use_errno, const char *file, int line, const char *func, } } - out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", errormsg, + out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", last_error, suffix); out_print_func(buf); diff --git a/src/core/pmemcore.h b/src/core/pmemcore.h index 4e25a53a7b2..5f68c308db4 100644 --- a/src/core/pmemcore.h +++ b/src/core/pmemcore.h @@ -10,7 +10,7 @@ #include "util.h" #include "out.h" -#include "error_msg.h" +#include "last_error_msg.h" #include "log_internal.h" #ifdef __cplusplus @@ -39,7 +39,7 @@ core_fini(void) { out_fini(); core_log_fini(); - error_msg_fini(); + last_error_msg_fini(); } #ifdef __cplusplus diff --git a/src/core/pmemcore.inc b/src/core/pmemcore.inc index 920cd398b48..4b7f36c0f16 100644 --- a/src/core/pmemcore.inc +++ b/src/core/pmemcore.inc @@ -33,7 +33,6 @@ SOURCE +=\ $(CORE)/alloc.c\ - $(CORE)/error_msg.c\ $(CORE)/fs_posix.c\ $(CORE)/os_posix.c\ $(CORE)/os_thread_posix.c\ @@ -42,6 +41,7 @@ SOURCE +=\ $(CORE)/ravl_interval.c\ $(CORE)/util.c\ $(CORE)/util_posix.c \ + $(CORE)/last_error_msg.c\ $(CORE)/log.c \ $(CORE)/log_default.c diff --git a/src/libpmem/Makefile b/src/libpmem/Makefile index 5ad7173e780..1e0a567128e 100644 --- a/src/libpmem/Makefile +++ b/src/libpmem/Makefile @@ -12,13 +12,13 @@ LIBRARY_SO_VERSION = 1 LIBRARY_VERSION = 0.0 SOURCE =\ $(CORE)/alloc.c\ - $(CORE)/error_msg.c\ $(CORE)/fs_posix.c\ $(CORE)/os_posix.c\ $(CORE)/os_thread_posix.c\ $(CORE)/out.c\ $(CORE)/util.c\ $(CORE)/util_posix.c\ + $(CORE)/last_error_msg.c\ $(CORE)/log.c\ $(CORE)/log_default.c\ $(COMMON)/file.c\ diff --git a/src/libpmem/libpmem.c b/src/libpmem/libpmem.c index f10ac6647ce..d2705f67cfb 100644 --- a/src/libpmem/libpmem.c +++ b/src/libpmem/libpmem.c @@ -56,14 +56,14 @@ pmem_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmem major version mismatch (need %u, found %u)", major_required, PMEM_MAJOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } if (minor_required > PMEM_MINOR_VERSION) { ERR_WO_ERRNO( "libpmem minor version mismatch (need %u, found %u)", minor_required, PMEM_MINOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } return NULL; @@ -79,17 +79,17 @@ pmem_check_version(unsigned major_required, unsigned minor_required) } /* - * pmem_errormsgU -- return last error message + * pmem_errormsgU -- return the last error message */ static inline const char * pmem_errormsgU(void) { - return error_msg_get(); + return last_error_msg_get(); } /* - * pmem_errormsg -- return last error message + * pmem_errormsg -- return the last error message */ const char * pmem_errormsg(void) diff --git a/src/libpmem2/errormsg.c b/src/libpmem2/errormsg.c index b14d22d6713..9146bf39345 100644 --- a/src/libpmem2/errormsg.c +++ b/src/libpmem2/errormsg.c @@ -10,17 +10,17 @@ #include "pmem2_utils.h" /* - * pmem2_errormsgU -- return last error message + * pmem2_errormsgU -- return the last error message */ static inline const char * pmem2_errormsgU(void) { - return error_msg_get(); + return last_error_msg_get(); } /* - * pmem2_errormsg -- return last error message + * pmem2_errormsg -- return the last error message */ const char * pmem2_errormsg(void) diff --git a/src/libpmem2/pmem2_utils.h b/src/libpmem2/pmem2_utils.h index 193bcde05a1..2a698f63f73 100644 --- a/src/libpmem2/pmem2_utils.h +++ b/src/libpmem2/pmem2_utils.h @@ -12,7 +12,7 @@ #include "os.h" #include "out.h" -#include "error_msg.h" +#include "last_error_msg.h" #include "source.h" static inline int @@ -33,7 +33,7 @@ pmem2_assert_errno(void) #define PMEM2_ERR_CLR() \ {\ errno = 0;\ - char *errormsg = (char *)error_msg_get();\ + char *errormsg = (char *)last_error_msg_get();\ strcpy(errormsg, "\0");\ } #else diff --git a/src/libpmemobj/libpmemobj.c b/src/libpmemobj/libpmemobj.c index 8d09adc305c..b289671c0e3 100644 --- a/src/libpmemobj/libpmemobj.c +++ b/src/libpmemobj/libpmemobj.c @@ -52,14 +52,14 @@ pmemobj_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmemobj major version mismatch (need %u, found %u)", major_required, PMEMOBJ_MAJOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } if (minor_required > PMEMOBJ_MINOR_VERSION) { ERR_WO_ERRNO( "libpmemobj minor version mismatch (need %u, found %u)", minor_required, PMEMOBJ_MINOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } return NULL; @@ -90,17 +90,17 @@ pmemobj_set_funcs( } /* - * pmemobj_errormsgU -- return last error message + * pmemobj_errormsgU -- return the last error message */ static inline const char * pmemobj_errormsgU(void) { - return error_msg_get(); + return last_error_msg_get(); } /* - * pmemobj_errormsg -- return last error message + * pmemobj_errormsg -- return the last error message */ const char * pmemobj_errormsg(void) diff --git a/src/libpmempool/libpmempool.c b/src/libpmempool/libpmempool.c index bbbd9c350ad..73413c8329a 100644 --- a/src/libpmempool/libpmempool.c +++ b/src/libpmempool/libpmempool.c @@ -59,14 +59,14 @@ pmempool_check_versionU(unsigned major_required, unsigned minor_required) ERR_WO_ERRNO( "libpmempool major version mismatch (need %u, found %u)", major_required, PMEMPOOL_MAJOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } if (minor_required > PMEMPOOL_MINOR_VERSION) { ERR_WO_ERRNO( "libpmempool minor version mismatch (need %u, found %u)", minor_required, PMEMPOOL_MINOR_VERSION); - return error_msg_get(); + return last_error_msg_get(); } return NULL; @@ -82,17 +82,17 @@ pmempool_check_version(unsigned major_required, unsigned minor_required) } /* - * pmempool_errormsgU -- return last error message + * pmempool_errormsgU -- return the last error message */ static inline const char * pmempool_errormsgU(void) { - return error_msg_get(); + return last_error_msg_get(); } /* - * pmempool_errormsg -- return last error message + * pmempool_errormsg -- return the last error message */ const char * pmempool_errormsg(void) diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index d3a3f50256b..f9f635758e4 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -394,8 +394,8 @@ ifeq ($(LIBPMEMCORE), internal-nondebug) USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/nondebug/core/alloc.o\ - $(TOP)/src/nondebug/core/error_msg.o\ $(TOP)/src/nondebug/core/fs_posix.o\ + $(TOP)/src/nondebug/core/last_error_msg.o\ $(TOP)/src/nondebug/core/log.o\ $(TOP)/src/nondebug/core/log_default.o\ $(TOP)/src/nondebug/core/os_posix.o\ @@ -413,8 +413,8 @@ ifeq ($(LIBPMEMCORE), internal-debug) USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/debug/core/alloc.o\ - $(TOP)/src/debug/core/error_msg.o\ $(TOP)/src/debug/core/fs_posix.o\ + $(TOP)/src/debug/core/last_error_msg.o\ $(TOP)/src/debug/core/log.o\ $(TOP)/src/debug/core/log_default.o\ $(TOP)/src/debug/core/os_posix.o\ @@ -544,8 +544,8 @@ endif # In case the binary is built with directly linking with core units it is # assumed the following are among them already. ifneq ($(USE_LOG_PMEMCORE),y) -OBJS += $(TOP)/src/debug/core/error_msg.o OBJS += $(TOP)/src/debug/core/out.o +OBJS += $(TOP)/src/debug/core/last_error_msg.o OBJS += $(TOP)/src/debug/core/log.o OBJS += $(TOP)/src/debug/core/log_default.o OBJS += $(TOP)/src/debug/core/util_posix.o diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index d652663108e..2c363c2350a 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -29,27 +29,27 @@ main(int argc, char *argv[]) errno = 0; ERR_WO_ERRNO("ERR #%d", 1); - UT_OUT("%s", error_msg_get()); + UT_OUT("%s", last_error_msg_get()); errno = 0; ERR_W_ERRNO("ERR #%d", 2); - UT_OUT("%s", error_msg_get()); + UT_OUT("%s", last_error_msg_get()); errno = EINVAL; ERR_W_ERRNO("ERR #%d", 3); - UT_OUT("%s", error_msg_get()); + UT_OUT("%s", last_error_msg_get()); errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); out_err(0, __FILE__, 100, __func__, "ERR1: %s:%d", buff, 1234); - UT_OUT("%s", error_msg_get()); + UT_OUT("%s", last_error_msg_get()); errno = EBADF; strerror_r(errno, buff, UT_MAX_ERR_MSG); out_err(0, NULL, 0, NULL, "ERR2: %s:%d", buff, 1234); - UT_OUT("%s", error_msg_get()); + UT_OUT("%s", last_error_msg_get()); /* Cleanup */ common_fini(); diff --git a/src/tools/pmempool/rm.c b/src/tools/pmempool/rm.c index 361c72b2976..aa106dd8c25 100644 --- a/src/tools/pmempool/rm.c +++ b/src/tools/pmempool/rm.c @@ -14,7 +14,7 @@ #include "os.h" #include "out.h" -#include "error_msg.h" +#include "last_error_msg.h" #include "common.h" #include "output.h" #include "file.h" @@ -170,7 +170,7 @@ rm_poolset(const char *file) int ret = util_poolset_foreach_part(file, rm_poolset_cb, &error); if (ret == -1) { outv_err("parsing poolset failed: %s\n", - error_msg_get()); + last_error_msg_get()); return ret; } From 0972b10f9a4c62277caf3fc5125b612a212718d5 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 8 Feb 2024 11:43:33 -0500 Subject: [PATCH 060/182] test: re-enable pmempool_transform[9,12] The test 9 needed no special treatment to just work. The test 12 needs just the kind of filtering other pmempool tests received. Ref: #5966 #5982 Signed-off-by: Jan Michalski --- src/test/pmempool_transform/TEST12 | 10 +++++++--- src/test/pmempool_transform/TEST9 | 3 --- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/pmempool_transform/TEST12 b/src/test/pmempool_transform/TEST12 index 7bc7fdf4280..29512532abb 100755 --- a/src/test/pmempool_transform/TEST12 +++ b/src/test/pmempool_transform/TEST12 @@ -10,9 +10,6 @@ # . ../unittest/unittest.sh -# disabled due to crash until #5982 is fixed -# https://github.com/pmem/pmdk/issues/5982 -DISABLED require_test_type medium require_fs_type any @@ -34,6 +31,7 @@ dax_device_zero LOG=out${UNITTEST_NUM}.log ERR_LOG=err${UNITTEST_NUM}.log LOG_TEMP=out${UNITTEST_NUM}_part.log +ERR_TEMP=err${UNITTEST_NUM}_temp.log rm -f $LOG && touch $LOG rm -f $LOG_TEMP && touch $LOG_TEMP @@ -107,6 +105,12 @@ dump_pool_info $POOLSET_2 >> $LOG_TEMP dump_pool_info ${DEVICE_DAX_PATH[0]} >> $LOG_TEMP mv $LOG_TEMP $LOG + +# Exclude error messages printed out on the stderr by PMDK in debug +mv $ERR_LOG $ERR_TEMP +grep -v "*ERROR*" $ERR_TEMP > $ERR_LOG +rm $ERR_TEMP + check pass diff --git a/src/test/pmempool_transform/TEST9 b/src/test/pmempool_transform/TEST9 index e778b5e5a32..b3089e9f058 100755 --- a/src/test/pmempool_transform/TEST9 +++ b/src/test/pmempool_transform/TEST9 @@ -9,9 +9,6 @@ # . ../unittest/unittest.sh -# disabled due to crash until #5982 is fixed -# https://github.com/pmem/pmdk/issues/5982 -DISABLED require_test_type medium require_dax_devices 2 From f7707e30891ed257c57c730e88133553ef2ac57c Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 8 Feb 2024 11:57:44 -0500 Subject: [PATCH 061/182] test: re-enable obj_tx_add_range[3] It seems to just passed away by itself. Ref: #5965 #5972 Signed-off-by: Jan Michalski --- src/test/obj_tx_add_range/TESTS.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/obj_tx_add_range/TESTS.py b/src/test/obj_tx_add_range/TESTS.py index 8f739cc5707..4a22c3220a8 100755 --- a/src/test/obj_tx_add_range/TESTS.py +++ b/src/test/obj_tx_add_range/TESTS.py @@ -38,9 +38,6 @@ def run(self, ctx): ctx.exec('obj_tx_add_range', testfile, '1') -# XXX disable test until issue #5972 is fixed -# https://github.com/pmem/pmdk/issues/5972 -@t.DISABLED() @t.require_valgrind_enabled('memcheck') @t.require_build('debug') class TEST3(t.Test): From f736f36c32275d01b4aa0ece2b17d5924a4a3095 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 8 Feb 2024 12:03:26 -0500 Subject: [PATCH 062/182] test: re-enable obj_tx_add_range_direct[2] It seems to just passed away by itself. Ref: #5965 #5974 Signed-off-by: Jan Michalski --- src/test/obj_tx_add_range_direct/TESTS.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/obj_tx_add_range_direct/TESTS.py b/src/test/obj_tx_add_range_direct/TESTS.py index cce27cf874d..b16aeb4127e 100755 --- a/src/test/obj_tx_add_range_direct/TESTS.py +++ b/src/test/obj_tx_add_range_direct/TESTS.py @@ -32,9 +32,6 @@ def run(self, ctx): ctx.exec('obj_tx_add_range_direct', testfile) -# XXX disable test until issue #5974 is fixed -# https://github.com/pmem/pmdk/issues/5974 -@t.DISABLED() @t.require_valgrind_enabled('memcheck') @t.require_build('debug') class TEST2(t.Test): From a4e313b56dd863ab7ba8ae35587f467d41f8364b Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 6 Feb 2024 11:49:19 -0500 Subject: [PATCH 063/182] common: CORE_LOG_ERROR_WITH_ERRNO -> _W_ERRNO Signed-off-by: Jan Michalski --- src/common/os_deep_linux.c | 4 ++-- src/common/uuid_linux.c | 4 ++-- src/core/log_internal.h | 4 ++-- src/core/out.h | 2 +- src/libpmem2/auto_flush_linux.c | 2 +- src/libpmem2/deep_flush_linux.c | 4 ++-- src/libpmemobj/obj.c | 6 +++--- src/test/log_errno/TEST0 | 2 +- src/test/log_errno/log_errno.c | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/os_deep_linux.c b/src/common/os_deep_linux.c index ce5dc011d04..c9185c24467 100644 --- a/src/common/os_deep_linux.c +++ b/src/common/os_deep_linux.c @@ -35,7 +35,7 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len) if (ret < 0) { if (ret == PMEM2_E_NOSUPP) { errno = ENOTSUP; - CORE_LOG_ERROR_WITH_ERRNO( + CORE_LOG_ERROR_W_ERRNO( "deep_flush not supported"); } else { errno = pmem2_err_to_errno(ret); @@ -153,7 +153,7 @@ os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr, if (ret < 0) { if (errno == ENOENT) { errno = ENOTSUP; - CORE_LOG_ERROR_WITH_ERRNO( + CORE_LOG_ERROR_W_ERRNO( "deep_flush not supported"); } else { CORE_LOG_ERROR("invalid dax_region id %u", diff --git a/src/common/uuid_linux.c b/src/common/uuid_linux.c index 82d0a8dbcb7..43a9291cefd 100644 --- a/src/common/uuid_linux.c +++ b/src/common/uuid_linux.c @@ -28,13 +28,13 @@ util_uuid_generate(uuid_t uuid) int fd = os_open(POOL_HDR_UUID_GEN_FILE, O_RDONLY); if (fd < 0) { /* Fatal error */ - CORE_LOG_ERROR_WITH_ERRNO("open(uuid)"); + CORE_LOG_ERROR_W_ERRNO("open(uuid)"); return -1; } ssize_t num = read(fd, uu, POOL_HDR_UUID_STR_LEN); if (num < POOL_HDR_UUID_STR_LEN) { /* Fatal error */ - CORE_LOG_ERROR_WITH_ERRNO("read(uuid)"); + CORE_LOG_ERROR_W_ERRNO("read(uuid)"); os_close(fd); return -1; } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 33804af712d..91f2bdbc9ca 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -174,14 +174,14 @@ void core_log_default_function(void *context, enum core_log_level level, * additional arguments. */ #ifdef _GNU_SOURCE -#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \ +#define CORE_LOG_ERROR_W_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ } while (0) #else -#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \ +#define CORE_LOG_ERROR_W_ERRNO(format, ...) \ do { \ char buff[CORE_LOG_MAX_ERR_MSG]; \ uint64_t ret = (uint64_t)strerror_r(errno, buff, \ diff --git a/src/core/out.h b/src/core/out.h index eba7ec2598f..a892ed0fef3 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -168,7 +168,7 @@ out_nonl_discard(int level, const char *fmt, ...) #define ERR_W_ERRNO(f, ...)\ do {\ ERR(1, "*" f, ##__VA_ARGS__);\ - CORE_LOG_ERROR_WITH_ERRNO(f, ##__VA_ARGS__);\ + CORE_LOG_ERROR_W_ERRNO(f, ##__VA_ARGS__);\ } while (0) #define ERR_WO_ERRNO(f, ...)\ diff --git a/src/libpmem2/auto_flush_linux.c b/src/libpmem2/auto_flush_linux.c index ebe0fe84323..944f4e0da65 100644 --- a/src/libpmem2/auto_flush_linux.c +++ b/src/libpmem2/auto_flush_linux.c @@ -34,7 +34,7 @@ check_cpu_cache(const char *domain_path) int cpu_cache = 0; if ((domain_fd = os_open(domain_path, O_RDONLY)) < 0) { - CORE_LOG_ERROR_WITH_ERRNO("open(\"%s\", O_RDONLY)", + CORE_LOG_ERROR_W_ERRNO("open(\"%s\", O_RDONLY)", domain_path); goto end; } diff --git a/src/libpmem2/deep_flush_linux.c b/src/libpmem2/deep_flush_linux.c index 44b98ada5dc..df625db08cf 100644 --- a/src/libpmem2/deep_flush_linux.c +++ b/src/libpmem2/deep_flush_linux.c @@ -39,13 +39,13 @@ pmem2_deep_flush_write(unsigned region_id) } if ((deep_flush_fd = os_open(deep_flush_path, O_RDONLY)) < 0) { - CORE_LOG_ERROR_WITH_ERRNO("os_open(\"%s\", O_RDONLY)", + CORE_LOG_ERROR_W_ERRNO("os_open(\"%s\", O_RDONLY)", deep_flush_path); return 0; } if (read(deep_flush_fd, rbuf, sizeof(rbuf)) != 2) { - CORE_LOG_ERROR_WITH_ERRNO("read(%d)", deep_flush_fd); + CORE_LOG_ERROR_W_ERRNO("read(%d)", deep_flush_fd); goto end; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 077a6f581ba..90b69825c76 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -87,7 +87,7 @@ obj_ctl_init_and_load(PMEMobjpool *pop) LOG(3, "pop %p", pop); if (pop != NULL && (pop->ctl = ctl_new()) == NULL) { - CORE_LOG_ERROR_WITH_ERRNO("ctl_new"); + CORE_LOG_ERROR_W_ERRNO("ctl_new"); return -1; } @@ -1186,7 +1186,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) } if ((errno = lane_check(pop)) != 0) { - CORE_LOG_ERROR_WITH_ERRNO("lane_check"); + CORE_LOG_ERROR_W_ERRNO("lane_check"); consistent = 0; } @@ -1195,7 +1195,7 @@ obj_check_basic_local(PMEMobjpool *pop, size_t mapped_size) errno = palloc_heap_check((char *)pop + pop->heap_offset, heap_size); if (errno != 0) { - CORE_LOG_ERROR_WITH_ERRNO("heap_check"); + CORE_LOG_ERROR_W_ERRNO("heap_check"); consistent = 0; } diff --git a/src/test/log_errno/TEST0 b/src/test/log_errno/TEST0 index 2cc70cc5569..8e873718163 100755 --- a/src/test/log_errno/TEST0 +++ b/src/test/log_errno/TEST0 @@ -3,7 +3,7 @@ # Copyright 2024, Intel Corporation # -# src/test/log_errno/TEST0 -- unit test for CORE_LOG_ERROR_WITH_ERRNO macro +# src/test/log_errno/TEST0 -- unit test for CORE_LOG_ERROR_W_ERRNO macro # . ../unittest/unittest.sh diff --git a/src/test/log_errno/log_errno.c b/src/test/log_errno/log_errno.c index 38c4ea190ed..251e7cdd264 100644 --- a/src/test/log_errno/log_errno.c +++ b/src/test/log_errno/log_errno.c @@ -2,7 +2,7 @@ /* Copyright 2024, Intel Corporation */ /* - * log_errno.c -- unit test for CORE_LOG_ERROR_WITH_ERRNO macro + * log_errno.c -- unit test for CORE_LOG_ERROR_W_ERRNO macro */ #include @@ -15,7 +15,7 @@ main(int argc, char *argv[]) START(argc, argv, "log_errno"); core_log_init(); - CORE_LOG_ERROR_WITH_ERRNO("open file %s", "lolek"); + CORE_LOG_ERROR_W_ERRNO("open file %s", "lolek"); core_log_fini(); /* * The fini function above intentionally does not close the syslog From cd4b6f8ec61afc8b03869420c29ab7a62ef44675 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 6 Feb 2024 13:07:55 -0500 Subject: [PATCH 064/182] core: refactor CORE_LOG_*_W_ERRNO macros Signed-off-by: Jan Michalski --- src/core/log_internal.h | 104 +++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 91f2bdbc9ca..b295d46a3fb 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -114,9 +114,33 @@ void core_log_fini(void); #define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1) -void core_log_default_function(void *context, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, - const char *message_format, ...); +/* + * Required to handle both variants' return types. + * The ideal solution would be to force using one variant or another. + */ +#ifdef _GNU_SOURCE +#define _CORE_LOG_STRERROR_R(buf, buf_len, out) \ + do { \ + char *ret = strerror_r(errno, (buf), (buf_len)); \ + *(out) = ret; \ + } while (0) +#else +#define _CORE_LOG_STRERROR_R(buf, buf_len, out) \ + do { \ + int ret = strerror_r(errno, (buf), (buf_len)); \ + (void) ret; \ + *(out) = buf; \ + } while (0) +#endif + +#define _CORE_LOG_STRERROR(buf, buf_len, out) \ + do { \ + int oerrno = errno; \ + _CORE_LOG_STRERROR_R((buf), (buf_len), (out)); \ + errno = oerrno; \ + } while (0) + +#define CORE_LOG_MAX_ERR_MSG 128 /* * Set of macros that should be used as the primary API for logging. @@ -143,73 +167,41 @@ void core_log_default_function(void *context, enum core_log_level level, abort(); \ } while (0) -#define CORE_LOG_MAX_ERR_MSG 128 -#ifdef _GNU_SOURCE -#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ - do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ - strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ - abort(); \ - } while (0) -#else -#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ - do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - uint64_t ret = (uint64_t)strerror_r(errno, buff, \ - CORE_LOG_MAX_ERR_MSG); \ - ret = ret; \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ - buff); \ - abort(); \ - } while (0) -#endif - #define CORE_LOG_ALWAYS(format, ...) \ CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) /* - * Replacement for ERR("!*") macro (w/ errno). - * 'f' stands here for 'function' or 'format' where the latter may accept - * additional arguments. + * 'With errno' macros' flavours. Append string describing the current errno + * value. */ -#ifdef _GNU_SOURCE -#define CORE_LOG_ERROR_W_ERRNO(format, ...) \ + +#define CORE_LOG_WARNING_W_ERRNO(format, ...) \ do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ - strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ + char buf[CORE_LOG_MAX_ERR_MSG]; \ + char *error_str; \ + _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ + CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ + error_str); \ } while (0) -#else + #define CORE_LOG_ERROR_W_ERRNO(format, ...) \ do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - uint64_t ret = (uint64_t)strerror_r(errno, buff, \ - CORE_LOG_MAX_ERR_MSG); \ - ret = ret; \ + char buf[CORE_LOG_MAX_ERR_MSG]; \ + char *error_str; \ + _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ - buff); \ + error_str); \ } while (0) -#endif -#ifdef _GNU_SOURCE -#define CORE_LOG_WARNING_W_ERRNO(format, ...) \ - do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ - strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ - } while (0) -#else -#define CORE_LOG_WARNING_W_ERRNO(format, ...) \ +#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ do { \ - char buff[CORE_LOG_MAX_ERR_MSG]; \ - uint64_t ret = (uint64_t)strerror_r(errno, buff, \ - CORE_LOG_MAX_ERR_MSG); \ - ret = ret; \ - CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ - buff); \ + char buf[CORE_LOG_MAX_ERR_MSG]; \ + char *error_str; \ + _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ + error_str); \ + abort(); \ } while (0) -#endif static inline int core_log_error_translate(int ret) From c8662de46bfcc3f4d6bbe94164f51edcb8f6531c Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 7 Feb 2024 15:31:58 -0500 Subject: [PATCH 065/182] common: do not call ERR() just to write to TLS - introduce CORE_LOG_ERROR_(W_ERRNO_)LAST macros - targeting the last error message TLS buffer instead of a buffer allocated on stack - before calling the logging function: - process message format - add 'extern "C"' to the log_internal.h header to work properly with pmembench - ERR_W(O)_ERRNO to just call CORE_LOG_ERROR(_W_ERRNO)_LAST Signed-off-by: Jan Michalski --- src/core/log.c | 55 +++++++++++++++++++++++++++ src/core/log_default.c | 11 +----- src/core/log_default.h | 2 +- src/core/log_internal.h | 73 +++++++++++++++++++++++++++--------- src/core/out.c | 13 +------ src/core/out.h | 10 +---- src/test/unittest/unittest.h | 2 +- src/test/unittest/ut_log.c | 10 ++--- 8 files changed, 120 insertions(+), 56 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 7ee2208152e..1575bfb1553 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -14,9 +14,11 @@ #include #endif /* ATOMIC_OPERATIONS_SUPPORTED */ #include +#include #include "log_internal.h" #include "log_default.h" +#include "last_error_msg.h" /* * Default levels of the logging thresholds @@ -181,3 +183,56 @@ core_log_get_threshold(enum core_log_threshold threshold, return 0; } + +static void inline +core_log_va(char *buf, size_t buf_len, enum core_log_level level, + const char *file_name, int line_no, const char *function_name, + const char *message_format, va_list arg) +{ + if (vsnprintf(buf, buf_len, message_format, arg) < 0) { + return; + } + + /* + * Despite this check is already done when the function is called from + * the CORE_LOG() macro it has to be done here again since it is not + * performed in the case of the CORE_LOG_TO_LAST macro. Sorry. + */ + if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) { + return; + } + + if (0 == Core_log_function) { + return; + } + + ((core_log_function *)Core_log_function)(Core_log_function_context, + level, file_name, line_no, function_name, buf); +} + +void +core_log(enum core_log_level level, const char *file_name, int line_no, + const char *function_name, const char *message_format, ...) +{ + char message[1024] = ""; + va_list arg; + + va_start(arg, message_format); + core_log_va(message, sizeof(message), level, file_name, line_no, + function_name, message_format, arg); + va_end(arg); +} + +void +core_log_to_last(const char *file_name, int line_no, const char *function_name, + const char *message_format, ...) +{ + char *last_error = (char *)last_error_msg_get(); + va_list arg; + + va_start(arg, message_format); + core_log_va(last_error, CORE_LAST_ERROR_MSG_MAXPRINT, + CORE_LOG_LEVEL_ERROR, file_name, line_no, function_name, + message_format, arg); + va_end(arg); +} diff --git a/src/core/log_default.c b/src/core/log_default.c index 7b613203725..e19c394589c 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -98,13 +98,12 @@ get_timestamp_prefix(char *buf, size_t buf_size) void core_log_default_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, - const char *message_format, ...) + const char *message) { SUPPRESS_UNUSED(context); char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; - char message[1024] = ""; const char file_info_error[] = "[file info error]: "; bool is_always = false; @@ -116,14 +115,6 @@ core_log_default_function(void *context, enum core_log_level level, level = CORE_LOG_LEVEL_NOTICE; } - va_list arg; - va_start(arg, message_format); - if (vsnprintf(message, sizeof(message), message_format, arg) < 0) { - va_end(arg); - return; - } - va_end(arg); - if (file_name) { /* extract base_file_name */ const char *base_file_name = strrchr(file_name, '/'); diff --git a/src/core/log_default.h b/src/core/log_default.h index 613e0e594c9..c7bdde7023b 100644 --- a/src/core/log_default.h +++ b/src/core/log_default.h @@ -10,7 +10,7 @@ void core_log_default_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, - const char *message_format, ...); + const char *message); void core_log_default_init(void); diff --git a/src/core/log_internal.h b/src/core/log_internal.h index b295d46a3fb..33c75c97d1c 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -17,6 +17,11 @@ #include #endif /* ATOMIC_OPERATIONS_SUPPORTED */ +/* Required to work properly with pmembench. */ +#ifdef __cplusplus +extern "C" { +#endif + enum core_log_level { /* all messages will be suppressed */ CORE_LOG_DISABLED = -1, @@ -34,6 +39,9 @@ enum core_log_level { CORE_LOG_LEVEL_DEBUG, }; +/* Not meant to be used directly. */ +#define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1) + enum core_log_threshold { /* * the main threshold level - the logging messages above this level @@ -68,10 +76,8 @@ typedef void core_log_function( const int line_no, /* the function name where the message coming from */ const char *function_name, - /* printf(3)-like format string of the message */ - const char *message_format, - /* additional arguments of the message format string */ - ...); + /* message */ + const char *message); #define CORE_LOG_USE_DEFAULT_FUNCTION (NULL) @@ -102,17 +108,38 @@ void core_log_init(void); void core_log_fini(void); +static inline int +core_log_error_translate(int ret) +{ + if (ret != 0) { + errno = ret; + return 1; + } + + return 0; +} + +void core_log(enum core_log_level level, const char *file_name, int line_no, + const char *function_name, const char *message_format, ...); + +/* Only error messages can last. So, no level has to be specified. */ +void core_log_to_last(const char *file_name, int line_no, + const char *function_name, const char *message_format, ...); + #define CORE_LOG(level, format, ...) \ do { \ - if (level <= Core_log_threshold[CORE_LOG_THRESHOLD] && \ - 0 != Core_log_function) { \ - ((core_log_function *)Core_log_function)( \ - Core_log_function_context, level, __FILE__, \ - __LINE__, __func__, format, ##__VA_ARGS__); \ + if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ + core_log(level, __FILE__, __LINE__, __func__, \ + format, ##__VA_ARGS__); \ } \ } while (0) -#define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1) +/* + * Can't check the logging level here when logging to the last error message. + * Since the log message has to be generated anyway. + */ +#define CORE_LOG_TO_LAST(format, ...) \ + core_log_to_last(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__) /* * Required to handle both variants' return types. @@ -203,15 +230,25 @@ void core_log_fini(void); abort(); \ } while (0) -static inline int -core_log_error_translate(int ret) -{ - if (ret != 0) { - errno = ret; - return 1; - } +/* + * 'Last' macros' flavours. Additionally writes the produced error message + * to the last error message's TLS buffer making it available to the end user + * via the *_errormsg() API calls. + */ - return 0; +#define CORE_LOG_ERROR_LAST(format, ...) \ + CORE_LOG_TO_LAST(format, ##__VA_ARGS__) + +#define CORE_LOG_ERROR_W_ERRNO_LAST(format, ...) \ + do { \ + char buf[CORE_LOG_MAX_ERR_MSG]; \ + char *error_str; \ + _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ + CORE_LOG_TO_LAST(format ": %s", ##__VA_ARGS__, error_str); \ + } while (0) + +#ifdef __cplusplus } +#endif #endif /* CORE_LOG_INTERNAL_H */ diff --git a/src/core/out.c b/src/core/out.c index b1276cb2166..b55142e6906 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -264,7 +264,6 @@ out_error(int use_errno, const char *file, int line, const char *func, if (use_errno) oerrno = errno; unsigned cc = 0; - unsigned print_msg = 1; int ret; const char *sep = ""; char errstr[UTIL_MAX_ERR_MSG] = ""; @@ -277,14 +276,6 @@ out_error(int use_errno, const char *file, int line, const char *func, } if (fmt) { - /* - * '*' at the begining means 'do not push message to output' - */ - if (*fmt == '*') { - print_msg = 0; - fmt++; - } - if (use_errno) { sep = ": "; util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); @@ -301,7 +292,7 @@ out_error(int use_errno, const char *file, int line, const char *func, } #ifdef DEBUG - if (Log_level >= 1 && print_msg) { + if (Log_level >= 1) { char buf[MAXPRINT]; cc = 0; @@ -330,7 +321,7 @@ out_error(int use_errno, const char *file, int line, const char *func, } #else /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, suffix, print_msg); + SUPPRESS_UNUSED(file, line, func, suffix); #endif end: diff --git a/src/core/out.h b/src/core/out.h index a892ed0fef3..78ffc0c8bb8 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -166,16 +166,10 @@ out_nonl_discard(int level, const char *fmt, ...) out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ - do {\ - ERR(1, "*" f, ##__VA_ARGS__);\ - CORE_LOG_ERROR_W_ERRNO(f, ##__VA_ARGS__);\ - } while (0) + CORE_LOG_ERROR_W_ERRNO_LAST(f, ##__VA_ARGS__) #define ERR_WO_ERRNO(f, ...)\ - do {\ - ERR(0, "*" f, ##__VA_ARGS__);\ - CORE_LOG_ERROR(f, ##__VA_ARGS__);\ - } while (0) + CORE_LOG_ERROR_LAST(f, ##__VA_ARGS__) void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 0874996ccd7..2c0f89e706d 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -123,7 +123,7 @@ void ut_err(const char *file, int line, const char *func, void ut_log_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, - const char *message_format, ...); + const char *message); #ifdef USE_LOG_PMEMCORE #define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL) diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c index 76767d01cd2..bd6fa87ba37 100644 --- a/src/test/unittest/ut_log.c +++ b/src/test/unittest/ut_log.c @@ -20,15 +20,11 @@ static const int core_log_level_to_out_level[] = { void ut_log_function(void *context, enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, - const char *message_format, ...) + const int line_no, const char *function_name, const char *message) { if (level == CORE_LOG_LEVEL_ALWAYS) level = CORE_LOG_LEVEL_ERROR; - va_list arg; - va_start(arg, message_format); - out_log_va(file_name, line_no, function_name, - core_log_level_to_out_level[(int)level], message_format, arg); - va_end(arg); + out_log(file_name, line_no, function_name, + core_log_level_to_out_level[(int)level], "%s", message); } From 0fdeb5568d31709fe76f96f6983140152399733e Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 12 Feb 2024 09:07:59 -0500 Subject: [PATCH 066/182] core: deduplicate core log definitions and... ... prepend all non-interfacial definitions with '_'. Signed-off-by: Jan Michalski --- src/core/log_internal.h | 55 +++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 33c75c97d1c..dde6c9c01db 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -126,7 +126,7 @@ void core_log(enum core_log_level level, const char *file_name, int line_no, void core_log_to_last(const char *file_name, int line_no, const char *function_name, const char *message_format, ...); -#define CORE_LOG(level, format, ...) \ +#define _CORE_LOG(level, format, ...) \ do { \ if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ core_log(level, __FILE__, __LINE__, __func__, \ @@ -167,35 +167,43 @@ void core_log_to_last(const char *file_name, int line_no, errno = oerrno; \ } while (0) -#define CORE_LOG_MAX_ERR_MSG 128 +#define _CORE_LOG_MAX_ERR_MSG 128 + +#define _CORE_LOG_W_ERRNO(level, format, ...) \ + do { \ + char buf[_CORE_LOG_MAX_ERR_MSG]; \ + char *error_str; \ + _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERR_MSG, &error_str); \ + _CORE_LOG(level, format ": %s", ##__VA_ARGS__, error_str); \ + } while (0) /* * Set of macros that should be used as the primary API for logging. * Direct call to log shall be used only in exceptional, corner cases. */ #define CORE_LOG_DEBUG(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) #define CORE_LOG_INFO(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_INFO, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_INFO, format, ##__VA_ARGS__) #define CORE_LOG_NOTICE(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_NOTICE, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_NOTICE, format, ##__VA_ARGS__) #define CORE_LOG_WARNING(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) #define CORE_LOG_ERROR(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL(format, ...) \ do { \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__); \ + _CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__); \ abort(); \ } while (0) #define CORE_LOG_ALWAYS(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) /* * 'With errno' macros' flavours. Append string describing the current errno @@ -203,32 +211,13 @@ void core_log_to_last(const char *file_name, int line_no, */ #define CORE_LOG_WARNING_W_ERRNO(format, ...) \ - do { \ - char buf[CORE_LOG_MAX_ERR_MSG]; \ - char *error_str; \ - _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ - CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \ - error_str); \ - } while (0) + _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) #define CORE_LOG_ERROR_W_ERRNO(format, ...) \ - do { \ - char buf[CORE_LOG_MAX_ERR_MSG]; \ - char *error_str; \ - _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ - CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \ - error_str); \ - } while (0) + _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL_W_ERRNO(format, ...) \ - do { \ - char buf[CORE_LOG_MAX_ERR_MSG]; \ - char *error_str; \ - _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ - error_str); \ - abort(); \ - } while (0) + _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) /* * 'Last' macros' flavours. Additionally writes the produced error message @@ -241,9 +230,9 @@ void core_log_to_last(const char *file_name, int line_no, #define CORE_LOG_ERROR_W_ERRNO_LAST(format, ...) \ do { \ - char buf[CORE_LOG_MAX_ERR_MSG]; \ + char buf[_CORE_LOG_MAX_ERR_MSG]; \ char *error_str; \ - _CORE_LOG_STRERROR(buf, CORE_LOG_MAX_ERR_MSG, &error_str); \ + _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERR_MSG, &error_str); \ CORE_LOG_TO_LAST(format ": %s", ##__VA_ARGS__, error_str); \ } while (0) From 5a2bf23248eaa5d0cdaf98106eda27c199e5fcdd Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 7 Feb 2024 18:03:50 -0500 Subject: [PATCH 067/182] common: extract core_log aliases and core_asserts Signed-off-by: Jan Michalski --- src/core/core_assert.h | 112 ++++++++++++++++++++++++++++++++++++ src/core/log_internal.h | 8 +++ src/core/out.h | 107 +--------------------------------- src/libpmem2/errormsg.c | 2 + src/tools/pmempool/output.c | 2 +- 5 files changed, 124 insertions(+), 107 deletions(-) create mode 100644 src/core/core_assert.h diff --git a/src/core/core_assert.h b/src/core/core_assert.h new file mode 100644 index 00000000000..fdcfeaafc14 --- /dev/null +++ b/src/core/core_assert.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2014-2024, Intel Corporation */ + +/* + * core_assert.h -- definitions for the "core_assert" module + */ + +#ifndef CORE_ASSERT_H +#define CORE_ASSERT_H + +#include "log_internal.h" +#include "util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__KLOCWORK__) +#define TEST_ALWAYS_TRUE_EXPR(cnd) +#define TEST_ALWAYS_EQ_EXPR(cnd) +#define TEST_ALWAYS_NE_EXPR(cnd) +#else +#define TEST_ALWAYS_TRUE_EXPR(cnd)\ + if (__builtin_constant_p(cnd))\ + ASSERT_COMPILE_ERROR_ON(cnd); +#define TEST_ALWAYS_EQ_EXPR(lhs, rhs)\ + if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\ + ASSERT_COMPILE_ERROR_ON((lhs) == (rhs)); +#define TEST_ALWAYS_NE_EXPR(lhs, rhs)\ + if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\ + ASSERT_COMPILE_ERROR_ON((lhs) != (rhs)); +#endif + +/* assert a condition is true at runtime */ +#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ + defined(__KLOCWORK__) +#define ASSERT_rt(cnd) do { \ + if ((cnd)) break; \ + CORE_LOG_FATAL("assertion failure: %s", #cnd);\ +} while (0) + +/* assertion with extra info printed if assertion fails at runtime */ +#define ASSERTinfo_rt(cnd, info) do { \ + if ((cnd)) break; \ + CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ +} while (0) + +/* assert two integer values are equal at runtime */ +#define ASSERTeq_rt(lhs, rhs) do { \ + if ((lhs) == (rhs)) break; \ + CORE_LOG_FATAL( \ + "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs, \ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ +} while (0) + +/* assert two integer values are not equal at runtime */ +#define ASSERTne_rt(lhs, rhs) do { \ + if ((lhs) != (rhs)) break; \ + CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ +} while (0) + +/* assert a condition is true */ +#define ASSERT(cnd)\ + do {\ + /*\ + * Detect useless asserts on always true expression. Please use\ + * COMPILE_ERROR_ON(!cnd) or ASSERT_rt(cnd) in such cases.\ + */\ + TEST_ALWAYS_TRUE_EXPR(cnd);\ + ASSERT_rt(cnd);\ + } while (0) + +/* assertion with extra info printed if assertion fails */ +#define ASSERTinfo(cnd, info)\ + do {\ + /* See comment in ASSERT. */\ + TEST_ALWAYS_TRUE_EXPR(cnd);\ + ASSERTinfo_rt(cnd, info);\ + } while (0) + +/* assert two integer values are equal */ +#define ASSERTeq(lhs, rhs)\ + do {\ + /* See comment in ASSERT. */\ + TEST_ALWAYS_EQ_EXPR(lhs, rhs);\ + ASSERTeq_rt(lhs, rhs);\ + } while (0) + +/* assert two integer values are not equal */ +#define ASSERTne(lhs, rhs)\ + do {\ + /* See comment in ASSERT. */\ + TEST_ALWAYS_NE_EXPR(lhs, rhs);\ + ASSERTne_rt(lhs, rhs);\ + } while (0) +#else +#define ASSERT_rt(cnd) +#define ASSERTinfo_rt(cnd, info) +#define ASSERTeq_rt(lhs, rhs) +#define ASSERTne_rt(lhs, rhs) +#define ASSERT(cnd) +#define ASSERTinfo(cnd, info) +#define ASSERTeq(lhs, rhs) +#define ASSERTne(lhs, rhs) +#endif /* DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* CORE_ASSERT_H */ diff --git a/src/core/log_internal.h b/src/core/log_internal.h index dde6c9c01db..d2919dbb2eb 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -236,6 +236,14 @@ void core_log_to_last(const char *file_name, int line_no, CORE_LOG_TO_LAST(format ": %s", ##__VA_ARGS__, error_str); \ } while (0) +/* Aliases */ + +#define ERR_W_ERRNO(f, ...)\ + CORE_LOG_ERROR_W_ERRNO_LAST(f, ##__VA_ARGS__) + +#define ERR_WO_ERRNO(f, ...)\ + CORE_LOG_ERROR_LAST(f, ##__VA_ARGS__) + #ifdef __cplusplus } #endif diff --git a/src/core/out.h b/src/core/out.h index 78ffc0c8bb8..19e379a4eea 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -8,12 +8,8 @@ #ifndef PMDK_OUT_H #define PMDK_OUT_H 1 -#include -#include -#include - #include "util.h" -#include "log_internal.h" +#include "core_assert.h" #ifdef __cplusplus extern "C" { @@ -34,10 +30,8 @@ extern "C" { /* klocwork does not seem to respect __attribute__((noreturn)) */ #if defined(DEBUG) || defined(__KLOCWORK__) - #define OUT_LOG out_log #define OUT_NONL out_nonl - #else static __attribute__((always_inline)) inline void @@ -60,22 +54,6 @@ out_nonl_discard(int level, const char *fmt, ...) #endif -#if defined(__KLOCWORK__) -#define TEST_ALWAYS_TRUE_EXPR(cnd) -#define TEST_ALWAYS_EQ_EXPR(cnd) -#define TEST_ALWAYS_NE_EXPR(cnd) -#else -#define TEST_ALWAYS_TRUE_EXPR(cnd)\ - if (__builtin_constant_p(cnd))\ - ASSERT_COMPILE_ERROR_ON(cnd); -#define TEST_ALWAYS_EQ_EXPR(lhs, rhs)\ - if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\ - ASSERT_COMPILE_ERROR_ON((lhs) == (rhs)); -#define TEST_ALWAYS_NE_EXPR(lhs, rhs)\ - if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\ - ASSERT_COMPILE_ERROR_ON((lhs) != (rhs)); -#endif - /* produce debug/trace output */ #define LOG(level, ...) do { \ if (!EVALUATE_DBG_EXPRESSIONS) break;\ @@ -88,89 +66,6 @@ out_nonl_discard(int level, const char *fmt, ...) OUT_NONL(level, __VA_ARGS__); \ } while (0) -/* assert a condition is true at runtime */ -#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ - defined(__KLOCWORK__) -#define ASSERT_rt(cnd) do { \ - if ((cnd)) break; \ - CORE_LOG_FATAL("assertion failure: %s", #cnd);\ -} while (0) - -/* assertion with extra info printed if assertion fails at runtime */ -#define ASSERTinfo_rt(cnd, info) do { \ - if ((cnd)) break; \ - CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ -} while (0) - -/* assert two integer values are equal at runtime */ -#define ASSERTeq_rt(lhs, rhs) do { \ - if ((lhs) == (rhs)) break; \ - CORE_LOG_FATAL( \ - "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs, \ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ -} while (0) - -/* assert two integer values are not equal at runtime */ -#define ASSERTne_rt(lhs, rhs) do { \ - if ((lhs) != (rhs)) break; \ - CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ -} while (0) - -/* assert a condition is true */ -#define ASSERT(cnd)\ - do {\ - /*\ - * Detect useless asserts on always true expression. Please use\ - * COMPILE_ERROR_ON(!cnd) or ASSERT_rt(cnd) in such cases.\ - */\ - TEST_ALWAYS_TRUE_EXPR(cnd);\ - ASSERT_rt(cnd);\ - } while (0) - -/* assertion with extra info printed if assertion fails */ -#define ASSERTinfo(cnd, info)\ - do {\ - /* See comment in ASSERT. */\ - TEST_ALWAYS_TRUE_EXPR(cnd);\ - ASSERTinfo_rt(cnd, info);\ - } while (0) - -/* assert two integer values are equal */ -#define ASSERTeq(lhs, rhs)\ - do {\ - /* See comment in ASSERT. */\ - TEST_ALWAYS_EQ_EXPR(lhs, rhs);\ - ASSERTeq_rt(lhs, rhs);\ - } while (0) - -/* assert two integer values are not equal */ -#define ASSERTne(lhs, rhs)\ - do {\ - /* See comment in ASSERT. */\ - TEST_ALWAYS_NE_EXPR(lhs, rhs);\ - ASSERTne_rt(lhs, rhs);\ - } while (0) -#else -#define ASSERT_rt(cnd) -#define ASSERTinfo_rt(cnd, info) -#define ASSERTeq_rt(lhs, rhs) -#define ASSERTne_rt(lhs, rhs) -#define ASSERT(cnd) -#define ASSERTinfo(cnd, info) -#define ASSERTeq(lhs, rhs) -#define ASSERTne(lhs, rhs) -#endif /* DEBUG */ - -#define ERR(use_errno, ...)\ - out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) - -#define ERR_W_ERRNO(f, ...)\ - CORE_LOG_ERROR_W_ERRNO_LAST(f, ##__VA_ARGS__) - -#define ERR_WO_ERRNO(f, ...)\ - CORE_LOG_ERROR_LAST(f, ##__VA_ARGS__) - void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version); diff --git a/src/libpmem2/errormsg.c b/src/libpmem2/errormsg.c index 9146bf39345..48303b43adf 100644 --- a/src/libpmem2/errormsg.c +++ b/src/libpmem2/errormsg.c @@ -5,6 +5,8 @@ * errormsg.c -- pmem2_errormsg* implementation */ +#include + #include "libpmem2.h" #include "out.h" #include "pmem2_utils.h" diff --git a/src/tools/pmempool/output.c b/src/tools/pmempool/output.c index 19b2527464a..f1ed75b5bd1 100644 --- a/src/tools/pmempool/output.c +++ b/src/tools/pmempool/output.c @@ -774,7 +774,7 @@ out_get_incompat_features_str(uint32_t incompat) /* print the value and the left square bracket */ ret = util_snprintf(str_buff, STR_MAX, "0x%x [", incompat); if (ret < 0) { - ERR(0, "snprintf for incompat features: %d", ret); + ERR_WO_ERRNO("snprintf for incompat features: %d", ret); return ""; } From 4a3be8a5cba917afd185c9c9b23fc2e52ae2e3ab Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 7 Feb 2024 18:39:11 -0500 Subject: [PATCH 068/182] common: remove core_assert.h from out.h Signed-off-by: Jan Michalski --- src/common/bad_blocks.c | 1 + src/common/ctl.c | 1 + src/common/mmap_posix.c | 2 +- src/common/pool_hdr.c | 1 + src/common/set.h | 4 ++-- src/common/util_pmem.h | 1 + src/common/uuid.c | 3 ++- src/common/uuid_linux.c | 2 +- src/common/vec.h | 2 +- src/core/alloc.c | 3 ++- src/core/last_error_msg.c | 2 +- src/core/out.h | 1 - src/core/ravl.c | 2 ++ src/core/sys_util.h | 2 +- src/core/util_posix.c | 1 + src/libpmem/pmem_posix.c | 2 +- src/libpmem2/auto_flush_linux.c | 1 + src/libpmem2/badblocks.c | 1 + src/libpmem2/numa_none.c | 3 ++- src/libpmem2/pmem2_arch.h | 4 +++- src/libpmem2/pmem2_utils.h | 2 +- src/libpmem2/usc_none.c | 3 ++- src/libpmem2/x86_64/init.c | 1 + src/libpmem2/x86_64/memcpy/memcpy_avx.h | 4 ++-- src/libpmem2/x86_64/memcpy/memcpy_sse2.h | 4 ++-- src/libpmem2/x86_64/memset/memset_avx.h | 4 ++-- src/libpmem2/x86_64/memset/memset_sse2.h | 4 ++-- src/libpmemobj/alloc_class.c | 2 +- src/libpmemobj/lane.c | 2 +- src/libpmemobj/list.c | 2 +- src/libpmemobj/memblock.c | 2 +- src/libpmemobj/stats.c | 1 + src/libpmemobj/tx.c | 2 +- src/libpmemobj/ulog.c | 2 +- src/test/tools/obj_verify/obj_verify.c | 3 ++- src/test/unittest/unittest.h | 1 + src/tools/pmempool/output.c | 2 ++ 37 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/common/bad_blocks.c b/src/common/bad_blocks.c index f44ec4848e3..54f89d65d17 100644 --- a/src/common/bad_blocks.c +++ b/src/common/bad_blocks.c @@ -11,6 +11,7 @@ #include "libpmem2.h" #include "badblocks.h" #include "out.h" +#include "core_assert.h" #include "vec.h" #include "os.h" diff --git a/src/common/ctl.c b/src/common/ctl.c index fa721dbeda3..13d4e94f978 100644 --- a/src/common/ctl.c +++ b/src/common/ctl.c @@ -8,6 +8,7 @@ #include "ctl.h" #include "os.h" #include "alloc.h" +#include "core_assert.h" #define CTL_MAX_ENTRIES 100 diff --git a/src/common/mmap_posix.c b/src/common/mmap_posix.c index faf6a8018d0..00a46ec7e33 100644 --- a/src/common/mmap_posix.c +++ b/src/common/mmap_posix.c @@ -9,7 +9,7 @@ #include #include #include "mmap.h" -#include "out.h" +#include "core_assert.h" #include "os.h" #define PROCMAXLEN 2048 /* maximum expected line length in /proc files */ diff --git a/src/common/pool_hdr.c b/src/common/pool_hdr.c index 495e39c9bed..47e754eccd8 100644 --- a/src/common/pool_hdr.c +++ b/src/common/pool_hdr.c @@ -11,6 +11,7 @@ #include #include "out.h" +#include "log_internal.h" #include "pool_hdr.h" /* Determine ISA for which PMDK is currently compiled */ diff --git a/src/common/set.h b/src/common/set.h index 8e691e880c7..b34c9928387 100644 --- a/src/common/set.h +++ b/src/common/set.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2022, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * @@ -45,7 +45,7 @@ #include -#include "out.h" +#include "core_assert.h" #include "vec.h" #include "pool_hdr.h" diff --git a/src/common/util_pmem.h b/src/common/util_pmem.h index 743fbc31cc9..720d1d78d76 100644 --- a/src/common/util_pmem.h +++ b/src/common/util_pmem.h @@ -10,6 +10,7 @@ #include "libpmem.h" #include "out.h" +#include "log_internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/common/uuid.c b/src/common/uuid.c index c92de54c8c6..66cc1c1ae18 100644 --- a/src/common/uuid.c +++ b/src/common/uuid.c @@ -8,8 +8,9 @@ #include #include #include + #include "uuid.h" -#include "out.h" +#include "log_internal.h" /* * util_uuid_to_string -- generate a string form of the uuid diff --git a/src/common/uuid_linux.c b/src/common/uuid_linux.c index 43a9291cefd..3ec2abd64ba 100644 --- a/src/common/uuid_linux.c +++ b/src/common/uuid_linux.c @@ -11,7 +11,7 @@ #include "uuid.h" #include "os.h" -#include "out.h" +#include "log_internal.h" /* * util_uuid_generate -- generate a uuid diff --git a/src/common/vec.h b/src/common/vec.h index 4ef4cc24047..5d7cfbb6fd6 100644 --- a/src/common/vec.h +++ b/src/common/vec.h @@ -11,7 +11,7 @@ #include #include "valgrind_internal.h" #include "util.h" -#include "out.h" +#include "log_internal.h" #include "alloc.h" #ifdef __cplusplus diff --git a/src/core/alloc.c b/src/core/alloc.c index 7d508d8cbf7..e50426b2b46 100644 --- a/src/core/alloc.c +++ b/src/core/alloc.c @@ -5,12 +5,13 @@ #include "alloc.h" #include "fault_injection.h" -#include "out.h" Malloc_func fn_malloc = malloc; Realloc_func fn_realloc = realloc; #if FAULT_INJECTION +#include "log_internal.h" + static __thread int malloc_num; static __thread int fail_malloc_num; static __thread const char *fail_malloc_from; diff --git a/src/core/last_error_msg.c b/src/core/last_error_msg.c index 83a86a94984..b03e07669c4 100644 --- a/src/core/last_error_msg.c +++ b/src/core/last_error_msg.c @@ -18,7 +18,7 @@ #include "last_error_msg.h" #include "os_thread.h" -#include "out.h" +#include "log_internal.h" #include "valgrind_internal.h" struct lasterrormsg diff --git a/src/core/out.h b/src/core/out.h index 19e379a4eea..88010e5417d 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -9,7 +9,6 @@ #define PMDK_OUT_H 1 #include "util.h" -#include "core_assert.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/ravl.c b/src/core/ravl.c index b0537e653ae..3352a384973 100644 --- a/src/core/ravl.c +++ b/src/core/ravl.c @@ -9,7 +9,9 @@ #include #include #include + #include "out.h" +#include "core_assert.h" #include "ravl.h" #include "alloc.h" diff --git a/src/core/sys_util.h b/src/core/sys_util.h index 931c73e4cdb..357ae7b669d 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -11,7 +11,7 @@ #include #include "os_thread.h" -#include "out.h" +#include "core_assert.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/util_posix.c b/src/core/util_posix.c index d55e0c89f52..79ab2c63357 100644 --- a/src/core/util_posix.c +++ b/src/core/util_posix.c @@ -14,6 +14,7 @@ #include #include "os.h" #include "out.h" +#include "core_assert.h" #include "util.h" /* pass through for Posix */ diff --git a/src/libpmem/pmem_posix.c b/src/libpmem/pmem_posix.c index c06308ffcdd..c8c802699de 100644 --- a/src/libpmem/pmem_posix.c +++ b/src/libpmem/pmem_posix.c @@ -9,7 +9,7 @@ #include #include "pmem.h" -#include "out.h" +#include "log_internal.h" #include "mmap.h" /* diff --git a/src/libpmem2/auto_flush_linux.c b/src/libpmem2/auto_flush_linux.c index 944f4e0da65..738f02742f9 100644 --- a/src/libpmem2/auto_flush_linux.c +++ b/src/libpmem2/auto_flush_linux.c @@ -13,6 +13,7 @@ #include #include #include "out.h" +#include "core_assert.h" #include "os.h" #include "fs.h" #include "auto_flush.h" diff --git a/src/libpmem2/badblocks.c b/src/libpmem2/badblocks.c index c702d4f65cd..e39304b2959 100644 --- a/src/libpmem2/badblocks.c +++ b/src/libpmem2/badblocks.c @@ -8,6 +8,7 @@ #include "badblocks.h" #include "alloc.h" #include "out.h" +#include "log_internal.h" /* * badblocks_new -- zalloc bad blocks structure diff --git a/src/libpmem2/numa_none.c b/src/libpmem2/numa_none.c index 54f0106f742..fed528dda23 100644 --- a/src/libpmem2/numa_none.c +++ b/src/libpmem2/numa_none.c @@ -2,7 +2,8 @@ /* Copyright 2020-2024, Intel Corporation */ #include "libpmem2.h" -#include "out.h" +#include "util.h" +#include "log_internal.h" #include "source.h" /* diff --git a/src/libpmem2/pmem2_arch.h b/src/libpmem2/pmem2_arch.h index e14dec4598e..f0bf232d80e 100644 --- a/src/libpmem2/pmem2_arch.h +++ b/src/libpmem2/pmem2_arch.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2022, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * pmem2_arch.h -- core-arch interface @@ -8,9 +8,11 @@ #define PMEM2_ARCH_H #include + #include "libpmem2.h" #include "util.h" #include "valgrind_internal.h" +#include "out.h" #ifdef __cplusplus extern "C" { diff --git a/src/libpmem2/pmem2_utils.h b/src/libpmem2/pmem2_utils.h index 2a698f63f73..43f7b211615 100644 --- a/src/libpmem2/pmem2_utils.h +++ b/src/libpmem2/pmem2_utils.h @@ -11,7 +11,7 @@ #include #include "os.h" -#include "out.h" +#include "core_assert.h" #include "last_error_msg.h" #include "source.h" diff --git a/src/libpmem2/usc_none.c b/src/libpmem2/usc_none.c index a4f61d2124a..9c1652d5a9d 100644 --- a/src/libpmem2/usc_none.c +++ b/src/libpmem2/usc_none.c @@ -6,7 +6,8 @@ */ #include "libpmem2.h" -#include "out.h" +#include "log_internal.h" +#include "util.h" int pmem2_source_device_id(const struct pmem2_source *src, char *id, size_t *len) diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index 66867f2e84d..3ae6592a523 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -10,6 +10,7 @@ #include "memcpy_memset.h" #include "os.h" #include "out.h" +#include "core_assert.h" #include "pmem2_arch.h" #include "valgrind_internal.h" diff --git a/src/libpmem2/x86_64/memcpy/memcpy_avx.h b/src/libpmem2/x86_64/memcpy/memcpy_avx.h index 2a01739bf41..5d274035d95 100644 --- a/src/libpmem2/x86_64/memcpy/memcpy_avx.h +++ b/src/libpmem2/x86_64/memcpy/memcpy_avx.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2022, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ #ifndef PMEM2_MEMCPY_AVX_H #define PMEM2_MEMCPY_AVX_H @@ -8,7 +8,7 @@ #include #include -#include "out.h" +#include "core_assert.h" static force_inline void memmove_small_avx_noflush(char *dest, const char *src, size_t len) diff --git a/src/libpmem2/x86_64/memcpy/memcpy_sse2.h b/src/libpmem2/x86_64/memcpy/memcpy_sse2.h index dc0d8351dc8..4c56ca193c6 100644 --- a/src/libpmem2/x86_64/memcpy/memcpy_sse2.h +++ b/src/libpmem2/x86_64/memcpy/memcpy_sse2.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2022, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ #ifndef PMEM2_MEMCPY_SSE2_H #define PMEM2_MEMCPY_SSE2_H @@ -8,7 +8,7 @@ #include #include -#include "out.h" +#include "core_assert.h" static force_inline void memmove_small_sse2_noflush(char *dest, const char *src, size_t len) diff --git a/src/libpmem2/x86_64/memset/memset_avx.h b/src/libpmem2/x86_64/memset/memset_avx.h index db43691176d..f52e8cba736 100644 --- a/src/libpmem2/x86_64/memset/memset_avx.h +++ b/src/libpmem2/x86_64/memset/memset_avx.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2022, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ #ifndef PMEM2_MEMSET_AVX_H #define PMEM2_MEMSET_AVX_H @@ -10,7 +10,7 @@ #include #include "avx.h" -#include "out.h" +#include "core_assert.h" static force_inline void memset_small_avx_noflush(char *dest, __m256i ymm, size_t len) diff --git a/src/libpmem2/x86_64/memset/memset_sse2.h b/src/libpmem2/x86_64/memset/memset_sse2.h index 83a67f148b3..8654aa6c167 100644 --- a/src/libpmem2/x86_64/memset/memset_sse2.h +++ b/src/libpmem2/x86_64/memset/memset_sse2.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2022, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ #ifndef PMEM2_MEMSET_SSE2_H #define PMEM2_MEMSET_SSE2_H @@ -9,7 +9,7 @@ #include #include -#include "out.h" +#include "core_assert.h" static force_inline void memset_small_sse2_noflush(char *dest, __m128i xmm, size_t len) diff --git a/src/libpmemobj/alloc_class.c b/src/libpmemobj/alloc_class.c index 6b807d64f6d..52702ff1050 100644 --- a/src/libpmemobj/alloc_class.c +++ b/src/libpmemobj/alloc_class.c @@ -11,7 +11,7 @@ #include "alloc_class.h" #include "heap_layout.h" #include "util.h" -#include "out.h" +#include "core_assert.h" #include "bucket.h" #include "critnib.h" diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index fee0bfed92b..f5c1b478172 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -17,7 +17,7 @@ #include "libpmemobj.h" #include "critnib.h" #include "lane.h" -#include "out.h" +#include "core_assert.h" #include "util.h" #include "obj.h" #include "os_thread.h" diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index 614d38fbd4c..108ed9814b5 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -9,7 +9,7 @@ #include "list.h" #include "obj.h" #include "os_thread.h" -#include "out.h" +#include "core_assert.h" #include "sync.h" #include "valgrind_internal.h" #include "memops.h" diff --git a/src/libpmemobj/memblock.c b/src/libpmemobj/memblock.c index ee5dc7141c5..0276ad80baf 100644 --- a/src/libpmemobj/memblock.c +++ b/src/libpmemobj/memblock.c @@ -21,7 +21,7 @@ #include "obj.h" #include "heap.h" #include "memblock.h" -#include "out.h" +#include "core_assert.h" #include "valgrind_internal.h" #include "alloc_class.h" diff --git a/src/libpmemobj/stats.c b/src/libpmemobj/stats.c index 1e17b3e3539..2f3e23e302e 100644 --- a/src/libpmemobj/stats.c +++ b/src/libpmemobj/stats.c @@ -7,6 +7,7 @@ #include "obj.h" #include "stats.h" +#include "core_assert.h" STATS_CTL_HANDLER(persistent, curr_allocated, heap_curr_allocated); diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index f9fe29de58d..13b6d77901f 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -11,7 +11,7 @@ #include "queue.h" #include "ravl.h" #include "obj.h" -#include "out.h" +#include "core_assert.h" #include "pmalloc.h" #include "tx.h" #include "valgrind_internal.h" diff --git a/src/libpmemobj/ulog.c b/src/libpmemobj/ulog.c index 6d7ab9153d1..81289c283cf 100644 --- a/src/libpmemobj/ulog.c +++ b/src/libpmemobj/ulog.c @@ -12,7 +12,7 @@ #include "pmemops.h" #include "ulog.h" #include "obj.h" -#include "out.h" +#include "core_assert.h" #include "util.h" #include "valgrind_internal.h" diff --git a/src/test/tools/obj_verify/obj_verify.c b/src/test/tools/obj_verify/obj_verify.c index d9b1bb842a4..4e8d58ff44e 100644 --- a/src/test/tools/obj_verify/obj_verify.c +++ b/src/test/tools/obj_verify/obj_verify.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2020, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * obj_verify.c -- tool for creating and verifying a pmemobj pool @@ -12,6 +12,7 @@ #include "libpmemobj.h" #include "set.h" #include "os.h" +#include "out.h" #define SIGNATURE_LEN 10 #define NUMBER_LEN 10 diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 2c0f89e706d..a162667bb17 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -88,6 +88,7 @@ extern "C" { #include "os_thread.h" #include "util.h" #include "log_internal.h" +#include "core_assert.h" #ifdef USE_LOG_PMEMOBJ #include "libpmemobj/log.h" diff --git a/src/tools/pmempool/output.c b/src/tools/pmempool/output.c index f1ed75b5bd1..cf5e929d3ac 100644 --- a/src/tools/pmempool/output.c +++ b/src/tools/pmempool/output.c @@ -16,9 +16,11 @@ #include #include #include + #include "feature.h" #include "common.h" #include "output.h" +#include "core_assert.h" #define _STR(s) #s #define STR(s) _STR(s) From 6ac049be857e216d5e8e8c3e3b37fa785b1f0c18 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Fri, 9 Feb 2024 22:14:19 -0500 Subject: [PATCH 069/182] common: pass all logs through legacy out if... ...any of the debug logging environment variables are set. Signed-off-by: Jan Michalski --- src/core/out.c | 59 +++++++++++++++++++++++++ src/test/traces/TEST6 | 23 ---------- src/test/traces/custom_file0.log.match | 32 +++++++------- src/test/traces/redir_stderr1.log.match | 1 - src/test/traces/redir_stderr2.log.match | 22 ++++----- src/test/traces/redir_stderr3.log.match | 24 +++++----- src/test/traces/redir_stderr4.log.match | 30 ++++++------- src/test/traces/redir_stderr5.log.match | 32 +++++++------- src/test/traces/redir_stderr6.log.match | 16 ------- src/test/traces/traces.c | 2 +- 10 files changed, 130 insertions(+), 111 deletions(-) delete mode 100755 src/test/traces/TEST6 delete mode 100644 src/test/traces/redir_stderr6.log.match diff --git a/src/core/out.c b/src/core/out.c index b55142e6906..3c0790f790f 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -29,6 +29,43 @@ static int Log_level; static FILE *Out_fp; static unsigned Log_alignment; +#ifdef DEBUG +static const enum core_log_level level_to_core_log_level[5] = { + [0] = CORE_LOG_DISABLED, + [1] = CORE_LOG_LEVEL_ERROR, + [2] = CORE_LOG_LEVEL_NOTICE, + [3] = CORE_LOG_LEVEL_INFO, + [4] = CORE_LOG_LEVEL_DEBUG, +}; + +static const int core_log_level_to_level[6] = { + [CORE_LOG_LEVEL_FATAL] = 1, + [CORE_LOG_LEVEL_ERROR] = 1, + [CORE_LOG_LEVEL_WARNING] = 2, + [CORE_LOG_LEVEL_NOTICE] = 2, + [CORE_LOG_LEVEL_INFO] = 3, + [CORE_LOG_LEVEL_DEBUG] = 4, +}; + +#define OUT_MAX_LEVEL 4 + +static void +out_legacy(void *context, enum core_log_level core_level, const char *file_name, + const int line_no, const char *function_name, const char *message) +{ + SUPPRESS_UNUSED(context); + + int level; + if (core_level == CORE_LOG_LEVEL_ALWAYS) { + level = 1; /* traditionally used for this kind of messages */ + } else { + level = core_log_level_to_level[core_level]; + } + + out_log(file_name, line_no, function_name, level, "%s", message); +} +#endif /* DEBUG */ + /* * out_init -- initialize the log * @@ -54,12 +91,27 @@ out_init(const char *log_prefix, const char *log_level_var, #ifdef DEBUG char *log_level; char *log_file; + int log_level_cropped = 0; + int ret; if ((log_level = os_getenv(log_level_var)) != NULL) { Log_level = atoi(log_level); if (Log_level < 0) { Log_level = 0; } + if (Log_level <= OUT_MAX_LEVEL) { + log_level_cropped = Log_level; + } else { + log_level_cropped = OUT_MAX_LEVEL; + } + } + + if (log_level != NULL) { + ret = core_log_set_threshold(CORE_LOG_THRESHOLD, + level_to_core_log_level[log_level_cropped]); + if (ret) { + CORE_LOG_FATAL("Cannot set log threshold"); + } } if ((log_file = os_getenv(log_file_var)) != NULL && @@ -86,6 +138,13 @@ out_init(const char *log_prefix, const char *log_level_var, abort(); } } + + if (log_level != NULL || log_file != NULL) { + ret = core_log_set_function(out_legacy, NULL); + if (ret) { + CORE_LOG_FATAL("Cannot set legacy log function"); + } + } #endif /* DEBUG */ char *log_alignment = os_getenv("PMDK_LOG_ALIGN"); diff --git a/src/test/traces/TEST6 b/src/test/traces/TEST6 deleted file mode 100755 index 05da8876e43..00000000000 --- a/src/test/traces/TEST6 +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2019, Intel Corporation - -# -# src/test/traces/TEST6 -- unit test for traces -# - -. ../unittest/unittest.sh - -require_test_type medium - -require_fs_type none -require_build_type debug - -setup - -export UT_LOG_LEVEL=4 -expect_normal_exit ./traces$EXESUFFIX 2>redir_stderr$UNITTEST_NUM.log - -check - -pass diff --git a/src/test/traces/custom_file0.log.match b/src/test/traces/custom_file0.log.match index 9209b0590f2..a3733783de9 100644 --- a/src/test/traces/custom_file0.log.match +++ b/src/test/traces/custom_file0.log.match @@ -1,16 +1,16 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*) -$(*)Log level NONE -$(*)Log level ERROR -$(*)Log level WARNING -$(*)Log level INFO -$(*)Log level DEBUG -$(*) +$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) +$(nW) <1> $(nW) $(nW) ut version 1.0 +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(nW) <3> $(nW) $(nW) +$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level ERROR +$(nW) <2> $(nW) $(nW) Log level WARNING +$(nW) <3> $(nW) $(nW) Log level INFO +$(nW) <4> $(nW) $(nW) Log level DEBUG +$(nW) <3> $(nW) $(nW) diff --git a/src/test/traces/redir_stderr1.log.match b/src/test/traces/redir_stderr1.log.match index 3d739c871d8..e69de29bb2d 100644 --- a/src/test/traces/redir_stderr1.log.match +++ b/src/test/traces/redir_stderr1.log.match @@ -1 +0,0 @@ -$(*)Log level NONE diff --git a/src/test/traces/redir_stderr2.log.match b/src/test/traces/redir_stderr2.log.match index 0ff6e699564..79271cadab2 100644 --- a/src/test/traces/redir_stderr2.log.match +++ b/src/test/traces/redir_stderr2.log.match @@ -1,11 +1,11 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*)Log level NONE -$(*)Log level ERROR +$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) +$(nW) <1> $(nW) $(nW) ut version 1.0 +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/traces/redir_stderr3.log.match b/src/test/traces/redir_stderr3.log.match index 1f4b14419a3..dfee35a04d7 100644 --- a/src/test/traces/redir_stderr3.log.match +++ b/src/test/traces/redir_stderr3.log.match @@ -1,12 +1,12 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*)Log level NONE -$(*)Log level ERROR -$(*)Log level WARNING +$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) +$(nW) <1> $(nW) $(nW) ut version 1.0 +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level ERROR +$(nW) <2> $(nW) $(nW) Log level WARNING diff --git a/src/test/traces/redir_stderr4.log.match b/src/test/traces/redir_stderr4.log.match index 97f9f09bf48..15cb460f06a 100644 --- a/src/test/traces/redir_stderr4.log.match +++ b/src/test/traces/redir_stderr4.log.match @@ -1,15 +1,15 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*) -$(*)Log level NONE -$(*)Log level ERROR -$(*)Log level WARNING -$(*)Log level INFO -$(*) +$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) +$(nW) <1> $(nW) $(nW) ut version 1.0 +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(nW) <3> $(nW) $(nW) +$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level ERROR +$(nW) <2> $(nW) $(nW) Log level WARNING +$(nW) <3> $(nW) $(nW) Log level INFO +$(nW) <3> $(nW) $(nW) diff --git a/src/test/traces/redir_stderr5.log.match b/src/test/traces/redir_stderr5.log.match index 9209b0590f2..a3733783de9 100644 --- a/src/test/traces/redir_stderr5.log.match +++ b/src/test/traces/redir_stderr5.log.match @@ -1,16 +1,16 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*) -$(*)Log level NONE -$(*)Log level ERROR -$(*)Log level WARNING -$(*)Log level INFO -$(*)Log level DEBUG -$(*) +$(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) +$(nW) <1> $(nW) $(nW) ut version 1.0 +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(nW) <3> $(nW) $(nW) +$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level ERROR +$(nW) <2> $(nW) $(nW) Log level WARNING +$(nW) <3> $(nW) $(nW) Log level INFO +$(nW) <4> $(nW) $(nW) Log level DEBUG +$(nW) <3> $(nW) $(nW) diff --git a/src/test/traces/redir_stderr6.log.match b/src/test/traces/redir_stderr6.log.match deleted file mode 100644 index c96567c6243..00000000000 --- a/src/test/traces/redir_stderr6.log.match +++ /dev/null @@ -1,16 +0,0 @@ -$(*) -$(*) -$(*) -$(OPT)$(*) compiled with support for Valgrind pmemcheck -$(OPT)$(*) compiled with support for Valgrind helgrind -$(OPT)$(*) compiled with support for Valgrind memcheck -$(OPT)$(*) compiled with support for Valgrind drd -$(OPT)$(*) compiled with support for shutdown state -$(OPT)$(*) compiled with libndctl 63+ -$(*) -: <0> [traces.c:$(*) main]$(W)Log level NONE -: <1> [traces.c:$(*) main]$(W)Log level ERROR -: <2> [traces.c:$(*) main]$(W)Log level WARNING -: <3> [traces.c:$(*) main]$(W)Log level INFO -: <4> [traces.c:$(*) main]$(W)Log level DEBUG -$(*) diff --git a/src/test/traces/traces.c b/src/test/traces/traces.c index e61046bcebf..05e08499026 100644 --- a/src/test/traces/traces.c +++ b/src/test/traces/traces.c @@ -24,7 +24,7 @@ main(int argc, char *argv[]) /* Execute test */ common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); - LOG(0, "Log level NONE"); + CORE_LOG_ALWAYS("Log level ALWAYS"); CORE_LOG_ERROR("Log level ERROR"); CORE_LOG_WARNING("Log level WARNING"); LOG(3, "Log level INFO"); From 04229982b711743f78658e3f5716dbeb9d51d759 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 12 Feb 2024 18:11:37 -0500 Subject: [PATCH 070/182] test: revert exclusions needed for #5988 #5966 Signed-off-by: Jan Michalski --- src/test/ex_libpmemobj/TEST0 | 4 +--- src/test/ex_libpmemobj/TEST1 | 4 +--- src/test/ex_libpmemobj/TEST17 | 4 +--- src/test/ex_libpmemobj/TEST7 | 4 +--- src/test/ex_libpmemobj/TEST8 | 4 +--- src/test/ex_libpmemobj/TEST9 | 4 +--- src/test/pmempool_sync/TEST10 | 4 +--- src/test/pmempool_sync/TEST11 | 4 +--- src/test/pmempool_sync/TEST12 | 4 +--- src/test/pmempool_sync/TEST23 | 4 +--- src/test/pmempool_sync/TEST24 | 4 +--- src/test/pmempool_sync/TEST25 | 4 +--- src/test/pmempool_sync/TEST26 | 4 +--- src/test/pmempool_sync/TEST29 | 5 ----- src/test/pmempool_sync/TEST32 | 5 ----- src/test/pmempool_sync/TEST33 | 5 ----- src/test/pmempool_sync/TEST34 | 5 ----- src/test/pmempool_sync/TEST35 | 5 ----- src/test/pmempool_sync/TEST36 | 5 ----- src/test/pmempool_sync/TEST37 | 5 ----- src/test/pmempool_sync/TEST42 | 5 ----- src/test/pmempool_sync/TEST43 | 5 ----- src/test/pmempool_sync/TEST44 | 5 ----- src/test/pmempool_sync/TEST45 | 5 ----- src/test/pmempool_sync/TEST46 | 5 ----- src/test/pmempool_sync/TEST47 | 5 ----- src/test/pmempool_sync/TEST48 | 5 ----- src/test/pmempool_sync/TEST49 | 5 ----- src/test/pmempool_sync/TEST50 | 5 ----- src/test/pmempool_sync/TEST51 | 5 ----- src/test/pmempool_sync/TEST52 | 5 ----- src/test/pmempool_sync/TEST53 | 5 ----- src/test/pmempool_sync/TEST8 | 4 +--- src/test/pmempool_sync/TEST9 | 4 +--- src/test/pmempool_transform/TEST10 | 4 +--- src/test/pmempool_transform/TEST12 | 5 ----- src/test/pmempool_transform/TEST3 | 4 +--- src/test/pmempool_transform/TEST5 | 4 +--- src/test/pmempool_transform/TEST6 | 4 +--- 39 files changed, 19 insertions(+), 157 deletions(-) diff --git a/src/test/ex_libpmemobj/TEST0 b/src/test/ex_libpmemobj/TEST0 index a3ac967685a..fa1ec47b245 100755 --- a/src/test/ex_libpmemobj/TEST0 +++ b/src/test/ex_libpmemobj/TEST0 @@ -22,9 +22,7 @@ EX_PATH=../../examples/libpmemobj expect_normal_exit $EX_PATH/pi $DIR/testfile1 c 2 20 > $LOG_TEMP 2>&1 expect_normal_exit $EX_PATH/pi $DIR/testfile1 p >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/ex_libpmemobj/TEST1 b/src/test/ex_libpmemobj/TEST1 index bb6256c31a6..82fc2e98cf3 100755 --- a/src/test/ex_libpmemobj/TEST1 +++ b/src/test/ex_libpmemobj/TEST1 @@ -25,9 +25,7 @@ expect_normal_exit $EX_PATH/btree $DIR/testfile1 i 2 World! >> $LOG_TEMP 2>&1 expect_normal_exit $EX_PATH/btree $DIR/testfile1 p >> $LOG_TEMP 2>&1 expect_normal_exit $EX_PATH/btree $DIR/testfile1 f 4321 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/ex_libpmemobj/TEST17 b/src/test/ex_libpmemobj/TEST17 index 91b6e79de22..3ef613d42cc 100755 --- a/src/test/ex_libpmemobj/TEST17 +++ b/src/test/ex_libpmemobj/TEST17 @@ -26,9 +26,7 @@ expect_normal_exit $EX_PATH/lists $DIR/testfile1 2 bar print >> $LOG_TEMP 2>&1 expect_normal_exit $EX_PATH/lists $DIR/testfile1 3 foo print >> $LOG_TEMP 2>&1 expect_normal_exit $EX_PATH/lists $DIR/testfile1 1 bar print >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/ex_libpmemobj/TEST7 b/src/test/ex_libpmemobj/TEST7 index 39582372ebe..c5c968e5faf 100755 --- a/src/test/ex_libpmemobj/TEST7 +++ b/src/test/ex_libpmemobj/TEST7 @@ -24,9 +24,7 @@ EOF expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/ex_libpmemobj/TEST8 b/src/test/ex_libpmemobj/TEST8 index e084c188e92..8d7b7a1494e 100755 --- a/src/test/ex_libpmemobj/TEST8 +++ b/src/test/ex_libpmemobj/TEST8 @@ -24,9 +24,7 @@ EOF expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/ex_libpmemobj/TEST9 b/src/test/ex_libpmemobj/TEST9 index 266b8cfbb93..f42a527129a 100755 --- a/src/test/ex_libpmemobj/TEST9 +++ b/src/test/ex_libpmemobj/TEST9 @@ -23,9 +23,7 @@ EOF expect_normal_exit $EX_PATH/reader $DIR/testfile1 >> $LOG_TEMP 2>&1 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST10 b/src/test/pmempool_sync/TEST10 index 13c78b73e0e..fabdba79d1d 100755 --- a/src/test/pmempool_sync/TEST10 +++ b/src/test/pmempool_sync/TEST10 @@ -51,9 +51,7 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST11 b/src/test/pmempool_sync/TEST11 index 22ed47b9afd..890c2ae850b 100755 --- a/src/test/pmempool_sync/TEST11 +++ b/src/test/pmempool_sync/TEST11 @@ -61,9 +61,7 @@ expect_normal_exit $DDMAP$EXESUFFIX -o $DIR/part20 -n 10 -b 1 # Try to synchronize replicas using the third poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET3 &>> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST12 b/src/test/pmempool_sync/TEST12 index de0a8a6a91b..1b517aa2654 100755 --- a/src/test/pmempool_sync/TEST12 +++ b/src/test/pmempool_sync/TEST12 @@ -44,9 +44,7 @@ expect_normal_exit $PMEMSPOIL $DIR/testfile1 pool_hdr.uuid=0000000000000000\ # Try to synchronize replicas expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET &>> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST23 b/src/test/pmempool_sync/TEST23 index 923fccd3220..a087d0d80f0 100755 --- a/src/test/pmempool_sync/TEST23 +++ b/src/test/pmempool_sync/TEST23 @@ -63,9 +63,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check pass diff --git a/src/test/pmempool_sync/TEST24 b/src/test/pmempool_sync/TEST24 index e70d3e2ef00..21fb8a3b613 100755 --- a/src/test/pmempool_sync/TEST24 +++ b/src/test/pmempool_sync/TEST24 @@ -60,9 +60,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST25 b/src/test/pmempool_sync/TEST25 index a84e7cfa75f..d197bc04b71 100755 --- a/src/test/pmempool_sync/TEST25 +++ b/src/test/pmempool_sync/TEST25 @@ -62,9 +62,7 @@ expect_normal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET1 >> $LOG_TEMP # Check metadata using pmempool info dump_pool_info $POOLSET1 >> $LOG_TEMP -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST26 b/src/test/pmempool_sync/TEST26 index 6457a20b2e9..172f720010c 100755 --- a/src/test/pmempool_sync/TEST26 +++ b/src/test/pmempool_sync/TEST26 @@ -47,9 +47,7 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET >> $LOG_TEMP 2>&1 # Remove poolset expect_normal_exit $PMEMPOOL$EXESUFFIX rm $POOLSET -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST29 b/src/test/pmempool_sync/TEST29 index a73aa3b8f17..ed17b57d6c8 100755 --- a/src/test/pmempool_sync/TEST29 +++ b/src/test/pmempool_sync/TEST29 @@ -40,11 +40,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST32 b/src/test/pmempool_sync/TEST32 index fadb39e2271..3f00abadecc 100755 --- a/src/test/pmempool_sync/TEST32 +++ b/src/test/pmempool_sync/TEST32 @@ -50,11 +50,6 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST33 b/src/test/pmempool_sync/TEST33 index 2ada861d978..d6ec59271a5 100755 --- a/src/test/pmempool_sync/TEST33 +++ b/src/test/pmempool_sync/TEST33 @@ -50,11 +50,6 @@ expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST34 b/src/test/pmempool_sync/TEST34 index d0d7d92571c..72e18b4aabc 100755 --- a/src/test/pmempool_sync/TEST34 +++ b/src/test/pmempool_sync/TEST34 @@ -59,11 +59,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST35 b/src/test/pmempool_sync/TEST35 index 856837f5182..5a4368fea6c 100755 --- a/src/test/pmempool_sync/TEST35 +++ b/src/test/pmempool_sync/TEST35 @@ -59,11 +59,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST36 b/src/test/pmempool_sync/TEST36 index 827b588f75c..3eac293e51a 100755 --- a/src/test/pmempool_sync/TEST36 +++ b/src/test/pmempool_sync/TEST36 @@ -63,11 +63,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST37 b/src/test/pmempool_sync/TEST37 index 1e2dd7fd87a..9f87982184d 100755 --- a/src/test/pmempool_sync/TEST37 +++ b/src/test/pmempool_sync/TEST37 @@ -63,11 +63,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX sync -b -v $POOLSET >> $LOG" # sync was uneable to fix bad blocks, because one recovery file was missing expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST42 b/src/test/pmempool_sync/TEST42 index bbdf8eee097..32272d0ee17 100755 --- a/src/test/pmempool_sync/TEST42 +++ b/src/test/pmempool_sync/TEST42 @@ -62,11 +62,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST43 b/src/test/pmempool_sync/TEST43 index d6c9cba7e3a..d46eeda96f2 100755 --- a/src/test/pmempool_sync/TEST43 +++ b/src/test/pmempool_sync/TEST43 @@ -63,11 +63,6 @@ expect_abnormal_exit "$PMEMPOOL$EXESUFFIX sync -v -b $POOLSET &>> $LOG" # pool verification should fail expect_abnormal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST44 b/src/test/pmempool_sync/TEST44 index 534794c2144..da8b2a07f17 100755 --- a/src/test/pmempool_sync/TEST44 +++ b/src/test/pmempool_sync/TEST44 @@ -82,11 +82,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST45 b/src/test/pmempool_sync/TEST45 index a3101b33425..b28b086a7e7 100755 --- a/src/test/pmempool_sync/TEST45 +++ b/src/test/pmempool_sync/TEST45 @@ -80,11 +80,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST46 b/src/test/pmempool_sync/TEST46 index 7268fbe034c..6758b2e95be 100755 --- a/src/test/pmempool_sync/TEST46 +++ b/src/test/pmempool_sync/TEST46 @@ -80,11 +80,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST47 b/src/test/pmempool_sync/TEST47 index d4eb0f2e589..19f769567a6 100755 --- a/src/test/pmempool_sync/TEST47 +++ b/src/test/pmempool_sync/TEST47 @@ -83,11 +83,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST48 b/src/test/pmempool_sync/TEST48 index 244e96f21ae..27d85005bbd 100755 --- a/src/test/pmempool_sync/TEST48 +++ b/src/test/pmempool_sync/TEST48 @@ -86,11 +86,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST49 b/src/test/pmempool_sync/TEST49 index 604dd765c24..4db82bf4c2d 100755 --- a/src/test/pmempool_sync/TEST49 +++ b/src/test/pmempool_sync/TEST49 @@ -85,11 +85,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST50 b/src/test/pmempool_sync/TEST50 index f26241efb05..963cf1cf25d 100755 --- a/src/test/pmempool_sync/TEST50 +++ b/src/test/pmempool_sync/TEST50 @@ -85,11 +85,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST51 b/src/test/pmempool_sync/TEST51 index 5bcf8548032..5902a68634c 100755 --- a/src/test/pmempool_sync/TEST51 +++ b/src/test/pmempool_sync/TEST51 @@ -86,11 +86,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST52 b/src/test/pmempool_sync/TEST52 index 5fee861d20f..721eeb53487 100755 --- a/src/test/pmempool_sync/TEST52 +++ b/src/test/pmempool_sync/TEST52 @@ -83,11 +83,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST53 b/src/test/pmempool_sync/TEST53 index 2de6af42801..abd2e08eb28 100755 --- a/src/test/pmempool_sync/TEST53 +++ b/src/test/pmempool_sync/TEST53 @@ -85,11 +85,6 @@ expect_normal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG" expect_normal_exit "$PMEMPOOL$EXESUFFIX info --bad-blocks=yes $POOLSET >> $LOG" expect_normal_exit "$OBJ_VERIFY$EXESUFFIX $POOLSET pmempool$SUFFIX v &>> $LOG" -# Exclude error and warn messages printed out on the stderr by PMDK in debug -LOG_TEMP=$LOG.log -fgrep -v "*ERROR*" $LOG | fgrep -v "*WARN*" > $LOG_TEMP -mv $LOG_TEMP $LOG - check pass diff --git a/src/test/pmempool_sync/TEST8 b/src/test/pmempool_sync/TEST8 index 6a0c54ca2c6..dc0f668fac0 100755 --- a/src/test/pmempool_sync/TEST8 +++ b/src/test/pmempool_sync/TEST8 @@ -55,9 +55,7 @@ rm -f $DIR/part11 # Synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_sync/TEST9 b/src/test/pmempool_sync/TEST9 index 699acb4a692..3186f5fef7b 100755 --- a/src/test/pmempool_sync/TEST9 +++ b/src/test/pmempool_sync/TEST9 @@ -58,9 +58,7 @@ rm -f $DIR/part01 # Try to synchronize replicas using the second poolset expect_abnormal_exit $PMEMPOOL$EXESUFFIX sync $POOLSET2 >> $LOG_TEMP 2>&1 -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_transform/TEST10 b/src/test/pmempool_transform/TEST10 index 06d897c85b5..63388f80030 100755 --- a/src/test/pmempool_transform/TEST10 +++ b/src/test/pmempool_transform/TEST10 @@ -56,9 +56,7 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_IN >> $LOG_TEMP -# Exclude warning messages printed out on the stderr by PMDK in debug -grep -v "*WARN*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_transform/TEST12 b/src/test/pmempool_transform/TEST12 index 29512532abb..92b4c9ade85 100755 --- a/src/test/pmempool_transform/TEST12 +++ b/src/test/pmempool_transform/TEST12 @@ -106,11 +106,6 @@ dump_pool_info ${DEVICE_DAX_PATH[0]} >> $LOG_TEMP mv $LOG_TEMP $LOG -# Exclude error messages printed out on the stderr by PMDK in debug -mv $ERR_LOG $ERR_TEMP -grep -v "*ERROR*" $ERR_TEMP > $ERR_LOG -rm $ERR_TEMP - check pass diff --git a/src/test/pmempool_transform/TEST3 b/src/test/pmempool_transform/TEST3 index 259ababaa1c..f67ed2b94a4 100755 --- a/src/test/pmempool_transform/TEST3 +++ b/src/test/pmempool_transform/TEST3 @@ -83,9 +83,7 @@ dump_pool_info $DIR/testfile00 >> $LOG_TEMP # Make sure no other parts were created check_no_files $DIR/testfile10 $DIR/testfile11 -# Exclude error messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_transform/TEST5 b/src/test/pmempool_transform/TEST5 index 47541d1a92c..81fee2d215f 100755 --- a/src/test/pmempool_transform/TEST5 +++ b/src/test/pmempool_transform/TEST5 @@ -92,9 +92,7 @@ dump_pool_info $DIR/testfile01 >> $LOG_TEMP dump_pool_info $DIR/testfile02 >> $LOG_TEMP dump_pool_info $DIR/testfile10 >> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check diff --git a/src/test/pmempool_transform/TEST6 b/src/test/pmempool_transform/TEST6 index 420a5f03ab8..394ab5fbda4 100755 --- a/src/test/pmempool_transform/TEST6 +++ b/src/test/pmempool_transform/TEST6 @@ -71,9 +71,7 @@ expect_abnormal_exit $PMEMPOOL$EXESUFFIX transform \ # Check metadata by pmempool info dump_pool_info $POOLSET_OUT1 >> $LOG_TEMP -# Exclude error and warn messages printed out on the stderr by PMDK in debug -fgrep -v "*ERROR*" $LOG_TEMP | fgrep -v "*WARN*" > $LOG -rm $LOG_TEMP +mv $LOG_TEMP $LOG check From d1f746755a7634fdc63fdb5257c84f2259559df2 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 12 Feb 2024 22:46:20 -0500 Subject: [PATCH 071/182] common: fine-tuned _CORE_LOG_MAX_ERRNO_MSG Signed-off-by: Jan Michalski --- src/core/log_internal.h | 11 ++--- src/test/Makefile | 1 + src/test/core_log/.gitignore | 1 + src/test/core_log/Makefile | 11 +++++ src/test/core_log/TESTS.py | 21 ++++++++++ src/test/core_log/core_log.c | 81 ++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 src/test/core_log/.gitignore create mode 100644 src/test/core_log/Makefile create mode 100755 src/test/core_log/TESTS.py create mode 100644 src/test/core_log/core_log.c diff --git a/src/core/log_internal.h b/src/core/log_internal.h index d2919dbb2eb..8acaaf5e979 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -167,13 +167,14 @@ void core_log_to_last(const char *file_name, int line_no, errno = oerrno; \ } while (0) -#define _CORE_LOG_MAX_ERR_MSG 128 +/* The value fine-tuned to accommodate all possible errno message strings. */ +#define _CORE_LOG_MAX_ERRNO_MSG 50 #define _CORE_LOG_W_ERRNO(level, format, ...) \ do { \ - char buf[_CORE_LOG_MAX_ERR_MSG]; \ + char buf[_CORE_LOG_MAX_ERRNO_MSG]; \ char *error_str; \ - _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERR_MSG, &error_str); \ + _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERRNO_MSG, &error_str); \ _CORE_LOG(level, format ": %s", ##__VA_ARGS__, error_str); \ } while (0) @@ -230,9 +231,9 @@ void core_log_to_last(const char *file_name, int line_no, #define CORE_LOG_ERROR_W_ERRNO_LAST(format, ...) \ do { \ - char buf[_CORE_LOG_MAX_ERR_MSG]; \ + char buf[_CORE_LOG_MAX_ERRNO_MSG]; \ char *error_str; \ - _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERR_MSG, &error_str); \ + _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERRNO_MSG, &error_str); \ CORE_LOG_TO_LAST(format ": %s", ##__VA_ARGS__, error_str); \ } while (0) diff --git a/src/test/Makefile b/src/test/Makefile index bec0d1126fa..786c7fce13b 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -108,6 +108,7 @@ OBJ_TESTS = \ OTHER_TESTS = \ arch_flags\ + core_log\ checksum\ compat_incompat_features\ ctl_prefault\ diff --git a/src/test/core_log/.gitignore b/src/test/core_log/.gitignore new file mode 100644 index 00000000000..077e6928a11 --- /dev/null +++ b/src/test/core_log/.gitignore @@ -0,0 +1 @@ +core_log diff --git a/src/test/core_log/Makefile b/src/test/core_log/Makefile new file mode 100644 index 00000000000..0dffa9240a7 --- /dev/null +++ b/src/test/core_log/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log +OBJS = core_log.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +LIBPMEMCORE=y +include ../Makefile.inc diff --git a/src/test/core_log/TESTS.py b/src/test/core_log/TESTS.py new file mode 100755 index 00000000000..044a5f7020a --- /dev/null +++ b/src/test/core_log/TESTS.py @@ -0,0 +1,21 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +@t.require_build('nondebug') +class CORE_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log', self.test_case) + + +class TEST0(CORE_LOG): + test_case = 'test_CORE_LOG_MAX_ERRNO_MSG' diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c new file mode 100644 index 00000000000..1b88101ca56 --- /dev/null +++ b/src/test/core_log/core_log.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log.c -- unit test for core_log + */ + +#undef _GNU_SOURCE +#include +#include + +#include "log_internal.h" +#include "unittest.h" + +#define NO_ARGS_CONSUMED 0 + +#define BIG_BUF_SIZE 1024 + +/* + * test_CORE_LOG_MAX_ERRNO_MSG -- + * _CORE_LOG_MAX_ERRNO_MSG >= max(strlen(strerror(errnnum))) + * for errnum in errnums + */ +static int +test_CORE_LOG_MAX_ERRNO_MSG(const struct test_case *tc, int argc, char *argv[]) +{ + char buf[BIG_BUF_SIZE]; + int max_strerror_len = 0; + int correct_strerror_calls = 0; + + /* + * In general, valid errno values are all positive values of type int, + * but at the time of writing only the first 134 values are allocated. + * Out of which, 2 are not implemented hence 132 ought to be available. + * If not as expected please review the assumptions. + */ + for (int errnum = 0; errnum < 256; ++errnum) { + int ret = strerror_r(errnum, buf, BIG_BUF_SIZE); + + /* + * It is not forced on strerror_r(3) to end up correctly to + * accommodate not-implemented errno values already existing in + * Linux and to freely go over the biggest errno value known at + * the time of writing this comment and potentially discover + * newly introduced values. + */ + if (ret != 0) { + continue; + } + + ++correct_strerror_calls; + + int len = strlen(buf); + if (len > max_strerror_len) { + max_strerror_len = len; + } + } + UT_ASSERT(correct_strerror_calls == 132); + + /* + * The key aim of this test is to make sure the assumed errno message + * buffer size is big enough no matter the errno value. + */ + UT_ASSERT(max_strerror_len + 1 <= _CORE_LOG_MAX_ERRNO_MSG); + + return NO_ARGS_CONSUMED; +} + +static struct test_case test_cases[] = { + TEST_CASE(test_CORE_LOG_MAX_ERRNO_MSG) +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} From 87f3c0a1d3612933568234a8600ba88fcc887a33 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 13 Feb 2024 18:31:43 +0100 Subject: [PATCH 072/182] common: call abort() after reporting a fatal issue Signed-off-by: Tomasz Gromadzki --- src/core/log_internal.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 8acaaf5e979..6385438cb96 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -218,7 +218,11 @@ void core_log_to_last(const char *file_name, int line_no, _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL_W_ERRNO(format, ...) \ - _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) + do { \ + _CORE_LOG_W_ERRNO(CORE_LOG_LEVEL_FATAL, \ + format, ##__VA_ARGS__); \ + abort(); \ + } while (0) /* * 'Last' macros' flavours. Additionally writes the produced error message From 6bd6e870bb8ff1ce30a89b1e9f8e1e1d151ae3d5 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 14 Feb 2024 12:42:27 +0100 Subject: [PATCH 073/182] common: enable pmempool_info tests All pmempool_info tests were ignored because of missing TEST0 Signed-off-by: Tomasz Gromadzki --- src/test/pmempool_info/{TEST10 => TEST0} | 4 ++-- src/test/pmempool_info/{out10.log.match => out0.log.match} | 0 src/test/pmempool_info/out27.log.match | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) rename src/test/pmempool_info/{TEST10 => TEST0} (81%) rename src/test/pmempool_info/{out10.log.match => out0.log.match} (100%) diff --git a/src/test/pmempool_info/TEST10 b/src/test/pmempool_info/TEST0 similarity index 81% rename from src/test/pmempool_info/TEST10 rename to src/test/pmempool_info/TEST0 index 07181c78f55..6d489073701 100755 --- a/src/test/pmempool_info/TEST10 +++ b/src/test/pmempool_info/TEST0 @@ -1,9 +1,9 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2018, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # -# pmempool_info/TEST10 -- test for info command +# pmempool_info/TEST0 -- test for info command # . ../unittest/unittest.sh diff --git a/src/test/pmempool_info/out10.log.match b/src/test/pmempool_info/out0.log.match similarity index 100% rename from src/test/pmempool_info/out10.log.match rename to src/test/pmempool_info/out0.log.match diff --git a/src/test/pmempool_info/out27.log.match b/src/test/pmempool_info/out27.log.match index 5029eeed9b3..68781c7e77a 100644 --- a/src/test/pmempool_info/out27.log.match +++ b/src/test/pmempool_info/out27.log.match @@ -23,11 +23,13 @@ $(OPT)Machine : AMD X86-64 $(OPT)Machine : Aarch64 $(OPT)Machine : RISCV $(OPX)Machine : PPC64 -Last shutdown : dirty +$(OPT)Last shutdown : dirty +$(OPX)Last shutdown : clean Checksum : $(*) [OK] PMEM OBJ Header: -Layout : pmempool$(*) +$(OPT)Layout : pmempool$(*) +$(OPX)Layout : (null) Lanes offset : $(*) Number of lanes : $(*) Heap offset : $(*) From 2e7f5fb22cc9764f8ef7b783920d2cccd458ff6a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 14 Feb 2024 12:10:48 +0100 Subject: [PATCH 074/182] test: revert exclusion introduced by #5966 Revert temporar changes in libpmempool_feature tests Signed-off-by: Tomasz Gromadzki --- src/test/libpmempool_feature/common.sh | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/test/libpmempool_feature/common.sh b/src/test/libpmempool_feature/common.sh index 1b438a672f2..8b4741a6415 100644 --- a/src/test/libpmempool_feature/common.sh +++ b/src/test/libpmempool_feature/common.sh @@ -24,14 +24,9 @@ sds_enabled=$(is_ndctl_enabled ./libpmempool_feature$EXESUFFIX; echo $?) function libpmempool_feature_query_abnormal() { # query feature expect_abnormal_exit ./libpmempool_feature$EXESUFFIX $POOL q $1 - -# XXX disable log file verification until #5981 is resolved -# https://github.com/pmem/pmdk/issues/5981 -if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi -fi } # libpmempool_feature_query -- query feature @@ -62,19 +57,13 @@ function libpmempool_feature_query() { function libpmempool_feature_enable() { $exit_func ./libpmempool_feature$EXESUFFIX $POOL e $1 if [ "$exit_func" == "expect_abnormal_exit" ]; then - -# XXX disable log file verification until #5981 is resolved -# https://github.com/pmem/pmdk/issues/5981 -if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi -fi fi if [ "x$2" != "xno-query" ]; then libpmempool_feature_query $1 fi - echo normal end } # libpmempool_feature_disable -- disable feature @@ -83,13 +72,9 @@ fi function libpmempool_feature_disable() { $exit_func ./libpmempool_feature$EXESUFFIX $POOL d $1 if [ "$exit_func" == "expect_abnormal_exit" ]; then -# XXX disable log file verification until #5981 is resolved -# https://github.com/pmem/pmdk/issues/5981 -if false; then if [ -f "$PMEMPOOL_LOG_FILE" ]; then cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG fi -fi fi if [ "x$2" != "xno-query" ]; then libpmempool_feature_query $1 From fec5ac11b057c22991a08b9fd35be502fe75d923 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 14 Feb 2024 12:23:23 +0100 Subject: [PATCH 075/182] common: enable usc permision verification usc permision verification fails when executing for a folder. A temp file is used instead. Signed-off-by: Tomasz Gromadzki --- src/test/unittest/unittest.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/unittest/unittest.sh b/src/test/unittest/unittest.sh index 95f46348e99..fcc5d90bfc5 100644 --- a/src/test/unittest/unittest.sh +++ b/src/test/unittest/unittest.sh @@ -1268,8 +1268,10 @@ function require_native_fallocate() { # function require_usc_permission() { set +e - $USC_PERMISSION $1 2> $DIR/usc_permission.txt + touch $1/test.tmp + $USC_PERMISSION $1/test.tmp 2> $DIR/usc_permission.txt status=$? + rm -rf $1/test.tmp set -e # check if there were any messages printed to stderr, skip test if there were From 55e1165fdf4a33269b97f3fce72d2b6777040076 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 14 Feb 2024 16:51:37 +0100 Subject: [PATCH 076/182] common: remove support for NO_LIBPTHREAD build option Signed-off-by: Tomasz Gromadzki --- ChangeLog | 4 +++- src/core/last_error_msg.c | 33 --------------------------------- src/core/last_error_msg.h | 4 ---- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22693e1bb95..664a1a061c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,10 @@ XXX - * Version XXX + + * Version 2.1.0 This release - does not allow opening pmem pool without unsafe shoutdown counter if not explicitly disabled + - remove support for build time define NO_LIBPTHREAD Mon Dec 4 2023 Oksana Sałyk diff --git a/src/core/last_error_msg.c b/src/core/last_error_msg.c index b03e07669c4..799e11cff41 100644 --- a/src/core/last_error_msg.c +++ b/src/core/last_error_msg.c @@ -26,8 +26,6 @@ struct lasterrormsg char msg[CORE_LAST_ERROR_MSG_MAXPRINT]; }; -#ifndef NO_LIBPTHREAD - static os_once_t Last_errormsg_key_once = OS_ONCE_INIT; static os_tls_key_t Last_errormsg_key; @@ -82,37 +80,6 @@ last_error_msg_get_internal(void) return last; } -#else - -/* - * We don't want libpmem to depend on libpthread. Instead of using pthread - * API to dynamically allocate thread-specific error message buffer, we put - * it into TLS. However, keeping a pretty large static buffer (8K) in TLS - * may lead to some issues, so the maximum message length is reduced. - * Fortunately, it looks like the longest error message in libpmem should - * not be longer than about 90 chars (in case of pmem_check_version()). - */ - -static __thread struct errormsg Last_errormsg; - -static inline void -last_error_msg_init(void) -{ -} - -static inline void -last_error_msg_fini(void) -{ -} - -static inline const struct errormsg * -last_error_msg_get_internal(void) -{ - return &Last_errormsg; -} - -#endif /* NO_LIBPTHREAD */ - /* * last_error_msg_get -- get the last error message */ diff --git a/src/core/last_error_msg.h b/src/core/last_error_msg.h index be66ac8dcc9..9b11ed34b62 100644 --- a/src/core/last_error_msg.h +++ b/src/core/last_error_msg.h @@ -12,11 +12,7 @@ extern "C" { #endif -#ifndef NO_LIBPTHREAD #define CORE_LAST_ERROR_MSG_MAXPRINT 8192 /* maximum expected log line */ -#else -#define CORE_LAST_ERROR_MSG_MAXPRINT 256 /* ... for libpmem */ -#endif void last_error_msg_init(void); void last_error_msg_fini(void); From bc9a28493c5df660e80f9f1d7e577dd839f5a792 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 10:15:31 +0100 Subject: [PATCH 077/182] common: remove obsolete out_err() Signed-off-by: Tomasz Gromadzki --- CODING_STYLE.md | 2 +- src/core/out.c | 91 ------------------------ src/core/out.h | 4 -- src/test/out_err/out0.log.match | 2 - src/test/out_err/out_err.c | 13 ---- src/test/out_err/traces0.log.match | 2 - utils/call_stacks_analysis/make_extra.py | 1 - 7 files changed, 1 insertion(+), 114 deletions(-) diff --git a/CODING_STYLE.md b/CODING_STYLE.md index 3ca517d5e2a..9b99b7b9df3 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -76,7 +76,7 @@ for width-based integral types (`uint32_t`, `int64_t`, etc.). - Put `LOG(3, ...)` at the beginning of each function. Consider using higher log level for most frequently called routines. - Make use of `COMPILE_ERROR_ON` and `ASSERT*` macros. -- Use `ERR()` macro to log error messages. +- Use `ERR_W_ERRNO()`/`ERR_WO_ERRNO()` macros to log error messages. ### Unit tests - There **must** be unit tests provided for each new function/module added. diff --git a/src/core/out.c b/src/core/out.c index 3c0790f790f..f3155188990 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -312,82 +312,6 @@ out_common(const char *file, int line, const char *func, int level, errno = oerrno; } -/* - * out_error -- common error output code, all error messages go through here - */ -static void -out_error(int use_errno, const char *file, int line, const char *func, - const char *suffix, const char *fmt, va_list ap) -{ - int oerrno = 0; - if (use_errno) - oerrno = errno; - unsigned cc = 0; - int ret; - const char *sep = ""; - char errstr[UTIL_MAX_ERR_MSG] = ""; - - char *last_error = (char *)last_error_msg_get(); - - if (last_error == NULL) { - out_print_func("No memory to properly format error strings."); - return; - } - - if (fmt) { - if (use_errno) { - sep = ": "; - util_strerror(oerrno, errstr, UTIL_MAX_ERR_MSG); - } - - ret = vsnprintf(&last_error[cc], MAXPRINT, fmt, ap); - if (ret < 0) { - strcpy(last_error, "vsnprintf failed"); - goto end; - } - cc += (unsigned)ret; - out_snprintf(&last_error[cc], MAXPRINT - cc, "%s%s", - sep, errstr); - } - -#ifdef DEBUG - if (Log_level >= 1) { - char buf[MAXPRINT]; - cc = 0; - - if (file) { - char *f = strrchr(file, OS_DIR_SEPARATOR); - if (f) - file = f + 1; - ret = out_snprintf(&buf[cc], MAXPRINT, - "<%s>: <1> [%s:%d %s] ", - Log_prefix, file, line, func); - if (ret < 0) { - out_print_func("out_snprintf failed"); - goto end; - } - cc += (unsigned)ret; - if (cc < Log_alignment) { - memset(buf + cc, ' ', Log_alignment - cc); - cc = Log_alignment; - } - } - - out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", last_error, - suffix); - - out_print_func(buf); - } -#else - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, suffix); -#endif - -end: - if (use_errno) - errno = oerrno; -} - /* * out -- output a line, newline added automatically */ @@ -442,18 +366,3 @@ out_log(const char *file, int line, const char *func, int level, va_end(ap); } - -/* - * out_err -- output an error message - */ -void -out_err(int use_errno, const char *file, int line, const char *func, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - out_error(use_errno, file, line, func, "\n", fmt, ap); - - va_end(ap); -} diff --git a/src/core/out.h b/src/core/out.h index 88010e5417d..6c2ef1b6f44 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -75,10 +75,6 @@ void out_log_va(const char *file, int line, const char *func, int level, const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); -void out_err(int use_errno, const char *file, int line, const char *func, - const char *fmt, ...) FORMAT_PRINTF(5, 6); -void NORETURN out_fatal(const char *file, int line, const char *func, - const char *fmt, ...) FORMAT_PRINTF(4, 5); #ifdef __cplusplus } diff --git a/src/test/out_err/out0.log.match b/src/test/out_err/out0.log.match index 506ea5d3997..7da50af156a 100644 --- a/src/test/out_err/out0.log.match +++ b/src/test/out_err/out0.log.match @@ -4,6 +4,4 @@ ERR #1 $(OPT)ERR #2: Success $(OPX)ERR #2: No error: 0 ERR #3: Invalid argument -ERR1: Bad file descriptor:1234 -ERR2: Bad file descriptor:1234 out_err$(nW)TEST0: DONE diff --git a/src/test/out_err/out_err.c b/src/test/out_err/out_err.c index 2c363c2350a..d1b91a4e607 100644 --- a/src/test/out_err/out_err.c +++ b/src/test/out_err/out_err.c @@ -19,7 +19,6 @@ int main(int argc, char *argv[]) { - char buff[UT_MAX_ERR_MSG]; START(argc, argv, "out_err"); @@ -39,18 +38,6 @@ main(int argc, char *argv[]) ERR_W_ERRNO("ERR #%d", 3); UT_OUT("%s", last_error_msg_get()); - errno = EBADF; - strerror_r(errno, buff, UT_MAX_ERR_MSG); - out_err(0, __FILE__, 100, __func__, - "ERR1: %s:%d", buff, 1234); - UT_OUT("%s", last_error_msg_get()); - - errno = EBADF; - strerror_r(errno, buff, UT_MAX_ERR_MSG); - out_err(0, NULL, 0, NULL, - "ERR2: %s:%d", buff, 1234); - UT_OUT("%s", last_error_msg_get()); - /* Cleanup */ common_fini(); diff --git a/src/test/out_err/traces0.log.match b/src/test/out_err/traces0.log.match index e49c59d1fd7..0e34ec94875 100644 --- a/src/test/out_err/traces0.log.match +++ b/src/test/out_err/traces0.log.match @@ -11,5 +11,3 @@ $(OPT): <1> [out.c:$(N) out_init]$(W)compiled with libndctl 63+ $(OPT): <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: Success $(OPX): <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: No error: 0 : <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #3: Invalid argument -: <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR1: Bad file descriptor:1234 -ERR2: Bad file descriptor:1234 diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index 4b396f2857f..5ba25b4ed0e 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -23,7 +23,6 @@ def inlines(calls: Calls) -> Calls: # common calls['core_init'] = ['util_init', 'out_init'] calls['core_fini'] = ['out_fini'] - calls['ERR'] = ['out_err'] calls['common_init'] = ['core_init', 'util_mmap_init'] calls['common_fini'] = ['util_mmap_fini', 'core_fini'] calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] From 41ff803241d5ca2315e516f8b11b07c7d24f5146 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 11:26:02 +0100 Subject: [PATCH 078/182] common: include core_log_default_function in call stack analysis Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_extra.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index 5ba25b4ed0e..bacc71a9acf 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -28,6 +28,7 @@ def inlines(calls: Calls) -> Calls: calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] calls['_Last_errormsg_key_alloc'] = ['os_once', 'os_tls_key_create'] calls['out_common'] = ['out_snprintf'] + calls['core_log_va'] = ['core_log_default_function'] # libpmem calls['flush_empty'] = ['flush_empty_nolog'] From c52608a10b849b190c95640014baf655b5e05567 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 12:47:38 +0100 Subject: [PATCH 079/182] common: make LOG() macro a nop (empty) in release version Signed-off-by: Tomasz Gromadzki --- src/core/out.h | 23 ++++++++++++++++++----- src/core/util.h | 2 +- src/libpmempool/feature.c | 4 ++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/core/out.h b/src/core/out.h index 6c2ef1b6f44..75247424388 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -53,17 +53,30 @@ out_nonl_discard(int level, const char *fmt, ...) #endif +#if defined(DEBUG) || defined(__KLOCWORK__) + /* produce debug/trace output */ #define LOG(level, ...) do { \ if (!EVALUATE_DBG_EXPRESSIONS) break;\ OUT_LOG(__FILE__, __LINE__, __func__, level, __VA_ARGS__);\ } while (0) -/* produce debug/trace output without prefix and new line */ -#define LOG_NONL(level, ...) do { \ - if (!EVALUATE_DBG_EXPRESSIONS) break; \ - OUT_NONL(level, __VA_ARGS__); \ -} while (0) +#else +/* macro for suppresing errors from unused variables (up to 9) */ +#define LOG_SUPPRESS_UNUSED(...)\ + GLUE(LOG_SUPPRESS_ARG_, COUNT(__VA_ARGS__))(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_1(X) +#define LOG_SUPPRESS_ARG_2(X, ...) SUPPRESS_ARG_1(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_3(X, ...) SUPPRESS_ARG_2(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_4(X, ...) SUPPRESS_ARG_3(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_5(X, ...) SUPPRESS_ARG_4(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_6(X, ...) SUPPRESS_ARG_5(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_7(X, ...) SUPPRESS_ARG_6(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_8(X, ...) SUPPRESS_ARG_7(__VA_ARGS__) +#define LOG_SUPPRESS_ARG_9(X, ...) SUPPRESS_ARG_8(__VA_ARGS__) + +#define LOG(level, ...) LOG_SUPPRESS_UNUSED(__VA_ARGS__) +#endif void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, diff --git a/src/core/util.h b/src/core/util.h index 003a48da1b9..52d591fd7bd 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -321,7 +321,7 @@ char *util_concat_str(const char *s1, const char *s2); /* macro for suppresing errors from unused variables (up to 9) */ #define SUPPRESS_UNUSED(...)\ GLUE(SUPPRESS_ARG_, COUNT(__VA_ARGS__))(__VA_ARGS__) -#define SUPPRESS_ARG_1(X) (void) X +#define SUPPRESS_ARG_1(X) (void) (X) #define SUPPRESS_ARG_2(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_1(__VA_ARGS__) #define SUPPRESS_ARG_3(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_2(__VA_ARGS__) #define SUPPRESS_ARG_4(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_3(__VA_ARGS__) diff --git a/src/libpmempool/feature.c b/src/libpmempool/feature.c index f3bfcec6a01..d9698dbe787 100644 --- a/src/libpmempool/feature.c +++ b/src/libpmempool/feature.c @@ -261,8 +261,10 @@ typedef enum { ENABLED } fstate_t; +#ifdef DEBUG #define FEATURE_IS_ENABLED_STR "feature already enabled: %s" #define FEATURE_IS_DISABLED_STR "feature already disabled: %s" +#endif /* * require_feature_is -- (internal) check if required feature is enabled @@ -277,9 +279,11 @@ require_feature_is(struct pool_set *set, features_t feature, fstate_t req_state) if (state == req_state) return 1; +#ifdef DEBUG const char *msg = (state == ENABLED) ? FEATURE_IS_ENABLED_STR : FEATURE_IS_DISABLED_STR; LOG(3, msg, util_feature2str(feature, NULL)); +#endif return 0; } From 1143712409d9a84cd16f0900d63933ff7379f134 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 13:16:03 +0100 Subject: [PATCH 080/182] common: remove obsolete out_nonl() funcione code Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 17 ----------------- src/core/out.h | 10 ---------- 2 files changed, 27 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index f3155188990..28188b90757 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -326,23 +326,6 @@ out(const char *fmt, ...) va_end(ap); } -/* - * out_nonl -- output a line, no newline added automatically - */ -void -out_nonl(int level, const char *fmt, ...) -{ - va_list ap; - - if (Log_level < level) - return; - - va_start(ap, fmt); - out_common(NULL, 0, NULL, level, "", fmt, ap); - - va_end(ap); -} - /* * out_log_va/out_log -- output a log line if Log_level >= level */ diff --git a/src/core/out.h b/src/core/out.h index 75247424388..2de46c07ce9 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -30,7 +30,6 @@ extern "C" { /* klocwork does not seem to respect __attribute__((noreturn)) */ #if defined(DEBUG) || defined(__KLOCWORK__) #define OUT_LOG out_log -#define OUT_NONL out_nonl #else static __attribute__((always_inline)) inline void @@ -41,15 +40,7 @@ out_log_discard(const char *file, int line, const char *func, int level, SUPPRESS_UNUSED(file, line, func, level, fmt); } -static __attribute__((always_inline)) inline void -out_nonl_discard(int level, const char *fmt, ...) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(level, fmt); -} - #define OUT_LOG out_log_discard -#define OUT_NONL out_nonl_discard #endif @@ -83,7 +74,6 @@ void out_init(const char *log_prefix, const char *log_level_var, int minor_version); void out_fini(void); void out(const char *fmt, ...) FORMAT_PRINTF(1, 2); -void out_nonl(int level, const char *fmt, ...) FORMAT_PRINTF(2, 3); void out_log_va(const char *file, int line, const char *func, int level, const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, From 151220815929d1d907997bd8a96a2e01a070ec74 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 13:46:52 +0100 Subject: [PATCH 081/182] common: remove obsolete out() function Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 14 -------------- src/core/out.h | 1 - 2 files changed, 15 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index 28188b90757..68fe54000d5 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -312,20 +312,6 @@ out_common(const char *file, int line, const char *func, int level, errno = oerrno; } -/* - * out -- output a line, newline added automatically - */ -void -out(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - out_common(NULL, 0, NULL, 0, "\n", fmt, ap); - - va_end(ap); -} - /* * out_log_va/out_log -- output a log line if Log_level >= level */ diff --git a/src/core/out.h b/src/core/out.h index 2de46c07ce9..139ba3ec56f 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -73,7 +73,6 @@ void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version); void out_fini(void); -void out(const char *fmt, ...) FORMAT_PRINTF(1, 2); void out_log_va(const char *file, int line, const char *func, int level, const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, From f002940ca087da34cb4a7c49e6c287c3b3ba390f Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 14:44:19 +0100 Subject: [PATCH 082/182] test: replace out() by printf() out() has been removed from the code. Let's use simple printf(). Signed-off-by: Tomasz Gromadzki --- .../tools/anonymous_mmap/anonymous_mmap.c | 9 ++--- src/test/tools/obj_verify/obj_verify.c | 36 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/test/tools/anonymous_mmap/anonymous_mmap.c b/src/test/tools/anonymous_mmap/anonymous_mmap.c index 2fc6e5e085b..87f945120cd 100644 --- a/src/test/tools/anonymous_mmap/anonymous_mmap.c +++ b/src/test/tools/anonymous_mmap/anonymous_mmap.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018, Intel Corporation */ +/* Copyright 2018-2024, Intel Corporation */ /* * anonymous_mmap.c -- tool for verifying if given memory length can be @@ -18,7 +18,7 @@ main(int argc, char *argv[]) out_init("ANONYMOUS_MMAP", "ANONYMOUS_MMAP", "", 1, 0); if (argc != 2) { - out("Usage: %s ", argv[0]); + printf("Usage: %s \n", argv[0]); return -1; } @@ -26,8 +26,9 @@ main(int argc, char *argv[]) char *addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) { - out("anonymous_mmap.c: Failed to mmap length=%lu of memory, " - "errno=%d", length, errno); + printf( + "anonymous_mmap.c: Failed to mmap length=%lu of memory, errno=%d\n", + length, errno); return errno; } diff --git a/src/test/tools/obj_verify/obj_verify.c b/src/test/tools/obj_verify/obj_verify.c index 4e8d58ff44e..ab02182e9f8 100644 --- a/src/test/tools/obj_verify/obj_verify.c +++ b/src/test/tools/obj_verify/obj_verify.c @@ -94,13 +94,13 @@ do_create(const char *path, const char *layout) if ((pop = pmemobj_create(path, layout, 0, S_IWUSR | S_IRUSR)) == NULL) { if (errno != EEXIST) { - out("!%s: pmemobj_create: %s", + printf("!%s: pmemobj_create: %s\n", path, pmemobj_errormsg()); exit(-1); } if ((pop = pmemobj_open(path, layout)) == NULL) { - out("!%s: pmemobj_open: %s", + printf("!%s: pmemobj_open: %s\n", path, pmemobj_errormsg()); exit(-1); } @@ -115,11 +115,11 @@ do_create(const char *path, const char *layout) if (pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &class) != 0) { pmemobj_close(pop); - out("!pmemobj_ctl_set: %s", path); + printf("!pmemobj_ctl_set: %s\n", path); exit(-1); } - out("create(%s): allocating records in the pool ...", path); + printf("create(%s): allocating records in the pool ...\n", path); count = D_RO(root)->count; @@ -129,10 +129,10 @@ do_create(const char *path, const char *layout) count = D_RO(root)->count - count; if (count) { - out("create(%s): allocated %lu records (of size %zu)", + printf("create(%s): allocated %lu records (of size %zu)\n", path, count, sizeof(struct data_s)); } else { - out("create(%s): pool is full", path); + printf("create(%s): pool is full\n", path); } pmemobj_close(pop); @@ -148,10 +148,12 @@ do_verify(const char *path, const char *layout) PMEMoid oid; uint64_t count = 0; int error = 0; + char buff[128]; if ((pop = pmemobj_open(path, layout)) == NULL) { - out("!%s: pmemobj_open: %s", - path, pmemobj_errormsg()); + strerror_r(errno, buff, 128); + printf("%s: pmemobj_open: %s: %s\n", + path, pmemobj_errormsg(), buff); exit(-1); } @@ -163,7 +165,7 @@ do_verify(const char *path, const char *layout) if (!util_checksum(D_RW(rec), sizeof(*D_RW(rec)), &D_RW(rec)->checksum, 0 /* verify */, SKIP_OFFSET)) { - out("verify(%s): incorrect record: %s (#%lu)", + printf("verify(%s): incorrect record: %s (#%lu)\n", path, D_RW(rec)->signature, count); error = 1; break; @@ -173,8 +175,8 @@ do_verify(const char *path, const char *layout) } if (D_RO(root)->count != count) { - out( - "verify(%s): incorrect number of records (is: %lu, should be: %lu)", + printf( + "verify(%s): incorrect number of records (is: %lu, should be: %lu)\n", path, count, D_RO(root)->count); error = 1; } @@ -182,12 +184,12 @@ do_verify(const char *path, const char *layout) pmemobj_close(pop); if (error) { - out("verify(%s): pool file contains error", path); + printf("verify(%s): pool file contains error\n", path); exit(-1); } - out( - "verify(%s): pool file successfully verified (%lu records of size %zu)", + printf( + "verify(%s): pool file successfully verified (%lu records of size %zu)\n", path, count, sizeof(struct data_s)); } @@ -198,7 +200,7 @@ main(int argc, char *argv[]) out_init("OBJ_VERIFY", "OBJ_VERIFY", "", 1, 0); if (argc < 4) { - out("Usage: %s \n" + printf("Usage: %s \n" "Options:\n" " c - create\n" " v - verify\n", @@ -222,7 +224,7 @@ main(int argc, char *argv[]) op = argv[arg]; if (op[1] != '\0') { - out("op must be c or v (c=create, v=verify)"); + printf("op must be c or v (c=create, v=verify)\n"); exit(-1); } @@ -236,7 +238,7 @@ main(int argc, char *argv[]) break; default: - out("op must be c or v (c=create, v=verify)"); + printf("op must be c or v (c=create, v=verify)\n"); exit(-1); break; } From 92fd8a713706f3605696137d2de6839f18433ed5 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 14:48:25 +0100 Subject: [PATCH 083/182] common: out_err() no longer exists Signed-off-by: Tomasz Gromadzki --- src/test/helgrind-log.supp | 11 ----------- src/tools/pmempool/output.h | 2 -- 2 files changed, 13 deletions(-) diff --git a/src/test/helgrind-log.supp b/src/test/helgrind-log.supp index 6b29d37b022..eac51a6ada5 100644 --- a/src/test/helgrind-log.supp +++ b/src/test/helgrind-log.supp @@ -21,17 +21,6 @@ fun:out_log_va fun:out_log } -{ - - Helgrind:Race - fun:*mem*cpy - ... - fun:_IO_file_xsputn@@GLIBC* - ... - fun:out_print_func - fun:out_error - fun:out_err -} { diff --git a/src/tools/pmempool/output.h b/src/tools/pmempool/output.h index 0b86ac1f759..28b57aeebb1 100644 --- a/src/tools/pmempool/output.h +++ b/src/tools/pmempool/output.h @@ -14,8 +14,6 @@ void out_set_stream(FILE *stream); void out_set_prefix(const char *prefix); void out_set_col_width(unsigned col_width); void outv_err(const char *fmt, ...) FORMAT_PRINTF(1, 2); -void out_err(int use_errno, const char *file, int line, const char *func, - const char *fmt, ...) FORMAT_PRINTF(5, 6); void outv_err_vargs(const char *fmt, va_list ap); void outv_indent(int vlevel, int i); void outv(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3); From a6da38684621d39105362b87701e1eb0767b5fbf Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 14:49:08 +0100 Subject: [PATCH 084/182] common: out_nonl() no longer exists Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/white_list.json | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 89c7cacd11a..645c233af32 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -127,7 +127,6 @@ "os_writev", "out_log", "out_log_va", - "out_nonl", "pmalloc_operation_hold_no_start", "pmalloc", "pmem2_badblock_clear", From a814595cb8258dcaea70371faee122a6ad292f96 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 15:21:26 +0100 Subject: [PATCH 085/182] common: LOG() suppression simplified Signed-off-by: Tomasz Gromadzki --- src/core/out.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/core/out.h b/src/core/out.h index 139ba3ec56f..033dd18ce82 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -53,20 +53,7 @@ out_log_discard(const char *file, int line, const char *func, int level, } while (0) #else -/* macro for suppresing errors from unused variables (up to 9) */ -#define LOG_SUPPRESS_UNUSED(...)\ - GLUE(LOG_SUPPRESS_ARG_, COUNT(__VA_ARGS__))(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_1(X) -#define LOG_SUPPRESS_ARG_2(X, ...) SUPPRESS_ARG_1(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_3(X, ...) SUPPRESS_ARG_2(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_4(X, ...) SUPPRESS_ARG_3(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_5(X, ...) SUPPRESS_ARG_4(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_6(X, ...) SUPPRESS_ARG_5(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_7(X, ...) SUPPRESS_ARG_6(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_8(X, ...) SUPPRESS_ARG_7(__VA_ARGS__) -#define LOG_SUPPRESS_ARG_9(X, ...) SUPPRESS_ARG_8(__VA_ARGS__) - -#define LOG(level, ...) LOG_SUPPRESS_UNUSED(__VA_ARGS__) +#define LOG(level, ...) SUPPRESS_UNUSED(__VA_ARGS__) #endif void out_init(const char *log_prefix, const char *log_level_var, From 1fb3185a553d971d5c067fae08f4349ef2c78817 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 17:00:03 +0100 Subject: [PATCH 086/182] common: include core_log_init() in analysis Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_extra.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index bacc71a9acf..402cb78f6ba 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -21,7 +21,7 @@ def dict_extend(dict_, key, values): def inlines(calls: Calls) -> Calls: # common - calls['core_init'] = ['util_init', 'out_init'] + calls['core_init'] = ['util_init', 'core_log_init', 'out_init'] calls['core_fini'] = ['out_fini'] calls['common_init'] = ['core_init', 'util_mmap_init'] calls['common_fini'] = ['util_mmap_fini', 'core_fini'] From 5e66fa596753015b243813fd0fa9a49ac329d424 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 15 Feb 2024 17:54:40 +0100 Subject: [PATCH 087/182] common: new functions not used in release Add to whitelist functions that are only used in debug version. Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_extra.py | 1 - utils/call_stacks_analysis/white_list.json | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index 402cb78f6ba..466ed19eef6 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -27,7 +27,6 @@ def inlines(calls: Calls) -> Calls: calls['common_fini'] = ['util_mmap_fini', 'core_fini'] calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] calls['_Last_errormsg_key_alloc'] = ['os_once', 'os_tls_key_create'] - calls['out_common'] = ['out_snprintf'] calls['core_log_va'] = ['core_log_default_function'] # libpmem diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 645c233af32..a53696ca786 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -127,6 +127,8 @@ "os_writev", "out_log", "out_log_va", + "out_common", + "out_snprintf", "pmalloc_operation_hold_no_start", "pmalloc", "pmem2_badblock_clear", @@ -177,6 +179,7 @@ "util_safe_strcpy", "util_str2feature", "util_str2pmempool_feature", + "util_strerror", "util_unlink_flock", "util_uuid_to_string", "util_write_all" From d5f841e067f9b4b543d773600de226d57fae3bcb Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 13 Feb 2024 14:31:30 -0500 Subject: [PATCH 088/182] obj: remove an unnecessary explicit breaking character Signed-off-by: Jan Michalski --- src/libpmemobj/pmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 9956538b3ce..e0c0e236772 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -457,7 +457,7 @@ CTL_RUNNABLE_HANDLER(extend)(void *ctx, ssize_t arg_in = *(ssize_t *)arg; if (arg_in < (ssize_t)PMEMOBJ_MIN_PART) { ERR_WO_ERRNO( - "incorrect size for extend, must be larger than %" \ + "incorrect size for extend, must be larger than %" PRIu64, PMEMOBJ_MIN_PART); return -1; From 6eec12afddc4b676472f32763e21ba8b97ec88e6 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 13 Feb 2024 14:30:57 -0500 Subject: [PATCH 089/182] common: test all TLS log messages for length Signed-off-by: Jan Michalski --- src/core/last_error_msg.h | 2 +- src/test/core_log/.gitignore | 1 + src/test/core_log/Makefile | 3 +- src/test/core_log/TESTS.py | 4 + src/test/core_log/call_all.c | 21 + src/test/core_log/call_all.c.generated | 1246 +++++++++++++++++ src/test/core_log/call_all.h | 41 + src/test/core_log/core_log.c | 102 +- .../log_call_all_generate.py | 419 ++++++ 9 files changed, 1823 insertions(+), 16 deletions(-) create mode 100644 src/test/core_log/call_all.c create mode 100644 src/test/core_log/call_all.c.generated create mode 100644 src/test/core_log/call_all.h create mode 100755 utils/call_stacks_analysis/log_call_all_generate.py diff --git a/src/core/last_error_msg.h b/src/core/last_error_msg.h index 9b11ed34b62..f43821b2c13 100644 --- a/src/core/last_error_msg.h +++ b/src/core/last_error_msg.h @@ -12,7 +12,7 @@ extern "C" { #endif -#define CORE_LAST_ERROR_MSG_MAXPRINT 8192 /* maximum expected log line */ +#define CORE_LAST_ERROR_MSG_MAXPRINT 301 /* maximum expected log line */ void last_error_msg_init(void); void last_error_msg_fini(void); diff --git a/src/test/core_log/.gitignore b/src/test/core_log/.gitignore index 077e6928a11..001feb0f84e 100644 --- a/src/test/core_log/.gitignore +++ b/src/test/core_log/.gitignore @@ -1 +1,2 @@ core_log +call_all diff --git a/src/test/core_log/Makefile b/src/test/core_log/Makefile index 0dffa9240a7..4eb6aac574b 100644 --- a/src/test/core_log/Makefile +++ b/src/test/core_log/Makefile @@ -2,10 +2,11 @@ # Copyright 2024, Intel Corporation TARGET = core_log -OBJS = core_log.o +OBJS = core_log.o call_all.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n LIBPMEMCORE=y include ../Makefile.inc +LDFLAGS += $(call extract_funcs, core_log.c) diff --git a/src/test/core_log/TESTS.py b/src/test/core_log/TESTS.py index 044a5f7020a..e1acac9d831 100755 --- a/src/test/core_log/TESTS.py +++ b/src/test/core_log/TESTS.py @@ -19,3 +19,7 @@ def run(self, ctx): class TEST0(CORE_LOG): test_case = 'test_CORE_LOG_MAX_ERRNO_MSG' + + +class TEST1(CORE_LOG): + test_case = 'test_ERR_W_ERRNO' diff --git a/src/test/core_log/call_all.c b/src/test/core_log/call_all.c new file mode 100644 index 00000000000..313ed8354fc --- /dev/null +++ b/src/test/core_log/call_all.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +#include +#include +#include + +#include "call_all.h" +#include "unittest.h" + +static char *_s = PATH; +static char _8s[8] = "Posuere"; +static unsigned _u = UINT_MAX; +static unsigned long _lu = ULONG_MAX; +static int _d = INT_MAX; +static long _ld = LONG_MAX; +static size_t _zu = SIZE_MAX; +static void *_p = (void *)UINT64_MAX; +static uintmax_t _ju = UINTMAX_MAX; + +#include "call_all.c.generated" diff --git a/src/test/core_log/call_all.c.generated b/src/test/core_log/call_all.c.generated new file mode 100644 index 00000000000..8e20ba1dce4 --- /dev/null +++ b/src/test/core_log/call_all.c.generated @@ -0,0 +1,1246 @@ +/* + * This file is automatically generated by utils/call_stack_analysis/log_call_all_generate.py. + * Please do not modify manually. + */ +void +call_all_CORE_LOG_ERROR_LAST(void) +{ +} + +void +call_all_ERR_WO_ERRNO(void) +{ + // src/tools/pmempool/output.c:779 + ERR_WO_ERRNO("snprintf for incompat features: %d", _d); + // src/libpmem/pmem.c:413 + ERR_WO_ERRNO("invalid flag specified %x", _u); + // src/libpmem/pmem.c:420 + ERR_WO_ERRNO("flag unsupported for Device DAX %x", _u); + // src/libpmem/pmem.c:429 + ERR_WO_ERRNO("unable to read Device DAX size"); + // src/libpmem/pmem.c:434 + ERR_WO_ERRNO("Device DAX length must be either 0 or the exact size of the device: %zu", _zu); + // src/libpmem/pmem.c:446 + ERR_WO_ERRNO("invalid file length %zu", _zu); + // src/libpmem/pmem.c:457 + ERR_WO_ERRNO("non-zero 'len' not allowed without PMEM_FILE_CREATE"); + // src/libpmem/pmem.c:464 + ERR_WO_ERRNO("zero 'len' not allowed with PMEM_FILE_CREATE"); + // src/libpmem/pmem.c:470 + ERR_WO_ERRNO("PMEM_FILE_TMPFILE not allowed without PMEM_FILE_CREATE"); + // src/libpmem/pmem.c:513 + ERR_WO_ERRNO("stat %s: negative size", _s); + // src/libpmem/pmem.c:588 + ERR_WO_ERRNO("invalid flags 0x%x", _u); + // src/libpmem/pmem.c:619 + ERR_WO_ERRNO("invalid flags 0x%x", _u); + // src/libpmem/pmem.c:651 + ERR_WO_ERRNO("invalid flags 0x%x", _u); + // src/libpmem/libpmem.c:56 + ERR_WO_ERRNO("libpmem major version mismatch (need %u, found %u)", _u, _u); + // src/libpmem/libpmem.c:63 + ERR_WO_ERRNO("libpmem minor version mismatch (need %u, found %u)", _u, _u); + // src/libpmemobj/alloc_class.c:231 + ERR_WO_ERRNO("unable to register allocation class"); + // src/libpmemobj/tx.c:513 + ERR_WO_ERRNO("Unrecognized lock type"); + // src/libpmemobj/tx.c:550 + ERR_WO_ERRNO("Unrecognized lock type"); + // src/libpmemobj/tx.c:588 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/tx.c:617 + ERR_WO_ERRNO("out of memory"); + // src/libpmemobj/tx.c:633 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/tx.c:647 + ERR_WO_ERRNO("pmemobj_tx_free failed"); + // src/libpmemobj/tx.c:665 + ERR_WO_ERRNO("pmemobj_tx_free failed"); + // src/libpmemobj/tx.c:682 + ERR_WO_ERRNO("Buffer from a different pool"); + // src/libpmemobj/tx.c:739 + ERR_WO_ERRNO("nested transaction for different pool"); + // src/libpmemobj/tx.c:865 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1236 + ERR_WO_ERRNO("snapshot size too large"); + // src/libpmemobj/tx.c:1243 + ERR_WO_ERRNO("object outside of heap"); + // src/libpmemobj/tx.c:1383 + ERR_WO_ERRNO("out of memory"); + // src/libpmemobj/tx.c:1410 + ERR_WO_ERRNO("object outside of pool"); + // src/libpmemobj/tx.c:1448 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1456 + ERR_WO_ERRNO("object outside of pool"); + // src/libpmemobj/tx.c:1493 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1531 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1539 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1576 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1607 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1638 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1645 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1714 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1722 + ERR_WO_ERRNO("cannot duplicate NULL string"); + // src/libpmemobj/tx.c:1772 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1780 + ERR_WO_ERRNO("cannot duplicate NULL string"); + // src/libpmemobj/tx.c:1831 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1842 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1914 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1959 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:2208 + ERR_WO_ERRNO("invalid cache size, must be between 0 and max alloc size"); + // src/libpmemobj/tx.c:2232 + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); + // src/libpmemobj/tx.c:2247 + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); + // src/libpmemobj/palloc.c:196 + ERR_WO_ERRNO("no allocation class for size %lu bytes", _lu); + // src/libpmemobj/palloc.c:211 + ERR_WO_ERRNO("allocation class not suitable for size %lu bytes", _lu); + // src/libpmemobj/palloc.c:275 + ERR_WO_ERRNO("invalid operation or heap corruption"); + // src/libpmemobj/libpmemobj.c:52 + ERR_WO_ERRNO("libpmemobj major version mismatch (need %u, found %u)", _u, _u); + // src/libpmemobj/libpmemobj.c:59 + ERR_WO_ERRNO("libpmemobj minor version mismatch (need %u, found %u)", _u, _u); + // src/libpmemobj/stats.c:74 + ERR_WO_ERRNO("invalid enable type"); + // src/libpmemobj/ulog.c:245 + ERR_WO_ERRNO("cannot auto reserve next ulog"); + // src/libpmemobj/heap.c:768 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/heap.c:1051 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/heap.c:1167 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/heap.c:1410 + ERR_WO_ERRNO("at least one automatic arena must exist"); + // src/libpmemobj/heap.c:1605 + ERR_WO_ERRNO("mapped region smaller than the heap size"); + // src/libpmemobj/heap.c:1787 + ERR_WO_ERRNO("heap: invalid header's checksum"); + // src/libpmemobj/heap.c:1792 + ERR_WO_ERRNO("heap: invalid signature"); + // src/libpmemobj/heap.c:1810 + ERR_WO_ERRNO("heap: invalid zone size"); + // src/libpmemobj/heap.c:1825 + ERR_WO_ERRNO("heap: invalid chunk type"); + // src/libpmemobj/heap.c:1830 + ERR_WO_ERRNO("heap: unknown chunk type"); + // src/libpmemobj/heap.c:1835 + ERR_WO_ERRNO("heap: invalid chunk flags"); + // src/libpmemobj/heap.c:1852 + ERR_WO_ERRNO("heap: invalid zone magic"); + // src/libpmemobj/heap.c:1868 + ERR_WO_ERRNO("heap: chunk sizes mismatch"); + // src/libpmemobj/heap.c:1884 + ERR_WO_ERRNO("heap: invalid heap size"); + // src/libpmemobj/memops.c:575 + ERR_WO_ERRNO("Capacity insufficient"); + // src/libpmemobj/memops.c:586 + ERR_WO_ERRNO("Buffer currently used"); + // src/libpmemobj/memops.c:691 + ERR_WO_ERRNO("no extend function present"); + // src/libpmemobj/sync.c:43 + ERR_WO_ERRNO("error initializing lock"); + // src/libpmemobj/sync.c:50 + ERR_WO_ERRNO("error setting lock runid"); + // src/libpmemobj/obj.c:773 + ERR_WO_ERRNO("invalid checksum of pool descriptor"); + // src/libpmemobj/obj.c:780 + ERR_WO_ERRNO("wrong layout (\"%s\"), pool created with layout \"%s\"", _s, _s); + // src/libpmemobj/obj.c:788 + ERR_WO_ERRNO("unaligned heap: off %lu", _lu); + // src/libpmemobj/obj.c:1036 + ERR_WO_ERRNO("%s variable must be a positive integer", _s); + // src/libpmemobj/obj.c:1065 + ERR_WO_ERRNO("Layout too long"); + // src/libpmemobj/obj.c:1114 + ERR_WO_ERRNO("initialization of replica #%u failed", _u); + // src/libpmemobj/obj.c:1134 + ERR_WO_ERRNO("pool initialization failed"); + // src/libpmemobj/obj.c:1184 + ERR_WO_ERRNO("invalid run_id %lu", _lu); + // src/libpmemobj/obj.c:1246 + ERR_WO_ERRNO("read-only mode is not supported"); + // src/libpmemobj/obj.c:1279 + ERR_WO_ERRNO("initialization of replica #%u failed", _u); + // src/libpmemobj/obj.c:1319 + ERR_WO_ERRNO("inconsistent replica #%u", _u); + // src/libpmemobj/obj.c:1405 + ERR_WO_ERRNO("pool initialization failed"); + // src/libpmemobj/obj.c:1537 + ERR_WO_ERRNO("critnib_remove for pools_ht"); + // src/libpmemobj/obj.c:1541 + ERR_WO_ERRNO("critnib_remove for pools_tree"); + // src/libpmemobj/obj.c:1724 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/obj.c:1767 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/obj.c:1798 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/obj.c:1804 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/obj.c:1843 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/obj.c:1921 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/obj.c:2298 + ERR_WO_ERRNO("invalid flags 0x%x", _u); + // src/libpmemobj/obj.c:2316 + ERR_WO_ERRNO("invalid flags 0x%x", _u); + // src/libpmemobj/obj.c:2418 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/obj.c:2424 + ERR_WO_ERRNO("requested size cannot equals zero"); + // src/libpmemobj/obj.c:2560 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/obj.c:2669 + ERR_WO_ERRNO("Not all PMEMoids belong to the provided pool"); + // src/libpmemobj/obj.c:2739 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/pmalloc.c:237 + ERR_WO_ERRNO("unit size must be evenly divisible by alignment"); + // src/libpmemobj/pmalloc.c:243 + ERR_WO_ERRNO("alignment cannot be larger than 2 megabytes"); + // src/libpmemobj/pmalloc.c:261 + ERR_WO_ERRNO("invalid header type"); + // src/libpmemobj/pmalloc.c:268 + ERR_WO_ERRNO("no available free allocation class identifier"); + // src/libpmemobj/pmalloc.c:278 + ERR_WO_ERRNO("class id outside of the allowed range"); + // src/libpmemobj/pmalloc.c:286 + ERR_WO_ERRNO("attempted to overwrite an allocation class"); + // src/libpmemobj/pmalloc.c:344 + ERR_WO_ERRNO("invalid header type"); + // src/libpmemobj/pmalloc.c:369 + ERR_WO_ERRNO("class id outside of the allowed range"); + // src/libpmemobj/pmalloc.c:380 + ERR_WO_ERRNO("class with the given id does not exist"); + // src/libpmemobj/pmalloc.c:459 + ERR_WO_ERRNO("incorrect size for extend, must be larger than %lu", _lu); + // src/libpmemobj/pmalloc.c:511 + ERR_WO_ERRNO("incorrect grow size, must be 0 or larger than %lu", _lu); + // src/libpmemobj/pmalloc.c:576 + ERR_WO_ERRNO("cannot change max arena number"); + // src/libpmemobj/pmalloc.c:642 + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); + // src/libpmemobj/pmalloc.c:680 + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); + // src/libpmemobj/pmalloc.c:687 + ERR_WO_ERRNO("incorrect arena state, must be 0 or 1"); + // src/libpmemobj/pmalloc.c:719 + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); + // src/libpmemobj/pmalloc.c:767 + ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); + // src/libpmemobj/pmalloc.c:919 + ERR_WO_ERRNO("invalid arena assignment type"); + // src/libpmemobj/pmalloc.c:969 + ERR_WO_ERRNO("number of default arenas can't be 0"); + // src/common/set.c:257 + ERR_WO_ERRNO("unable to map at requested address %p", _p); + // src/common/set.c:476 + ERR_WO_ERRNO("size autodetection is supported only for device dax"); + // src/common/set.c:732 + ERR_WO_ERRNO("cannot mix directories and files in a set"); + // src/common/set.c:758 + ERR_WO_ERRNO("cannot mix directories and files in a set"); + // src/common/set.c:768 + ERR_WO_ERRNO("cannot resolve realpath of new directory"); + // src/common/set.c:780 + ERR_WO_ERRNO("cannot use the same directory twice"); + // src/common/set.c:877 + ERR_WO_ERRNO("replica #%u part %u %smapped with MAP_SYNC", _u, _u, _s); + // src/common/set.c:887 + ERR_WO_ERRNO("replica #%u part %u header %smapped with MAP_SYNC", _u, _u, _s); + // src/common/set.c:916 + ERR_WO_ERRNO("either all the parts must be Device DAX or none"); + // src/common/set.c:926 + ERR_WO_ERRNO("Multiple DAX devices with alignment other than 4KB. Use the SINGLEHDR poolset option."); + // src/common/set.c:945 + ERR_WO_ERRNO("both SINGLEHDR and NOHDR poolset options used at the same time"); + // src/common/set.c:1066 + ERR_WO_ERRNO("unable to load part %s", _s); + // src/common/set.c:1105 + ERR_WO_ERRNO("failed to load parts from directory %s", _s); + // src/common/set.c:1302 + ERR_WO_ERRNO("Remote replicas are no longer supported. This functionality is deprecated."); + // src/common/set.c:1339 + ERR_WO_ERRNO("%s [%s:%d]", _s, _s, _d); + // src/common/set.c:1357 + ERR_WO_ERRNO("cannot load part files from directories"); + // src/common/set.c:1511 + ERR_WO_ERRNO("file size does not match config: %s, %zu != %zu", _s, _zu, _zu); + // src/common/set.c:1609 + ERR_WO_ERRNO("size must be zero for device dax"); + // src/common/set.c:1643 + ERR_WO_ERRNO("file is not a poolset file and its size (%zu) is smaller than %zu", _zu, _zu); + // src/common/set.c:1680 + ERR_WO_ERRNO("poolset file options (%u) do not match incompat feature flags (%#x)", _u, _u); + // src/common/set.c:1708 + ERR_WO_ERRNO("Non-empty file detected"); + // src/common/set.c:1816 + ERR_WO_ERRNO("invalid major version (0)"); + // src/common/set.c:1823 + ERR_WO_ERRNO("wrong pool type: \"%.8s\"", _8s); + // src/common/set.c:1830 + ERR_WO_ERRNO("pool version %d (library expects %d)", _d, _d); + // src/common/set.c:1833 + ERR_WO_ERRNO("Please run the pmdk-convert utility to upgrade the pool."); + // src/common/set.c:1858 + ERR_WO_ERRNO("invalid checksum of pool header"); + // src/common/set.c:1866 + ERR_WO_ERRNO("wrong architecture flags"); + // src/common/set.c:1874 + ERR_WO_ERRNO("wrong pool set UUID"); + // src/common/set.c:1884 + ERR_WO_ERRNO("wrong part UUID"); + // src/common/set.c:1891 + ERR_WO_ERRNO("incompatible pool format"); + // src/common/set.c:1900 + ERR_WO_ERRNO("incompatible feature flags"); + // src/common/set.c:2253 + ERR_WO_ERRNO("cannot extend pool by 0 bytes"); + // src/common/set.c:2258 + ERR_WO_ERRNO("extending the pool by appending parts with headers is not supported!"); + // src/common/set.c:2266 + ERR_WO_ERRNO("exceeded reservation size"); + // src/common/set.c:2275 + ERR_WO_ERRNO("unable to append a new part to the pool"); + // src/common/set.c:2290 + ERR_WO_ERRNO("cannot open the new part"); + // src/common/set.c:2300 + ERR_WO_ERRNO("cannot map the new part"); + // src/common/set.c:2310 + ERR_WO_ERRNO("new part cannot be mapped with MAP_SYNC"); + // src/common/set.c:2313 + ERR_WO_ERRNO("new part mapped with MAP_SYNC"); + // src/common/set.c:2356 + ERR_WO_ERRNO("file contains bad blocks -- '%s'", _s); + // src/common/set.c:2390 + ERR_WO_ERRNO("file %s already exists", _s); + // src/common/set.c:2407 + ERR_WO_ERRNO("the NOHDRS poolset option is not supported for local poolsets"); + // src/common/set.c:2414 + ERR_WO_ERRNO("pool attributes are not supported for poolsets without headers (with the NOHDRS option)"); + // src/common/set.c:2421 + ERR_WO_ERRNO("directory based pools are not supported for poolsets with headers (without SINGLEHDR option)"); + // src/common/set.c:2428 + ERR_WO_ERRNO("reservation pool size %zu smaller than %zu", _zu, _zu); + // src/common/set.c:2436 + ERR_WO_ERRNO("cannot create a new part in provided directories"); + // src/common/set.c:2455 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be created, run 'pmempool create --clear-bad-blocks' utility to clear bad blocks and create a pool"); + // src/common/set.c:2463 + ERR_WO_ERRNO("net pool size %zu smaller than %zu", _zu, _zu); + // src/common/set.c:2470 + ERR_WO_ERRNO("replication not supported"); + // src/common/set.c:2633 + ERR_WO_ERRNO("pool mapping failed - address space reservation too small"); + // src/common/set.c:2806 + ERR_WO_ERRNO("wrong replica UUID"); + // src/common/set.c:2862 + ERR_WO_ERRNO("device dax cannot be mapped privately"); + // src/common/set.c:2877 + ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:2900 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:3018 + ERR_WO_ERRNO("device dax cannot be mapped privately"); + // src/common/set.c:3038 + ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:3064 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool -- '%s'", _s); + // src/common/set.c:3215 + ERR_WO_ERRNO("util_poolset_parse failed -- '%s'", _s); + // src/common/set_badblocks.c:46 + ERR_WO_ERRNO("checking the pool file for bad blocks failed -- '%s'", _s); + // src/common/set_badblocks.c:53 + ERR_WO_ERRNO("part file contains bad blocks -- '%s'", _s); + // src/common/set_badblocks.c:120 + ERR_WO_ERRNO("clearing bad blocks in the pool file failed -- '%s'", _s); + // src/common/shutdown_state.c:77 + ERR_WO_ERRNO("Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); + // src/common/shutdown_state.c:87 + ERR_WO_ERRNO("cannot read uuid of %d", _d); + // src/common/shutdown_state.c:101 + ERR_WO_ERRNO("cannot read uuid of %d", _d); + // src/common/shutdown_state.c:232 + ERR_WO_ERRNO("an ADR failure was detected, the pool might be corrupted"); + // src/common/file.c:111 + ERR_WO_ERRNO("invalid (NULL) path"); + // src/common/file.c:182 + ERR_WO_ERRNO("file size (%ld) too big to be represented in 64-bit signed integer", _ld); + // src/common/file.c:409 + ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); + // src/common/file.c:415 + ERR_WO_ERRNO("invalid size (%zu) for os_off_t", _zu); + // src/common/file.c:485 + ERR_WO_ERRNO("stat \"%s\": negative size", _s); + // src/common/file.c:491 + ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); + // src/common/mmap.c:287 + ERR_WO_ERRNO("duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu", _p, _zu); + // src/common/mmap.c:308 + ERR_WO_ERRNO("Cannot find DAX device region id"); + // src/common/mmap.c:336 + ERR_WO_ERRNO("invalid munmap length, must be non-zero and page aligned"); + // src/common/ctl.c:215 + ERR_WO_ERRNO("read queries require non-NULL argument"); + // src/common/ctl.c:231 + ERR_WO_ERRNO("write queries require non-NULL argument"); + // src/common/ctl.c:278 + ERR_WO_ERRNO("invalid query"); + // src/common/ctl.c:302 + ERR_WO_ERRNO("invalid query entry point %s", _s); + // src/common/ctl.c:374 + ERR_WO_ERRNO("failed to parse query %s", _s); + // src/common/ctl.c:436 + ERR_WO_ERRNO("Config file too large"); + // src/common/ctl.c:562 + ERR_WO_ERRNO("invalid destination size %zu", _zu); + // src/common/pool_hdr.c:116 + ERR_WO_ERRNO("invalid reserved values"); + // src/common/pool_hdr.c:121 + ERR_WO_ERRNO("invalid machine value"); + // src/common/pool_hdr.c:126 + ERR_WO_ERRNO("invalid data value"); + // src/common/pool_hdr.c:131 + ERR_WO_ERRNO("invalid machine_class value"); + // src/common/pool_hdr.c:136 + ERR_WO_ERRNO("invalid alignment_desc value"); + // src/common/pool_hdr.c:173 + ERR_WO_ERRNO("unsafe to continue due to unknown incompat features: %#x", _u); + // src/common/pool_hdr.c:182 + ERR_WO_ERRNO("switching to read-only mode due to unknown ro_compat features: %#x", _u); + // src/common/mmap_posix.c:90 + ERR_WO_ERRNO("end of address space reached"); +} + +void +call_all_CORE_LOG_WARNING(void) +{ + // src/libpmemobj/palloc.c:307 + CORE_LOG_WARNING("unable to track runtime chunk state"); + // src/libpmemobj/heap.c:1192 + CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); + // src/libpmemobj/heap.c:1204 + CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); + // src/libpmemobj/memops.c:352 + CORE_LOG_WARNING("out of memory - unable to track entries"); + // src/common/set.c:428 + CORE_LOG_WARNING("file permissions changed during pool initialization, file: %s (%o)", _s, _u); + // src/common/set.c:2002 + CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); + // src/common/set.c:2649 + CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); + // src/common/set.c:2897 + CORE_LOG_WARNING("pool set contains bad blocks, ignoring"); + // src/common/set.c:2955 + CORE_LOG_WARNING("cannot open the part -- \"%s\"", _s); + // src/common/set.c:3060 + CORE_LOG_WARNING("pool set contains bad blocks, ignoring -- '%s'", _s); + // src/common/shutdown_state.c:206 + CORE_LOG_WARNING("incorrect checksum - SDS will be reinitialized"); + // src/common/shutdown_state.c:219 + CORE_LOG_WARNING("the pool was not closed - SDS will be reinitialized"); + // src/common/shutdown_state.c:226 + CORE_LOG_WARNING("an ADR failure was detected but the pool was closed - SDS will be reinitialized"); + // src/common/file.c:263 + CORE_LOG_WARNING("requested size of write goes beyond the file length, %zu > %zu", _zu, _zu); + // src/common/file.c:326 + CORE_LOG_WARNING("requested size of write goes beyond the file length, %zu > %zu", _zu, _zu); + // src/common/file.c:380 + CORE_LOG_WARNING("requested size of read goes beyond the file length, %zu > %zu", _zu, _zu); + // src/common/mmap.c:54 + CORE_LOG_WARNING("Invalid PMEM_MMAP_HINT"); + // src/common/mmap.c:56 + CORE_LOG_WARNING("No /proc, PMEM_MMAP_HINT ignored"); +} + +void +call_all_CORE_LOG_ERROR(void) +{ + // src/tools/pmempool/common.c:1307 + CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); + // src/libpmem/pmem.c:480 + CORE_LOG_ERROR("failed to create temporary file at \"%s\"", _s); + // src/libpmem/pmem_posix.c:61 + CORE_LOG_ERROR("can't track mapped region"); + // src/libpmemobj/lane.c:417 + CORE_LOG_ERROR("lane %lu internal redo failed: %d", _lu, _d); + // src/libpmemobj/list.c:564 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:603 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:731 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:765 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:842 + CORE_LOG_ERROR("list_mutexes_lock failed"); + // src/libpmemobj/heap.c:1327 + CORE_LOG_ERROR("cannot decrease max number of arenas"); + // src/libpmemobj/obj.c:90 + CORE_LOG_ERROR("ctl_new"); + // src/libpmemobj/obj.c:105 + CORE_LOG_ERROR("unable to parse config stored in %s environment variable", _s); + // src/libpmemobj/obj.c:116 + CORE_LOG_ERROR("unable to parse config stored in %s file (from %s environment variable)", _s, _s); + // src/libpmemobj/obj.c:1090 + CORE_LOG_ERROR("cannot create pool or pool set"); + // src/libpmemobj/obj.c:1127 + CORE_LOG_ERROR("creation of pool descriptor failed"); + // src/libpmemobj/obj.c:1189 + CORE_LOG_ERROR("lane_check"); + // src/libpmemobj/obj.c:1198 + CORE_LOG_ERROR("heap_check"); + // src/libpmemobj/obj.c:1238 + CORE_LOG_ERROR("cannot open pool or pool set"); + // src/libpmemobj/obj.c:1375 + CORE_LOG_ERROR("descriptor check of replica #%u failed", _u); + // src/libpmemobj/obj.c:2438 + CORE_LOG_ERROR("obj_realloc_root failed"); + // src/common/file_posix.c:115 + CORE_LOG_ERROR("Cannot open file %s", _s); + // src/common/set.c:183 + CORE_LOG_ERROR("cannot find a contiguous region of given size"); + // src/common/set.c:343 + CORE_LOG_ERROR("replica open failed: replica %u", _u); + // src/common/set.c:1053 + CORE_LOG_ERROR("cannot read size of file (%s) in a poolset directory", _s); + // src/common/set.c:1484 + CORE_LOG_ERROR("failed to create file: %s", _s); + // src/common/set.c:1494 + CORE_LOG_ERROR("failed to open file: %s", _s); + // src/common/set.c:1964 + CORE_LOG_ERROR("cannot find a contiguous region of given size"); + // src/common/set.c:1972 + CORE_LOG_ERROR("pool mapping failed - replica #%u part #0", _u); + // src/common/set.c:2016 + CORE_LOG_ERROR("usable space mapping failed - part #%d", _d); + // src/common/set.c:2085 + CORE_LOG_ERROR("header mapping failed - part #%d", _d); + // src/common/set.c:2093 + CORE_LOG_ERROR("header creation failed - part #%d", _d); + // src/common/set.c:2130 + CORE_LOG_ERROR("replica #%u map failed", _u); + // src/common/set.c:2139 + CORE_LOG_ERROR("replica #%u headers initialization failed", _u); + // src/common/set.c:2398 + CORE_LOG_ERROR("cannot create pool set -- '%s'", _s); + // src/common/set.c:2445 + CORE_LOG_ERROR("failed to check pool set for bad blocks -- '%s'", _s); + // src/common/set.c:2485 + CORE_LOG_ERROR("cannot generate pool set UUID"); + // src/common/set.c:2497 + CORE_LOG_ERROR("cannot generate pool set part UUID"); + // src/common/set.c:2524 + CORE_LOG_ERROR("replica #%u creation failed", _u); + // src/common/set.c:2591 + CORE_LOG_ERROR("cannot find a contiguous region of given size"); + // src/common/set.c:2601 + CORE_LOG_ERROR("pool mapping failed - replica #%u part #0", _u); + // src/common/set.c:2615 + CORE_LOG_ERROR("header mapping failed - part #%d", _d); + // src/common/set.c:2662 + CORE_LOG_ERROR("usable space mapping failed - part #%d", _d); + // src/common/set.c:2793 + CORE_LOG_ERROR("header check failed - part #%d", _d); + // src/common/set.c:2823 + CORE_LOG_ERROR("ADR failure detected"); + // src/common/set.c:2883 + CORE_LOG_ERROR("an error occurred when checking whether recovery file exists."); + // src/common/set.c:2890 + CORE_LOG_ERROR("failed to check pool set for bad blocks"); + // src/common/set.c:2916 + CORE_LOG_ERROR("replica #%u open failed", _u); + // src/common/set.c:2963 + CORE_LOG_ERROR("header mapping failed -- \"%s\"", _s); + // src/common/set.c:3007 + CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); + // src/common/set.c:3030 + CORE_LOG_ERROR("reading compat features failed"); + // src/common/set.c:3045 + CORE_LOG_ERROR("an error occurred when checking whether recovery file exists."); + // src/common/set.c:3052 + CORE_LOG_ERROR("failed to check pool set for bad blocks -- '%s'", _s); + // src/common/set.c:3079 + CORE_LOG_ERROR("replica #%u open failed", _u); + // src/common/set.c:3316 + CORE_LOG_ERROR("os_part_deep_common(%p, %p, %lu)", _p, _p, _lu); + // src/common/set_badblocks.c:86 + CORE_LOG_ERROR("%i pool file(s) contain bad blocks", _d); + // src/common/set_badblocks.c:213 + CORE_LOG_ERROR("allocating name of bad block recovery file failed"); + // src/common/shutdown_state.c:80 + CORE_LOG_ERROR("cannot read unsafe shutdown count for %d", _d); + // src/common/file.c:212 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:218 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:250 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:256 + CORE_LOG_ERROR("offset beyond file length, %ju > %ju", _ju, _ju); + // src/common/file.c:272 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:307 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); + // src/common/file.c:320 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:335 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:361 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); + // src/common/file.c:374 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:389 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:547 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); + // src/common/mmap.c:94 + CORE_LOG_ERROR("cannot find a contiguous region of given size"); + // src/common/ctl.c:238 + CORE_LOG_ERROR("Invalid arguments"); + // src/common/bad_blocks.c:152 + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); + // src/common/bad_blocks.c:161 + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); + // src/common/bad_blocks.c:210 + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); + // src/common/bad_blocks.c:217 + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); + // src/common/bad_blocks.c:255 + CORE_LOG_ERROR("counting bad blocks failed -- '%s'", _s); + // src/common/bad_blocks.c:260 + CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", _s, _d); + // src/common/uuid.c:24 + CORE_LOG_ERROR("invalid buffer for uuid string"); + // src/common/uuid.c:29 + CORE_LOG_ERROR("invalid uuid structure"); + // src/common/uuid.c:42 + CORE_LOG_ERROR("snprintf(uuid): %d", _d); + // src/common/uuid.c:60 + CORE_LOG_ERROR("invalid uuid string"); + // src/common/uuid.c:66 + CORE_LOG_ERROR("invalid uuid string"); + // src/common/uuid.c:79 + CORE_LOG_ERROR("sscanf(uuid)"); + // src/common/os_deep_linux.c:38 + CORE_LOG_ERROR("deep_flush not supported"); + // src/common/os_deep_linux.c:42 + CORE_LOG_ERROR("cannot write to deep_flush in region %u", _u); + // src/common/os_deep_linux.c:127 + CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); + // src/common/os_deep_linux.c:156 + CORE_LOG_ERROR("deep_flush not supported"); + // src/common/os_deep_linux.c:159 + CORE_LOG_ERROR("invalid dax_region id %u", _u); + // src/common/os_deep_linux.c:166 + CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", _u); + // src/common/os_deep_linux.c:175 + CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); + // src/common/uuid_linux.c:31 + CORE_LOG_ERROR("open(uuid)"); + // src/common/uuid_linux.c:37 + CORE_LOG_ERROR("read(uuid)"); + // src/core/util_posix.c:52 + CORE_LOG_ERROR("stat failed for %s", _s); + // src/core/util_posix.c:62 + CORE_LOG_ERROR("stat failed for %s", _s); +} + +void +call_all_CORE_LOG_FATAL(void) +{ + // src/libpmem/pmem.c:362 + CORE_LOG_FATAL("util_bool_compare_and_swap32"); + // src/libpmem/pmem.c:915 + CORE_LOG_FATAL("invalid flush function address"); + // src/libpmemobj/lane.c:43 + CORE_LOG_FATAL("critnib_new"); + // src/libpmemobj/lane.c:80 + CORE_LOG_FATAL("os_tls_set"); + // src/libpmemobj/lane.c:105 + CORE_LOG_FATAL("os_tls_key_create"); + // src/libpmemobj/lane.c:483 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/lane.c:499 + CORE_LOG_FATAL("critnib_insert"); + // src/libpmemobj/lane.c:555 + CORE_LOG_FATAL("lane_release"); + // src/libpmemobj/lane.c:560 + CORE_LOG_FATAL("util_bool_compare_and_swap64"); + // src/libpmemobj/memblock.c:1106 + CORE_LOG_FATAL("failed to initialize valgrind state"); + // src/libpmemobj/memblock.c:1146 + CORE_LOG_FATAL("failed to initialize valgrind state"); + // src/libpmemobj/memblock.c:1466 + CORE_LOG_FATAL("possible zone chunks metadata corruption"); + // src/libpmemobj/tx.c:161 + CORE_LOG_FATAL("%s called outside of transaction", _s); + // src/libpmemobj/tx.c:272 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:284 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:321 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:574 + CORE_LOG_FATAL("invalid state of ranges tree"); + // src/libpmemobj/tx.c:769 + CORE_LOG_FATAL("Invalid stage %d to begin new transaction", _d); + // src/libpmemobj/tx.c:807 + CORE_LOG_FATAL("transaction callback is already set, old %p new %p old_arg %p new_arg %p", _p, _p, _p, _p); + // src/libpmemobj/tx.c:1049 + CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); + // src/libpmemobj/tx.c:1053 + CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); + // src/libpmemobj/palloc.c:304 + CORE_LOG_FATAL("duplicate runtime chunk state, possible double free"); + // src/libpmemobj/sync.h:87 + CORE_LOG_FATAL("pmemobj_mutex_lock"); + // src/libpmemobj/sync.h:102 + CORE_LOG_FATAL("pmemobj_mutex_unlock"); + // src/libpmemobj/obj.c:148 + CORE_LOG_FATAL("critnib_new for pools_ht"); + // src/libpmemobj/obj.c:156 + CORE_LOG_FATAL("critnib_new for pools_tree"); + // src/libpmemobj/obj.c:211 + CORE_LOG_FATAL("error: %s", _s); + // src/libpmemobj/obj.c:252 + CORE_LOG_FATAL("pmem_msync"); + // src/common/set.c:221 + CORE_LOG_FATAL("munmap: %s", _s); + // src/common/set.c:2220 + CORE_LOG_FATAL("cannot add a new part to the replica info"); + // src/common/util_pmem.h:30 + CORE_LOG_FATAL("pmem_msync"); + // src/core/last_error_msg.c:37 + CORE_LOG_FATAL("os_thread_key_create"); + // src/core/last_error_msg.c:78 + CORE_LOG_FATAL("os_tls_set"); + // src/core/sys_util.h:31 + CORE_LOG_FATAL("os_mutex_init"); + // src/core/sys_util.h:46 + CORE_LOG_FATAL("os_mutex_destroy"); + // src/core/sys_util.h:61 + CORE_LOG_FATAL("os_mutex_lock"); + // src/core/sys_util.h:77 + CORE_LOG_FATAL("os_mutex_trylock"); + // src/core/sys_util.h:93 + CORE_LOG_FATAL("os_mutex_unlock"); + // src/core/sys_util.h:108 + CORE_LOG_FATAL("os_rwlock_init"); + // src/core/sys_util.h:123 + CORE_LOG_FATAL("os_rwlock_rdlock"); + // src/core/sys_util.h:138 + CORE_LOG_FATAL("os_rwlock_wrlock"); + // src/core/sys_util.h:153 + CORE_LOG_FATAL("os_rwlock_unlock"); + // src/core/sys_util.h:168 + CORE_LOG_FATAL("os_rwlock_destroy"); + // src/core/sys_util.h:197 + CORE_LOG_FATAL("os_spin_destroy"); + // src/core/sys_util.h:211 + CORE_LOG_FATAL("os_spin_lock"); + // src/core/sys_util.h:226 + CORE_LOG_FATAL("os_spin_unlock"); + // src/core/sys_util.h:239 + CORE_LOG_FATAL("os_semaphore_init"); + // src/core/sys_util.h:249 + CORE_LOG_FATAL("os_semaphore_destroy"); + // src/core/sys_util.h:266 + CORE_LOG_FATAL("os_semaphore_wait"); + // src/core/sys_util.h:282 + CORE_LOG_FATAL("os_semaphore_trywait"); + // src/core/sys_util.h:294 + CORE_LOG_FATAL("os_semaphore_post"); + // src/core/sys_util.h:301 + CORE_LOG_FATAL("os_cond_init"); + // src/core/sys_util.h:308 + CORE_LOG_FATAL("os_cond_destroy"); + // src/core/core_assert.h:39 + CORE_LOG_FATAL("assertion failure: %s", _s); + // src/core/core_assert.h:45 + CORE_LOG_FATAL("assertion failure: %s (%s = %s)", _s, _s, _s); + // src/core/alloc.c:62 + CORE_LOG_FATAL("unknown allocation type"); + // src/core/out.c:113 + CORE_LOG_FATAL("Cannot set log threshold"); + // src/core/out.c:145 + CORE_LOG_FATAL("Cannot set legacy log function"); +} + +void +call_all_CORE_LOG_ERROR_W_ERRNO_LAST(int errnum) +{ + errno = errnum; +} + +void +call_all_ERR_W_ERRNO(int errnum) +{ + errno = errnum; + // src/libpmem/pmem.c:280 + ERR_W_ERRNO("msync"); + UT_ASSERTeq(errno, errnum); + // src/libpmem/pmem.c:487 + ERR_W_ERRNO("open %s", _s); + UT_ASSERTeq(errno, errnum); + // src/libpmem/pmem.c:500 + ERR_W_ERRNO("ftruncate"); + UT_ASSERTeq(errno, errnum); + // src/libpmem/pmem.c:506 + ERR_W_ERRNO("posix_fallocate"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:267 + ERR_W_ERRNO("Malloc of volatile lanes"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:276 + ERR_W_ERRNO("Malloc for lane locks"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:289 + ERR_W_ERRNO("lane_init"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:499 + ERR_W_ERRNO("pmemobj_mutex_lock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:508 + ERR_W_ERRNO("pmemobj_rwlock_wrlock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:776 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:945 + ERR_W_ERRNO("explicit transaction abort"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/list.c:473 + ERR_W_ERRNO("palloc_reserve"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/stats.c:124 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/critnib.c:279 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/critnib.c:316 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/heap.c:187 + ERR_W_ERRNO("heap: arena malloc error"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/memops.c:90 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/memops.c:116 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/memops.c:177 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:662 + ERR_W_ERRNO("lane_boot"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:667 + ERR_W_ERRNO("lane_recover_and_section_boot"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:725 + ERR_W_ERRNO("palloc_init"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:964 + ERR_W_ERRNO("critnib_insert to pools_ht"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:969 + ERR_W_ERRNO("critnib_insert to pools_tree"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:984 + ERR_W_ERRNO("ravl_new_sized"); + UT_ASSERTeq(errno, errnum); + // src/common/file_posix.c:158 + ERR_W_ERRNO("stat \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:195 + ERR_W_ERRNO("mmap: %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:252 + ERR_W_ERRNO("mmap: %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:283 + ERR_W_ERRNO("munmap: %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:369 + ERR_W_ERRNO("unlink %s failed (part %u, replica %u)", _s, _u, _u); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:422 + ERR_W_ERRNO("fstat %d %s", _d, _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:435 + ERR_W_ERRNO("chmod %u/%u/%s", _u, _u, _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:518 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:622 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:648 + ERR_W_ERRNO("Realloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:841 + ERR_W_ERRNO("Realloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:849 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1027 + ERR_W_ERRNO("fs_new: \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1060 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1139 + ERR_W_ERRNO("no directories in replica"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1156 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1196 + ERR_W_ERRNO("lseek %d", _d); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1202 + ERR_W_ERRNO("dup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1208 + ERR_W_ERRNO("fdopen %d", _d); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1219 + ERR_W_ERRNO("Reading poolset file"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1226 + ERR_W_ERRNO("Malloc for pool set"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1232 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1404 + ERR_W_ERRNO("Malloc for pool set"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1410 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1419 + ERR_W_ERRNO("Malloc for pool set replica"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1503 + ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1573 + ERR_W_ERRNO("open: path \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1632 + ERR_W_ERRNO("read %d", _d); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:1756 + ERR_W_ERRNO("fstat"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:2212 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:3013 + ERR_W_ERRNO("no parts in replicas"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:3144 + ERR_W_ERRNO("read"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:3208 + ERR_W_ERRNO("open: path \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set_badblocks.c:171 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/shutdown_state.c:95 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/common/vecq.h:68 + ERR_W_ERRNO("Realloc"); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:40 + ERR_W_ERRNO("os_access \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:94 + ERR_W_ERRNO("fstat"); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:126 + ERR_W_ERRNO("stat"); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:143 + ERR_W_ERRNO("open"); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:206 + ERR_W_ERRNO("open \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:244 + ERR_W_ERRNO("open \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:430 + ERR_W_ERRNO("open \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:435 + ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:440 + ERR_W_ERRNO("flock \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:469 + ERR_W_ERRNO("open \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:474 + ERR_W_ERRNO("flock \"%s\"", _s); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:507 + ERR_W_ERRNO("flock unlock"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:104 + ERR_W_ERRNO("mmap %zu bytes", _zu); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:126 + ERR_W_ERRNO("munmap"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:155 + ERR_W_ERRNO("mprotect: PROT_READ"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:184 + ERR_W_ERRNO("mprotect: PROT_READ|PROT_WRITE"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:213 + ERR_W_ERRNO("mprotect: PROT_NONE"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:297 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:360 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/mmap.c:375 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/ctl.c:132 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/common/ctl.c:142 + ERR_W_ERRNO("strtok_r"); + UT_ASSERTeq(errno, errnum); + // src/common/ctl.c:400 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/ctl.c:445 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/common/ctl.c:479 + ERR_W_ERRNO("Zalloc"); + UT_ASSERTeq(errno, errnum); + // src/common/bad_blocks.c:63 + ERR_W_ERRNO("open %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/bad_blocks.c:142 + ERR_W_ERRNO("open %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/bad_blocks.c:200 + ERR_W_ERRNO("open %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/mmap_posix.c:43 + ERR_W_ERRNO("%s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/mmap_posix.c:141 + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); + UT_ASSERTeq(errno, errnum); + // src/common/vec.h:62 + ERR_W_ERRNO("Realloc"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:181 + ERR_W_ERRNO("os_spin_init"); + UT_ASSERTeq(errno, errnum); + // src/core/ravl.c:51 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/core/ravl.c:167 + ERR_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/core/util_posix.c:49 + ERR_W_ERRNO("stat failed for %s", _s); + UT_ASSERTeq(errno, errnum); + // src/core/util_posix.c:59 + ERR_W_ERRNO("stat failed for %s", _s); + UT_ASSERTeq(errno, errnum); + // src/core/util_posix.c:99 + ERR_W_ERRNO("mkstemp"); + UT_ASSERTeq(errno, errnum); + // src/core/util_posix.c:138 + ERR_W_ERRNO("open"); + UT_ASSERTeq(errno, errnum); + // src/core/out.c:126 + ERR_W_ERRNO("snprintf"); + UT_ASSERTeq(errno, errnum); +} + +void +call_all_CORE_LOG_WARNING_W_ERRNO(int errnum) +{ + errno = errnum; + // src/common/set.c:2955 + CORE_LOG_WARNING_W_ERRNO("cannot open the part -- \"%s\"", _s); + UT_ASSERTeq(errno, errnum); +} + +void +call_all_CORE_LOG_ERROR_W_ERRNO(int errnum) +{ + errno = errnum; + // src/libpmemobj/obj.c:90 + CORE_LOG_ERROR_W_ERRNO("ctl_new"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:1189 + CORE_LOG_ERROR_W_ERRNO("lane_check"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:1198 + CORE_LOG_ERROR_W_ERRNO("heap_check"); + UT_ASSERTeq(errno, errnum); + // src/common/os_deep_linux.c:38 + CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); + UT_ASSERTeq(errno, errnum); + // src/common/os_deep_linux.c:156 + CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); + UT_ASSERTeq(errno, errnum); + // src/common/uuid_linux.c:31 + CORE_LOG_ERROR_W_ERRNO("open(uuid)"); + UT_ASSERTeq(errno, errnum); + // src/common/uuid_linux.c:37 + CORE_LOG_ERROR_W_ERRNO("read(uuid)"); + UT_ASSERTeq(errno, errnum); +} + +void +call_all_CORE_LOG_FATAL_W_ERRNO(int errnum) +{ + errno = errnum; + // src/libpmemobj/lane.c:80 + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:105 + CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:272 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:284 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:321 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/sync.h:87 + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/sync.h:102 + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:148 + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:156 + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:252 + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:221 + CORE_LOG_FATAL_W_ERRNO("munmap: %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/util_pmem.h:30 + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); + UT_ASSERTeq(errno, errnum); + // src/core/last_error_msg.c:37 + CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); + UT_ASSERTeq(errno, errnum); + // src/core/last_error_msg.c:78 + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:31 + CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:46 + CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:61 + CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:77 + CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:93 + CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:108 + CORE_LOG_FATAL_W_ERRNO("os_rwlock_init"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:123 + CORE_LOG_FATAL_W_ERRNO("os_rwlock_rdlock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:138 + CORE_LOG_FATAL_W_ERRNO("os_rwlock_wrlock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:153 + CORE_LOG_FATAL_W_ERRNO("os_rwlock_unlock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:168 + CORE_LOG_FATAL_W_ERRNO("os_rwlock_destroy"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:197 + CORE_LOG_FATAL_W_ERRNO("os_spin_destroy"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:211 + CORE_LOG_FATAL_W_ERRNO("os_spin_lock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:226 + CORE_LOG_FATAL_W_ERRNO("os_spin_unlock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:239 + CORE_LOG_FATAL_W_ERRNO("os_semaphore_init"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:249 + CORE_LOG_FATAL_W_ERRNO("os_semaphore_destroy"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:266 + CORE_LOG_FATAL_W_ERRNO("os_semaphore_wait"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:282 + CORE_LOG_FATAL_W_ERRNO("os_semaphore_trywait"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:294 + CORE_LOG_FATAL_W_ERRNO("os_semaphore_post"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:301 + CORE_LOG_FATAL_W_ERRNO("os_cond_init"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:308 + CORE_LOG_FATAL_W_ERRNO("os_cond_destroy"); + UT_ASSERTeq(errno, errnum); +} diff --git a/src/test/core_log/call_all.h b/src/test/core_log/call_all.h new file mode 100644 index 00000000000..c188e7518c8 --- /dev/null +++ b/src/test/core_log/call_all.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2024, Intel Corporation */ + +/* + * call_all.h -- + */ + +#ifndef CALL_ALL_H +#define CALL_ALL_H + +/* + * In general, a path in Linux can be as long as PATH_MAX (4096). However, + * because of the memory constraints, it is undesirable to allocate log buffers + * just in case the system is tested to its limits. Hence, we assumed a rational + * path length is 128 bytes. + * + * Note: If the assumption won't be met and no limitation on the path string + * will be introduced by the string format, the log buffer might be in great + * part consumed to store the path whereas the latter part of the log message + * would be lost. + */ +#define PATH \ + "Ut/imperdiet/dictum/dui/in/posuere/augue/accumsan/ut/Cras/et/neque/id/elit/porta/malesuada/Class/aptent/taciti/sociosqu//litora" + +/* Basic log APIs */ +void call_all_CORE_LOG_WARNING(void); +void call_all_CORE_LOG_ERROR(void); +void call_all_CORE_LOG_FATAL(void); + +/* Log APIs appending an error string */ +void call_all_CORE_LOG_WARNING_W_ERRNO(int errnum); +void call_all_CORE_LOG_ERROR_W_ERRNO(int errnum); +void call_all_CORE_LOG_FATAL_W_ERRNO(int errnum); + +/* Log APIs that also store the error message for later use via TLS */ +void call_all_CORE_LOG_ERROR_LAST(void); +void call_all_CORE_LOG_ERROR_W_ERRNO_LAST(int errnum); +void call_all_ERR_WO_ERRNO(void); +void call_all_ERR_W_ERRNO(int errnum); + +#endif /* CALL_ALL_H */ diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c index 1b88101ca56..2e2701eda98 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log/core_log.c @@ -10,24 +10,25 @@ #include #include "log_internal.h" +#include "last_error_msg.h" #include "unittest.h" +#include "call_all.h" #define NO_ARGS_CONSUMED 0 -#define BIG_BUF_SIZE 1024 +#define BIG_BUF_SIZE 4096 -/* - * test_CORE_LOG_MAX_ERRNO_MSG -- - * _CORE_LOG_MAX_ERRNO_MSG >= max(strlen(strerror(errnnum))) - * for errnum in errnums - */ -static int -test_CORE_LOG_MAX_ERRNO_MSG(const struct test_case *tc, int argc, char *argv[]) +#define MAX_STRERROR_NUM 0x54 + +static void +call_all_strerror_r(int *max_strerror_len, int *max_streerror_num) { char buf[BIG_BUF_SIZE]; - int max_strerror_len = 0; int correct_strerror_calls = 0; + *max_strerror_len = 0; + *max_streerror_num = 0; + /* * In general, valid errno values are all positive values of type int, * but at the time of writing only the first 134 values are allocated. @@ -51,23 +52,93 @@ test_CORE_LOG_MAX_ERRNO_MSG(const struct test_case *tc, int argc, char *argv[]) ++correct_strerror_calls; int len = strlen(buf); - if (len > max_strerror_len) { - max_strerror_len = len; + if (len > *max_strerror_len) { + *max_strerror_len = len; + *max_streerror_num = errnum; } } UT_ASSERT(correct_strerror_calls == 132); +} + +/* tests */ + +/* + * test_CORE_LOG_MAX_ERRNO_MSG -- + * _CORE_LOG_MAX_ERRNO_MSG >= max(strlen(strerror(errnnum))) + * for errnum in errnums + */ +static int +test_CORE_LOG_MAX_ERRNO_MSG(const struct test_case *tc, int argc, char *argv[]) +{ + int max_strerror_len = 0; + int max_streerror_num = 0; + + call_all_strerror_r(&max_strerror_len, &max_streerror_num); /* - * The key aim of this test is to make sure the assumed errno message - * buffer size is big enough no matter the errno value. + * The assumed errno message buffer size is big enough no matter + * the errno value. */ UT_ASSERT(max_strerror_len + 1 <= _CORE_LOG_MAX_ERRNO_MSG); + /* + * Other tests in this group makes use of this value so just make sure + * the generated strerror will be as long as it is possible. + */ + UT_ASSERTeq(max_streerror_num, MAX_STRERROR_NUM); + + return NO_ARGS_CONSUMED; +} + +static int Max_TLS_message_len; +static char The_longest_TLS_message[BIG_BUF_SIZE]; +static int Total_TLS_message_num; + +/* + * A hard-coded value as obtained when the call_all_*() source code was + * generated. + */ +#define TOTAL_TLS_MESSAGE_NUM_EXPECTED 311 + +FUNC_MOCK(core_log_to_last, void, const char *file_name, int line_no, + const char *function_name, const char *message_format, ...) + FUNC_MOCK_RUN_DEFAULT { + char buf[BIG_BUF_SIZE] = ""; + va_list arg; + va_start(arg, message_format); + int ret = vsnprintf(buf, BIG_BUF_SIZE, message_format, arg); + UT_ASSERT(ret > 0); + UT_ASSERTeq(ret, strlen(buf)); + if (ret > Max_TLS_message_len) { + Max_TLS_message_len = ret; + strncpy(The_longest_TLS_message, buf, BIG_BUF_SIZE); + } + ++Total_TLS_message_num; + return; + } +FUNC_MOCK_END + +static int +test_ERR_W_ERRNO(const struct test_case *tc, int argc, char *argv[]) +{ + Max_TLS_message_len = 0; + Total_TLS_message_num = 0; + + call_all_CORE_LOG_ERROR_LAST(); + call_all_ERR_WO_ERRNO(); + call_all_CORE_LOG_ERROR_W_ERRNO_LAST(MAX_STRERROR_NUM); + call_all_ERR_W_ERRNO(MAX_STRERROR_NUM); + + UT_OUT("%s", The_longest_TLS_message); + UT_ASSERTeq(Total_TLS_message_num, TOTAL_TLS_MESSAGE_NUM_EXPECTED); + UT_ASSERTeq(Max_TLS_message_len + 1, CORE_LAST_ERROR_MSG_MAXPRINT); + return NO_ARGS_CONSUMED; } static struct test_case test_cases[] = { - TEST_CASE(test_CORE_LOG_MAX_ERRNO_MSG) + TEST_CASE(test_CORE_LOG_MAX_ERRNO_MSG), + TEST_CASE(test_ERR_W_ERRNO), }; #define NTESTS ARRAY_SIZE(test_cases) @@ -76,6 +147,9 @@ int main(int argc, char *argv[]) { START(argc, argv, "core_log"); + + UT_COMPILE_ERROR_ON(sizeof(PATH) != 128); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); DONE(NULL); } diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py new file mode 100755 index 00000000000..48609252eeb --- /dev/null +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -0,0 +1,419 @@ +#!/usr/bin/env python3 + +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +import subprocess +import json +import re + +from typing import List, Dict, Any + +DEBUG = False +PARSER_DEBUG = False + +TOP = '../../' +OUTPUT_PATH = TOP + 'src/test/core_log/' +OUTPUT_C = OUTPUT_PATH + 'call_all.c.generated' + +NOTICE = """/* + * This file is automatically generated by utils/call_stack_analysis/log_call_all_generate.py. + * Please do not modify manually. + */""" + +C_FUNCTION_W_ERRNUM_PREFIX = """ +void +call_all_{}(int errnum) +{{ + errno = errnum; +""" + +C_FUNCTION_PREFIX = """ +void +call_all_{}(void) +{{ +""" + +C_FUNCTION_SUFFIX = """} +""" + +def dump(var: Any, name: str) -> None: + with open(f'{name}.json', 'w') as outfile: + json.dump(var, outfile, indent = 4) + +def bad_line(reason: str, line: str) -> None: + print(f'{reason}: {line}') + exit(1) + +# Extract all calls from the code base + +def extract_append_code(file_name: str, start_line: int, code: str) -> str: + if not re.search(f'\.[ch]$', file_name): + print(f'Unsupported file type: {file_name}') + exit(1) + + with open(TOP + file_name, 'r') as file: + # skip to the line + for _ in range(0, start_line): + file.readline() + # look up for the end of the statement + while True: + line = file.readline() + line = line.strip() + code += " " + line + if code[-1] == ';': + break + if re.search(f'(//|/\*)', code): + bad_line('Comment found', code) + return code + +IGNORE_FILES = [ + '.git/', + 'src/core/log_internal.h', + 'src/libpmem2/', + 'src/libpmempool/', + 'src/test/', + 'utils/', + 'CODING_STYLE.md', +] + +def file_should_be_ignored(file: str) -> bool: + for ignore in IGNORE_FILES: + if file.startswith(ignore): + return True + return False + +def extract_all_calls(func: str) -> List[Dict]: + cmd = f'cd {TOP}; grep -Irn {func}' + returned_output = subprocess.check_output(cmd, shell=True) + string = returned_output.decode("utf-8") + calls = [] + total = 0 + for line in string.splitlines(): + found = re.search(f'([a-zA-Z0-9_/.-]+):([0-9]+):[ \t]*(.+)', line) + if found: + total += 1 + file = found.group(1) + line_no = found.group(2) + code = found.group(3) + # Filter out known odd occurrences. + if file_should_be_ignored(file): + continue + if not code.startswith(func): + bad_line(f'Does not start with "{func}"', line) + if code[-1] == '\\': # template's type of ending a line + if code[-2] == ';': # a single line call can be extracted + code = code[:-1] + else: + print(f'SKIP call: Multiline calls in templates are not supported: {line}') + continue + elif code[-1] != ';': + code = extract_append_code(file, int(line_no), code) + call = { + 'file': file, + 'line': line_no, + 'code': code + } + calls.append(call) + else: + bad_line('An unexpected line format', line) + print(f'[{func}] total: {total}, included: {len(calls)}') + return calls + +# Parse a single call's code and tokenize the format string + +def parse_token_start(state: Dict, type: str) -> Dict: + if PARSER_DEBUG: + print('parse_token_start') + state['token_start'] = state['pos'] + state['in_' + type] = True + return state + +def parse_token_end(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_token_end') + + plus = 0 + if state['in_string'] and state['in_literal']: + bad_line("Both string and literal tokens detected at the same time", state['code']) + elif state['in_string']: + _type = 'string' + plus = 1 # the character ending a string literal belongs to it + elif state['in_literal']: + _type = 'literal' + else: + bad_line("End of an unknown token detected", state['code']) + + if state['token_start'] is None: + bad_line("End of a {_type} without the beginning", state['code']) + state['tokens'].append(state['code'][state['token_start']:(state['pos'] + plus)]) + state['token_start'] = None + state['in_' + _type] = False + return state + +def parse_call_quote(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_call_quote') + if state['in_string']: + if state['code'][state['pos'] - 1] == '\\': # escaped + pass + else: + state = parse_token_end(state) # string token ends here + elif state['in_literal']: + state = parse_token_end(state) # a literal token ends here + state = parse_token_start(state, 'string') # a string token starts here... + else: + state = parse_token_start(state, 'string') # ... and here as well. + return state + +def parse_call_comma_or_rbracket(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_call_comma_or_rbracket') + if state['in_string']: + pass + elif state['in_literal']: + state = parse_token_end(state) # a literal token ends here + state['end'] = True # the format ends here... + else: + state['end'] = True # ... and here + return state + +def parse_call_AZaz09(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_call_AZaz09') + if state['in_string']: + pass + elif state['in_literal']: + pass + else: + state = parse_token_start(state, 'literal') + return state + +def parse_call_space_or_minus(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_call_space_or_minus') + if state['in_string']: + pass + elif state['in_literal']: + state = parse_token_end(state) # a literal token ends here + return state + +def parse_call_odd(state: Dict) -> Dict: + if PARSER_DEBUG: + print('parse_call_odd') + if state['in_string']: + pass + else: + ch = state['code'][state['pos']] + bad_line('Unexpected "{ch}"', state['code']) + return state + +PARSER_CHAR_ACTION = { + '"': parse_call_quote, + ',': parse_call_comma_or_rbracket, + ')': parse_call_comma_or_rbracket, + ' ': parse_call_space_or_minus, + '-': parse_call_space_or_minus, + '(': parse_call_odd, + '#': parse_call_odd, + '%': parse_call_odd, + ':': parse_call_odd, + '+': parse_call_odd, + '\'': parse_call_odd, + '/': parse_call_odd, + '.': parse_call_odd, + '\\': parse_call_odd, + '<': parse_call_odd, + '>': parse_call_odd, + '=': parse_call_odd, + ';': parse_call_odd, + '[': parse_call_odd, + ']': parse_call_odd, + '!': parse_call_odd, + '|': parse_call_odd, + 'A-Za-z0-9_': parse_call_AZaz09, +} + +def call_get_format_tokens(call): + code = call['code'] + start = code.find('(') + state = { + 'code': code, + 'pos': None, + 'end': False, + 'in_string': False, + 'in_literal': False, + 'token_start': None, + 'tokens': [] + } + for i in range(start + 1, len(code)): + state['pos'] = i + ch = code[i] + if ch in PARSER_CHAR_ACTION.keys(): + state = PARSER_CHAR_ACTION[ch](state) + elif ch.isalpha() or ch.isdecimal() or ch == '_': + state = PARSER_CHAR_ACTION['A-Za-z0-9_'](state) + else: + bad_line(f'Unsupported character \'{ch}\'', code) + if state['end']: + break + if not state['end']: + bad_line('Cannot find the end of the format string', code) + return state['tokens'] + +# Generate a complete format string + +LITERAL_TO_STRING = { + 'PRIx64': 'lx', + 'PRIu64': 'lu' +} + +def token_stringify(token: str) -> str: + if token[0] == '"' and token[-1] == '"': + return token[1:-1] # strip quotes + if token in LITERAL_TO_STRING.keys(): + return LITERAL_TO_STRING[token] + else: + print(f'Unknown token: "{token}"') + exit(1) + +def format_stringify(tokens: List) -> str: + tokens_str = [token_stringify(token) for token in tokens] + return ''.join(tokens_str) + +# Identify required arguments + +SPECIFIERS = [ + 'd', + 'x', + 'u', + 's', + 'p', + 'o', + 'i', +] + +FORMAT_SPECIFIER_ARGS = { + '%s': '_s', + '%.8s': '_8s', + '%x': '_u', + '%lx': '_lu', + '%#x': '_u', + '%d': '_d', + '%ld': '_ld', + '%u': '_u', + '%lu': '_lu', + '%zu': '_zu', + '%ju': '_ju', + '%p': '_p', + '%o': '_u', + '%i': '_d', + '%li': '_d', +} + +def arg_identify(format: str, pos: int): + format_spec = None + end_pos = None + for i in range(pos + 1, len(format)): + ch = format[i] + if ch in SPECIFIERS: + format_spec = format[pos:i + 1] + end_pos = i + 1 + break + if format_spec is None: + visited = format[pos:] + print(f'Unrecognized specifier: "{visited}"') + exit(1) + if format_spec not in FORMAT_SPECIFIER_ARGS.keys(): + print(f'Unrecognized format specifier: "{format_spec}"') + exit(1) + return FORMAT_SPECIFIER_ARGS[format_spec], end_pos + +def args_parse(format: str) -> List: + pos = 0 + args = [] + while True: + pos = format.find('%', pos) + if pos == -1: + break + arg, pos = arg_identify(format, pos) + args.append(arg) + return args + +# Process raw source code: generate the complete format string and list of args + +def calls_process(calls: List) -> List: + for call in calls: + call['format_tokens'] = call_get_format_tokens(call) + call['format_string'] = format_stringify(call['format_tokens']) + call['args'] = args_parse(call['format_string']) + return calls + +# Generate the call all source file + +def init_source_file(): + with open(OUTPUT_C, 'w') as file: + file.write(NOTICE) + +def generate_call(file, func: str, call: Dict) -> str: + if len(call['args']) > 0: + args = ', ' + ', '.join(call['args']) + else: + args = '' + file.write(f'\t// {call["file"]}:{call["line"]}\n') + file.write(f'\t{func}("{call["format_string"]}"{args});\n') + +def generate_func_with_errno(func: str, calls: List[Dict]) -> None: + with open(OUTPUT_C, 'a') as file: + file.write(C_FUNCTION_W_ERRNUM_PREFIX.format(func)) + for call in calls: + generate_call(file, func, call) + file.write('\tUT_ASSERTeq(errno, errnum);\n') + file.write(C_FUNCTION_SUFFIX) + +def generate_func(func: str, calls: List[Dict]) -> None: + with open(OUTPUT_C, 'a') as file: + file.write(C_FUNCTION_PREFIX.format(func)) + for call in calls: + generate_call(file, func, call) + file.write(C_FUNCTION_SUFFIX) + +# Main + +API = { + 'void': [ + 'CORE_LOG_ERROR_LAST', + 'ERR_WO_ERRNO', + 'CORE_LOG_WARNING', + 'CORE_LOG_ERROR', + 'CORE_LOG_FATAL', + ], + 'errno': [ + 'CORE_LOG_ERROR_W_ERRNO_LAST', + 'ERR_W_ERRNO', + 'CORE_LOG_WARNING_W_ERRNO', + 'CORE_LOG_ERROR_W_ERRNO', + 'CORE_LOG_FATAL_W_ERRNO' + ] +} + +def main(): + global_total = 0 + init_source_file() + + for func in API['void']: + calls = extract_all_calls(func) + global_total += len(calls) + calls = calls_process(calls) + generate_func(func, calls) + + for func in API['errno']: + calls = extract_all_calls(func) + global_total += len(calls) + calls = calls_process(calls) + generate_func_with_errno(func, calls) + + print(f'Total: {global_total}') + +if __name__ == '__main__': + main() From e10a51a909698b9e5eaad18225ae32413ffc07c5 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Fri, 16 Feb 2024 13:39:51 -0500 Subject: [PATCH 090/182] common: sort call_all_*() by file and line Signed-off-by: Jan Michalski --- src/test/core_log/call_all.c.generated | 1512 ++++++++--------- .../log_call_all_generate.py | 4 + 2 files changed, 760 insertions(+), 756 deletions(-) diff --git a/src/test/core_log/call_all.c.generated b/src/test/core_log/call_all.c.generated index 8e20ba1dce4..15552125ed5 100644 --- a/src/test/core_log/call_all.c.generated +++ b/src/test/core_log/call_all.c.generated @@ -10,8 +10,188 @@ call_all_CORE_LOG_ERROR_LAST(void) void call_all_ERR_WO_ERRNO(void) { - // src/tools/pmempool/output.c:779 - ERR_WO_ERRNO("snprintf for incompat features: %d", _d); + // src/common/ctl.c:215 + ERR_WO_ERRNO("read queries require non-NULL argument"); + // src/common/ctl.c:231 + ERR_WO_ERRNO("write queries require non-NULL argument"); + // src/common/ctl.c:278 + ERR_WO_ERRNO("invalid query"); + // src/common/ctl.c:302 + ERR_WO_ERRNO("invalid query entry point %s", _s); + // src/common/ctl.c:374 + ERR_WO_ERRNO("failed to parse query %s", _s); + // src/common/ctl.c:436 + ERR_WO_ERRNO("Config file too large"); + // src/common/ctl.c:562 + ERR_WO_ERRNO("invalid destination size %zu", _zu); + // src/common/file.c:111 + ERR_WO_ERRNO("invalid (NULL) path"); + // src/common/file.c:182 + ERR_WO_ERRNO("file size (%ld) too big to be represented in 64-bit signed integer", _ld); + // src/common/file.c:409 + ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); + // src/common/file.c:415 + ERR_WO_ERRNO("invalid size (%zu) for os_off_t", _zu); + // src/common/file.c:485 + ERR_WO_ERRNO("stat \"%s\": negative size", _s); + // src/common/file.c:491 + ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); + // src/common/mmap.c:287 + ERR_WO_ERRNO("duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu", _p, _zu); + // src/common/mmap.c:308 + ERR_WO_ERRNO("Cannot find DAX device region id"); + // src/common/mmap.c:336 + ERR_WO_ERRNO("invalid munmap length, must be non-zero and page aligned"); + // src/common/mmap_posix.c:90 + ERR_WO_ERRNO("end of address space reached"); + // src/common/pool_hdr.c:116 + ERR_WO_ERRNO("invalid reserved values"); + // src/common/pool_hdr.c:121 + ERR_WO_ERRNO("invalid machine value"); + // src/common/pool_hdr.c:126 + ERR_WO_ERRNO("invalid data value"); + // src/common/pool_hdr.c:131 + ERR_WO_ERRNO("invalid machine_class value"); + // src/common/pool_hdr.c:136 + ERR_WO_ERRNO("invalid alignment_desc value"); + // src/common/pool_hdr.c:173 + ERR_WO_ERRNO("unsafe to continue due to unknown incompat features: %#x", _u); + // src/common/pool_hdr.c:182 + ERR_WO_ERRNO("switching to read-only mode due to unknown ro_compat features: %#x", _u); + // src/common/set.c:1066 + ERR_WO_ERRNO("unable to load part %s", _s); + // src/common/set.c:1105 + ERR_WO_ERRNO("failed to load parts from directory %s", _s); + // src/common/set.c:1302 + ERR_WO_ERRNO("Remote replicas are no longer supported. This functionality is deprecated."); + // src/common/set.c:1339 + ERR_WO_ERRNO("%s [%s:%d]", _s, _s, _d); + // src/common/set.c:1357 + ERR_WO_ERRNO("cannot load part files from directories"); + // src/common/set.c:1511 + ERR_WO_ERRNO("file size does not match config: %s, %zu != %zu", _s, _zu, _zu); + // src/common/set.c:1609 + ERR_WO_ERRNO("size must be zero for device dax"); + // src/common/set.c:1643 + ERR_WO_ERRNO("file is not a poolset file and its size (%zu) is smaller than %zu", _zu, _zu); + // src/common/set.c:1680 + ERR_WO_ERRNO("poolset file options (%u) do not match incompat feature flags (%#x)", _u, _u); + // src/common/set.c:1708 + ERR_WO_ERRNO("Non-empty file detected"); + // src/common/set.c:1816 + ERR_WO_ERRNO("invalid major version (0)"); + // src/common/set.c:1823 + ERR_WO_ERRNO("wrong pool type: \"%.8s\"", _8s); + // src/common/set.c:1830 + ERR_WO_ERRNO("pool version %d (library expects %d)", _d, _d); + // src/common/set.c:1833 + ERR_WO_ERRNO("Please run the pmdk-convert utility to upgrade the pool."); + // src/common/set.c:1858 + ERR_WO_ERRNO("invalid checksum of pool header"); + // src/common/set.c:1866 + ERR_WO_ERRNO("wrong architecture flags"); + // src/common/set.c:1874 + ERR_WO_ERRNO("wrong pool set UUID"); + // src/common/set.c:1884 + ERR_WO_ERRNO("wrong part UUID"); + // src/common/set.c:1891 + ERR_WO_ERRNO("incompatible pool format"); + // src/common/set.c:1900 + ERR_WO_ERRNO("incompatible feature flags"); + // src/common/set.c:2253 + ERR_WO_ERRNO("cannot extend pool by 0 bytes"); + // src/common/set.c:2258 + ERR_WO_ERRNO("extending the pool by appending parts with headers is not supported!"); + // src/common/set.c:2266 + ERR_WO_ERRNO("exceeded reservation size"); + // src/common/set.c:2275 + ERR_WO_ERRNO("unable to append a new part to the pool"); + // src/common/set.c:2290 + ERR_WO_ERRNO("cannot open the new part"); + // src/common/set.c:2300 + ERR_WO_ERRNO("cannot map the new part"); + // src/common/set.c:2310 + ERR_WO_ERRNO("new part cannot be mapped with MAP_SYNC"); + // src/common/set.c:2313 + ERR_WO_ERRNO("new part mapped with MAP_SYNC"); + // src/common/set.c:2356 + ERR_WO_ERRNO("file contains bad blocks -- '%s'", _s); + // src/common/set.c:2390 + ERR_WO_ERRNO("file %s already exists", _s); + // src/common/set.c:2407 + ERR_WO_ERRNO("the NOHDRS poolset option is not supported for local poolsets"); + // src/common/set.c:2414 + ERR_WO_ERRNO("pool attributes are not supported for poolsets without headers (with the NOHDRS option)"); + // src/common/set.c:2421 + ERR_WO_ERRNO("directory based pools are not supported for poolsets with headers (without SINGLEHDR option)"); + // src/common/set.c:2428 + ERR_WO_ERRNO("reservation pool size %zu smaller than %zu", _zu, _zu); + // src/common/set.c:2436 + ERR_WO_ERRNO("cannot create a new part in provided directories"); + // src/common/set.c:2455 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be created, run 'pmempool create --clear-bad-blocks' utility to clear bad blocks and create a pool"); + // src/common/set.c:2463 + ERR_WO_ERRNO("net pool size %zu smaller than %zu", _zu, _zu); + // src/common/set.c:2470 + ERR_WO_ERRNO("replication not supported"); + // src/common/set.c:257 + ERR_WO_ERRNO("unable to map at requested address %p", _p); + // src/common/set.c:2633 + ERR_WO_ERRNO("pool mapping failed - address space reservation too small"); + // src/common/set.c:2806 + ERR_WO_ERRNO("wrong replica UUID"); + // src/common/set.c:2862 + ERR_WO_ERRNO("device dax cannot be mapped privately"); + // src/common/set.c:2877 + ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:2900 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:3018 + ERR_WO_ERRNO("device dax cannot be mapped privately"); + // src/common/set.c:3038 + ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); + // src/common/set.c:3064 + ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool -- '%s'", _s); + // src/common/set.c:3215 + ERR_WO_ERRNO("util_poolset_parse failed -- '%s'", _s); + // src/common/set.c:476 + ERR_WO_ERRNO("size autodetection is supported only for device dax"); + // src/common/set.c:732 + ERR_WO_ERRNO("cannot mix directories and files in a set"); + // src/common/set.c:758 + ERR_WO_ERRNO("cannot mix directories and files in a set"); + // src/common/set.c:768 + ERR_WO_ERRNO("cannot resolve realpath of new directory"); + // src/common/set.c:780 + ERR_WO_ERRNO("cannot use the same directory twice"); + // src/common/set.c:877 + ERR_WO_ERRNO("replica #%u part %u %smapped with MAP_SYNC", _u, _u, _s); + // src/common/set.c:887 + ERR_WO_ERRNO("replica #%u part %u header %smapped with MAP_SYNC", _u, _u, _s); + // src/common/set.c:916 + ERR_WO_ERRNO("either all the parts must be Device DAX or none"); + // src/common/set.c:926 + ERR_WO_ERRNO("Multiple DAX devices with alignment other than 4KB. Use the SINGLEHDR poolset option."); + // src/common/set.c:945 + ERR_WO_ERRNO("both SINGLEHDR and NOHDR poolset options used at the same time"); + // src/common/set_badblocks.c:120 + ERR_WO_ERRNO("clearing bad blocks in the pool file failed -- '%s'", _s); + // src/common/set_badblocks.c:46 + ERR_WO_ERRNO("checking the pool file for bad blocks failed -- '%s'", _s); + // src/common/set_badblocks.c:53 + ERR_WO_ERRNO("part file contains bad blocks -- '%s'", _s); + // src/common/shutdown_state.c:101 + ERR_WO_ERRNO("cannot read uuid of %d", _d); + // src/common/shutdown_state.c:232 + ERR_WO_ERRNO("an ADR failure was detected, the pool might be corrupted"); + // src/common/shutdown_state.c:77 + ERR_WO_ERRNO("Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); + // src/common/shutdown_state.c:87 + ERR_WO_ERRNO("cannot read uuid of %d", _d); + // src/libpmem/libpmem.c:56 + ERR_WO_ERRNO("libpmem major version mismatch (need %u, found %u)", _u, _u); + // src/libpmem/libpmem.c:63 + ERR_WO_ERRNO("libpmem minor version mismatch (need %u, found %u)", _u, _u); // src/libpmem/pmem.c:413 ERR_WO_ERRNO("invalid flag specified %x", _u); // src/libpmem/pmem.c:420 @@ -36,161 +216,69 @@ call_all_ERR_WO_ERRNO(void) ERR_WO_ERRNO("invalid flags 0x%x", _u); // src/libpmem/pmem.c:651 ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmem/libpmem.c:56 - ERR_WO_ERRNO("libpmem major version mismatch (need %u, found %u)", _u, _u); - // src/libpmem/libpmem.c:63 - ERR_WO_ERRNO("libpmem minor version mismatch (need %u, found %u)", _u, _u); // src/libpmemobj/alloc_class.c:231 ERR_WO_ERRNO("unable to register allocation class"); - // src/libpmemobj/tx.c:513 - ERR_WO_ERRNO("Unrecognized lock type"); - // src/libpmemobj/tx.c:550 - ERR_WO_ERRNO("Unrecognized lock type"); - // src/libpmemobj/tx.c:588 - ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/tx.c:617 - ERR_WO_ERRNO("out of memory"); - // src/libpmemobj/tx.c:633 - ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/tx.c:647 - ERR_WO_ERRNO("pmemobj_tx_free failed"); - // src/libpmemobj/tx.c:665 - ERR_WO_ERRNO("pmemobj_tx_free failed"); - // src/libpmemobj/tx.c:682 - ERR_WO_ERRNO("Buffer from a different pool"); - // src/libpmemobj/tx.c:739 - ERR_WO_ERRNO("nested transaction for different pool"); - // src/libpmemobj/tx.c:865 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1236 - ERR_WO_ERRNO("snapshot size too large"); - // src/libpmemobj/tx.c:1243 - ERR_WO_ERRNO("object outside of heap"); - // src/libpmemobj/tx.c:1383 - ERR_WO_ERRNO("out of memory"); - // src/libpmemobj/tx.c:1410 - ERR_WO_ERRNO("object outside of pool"); - // src/libpmemobj/tx.c:1448 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1456 - ERR_WO_ERRNO("object outside of pool"); - // src/libpmemobj/tx.c:1493 - ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1531 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1539 - ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1576 - ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1607 - ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1638 - ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1645 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1714 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1722 - ERR_WO_ERRNO("cannot duplicate NULL string"); - // src/libpmemobj/tx.c:1772 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1780 - ERR_WO_ERRNO("cannot duplicate NULL string"); - // src/libpmemobj/tx.c:1831 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1842 - ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1914 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1959 - ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:2208 - ERR_WO_ERRNO("invalid cache size, must be between 0 and max alloc size"); - // src/libpmemobj/tx.c:2232 - ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - // src/libpmemobj/tx.c:2247 - ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - // src/libpmemobj/palloc.c:196 - ERR_WO_ERRNO("no allocation class for size %lu bytes", _lu); - // src/libpmemobj/palloc.c:211 - ERR_WO_ERRNO("allocation class not suitable for size %lu bytes", _lu); - // src/libpmemobj/palloc.c:275 - ERR_WO_ERRNO("invalid operation or heap corruption"); - // src/libpmemobj/libpmemobj.c:52 - ERR_WO_ERRNO("libpmemobj major version mismatch (need %u, found %u)", _u, _u); - // src/libpmemobj/libpmemobj.c:59 - ERR_WO_ERRNO("libpmemobj minor version mismatch (need %u, found %u)", _u, _u); - // src/libpmemobj/stats.c:74 - ERR_WO_ERRNO("invalid enable type"); - // src/libpmemobj/ulog.c:245 - ERR_WO_ERRNO("cannot auto reserve next ulog"); - // src/libpmemobj/heap.c:768 - ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/heap.c:1051 - ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/heap.c:1167 - ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/heap.c:1410 - ERR_WO_ERRNO("at least one automatic arena must exist"); - // src/libpmemobj/heap.c:1605 - ERR_WO_ERRNO("mapped region smaller than the heap size"); - // src/libpmemobj/heap.c:1787 - ERR_WO_ERRNO("heap: invalid header's checksum"); - // src/libpmemobj/heap.c:1792 - ERR_WO_ERRNO("heap: invalid signature"); - // src/libpmemobj/heap.c:1810 - ERR_WO_ERRNO("heap: invalid zone size"); - // src/libpmemobj/heap.c:1825 - ERR_WO_ERRNO("heap: invalid chunk type"); - // src/libpmemobj/heap.c:1830 - ERR_WO_ERRNO("heap: unknown chunk type"); - // src/libpmemobj/heap.c:1835 - ERR_WO_ERRNO("heap: invalid chunk flags"); - // src/libpmemobj/heap.c:1852 - ERR_WO_ERRNO("heap: invalid zone magic"); - // src/libpmemobj/heap.c:1868 - ERR_WO_ERRNO("heap: chunk sizes mismatch"); - // src/libpmemobj/heap.c:1884 - ERR_WO_ERRNO("heap: invalid heap size"); - // src/libpmemobj/memops.c:575 - ERR_WO_ERRNO("Capacity insufficient"); - // src/libpmemobj/memops.c:586 - ERR_WO_ERRNO("Buffer currently used"); - // src/libpmemobj/memops.c:691 - ERR_WO_ERRNO("no extend function present"); - // src/libpmemobj/sync.c:43 - ERR_WO_ERRNO("error initializing lock"); - // src/libpmemobj/sync.c:50 - ERR_WO_ERRNO("error setting lock runid"); - // src/libpmemobj/obj.c:773 - ERR_WO_ERRNO("invalid checksum of pool descriptor"); - // src/libpmemobj/obj.c:780 - ERR_WO_ERRNO("wrong layout (\"%s\"), pool created with layout \"%s\"", _s, _s); - // src/libpmemobj/obj.c:788 - ERR_WO_ERRNO("unaligned heap: off %lu", _lu); - // src/libpmemobj/obj.c:1036 - ERR_WO_ERRNO("%s variable must be a positive integer", _s); - // src/libpmemobj/obj.c:1065 - ERR_WO_ERRNO("Layout too long"); - // src/libpmemobj/obj.c:1114 - ERR_WO_ERRNO("initialization of replica #%u failed", _u); - // src/libpmemobj/obj.c:1134 - ERR_WO_ERRNO("pool initialization failed"); - // src/libpmemobj/obj.c:1184 - ERR_WO_ERRNO("invalid run_id %lu", _lu); - // src/libpmemobj/obj.c:1246 - ERR_WO_ERRNO("read-only mode is not supported"); - // src/libpmemobj/obj.c:1279 - ERR_WO_ERRNO("initialization of replica #%u failed", _u); - // src/libpmemobj/obj.c:1319 - ERR_WO_ERRNO("inconsistent replica #%u", _u); - // src/libpmemobj/obj.c:1405 - ERR_WO_ERRNO("pool initialization failed"); - // src/libpmemobj/obj.c:1537 - ERR_WO_ERRNO("critnib_remove for pools_ht"); - // src/libpmemobj/obj.c:1541 - ERR_WO_ERRNO("critnib_remove for pools_tree"); - // src/libpmemobj/obj.c:1724 + // src/libpmemobj/heap.c:1051 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/heap.c:1167 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/heap.c:1410 + ERR_WO_ERRNO("at least one automatic arena must exist"); + // src/libpmemobj/heap.c:1605 + ERR_WO_ERRNO("mapped region smaller than the heap size"); + // src/libpmemobj/heap.c:1787 + ERR_WO_ERRNO("heap: invalid header's checksum"); + // src/libpmemobj/heap.c:1792 + ERR_WO_ERRNO("heap: invalid signature"); + // src/libpmemobj/heap.c:1810 + ERR_WO_ERRNO("heap: invalid zone size"); + // src/libpmemobj/heap.c:1825 + ERR_WO_ERRNO("heap: invalid chunk type"); + // src/libpmemobj/heap.c:1830 + ERR_WO_ERRNO("heap: unknown chunk type"); + // src/libpmemobj/heap.c:1835 + ERR_WO_ERRNO("heap: invalid chunk flags"); + // src/libpmemobj/heap.c:1852 + ERR_WO_ERRNO("heap: invalid zone magic"); + // src/libpmemobj/heap.c:1868 + ERR_WO_ERRNO("heap: chunk sizes mismatch"); + // src/libpmemobj/heap.c:1884 + ERR_WO_ERRNO("heap: invalid heap size"); + // src/libpmemobj/heap.c:768 + ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); + // src/libpmemobj/libpmemobj.c:52 + ERR_WO_ERRNO("libpmemobj major version mismatch (need %u, found %u)", _u, _u); + // src/libpmemobj/libpmemobj.c:59 + ERR_WO_ERRNO("libpmemobj minor version mismatch (need %u, found %u)", _u, _u); + // src/libpmemobj/memops.c:575 + ERR_WO_ERRNO("Capacity insufficient"); + // src/libpmemobj/memops.c:586 + ERR_WO_ERRNO("Buffer currently used"); + // src/libpmemobj/memops.c:691 + ERR_WO_ERRNO("no extend function present"); + // src/libpmemobj/obj.c:1036 + ERR_WO_ERRNO("%s variable must be a positive integer", _s); + // src/libpmemobj/obj.c:1065 + ERR_WO_ERRNO("Layout too long"); + // src/libpmemobj/obj.c:1114 + ERR_WO_ERRNO("initialization of replica #%u failed", _u); + // src/libpmemobj/obj.c:1134 + ERR_WO_ERRNO("pool initialization failed"); + // src/libpmemobj/obj.c:1184 + ERR_WO_ERRNO("invalid run_id %lu", _lu); + // src/libpmemobj/obj.c:1246 + ERR_WO_ERRNO("read-only mode is not supported"); + // src/libpmemobj/obj.c:1279 + ERR_WO_ERRNO("initialization of replica #%u failed", _u); + // src/libpmemobj/obj.c:1319 + ERR_WO_ERRNO("inconsistent replica #%u", _u); + // src/libpmemobj/obj.c:1405 + ERR_WO_ERRNO("pool initialization failed"); + // src/libpmemobj/obj.c:1537 + ERR_WO_ERRNO("critnib_remove for pools_ht"); + // src/libpmemobj/obj.c:1541 + ERR_WO_ERRNO("critnib_remove for pools_tree"); + // src/libpmemobj/obj.c:1724 ERR_WO_ERRNO("requested size too large"); // src/libpmemobj/obj.c:1767 ERR_WO_ERRNO("allocation with size 0"); @@ -216,6 +304,18 @@ call_all_ERR_WO_ERRNO(void) ERR_WO_ERRNO("Not all PMEMoids belong to the provided pool"); // src/libpmemobj/obj.c:2739 ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/obj.c:773 + ERR_WO_ERRNO("invalid checksum of pool descriptor"); + // src/libpmemobj/obj.c:780 + ERR_WO_ERRNO("wrong layout (\"%s\"), pool created with layout \"%s\"", _s, _s); + // src/libpmemobj/obj.c:788 + ERR_WO_ERRNO("unaligned heap: off %lu", _lu); + // src/libpmemobj/palloc.c:196 + ERR_WO_ERRNO("no allocation class for size %lu bytes", _lu); + // src/libpmemobj/palloc.c:211 + ERR_WO_ERRNO("allocation class not suitable for size %lu bytes", _lu); + // src/libpmemobj/palloc.c:275 + ERR_WO_ERRNO("invalid operation or heap corruption"); // src/libpmemobj/pmalloc.c:237 ERR_WO_ERRNO("unit size must be evenly divisible by alignment"); // src/libpmemobj/pmalloc.c:243 @@ -254,215 +354,89 @@ call_all_ERR_WO_ERRNO(void) ERR_WO_ERRNO("invalid arena assignment type"); // src/libpmemobj/pmalloc.c:969 ERR_WO_ERRNO("number of default arenas can't be 0"); - // src/common/set.c:257 - ERR_WO_ERRNO("unable to map at requested address %p", _p); - // src/common/set.c:476 - ERR_WO_ERRNO("size autodetection is supported only for device dax"); - // src/common/set.c:732 - ERR_WO_ERRNO("cannot mix directories and files in a set"); - // src/common/set.c:758 - ERR_WO_ERRNO("cannot mix directories and files in a set"); - // src/common/set.c:768 - ERR_WO_ERRNO("cannot resolve realpath of new directory"); - // src/common/set.c:780 - ERR_WO_ERRNO("cannot use the same directory twice"); - // src/common/set.c:877 - ERR_WO_ERRNO("replica #%u part %u %smapped with MAP_SYNC", _u, _u, _s); - // src/common/set.c:887 - ERR_WO_ERRNO("replica #%u part %u header %smapped with MAP_SYNC", _u, _u, _s); - // src/common/set.c:916 - ERR_WO_ERRNO("either all the parts must be Device DAX or none"); - // src/common/set.c:926 - ERR_WO_ERRNO("Multiple DAX devices with alignment other than 4KB. Use the SINGLEHDR poolset option."); - // src/common/set.c:945 - ERR_WO_ERRNO("both SINGLEHDR and NOHDR poolset options used at the same time"); - // src/common/set.c:1066 - ERR_WO_ERRNO("unable to load part %s", _s); - // src/common/set.c:1105 - ERR_WO_ERRNO("failed to load parts from directory %s", _s); - // src/common/set.c:1302 - ERR_WO_ERRNO("Remote replicas are no longer supported. This functionality is deprecated."); - // src/common/set.c:1339 - ERR_WO_ERRNO("%s [%s:%d]", _s, _s, _d); - // src/common/set.c:1357 - ERR_WO_ERRNO("cannot load part files from directories"); - // src/common/set.c:1511 - ERR_WO_ERRNO("file size does not match config: %s, %zu != %zu", _s, _zu, _zu); - // src/common/set.c:1609 - ERR_WO_ERRNO("size must be zero for device dax"); - // src/common/set.c:1643 - ERR_WO_ERRNO("file is not a poolset file and its size (%zu) is smaller than %zu", _zu, _zu); - // src/common/set.c:1680 - ERR_WO_ERRNO("poolset file options (%u) do not match incompat feature flags (%#x)", _u, _u); - // src/common/set.c:1708 - ERR_WO_ERRNO("Non-empty file detected"); - // src/common/set.c:1816 - ERR_WO_ERRNO("invalid major version (0)"); - // src/common/set.c:1823 - ERR_WO_ERRNO("wrong pool type: \"%.8s\"", _8s); - // src/common/set.c:1830 - ERR_WO_ERRNO("pool version %d (library expects %d)", _d, _d); - // src/common/set.c:1833 - ERR_WO_ERRNO("Please run the pmdk-convert utility to upgrade the pool."); - // src/common/set.c:1858 - ERR_WO_ERRNO("invalid checksum of pool header"); - // src/common/set.c:1866 - ERR_WO_ERRNO("wrong architecture flags"); - // src/common/set.c:1874 - ERR_WO_ERRNO("wrong pool set UUID"); - // src/common/set.c:1884 - ERR_WO_ERRNO("wrong part UUID"); - // src/common/set.c:1891 - ERR_WO_ERRNO("incompatible pool format"); - // src/common/set.c:1900 - ERR_WO_ERRNO("incompatible feature flags"); - // src/common/set.c:2253 - ERR_WO_ERRNO("cannot extend pool by 0 bytes"); - // src/common/set.c:2258 - ERR_WO_ERRNO("extending the pool by appending parts with headers is not supported!"); - // src/common/set.c:2266 - ERR_WO_ERRNO("exceeded reservation size"); - // src/common/set.c:2275 - ERR_WO_ERRNO("unable to append a new part to the pool"); - // src/common/set.c:2290 - ERR_WO_ERRNO("cannot open the new part"); - // src/common/set.c:2300 - ERR_WO_ERRNO("cannot map the new part"); - // src/common/set.c:2310 - ERR_WO_ERRNO("new part cannot be mapped with MAP_SYNC"); - // src/common/set.c:2313 - ERR_WO_ERRNO("new part mapped with MAP_SYNC"); - // src/common/set.c:2356 - ERR_WO_ERRNO("file contains bad blocks -- '%s'", _s); - // src/common/set.c:2390 - ERR_WO_ERRNO("file %s already exists", _s); - // src/common/set.c:2407 - ERR_WO_ERRNO("the NOHDRS poolset option is not supported for local poolsets"); - // src/common/set.c:2414 - ERR_WO_ERRNO("pool attributes are not supported for poolsets without headers (with the NOHDRS option)"); - // src/common/set.c:2421 - ERR_WO_ERRNO("directory based pools are not supported for poolsets with headers (without SINGLEHDR option)"); - // src/common/set.c:2428 - ERR_WO_ERRNO("reservation pool size %zu smaller than %zu", _zu, _zu); - // src/common/set.c:2436 - ERR_WO_ERRNO("cannot create a new part in provided directories"); - // src/common/set.c:2455 - ERR_WO_ERRNO("pool set contains bad blocks and cannot be created, run 'pmempool create --clear-bad-blocks' utility to clear bad blocks and create a pool"); - // src/common/set.c:2463 - ERR_WO_ERRNO("net pool size %zu smaller than %zu", _zu, _zu); - // src/common/set.c:2470 - ERR_WO_ERRNO("replication not supported"); - // src/common/set.c:2633 - ERR_WO_ERRNO("pool mapping failed - address space reservation too small"); - // src/common/set.c:2806 - ERR_WO_ERRNO("wrong replica UUID"); - // src/common/set.c:2862 - ERR_WO_ERRNO("device dax cannot be mapped privately"); - // src/common/set.c:2877 - ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:2900 - ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:3018 - ERR_WO_ERRNO("device dax cannot be mapped privately"); - // src/common/set.c:3038 - ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:3064 - ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool -- '%s'", _s); - // src/common/set.c:3215 - ERR_WO_ERRNO("util_poolset_parse failed -- '%s'", _s); - // src/common/set_badblocks.c:46 - ERR_WO_ERRNO("checking the pool file for bad blocks failed -- '%s'", _s); - // src/common/set_badblocks.c:53 - ERR_WO_ERRNO("part file contains bad blocks -- '%s'", _s); - // src/common/set_badblocks.c:120 - ERR_WO_ERRNO("clearing bad blocks in the pool file failed -- '%s'", _s); - // src/common/shutdown_state.c:77 - ERR_WO_ERRNO("Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); - // src/common/shutdown_state.c:87 - ERR_WO_ERRNO("cannot read uuid of %d", _d); - // src/common/shutdown_state.c:101 - ERR_WO_ERRNO("cannot read uuid of %d", _d); - // src/common/shutdown_state.c:232 - ERR_WO_ERRNO("an ADR failure was detected, the pool might be corrupted"); - // src/common/file.c:111 - ERR_WO_ERRNO("invalid (NULL) path"); - // src/common/file.c:182 - ERR_WO_ERRNO("file size (%ld) too big to be represented in 64-bit signed integer", _ld); - // src/common/file.c:409 - ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); - // src/common/file.c:415 - ERR_WO_ERRNO("invalid size (%zu) for os_off_t", _zu); - // src/common/file.c:485 - ERR_WO_ERRNO("stat \"%s\": negative size", _s); - // src/common/file.c:491 - ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); - // src/common/mmap.c:287 - ERR_WO_ERRNO("duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu", _p, _zu); - // src/common/mmap.c:308 - ERR_WO_ERRNO("Cannot find DAX device region id"); - // src/common/mmap.c:336 - ERR_WO_ERRNO("invalid munmap length, must be non-zero and page aligned"); - // src/common/ctl.c:215 - ERR_WO_ERRNO("read queries require non-NULL argument"); - // src/common/ctl.c:231 - ERR_WO_ERRNO("write queries require non-NULL argument"); - // src/common/ctl.c:278 - ERR_WO_ERRNO("invalid query"); - // src/common/ctl.c:302 - ERR_WO_ERRNO("invalid query entry point %s", _s); - // src/common/ctl.c:374 - ERR_WO_ERRNO("failed to parse query %s", _s); - // src/common/ctl.c:436 - ERR_WO_ERRNO("Config file too large"); - // src/common/ctl.c:562 - ERR_WO_ERRNO("invalid destination size %zu", _zu); - // src/common/pool_hdr.c:116 - ERR_WO_ERRNO("invalid reserved values"); - // src/common/pool_hdr.c:121 - ERR_WO_ERRNO("invalid machine value"); - // src/common/pool_hdr.c:126 - ERR_WO_ERRNO("invalid data value"); - // src/common/pool_hdr.c:131 - ERR_WO_ERRNO("invalid machine_class value"); - // src/common/pool_hdr.c:136 - ERR_WO_ERRNO("invalid alignment_desc value"); - // src/common/pool_hdr.c:173 - ERR_WO_ERRNO("unsafe to continue due to unknown incompat features: %#x", _u); - // src/common/pool_hdr.c:182 - ERR_WO_ERRNO("switching to read-only mode due to unknown ro_compat features: %#x", _u); - // src/common/mmap_posix.c:90 - ERR_WO_ERRNO("end of address space reached"); + // src/libpmemobj/stats.c:74 + ERR_WO_ERRNO("invalid enable type"); + // src/libpmemobj/sync.c:43 + ERR_WO_ERRNO("error initializing lock"); + // src/libpmemobj/sync.c:50 + ERR_WO_ERRNO("error setting lock runid"); + // src/libpmemobj/tx.c:1236 + ERR_WO_ERRNO("snapshot size too large"); + // src/libpmemobj/tx.c:1243 + ERR_WO_ERRNO("object outside of heap"); + // src/libpmemobj/tx.c:1383 + ERR_WO_ERRNO("out of memory"); + // src/libpmemobj/tx.c:1410 + ERR_WO_ERRNO("object outside of pool"); + // src/libpmemobj/tx.c:1448 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1456 + ERR_WO_ERRNO("object outside of pool"); + // src/libpmemobj/tx.c:1493 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1531 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1539 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1576 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1607 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1638 + ERR_WO_ERRNO("allocation with size 0"); + // src/libpmemobj/tx.c:1645 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1714 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1722 + ERR_WO_ERRNO("cannot duplicate NULL string"); + // src/libpmemobj/tx.c:1772 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1780 + ERR_WO_ERRNO("cannot duplicate NULL string"); + // src/libpmemobj/tx.c:1831 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1842 + ERR_WO_ERRNO("invalid pool uuid"); + // src/libpmemobj/tx.c:1914 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:1959 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/tx.c:2208 + ERR_WO_ERRNO("invalid cache size, must be between 0 and max alloc size"); + // src/libpmemobj/tx.c:2232 + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); + // src/libpmemobj/tx.c:2247 + ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); + // src/libpmemobj/tx.c:513 + ERR_WO_ERRNO("Unrecognized lock type"); + // src/libpmemobj/tx.c:550 + ERR_WO_ERRNO("Unrecognized lock type"); + // src/libpmemobj/tx.c:588 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/tx.c:617 + ERR_WO_ERRNO("out of memory"); + // src/libpmemobj/tx.c:633 + ERR_WO_ERRNO("requested size too large"); + // src/libpmemobj/tx.c:647 + ERR_WO_ERRNO("pmemobj_tx_free failed"); + // src/libpmemobj/tx.c:665 + ERR_WO_ERRNO("pmemobj_tx_free failed"); + // src/libpmemobj/tx.c:682 + ERR_WO_ERRNO("Buffer from a different pool"); + // src/libpmemobj/tx.c:739 + ERR_WO_ERRNO("nested transaction for different pool"); + // src/libpmemobj/tx.c:865 + ERR_WO_ERRNO("unknown flags 0x%lx", _lu); + // src/libpmemobj/ulog.c:245 + ERR_WO_ERRNO("cannot auto reserve next ulog"); + // src/tools/pmempool/output.c:779 + ERR_WO_ERRNO("snprintf for incompat features: %d", _d); } void call_all_CORE_LOG_WARNING(void) { - // src/libpmemobj/palloc.c:307 - CORE_LOG_WARNING("unable to track runtime chunk state"); - // src/libpmemobj/heap.c:1192 - CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); - // src/libpmemobj/heap.c:1204 - CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); - // src/libpmemobj/memops.c:352 - CORE_LOG_WARNING("out of memory - unable to track entries"); - // src/common/set.c:428 - CORE_LOG_WARNING("file permissions changed during pool initialization, file: %s (%o)", _s, _u); - // src/common/set.c:2002 - CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); - // src/common/set.c:2649 - CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); - // src/common/set.c:2897 - CORE_LOG_WARNING("pool set contains bad blocks, ignoring"); - // src/common/set.c:2955 - CORE_LOG_WARNING("cannot open the part -- \"%s\"", _s); - // src/common/set.c:3060 - CORE_LOG_WARNING("pool set contains bad blocks, ignoring -- '%s'", _s); - // src/common/shutdown_state.c:206 - CORE_LOG_WARNING("incorrect checksum - SDS will be reinitialized"); - // src/common/shutdown_state.c:219 - CORE_LOG_WARNING("the pool was not closed - SDS will be reinitialized"); - // src/common/shutdown_state.c:226 - CORE_LOG_WARNING("an ADR failure was detected but the pool was closed - SDS will be reinitialized"); // src/common/file.c:263 CORE_LOG_WARNING("requested size of write goes beyond the file length, %zu > %zu", _zu, _zu); // src/common/file.c:326 @@ -473,63 +447,101 @@ call_all_CORE_LOG_WARNING(void) CORE_LOG_WARNING("Invalid PMEM_MMAP_HINT"); // src/common/mmap.c:56 CORE_LOG_WARNING("No /proc, PMEM_MMAP_HINT ignored"); -} - -void -call_all_CORE_LOG_ERROR(void) -{ - // src/tools/pmempool/common.c:1307 - CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); - // src/libpmem/pmem.c:480 - CORE_LOG_ERROR("failed to create temporary file at \"%s\"", _s); - // src/libpmem/pmem_posix.c:61 - CORE_LOG_ERROR("can't track mapped region"); - // src/libpmemobj/lane.c:417 - CORE_LOG_ERROR("lane %lu internal redo failed: %d", _lu, _d); - // src/libpmemobj/list.c:564 - CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:603 - CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:731 - CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:765 - CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:842 - CORE_LOG_ERROR("list_mutexes_lock failed"); - // src/libpmemobj/heap.c:1327 - CORE_LOG_ERROR("cannot decrease max number of arenas"); - // src/libpmemobj/obj.c:90 - CORE_LOG_ERROR("ctl_new"); - // src/libpmemobj/obj.c:105 - CORE_LOG_ERROR("unable to parse config stored in %s environment variable", _s); - // src/libpmemobj/obj.c:116 - CORE_LOG_ERROR("unable to parse config stored in %s file (from %s environment variable)", _s, _s); - // src/libpmemobj/obj.c:1090 - CORE_LOG_ERROR("cannot create pool or pool set"); - // src/libpmemobj/obj.c:1127 - CORE_LOG_ERROR("creation of pool descriptor failed"); - // src/libpmemobj/obj.c:1189 - CORE_LOG_ERROR("lane_check"); - // src/libpmemobj/obj.c:1198 - CORE_LOG_ERROR("heap_check"); - // src/libpmemobj/obj.c:1238 - CORE_LOG_ERROR("cannot open pool or pool set"); - // src/libpmemobj/obj.c:1375 - CORE_LOG_ERROR("descriptor check of replica #%u failed", _u); - // src/libpmemobj/obj.c:2438 - CORE_LOG_ERROR("obj_realloc_root failed"); + // src/common/set.c:2002 + CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); + // src/common/set.c:2649 + CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); + // src/common/set.c:2897 + CORE_LOG_WARNING("pool set contains bad blocks, ignoring"); + // src/common/set.c:2955 + CORE_LOG_WARNING("cannot open the part -- \"%s\"", _s); + // src/common/set.c:3060 + CORE_LOG_WARNING("pool set contains bad blocks, ignoring -- '%s'", _s); + // src/common/set.c:428 + CORE_LOG_WARNING("file permissions changed during pool initialization, file: %s (%o)", _s, _u); + // src/common/shutdown_state.c:206 + CORE_LOG_WARNING("incorrect checksum - SDS will be reinitialized"); + // src/common/shutdown_state.c:219 + CORE_LOG_WARNING("the pool was not closed - SDS will be reinitialized"); + // src/common/shutdown_state.c:226 + CORE_LOG_WARNING("an ADR failure was detected but the pool was closed - SDS will be reinitialized"); + // src/libpmemobj/heap.c:1192 + CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); + // src/libpmemobj/heap.c:1204 + CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); + // src/libpmemobj/memops.c:352 + CORE_LOG_WARNING("out of memory - unable to track entries"); + // src/libpmemobj/palloc.c:307 + CORE_LOG_WARNING("unable to track runtime chunk state"); +} + +void +call_all_CORE_LOG_ERROR(void) +{ + // src/common/bad_blocks.c:152 + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); + // src/common/bad_blocks.c:161 + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); + // src/common/bad_blocks.c:210 + CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); + // src/common/bad_blocks.c:217 + CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); + // src/common/bad_blocks.c:255 + CORE_LOG_ERROR("counting bad blocks failed -- '%s'", _s); + // src/common/bad_blocks.c:260 + CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", _s, _d); + // src/common/ctl.c:238 + CORE_LOG_ERROR("Invalid arguments"); + // src/common/file.c:212 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:218 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:250 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:256 + CORE_LOG_ERROR("offset beyond file length, %ju > %ju", _ju, _ju); + // src/common/file.c:272 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:307 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); + // src/common/file.c:320 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:335 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:361 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); + // src/common/file.c:374 + CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); + // src/common/file.c:389 + CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); + // src/common/file.c:547 + CORE_LOG_ERROR("failed to open file \"%s\"", _s); // src/common/file_posix.c:115 CORE_LOG_ERROR("Cannot open file %s", _s); - // src/common/set.c:183 + // src/common/mmap.c:94 CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/set.c:343 - CORE_LOG_ERROR("replica open failed: replica %u", _u); + // src/common/os_deep_linux.c:127 + CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); + // src/common/os_deep_linux.c:156 + CORE_LOG_ERROR("deep_flush not supported"); + // src/common/os_deep_linux.c:159 + CORE_LOG_ERROR("invalid dax_region id %u", _u); + // src/common/os_deep_linux.c:166 + CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", _u); + // src/common/os_deep_linux.c:175 + CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); + // src/common/os_deep_linux.c:38 + CORE_LOG_ERROR("deep_flush not supported"); + // src/common/os_deep_linux.c:42 + CORE_LOG_ERROR("cannot write to deep_flush in region %u", _u); // src/common/set.c:1053 CORE_LOG_ERROR("cannot read size of file (%s) in a poolset directory", _s); // src/common/set.c:1484 CORE_LOG_ERROR("failed to create file: %s", _s); // src/common/set.c:1494 CORE_LOG_ERROR("failed to open file: %s", _s); + // src/common/set.c:183 + CORE_LOG_ERROR("cannot find a contiguous region of given size"); // src/common/set.c:1964 CORE_LOG_ERROR("cannot find a contiguous region of given size"); // src/common/set.c:1972 @@ -586,52 +598,14 @@ call_all_CORE_LOG_ERROR(void) CORE_LOG_ERROR("replica #%u open failed", _u); // src/common/set.c:3316 CORE_LOG_ERROR("os_part_deep_common(%p, %p, %lu)", _p, _p, _lu); - // src/common/set_badblocks.c:86 - CORE_LOG_ERROR("%i pool file(s) contain bad blocks", _d); + // src/common/set.c:343 + CORE_LOG_ERROR("replica open failed: replica %u", _u); // src/common/set_badblocks.c:213 CORE_LOG_ERROR("allocating name of bad block recovery file failed"); + // src/common/set_badblocks.c:86 + CORE_LOG_ERROR("%i pool file(s) contain bad blocks", _d); // src/common/shutdown_state.c:80 CORE_LOG_ERROR("cannot read unsafe shutdown count for %d", _d); - // src/common/file.c:212 - CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:218 - CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:250 - CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:256 - CORE_LOG_ERROR("offset beyond file length, %ju > %ju", _ju, _ju); - // src/common/file.c:272 - CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:307 - CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/file.c:320 - CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:335 - CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:361 - CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/file.c:374 - CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:389 - CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:547 - CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/mmap.c:94 - CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/ctl.c:238 - CORE_LOG_ERROR("Invalid arguments"); - // src/common/bad_blocks.c:152 - CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); - // src/common/bad_blocks.c:161 - CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); - // src/common/bad_blocks.c:210 - CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); - // src/common/bad_blocks.c:217 - CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); - // src/common/bad_blocks.c:255 - CORE_LOG_ERROR("counting bad blocks failed -- '%s'", _s); - // src/common/bad_blocks.c:260 - CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", _s, _d); // src/common/uuid.c:24 CORE_LOG_ERROR("invalid buffer for uuid string"); // src/common/uuid.c:29 @@ -644,20 +618,6 @@ call_all_CORE_LOG_ERROR(void) CORE_LOG_ERROR("invalid uuid string"); // src/common/uuid.c:79 CORE_LOG_ERROR("sscanf(uuid)"); - // src/common/os_deep_linux.c:38 - CORE_LOG_ERROR("deep_flush not supported"); - // src/common/os_deep_linux.c:42 - CORE_LOG_ERROR("cannot write to deep_flush in region %u", _u); - // src/common/os_deep_linux.c:127 - CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); - // src/common/os_deep_linux.c:156 - CORE_LOG_ERROR("deep_flush not supported"); - // src/common/os_deep_linux.c:159 - CORE_LOG_ERROR("invalid dax_region id %u", _u); - // src/common/os_deep_linux.c:166 - CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", _u); - // src/common/os_deep_linux.c:175 - CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); // src/common/uuid_linux.c:31 CORE_LOG_ERROR("open(uuid)"); // src/common/uuid_linux.c:37 @@ -666,87 +626,71 @@ call_all_CORE_LOG_ERROR(void) CORE_LOG_ERROR("stat failed for %s", _s); // src/core/util_posix.c:62 CORE_LOG_ERROR("stat failed for %s", _s); + // src/libpmem/pmem.c:480 + CORE_LOG_ERROR("failed to create temporary file at \"%s\"", _s); + // src/libpmem/pmem_posix.c:61 + CORE_LOG_ERROR("can't track mapped region"); + // src/libpmemobj/heap.c:1327 + CORE_LOG_ERROR("cannot decrease max number of arenas"); + // src/libpmemobj/lane.c:417 + CORE_LOG_ERROR("lane %lu internal redo failed: %d", _lu, _d); + // src/libpmemobj/list.c:564 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:603 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:731 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:765 + CORE_LOG_ERROR("pmemobj_mutex_lock failed"); + // src/libpmemobj/list.c:842 + CORE_LOG_ERROR("list_mutexes_lock failed"); + // src/libpmemobj/obj.c:105 + CORE_LOG_ERROR("unable to parse config stored in %s environment variable", _s); + // src/libpmemobj/obj.c:1090 + CORE_LOG_ERROR("cannot create pool or pool set"); + // src/libpmemobj/obj.c:1127 + CORE_LOG_ERROR("creation of pool descriptor failed"); + // src/libpmemobj/obj.c:116 + CORE_LOG_ERROR("unable to parse config stored in %s file (from %s environment variable)", _s, _s); + // src/libpmemobj/obj.c:1189 + CORE_LOG_ERROR("lane_check"); + // src/libpmemobj/obj.c:1198 + CORE_LOG_ERROR("heap_check"); + // src/libpmemobj/obj.c:1238 + CORE_LOG_ERROR("cannot open pool or pool set"); + // src/libpmemobj/obj.c:1375 + CORE_LOG_ERROR("descriptor check of replica #%u failed", _u); + // src/libpmemobj/obj.c:2438 + CORE_LOG_ERROR("obj_realloc_root failed"); + // src/libpmemobj/obj.c:90 + CORE_LOG_ERROR("ctl_new"); + // src/tools/pmempool/common.c:1307 + CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); } void call_all_CORE_LOG_FATAL(void) { - // src/libpmem/pmem.c:362 - CORE_LOG_FATAL("util_bool_compare_and_swap32"); - // src/libpmem/pmem.c:915 - CORE_LOG_FATAL("invalid flush function address"); - // src/libpmemobj/lane.c:43 - CORE_LOG_FATAL("critnib_new"); - // src/libpmemobj/lane.c:80 - CORE_LOG_FATAL("os_tls_set"); - // src/libpmemobj/lane.c:105 - CORE_LOG_FATAL("os_tls_key_create"); - // src/libpmemobj/lane.c:483 - CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/lane.c:499 - CORE_LOG_FATAL("critnib_insert"); - // src/libpmemobj/lane.c:555 - CORE_LOG_FATAL("lane_release"); - // src/libpmemobj/lane.c:560 - CORE_LOG_FATAL("util_bool_compare_and_swap64"); - // src/libpmemobj/memblock.c:1106 - CORE_LOG_FATAL("failed to initialize valgrind state"); - // src/libpmemobj/memblock.c:1146 - CORE_LOG_FATAL("failed to initialize valgrind state"); - // src/libpmemobj/memblock.c:1466 - CORE_LOG_FATAL("possible zone chunks metadata corruption"); - // src/libpmemobj/tx.c:161 - CORE_LOG_FATAL("%s called outside of transaction", _s); - // src/libpmemobj/tx.c:272 - CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:284 - CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:321 - CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:574 - CORE_LOG_FATAL("invalid state of ranges tree"); - // src/libpmemobj/tx.c:769 - CORE_LOG_FATAL("Invalid stage %d to begin new transaction", _d); - // src/libpmemobj/tx.c:807 - CORE_LOG_FATAL("transaction callback is already set, old %p new %p old_arg %p new_arg %p", _p, _p, _p, _p); - // src/libpmemobj/tx.c:1049 - CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); - // src/libpmemobj/tx.c:1053 - CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); - // src/libpmemobj/palloc.c:304 - CORE_LOG_FATAL("duplicate runtime chunk state, possible double free"); - // src/libpmemobj/sync.h:87 - CORE_LOG_FATAL("pmemobj_mutex_lock"); - // src/libpmemobj/sync.h:102 - CORE_LOG_FATAL("pmemobj_mutex_unlock"); - // src/libpmemobj/obj.c:148 - CORE_LOG_FATAL("critnib_new for pools_ht"); - // src/libpmemobj/obj.c:156 - CORE_LOG_FATAL("critnib_new for pools_tree"); - // src/libpmemobj/obj.c:211 - CORE_LOG_FATAL("error: %s", _s); - // src/libpmemobj/obj.c:252 - CORE_LOG_FATAL("pmem_msync"); // src/common/set.c:221 CORE_LOG_FATAL("munmap: %s", _s); // src/common/set.c:2220 CORE_LOG_FATAL("cannot add a new part to the replica info"); // src/common/util_pmem.h:30 CORE_LOG_FATAL("pmem_msync"); - // src/core/last_error_msg.c:37 - CORE_LOG_FATAL("os_thread_key_create"); - // src/core/last_error_msg.c:78 - CORE_LOG_FATAL("os_tls_set"); - // src/core/sys_util.h:31 - CORE_LOG_FATAL("os_mutex_init"); - // src/core/sys_util.h:46 - CORE_LOG_FATAL("os_mutex_destroy"); - // src/core/sys_util.h:61 - CORE_LOG_FATAL("os_mutex_lock"); - // src/core/sys_util.h:77 - CORE_LOG_FATAL("os_mutex_trylock"); - // src/core/sys_util.h:93 - CORE_LOG_FATAL("os_mutex_unlock"); + // src/core/alloc.c:62 + CORE_LOG_FATAL("unknown allocation type"); + // src/core/core_assert.h:39 + CORE_LOG_FATAL("assertion failure: %s", _s); + // src/core/core_assert.h:45 + CORE_LOG_FATAL("assertion failure: %s (%s = %s)", _s, _s, _s); + // src/core/last_error_msg.c:37 + CORE_LOG_FATAL("os_thread_key_create"); + // src/core/last_error_msg.c:78 + CORE_LOG_FATAL("os_tls_set"); + // src/core/out.c:113 + CORE_LOG_FATAL("Cannot set log threshold"); + // src/core/out.c:145 + CORE_LOG_FATAL("Cannot set legacy log function"); // src/core/sys_util.h:108 CORE_LOG_FATAL("os_rwlock_init"); // src/core/sys_util.h:123 @@ -777,16 +721,72 @@ call_all_CORE_LOG_FATAL(void) CORE_LOG_FATAL("os_cond_init"); // src/core/sys_util.h:308 CORE_LOG_FATAL("os_cond_destroy"); - // src/core/core_assert.h:39 - CORE_LOG_FATAL("assertion failure: %s", _s); - // src/core/core_assert.h:45 - CORE_LOG_FATAL("assertion failure: %s (%s = %s)", _s, _s, _s); - // src/core/alloc.c:62 - CORE_LOG_FATAL("unknown allocation type"); - // src/core/out.c:113 - CORE_LOG_FATAL("Cannot set log threshold"); - // src/core/out.c:145 - CORE_LOG_FATAL("Cannot set legacy log function"); + // src/core/sys_util.h:31 + CORE_LOG_FATAL("os_mutex_init"); + // src/core/sys_util.h:46 + CORE_LOG_FATAL("os_mutex_destroy"); + // src/core/sys_util.h:61 + CORE_LOG_FATAL("os_mutex_lock"); + // src/core/sys_util.h:77 + CORE_LOG_FATAL("os_mutex_trylock"); + // src/core/sys_util.h:93 + CORE_LOG_FATAL("os_mutex_unlock"); + // src/libpmem/pmem.c:362 + CORE_LOG_FATAL("util_bool_compare_and_swap32"); + // src/libpmem/pmem.c:915 + CORE_LOG_FATAL("invalid flush function address"); + // src/libpmemobj/lane.c:105 + CORE_LOG_FATAL("os_tls_key_create"); + // src/libpmemobj/lane.c:43 + CORE_LOG_FATAL("critnib_new"); + // src/libpmemobj/lane.c:483 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/lane.c:499 + CORE_LOG_FATAL("critnib_insert"); + // src/libpmemobj/lane.c:555 + CORE_LOG_FATAL("lane_release"); + // src/libpmemobj/lane.c:560 + CORE_LOG_FATAL("util_bool_compare_and_swap64"); + // src/libpmemobj/lane.c:80 + CORE_LOG_FATAL("os_tls_set"); + // src/libpmemobj/memblock.c:1106 + CORE_LOG_FATAL("failed to initialize valgrind state"); + // src/libpmemobj/memblock.c:1146 + CORE_LOG_FATAL("failed to initialize valgrind state"); + // src/libpmemobj/memblock.c:1466 + CORE_LOG_FATAL("possible zone chunks metadata corruption"); + // src/libpmemobj/obj.c:148 + CORE_LOG_FATAL("critnib_new for pools_ht"); + // src/libpmemobj/obj.c:156 + CORE_LOG_FATAL("critnib_new for pools_tree"); + // src/libpmemobj/obj.c:211 + CORE_LOG_FATAL("error: %s", _s); + // src/libpmemobj/obj.c:252 + CORE_LOG_FATAL("pmem_msync"); + // src/libpmemobj/palloc.c:304 + CORE_LOG_FATAL("duplicate runtime chunk state, possible double free"); + // src/libpmemobj/sync.h:102 + CORE_LOG_FATAL("pmemobj_mutex_unlock"); + // src/libpmemobj/sync.h:87 + CORE_LOG_FATAL("pmemobj_mutex_lock"); + // src/libpmemobj/tx.c:1049 + CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); + // src/libpmemobj/tx.c:1053 + CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); + // src/libpmemobj/tx.c:161 + CORE_LOG_FATAL("%s called outside of transaction", _s); + // src/libpmemobj/tx.c:272 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:284 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:321 + CORE_LOG_FATAL("Malloc"); + // src/libpmemobj/tx.c:574 + CORE_LOG_FATAL("invalid state of ranges tree"); + // src/libpmemobj/tx.c:769 + CORE_LOG_FATAL("Invalid stage %d to begin new transaction", _d); + // src/libpmemobj/tx.c:807 + CORE_LOG_FATAL("transaction callback is already set, old %p new %p old_arg %p new_arg %p", _p, _p, _p, _p); } void @@ -799,116 +799,98 @@ void call_all_ERR_W_ERRNO(int errnum) { errno = errnum; - // src/libpmem/pmem.c:280 - ERR_W_ERRNO("msync"); - UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:487 + // src/common/bad_blocks.c:142 ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:500 - ERR_W_ERRNO("ftruncate"); - UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:506 - ERR_W_ERRNO("posix_fallocate"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:267 - ERR_W_ERRNO("Malloc of volatile lanes"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:276 - ERR_W_ERRNO("Malloc for lane locks"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:289 - ERR_W_ERRNO("lane_init"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:499 - ERR_W_ERRNO("pmemobj_mutex_lock"); + // src/common/bad_blocks.c:200 + ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:508 - ERR_W_ERRNO("pmemobj_rwlock_wrlock"); + // src/common/bad_blocks.c:63 + ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:776 + // src/common/ctl.c:132 ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:945 - ERR_W_ERRNO("explicit transaction abort"); + // src/common/ctl.c:142 + ERR_W_ERRNO("strtok_r"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/list.c:473 - ERR_W_ERRNO("palloc_reserve"); + // src/common/ctl.c:400 + ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/stats.c:124 - ERR_W_ERRNO("Malloc"); + // src/common/ctl.c:445 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/critnib.c:279 - ERR_W_ERRNO("Malloc"); + // src/common/ctl.c:479 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/critnib.c:316 - ERR_W_ERRNO("Malloc"); + // src/common/file.c:126 + ERR_W_ERRNO("stat"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/heap.c:187 - ERR_W_ERRNO("heap: arena malloc error"); + // src/common/file.c:143 + ERR_W_ERRNO("open"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:90 - ERR_W_ERRNO("Zalloc"); + // src/common/file.c:206 + ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:116 - ERR_W_ERRNO("Zalloc"); + // src/common/file.c:244 + ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:177 - ERR_W_ERRNO("Zalloc"); + // src/common/file.c:40 + ERR_W_ERRNO("os_access \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:662 - ERR_W_ERRNO("lane_boot"); + // src/common/file.c:430 + ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:667 - ERR_W_ERRNO("lane_recover_and_section_boot"); + // src/common/file.c:435 + ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:725 - ERR_W_ERRNO("palloc_init"); + // src/common/file.c:440 + ERR_W_ERRNO("flock \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:964 - ERR_W_ERRNO("critnib_insert to pools_ht"); + // src/common/file.c:469 + ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:969 - ERR_W_ERRNO("critnib_insert to pools_tree"); + // src/common/file.c:474 + ERR_W_ERRNO("flock \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:984 - ERR_W_ERRNO("ravl_new_sized"); + // src/common/file.c:507 + ERR_W_ERRNO("flock unlock"); + UT_ASSERTeq(errno, errnum); + // src/common/file.c:94 + ERR_W_ERRNO("fstat"); UT_ASSERTeq(errno, errnum); // src/common/file_posix.c:158 ERR_W_ERRNO("stat \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:195 - ERR_W_ERRNO("mmap: %s", _s); - UT_ASSERTeq(errno, errnum); - // src/common/set.c:252 - ERR_W_ERRNO("mmap: %s", _s); + // src/common/mmap.c:104 + ERR_W_ERRNO("mmap %zu bytes", _zu); UT_ASSERTeq(errno, errnum); - // src/common/set.c:283 - ERR_W_ERRNO("munmap: %s", _s); + // src/common/mmap.c:126 + ERR_W_ERRNO("munmap"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:369 - ERR_W_ERRNO("unlink %s failed (part %u, replica %u)", _s, _u, _u); + // src/common/mmap.c:155 + ERR_W_ERRNO("mprotect: PROT_READ"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:422 - ERR_W_ERRNO("fstat %d %s", _d, _s); + // src/common/mmap.c:184 + ERR_W_ERRNO("mprotect: PROT_READ|PROT_WRITE"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:435 - ERR_W_ERRNO("chmod %u/%u/%s", _u, _u, _s); + // src/common/mmap.c:213 + ERR_W_ERRNO("mprotect: PROT_NONE"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:518 - ERR_W_ERRNO("Strdup"); + // src/common/mmap.c:297 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:622 - ERR_W_ERRNO("Strdup"); + // src/common/mmap.c:360 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:648 - ERR_W_ERRNO("Realloc"); + // src/common/mmap.c:375 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:841 - ERR_W_ERRNO("Realloc"); + // src/common/mmap_posix.c:141 + ERR_W_ERRNO("mmap MAP_ANONYMOUS"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:849 - ERR_W_ERRNO("Zalloc"); + // src/common/mmap_posix.c:43 + ERR_W_ERRNO("%s", _s); UT_ASSERTeq(errno, errnum); // src/common/set.c:1027 ERR_W_ERRNO("fs_new: \"%s\"", _s); @@ -961,9 +943,18 @@ call_all_ERR_W_ERRNO(int errnum) // src/common/set.c:1756 ERR_W_ERRNO("fstat"); UT_ASSERTeq(errno, errnum); + // src/common/set.c:195 + ERR_W_ERRNO("mmap: %s", _s); + UT_ASSERTeq(errno, errnum); // src/common/set.c:2212 ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); + // src/common/set.c:252 + ERR_W_ERRNO("mmap: %s", _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:283 + ERR_W_ERRNO("munmap: %s", _s); + UT_ASSERTeq(errno, errnum); // src/common/set.c:3013 ERR_W_ERRNO("no parts in replicas"); UT_ASSERTeq(errno, errnum); @@ -973,131 +964,140 @@ call_all_ERR_W_ERRNO(int errnum) // src/common/set.c:3208 ERR_W_ERRNO("open: path \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/set_badblocks.c:171 - ERR_W_ERRNO("Malloc"); + // src/common/set.c:369 + ERR_W_ERRNO("unlink %s failed (part %u, replica %u)", _s, _u, _u); UT_ASSERTeq(errno, errnum); - // src/common/shutdown_state.c:95 - ERR_W_ERRNO("Zalloc"); + // src/common/set.c:422 + ERR_W_ERRNO("fstat %d %s", _d, _s); UT_ASSERTeq(errno, errnum); - // src/common/vecq.h:68 + // src/common/set.c:435 + ERR_W_ERRNO("chmod %u/%u/%s", _u, _u, _s); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:518 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:622 + ERR_W_ERRNO("Strdup"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:648 ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:40 - ERR_W_ERRNO("os_access \"%s\"", _s); + // src/common/set.c:841 + ERR_W_ERRNO("Realloc"); + UT_ASSERTeq(errno, errnum); + // src/common/set.c:849 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:94 - ERR_W_ERRNO("fstat"); + // src/common/set_badblocks.c:171 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:126 - ERR_W_ERRNO("stat"); + // src/common/shutdown_state.c:95 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:143 - ERR_W_ERRNO("open"); + // src/common/vec.h:62 + ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:206 - ERR_W_ERRNO("open \"%s\"", _s); + // src/common/vecq.h:68 + ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:244 - ERR_W_ERRNO("open \"%s\"", _s); + // src/core/out.c:126 + ERR_W_ERRNO("snprintf"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:430 - ERR_W_ERRNO("open \"%s\"", _s); + // src/core/ravl.c:167 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:435 - ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); + // src/core/ravl.c:51 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:440 - ERR_W_ERRNO("flock \"%s\"", _s); + // src/core/sys_util.h:181 + ERR_W_ERRNO("os_spin_init"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:469 - ERR_W_ERRNO("open \"%s\"", _s); + // src/core/util_posix.c:138 + ERR_W_ERRNO("open"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:474 - ERR_W_ERRNO("flock \"%s\"", _s); + // src/core/util_posix.c:49 + ERR_W_ERRNO("stat failed for %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:507 - ERR_W_ERRNO("flock unlock"); + // src/core/util_posix.c:59 + ERR_W_ERRNO("stat failed for %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:104 - ERR_W_ERRNO("mmap %zu bytes", _zu); + // src/core/util_posix.c:99 + ERR_W_ERRNO("mkstemp"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:126 - ERR_W_ERRNO("munmap"); + // src/libpmem/pmem.c:280 + ERR_W_ERRNO("msync"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:155 - ERR_W_ERRNO("mprotect: PROT_READ"); + // src/libpmem/pmem.c:487 + ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:184 - ERR_W_ERRNO("mprotect: PROT_READ|PROT_WRITE"); + // src/libpmem/pmem.c:500 + ERR_W_ERRNO("ftruncate"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:213 - ERR_W_ERRNO("mprotect: PROT_NONE"); + // src/libpmem/pmem.c:506 + ERR_W_ERRNO("posix_fallocate"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:297 + // src/libpmemobj/critnib.c:279 ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:360 + // src/libpmemobj/critnib.c:316 ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:375 - ERR_W_ERRNO("Malloc"); + // src/libpmemobj/heap.c:187 + ERR_W_ERRNO("heap: arena malloc error"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:132 - ERR_W_ERRNO("Malloc"); + // src/libpmemobj/lane.c:267 + ERR_W_ERRNO("Malloc of volatile lanes"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:142 - ERR_W_ERRNO("strtok_r"); + // src/libpmemobj/lane.c:276 + ERR_W_ERRNO("Malloc for lane locks"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:400 - ERR_W_ERRNO("Strdup"); + // src/libpmemobj/lane.c:289 + ERR_W_ERRNO("lane_init"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:445 - ERR_W_ERRNO("Zalloc"); + // src/libpmemobj/list.c:473 + ERR_W_ERRNO("palloc_reserve"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:479 + // src/libpmemobj/memops.c:116 ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/bad_blocks.c:63 - ERR_W_ERRNO("open %s", _s); + // src/libpmemobj/memops.c:177 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/bad_blocks.c:142 - ERR_W_ERRNO("open %s", _s); + // src/libpmemobj/memops.c:90 + ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/bad_blocks.c:200 - ERR_W_ERRNO("open %s", _s); + // src/libpmemobj/obj.c:662 + ERR_W_ERRNO("lane_boot"); UT_ASSERTeq(errno, errnum); - // src/common/mmap_posix.c:43 - ERR_W_ERRNO("%s", _s); + // src/libpmemobj/obj.c:667 + ERR_W_ERRNO("lane_recover_and_section_boot"); UT_ASSERTeq(errno, errnum); - // src/common/mmap_posix.c:141 - ERR_W_ERRNO("mmap MAP_ANONYMOUS"); + // src/libpmemobj/obj.c:725 + ERR_W_ERRNO("palloc_init"); UT_ASSERTeq(errno, errnum); - // src/common/vec.h:62 - ERR_W_ERRNO("Realloc"); + // src/libpmemobj/obj.c:964 + ERR_W_ERRNO("critnib_insert to pools_ht"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:181 - ERR_W_ERRNO("os_spin_init"); + // src/libpmemobj/obj.c:969 + ERR_W_ERRNO("critnib_insert to pools_tree"); UT_ASSERTeq(errno, errnum); - // src/core/ravl.c:51 - ERR_W_ERRNO("Malloc"); + // src/libpmemobj/obj.c:984 + ERR_W_ERRNO("ravl_new_sized"); UT_ASSERTeq(errno, errnum); - // src/core/ravl.c:167 + // src/libpmemobj/stats.c:124 ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:49 - ERR_W_ERRNO("stat failed for %s", _s); - UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:59 - ERR_W_ERRNO("stat failed for %s", _s); + // src/libpmemobj/tx.c:499 + ERR_W_ERRNO("pmemobj_mutex_lock"); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:99 - ERR_W_ERRNO("mkstemp"); + // src/libpmemobj/tx.c:508 + ERR_W_ERRNO("pmemobj_rwlock_wrlock"); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:138 - ERR_W_ERRNO("open"); + // src/libpmemobj/tx.c:776 + ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/core/out.c:126 - ERR_W_ERRNO("snprintf"); + // src/libpmemobj/tx.c:945 + ERR_W_ERRNO("explicit transaction abort"); UT_ASSERTeq(errno, errnum); } @@ -1114,19 +1114,10 @@ void call_all_CORE_LOG_ERROR_W_ERRNO(int errnum) { errno = errnum; - // src/libpmemobj/obj.c:90 - CORE_LOG_ERROR_W_ERRNO("ctl_new"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:1189 - CORE_LOG_ERROR_W_ERRNO("lane_check"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:1198 - CORE_LOG_ERROR_W_ERRNO("heap_check"); - UT_ASSERTeq(errno, errnum); - // src/common/os_deep_linux.c:38 + // src/common/os_deep_linux.c:156 CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); UT_ASSERTeq(errno, errnum); - // src/common/os_deep_linux.c:156 + // src/common/os_deep_linux.c:38 CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); UT_ASSERTeq(errno, errnum); // src/common/uuid_linux.c:31 @@ -1135,42 +1126,21 @@ call_all_CORE_LOG_ERROR_W_ERRNO(int errnum) // src/common/uuid_linux.c:37 CORE_LOG_ERROR_W_ERRNO("read(uuid)"); UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:1189 + CORE_LOG_ERROR_W_ERRNO("lane_check"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:1198 + CORE_LOG_ERROR_W_ERRNO("heap_check"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:90 + CORE_LOG_ERROR_W_ERRNO("ctl_new"); + UT_ASSERTeq(errno, errnum); } void call_all_CORE_LOG_FATAL_W_ERRNO(int errnum) { errno = errnum; - // src/libpmemobj/lane.c:80 - CORE_LOG_FATAL_W_ERRNO("os_tls_set"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:105 - CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:272 - CORE_LOG_FATAL_W_ERRNO("Malloc"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:284 - CORE_LOG_FATAL_W_ERRNO("Malloc"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:321 - CORE_LOG_FATAL_W_ERRNO("Malloc"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/sync.h:87 - CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/sync.h:102 - CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:148 - CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:156 - CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); - UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:252 - CORE_LOG_FATAL_W_ERRNO("pmem_msync"); - UT_ASSERTeq(errno, errnum); // src/common/set.c:221 CORE_LOG_FATAL_W_ERRNO("munmap: %s", _s); UT_ASSERTeq(errno, errnum); @@ -1183,21 +1153,6 @@ call_all_CORE_LOG_FATAL_W_ERRNO(int errnum) // src/core/last_error_msg.c:78 CORE_LOG_FATAL_W_ERRNO("os_tls_set"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:31 - CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); - UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:46 - CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); - UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:61 - CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); - UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:77 - CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); - UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:93 - CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); - UT_ASSERTeq(errno, errnum); // src/core/sys_util.h:108 CORE_LOG_FATAL_W_ERRNO("os_rwlock_init"); UT_ASSERTeq(errno, errnum); @@ -1243,4 +1198,49 @@ call_all_CORE_LOG_FATAL_W_ERRNO(int errnum) // src/core/sys_util.h:308 CORE_LOG_FATAL_W_ERRNO("os_cond_destroy"); UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:31 + CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:46 + CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:61 + CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:77 + CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); + UT_ASSERTeq(errno, errnum); + // src/core/sys_util.h:93 + CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:105 + CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/lane.c:80 + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:148 + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:156 + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/obj.c:252 + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/sync.h:102 + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/sync.h:87 + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:272 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:284 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); + // src/libpmemobj/tx.c:321 + CORE_LOG_FATAL_W_ERRNO("Malloc"); + UT_ASSERTeq(errno, errnum); } diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py index 48609252eeb..84a93c10de3 100755 --- a/utils/call_stacks_analysis/log_call_all_generate.py +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -117,6 +117,10 @@ def extract_all_calls(func: str) -> List[Dict]: calls.append(call) else: bad_line('An unexpected line format', line) + # sort calls by file and line + def key_func(a: Dict) -> str: + return a['file'] + a['line'] + calls.sort(key=key_func) print(f'[{func}] total: {total}, included: {len(calls)}') return calls From 9c5f70f1b18da7060051f899e27c48fef5cb5183 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Fri, 16 Feb 2024 12:02:51 -0500 Subject: [PATCH 091/182] common: add a scanner for the log calls test Signed-off-by: Jan Michalski --- .github/workflows/scan_log_calls.yml | 38 ++++++++++++++++++++++++++++ .github/workflows/scans.yml | 3 +++ 2 files changed, 41 insertions(+) create mode 100644 .github/workflows/scan_log_calls.yml diff --git a/.github/workflows/scan_log_calls.yml b/.github/workflows/scan_log_calls.yml new file mode 100644 index 00000000000..fd257236a4b --- /dev/null +++ b/.github/workflows/scan_log_calls.yml @@ -0,0 +1,38 @@ +# Verify the log calls test is up-to-date +name: Log calls + +on: + workflow_dispatch: + workflow_call: + + +jobs: + log-calls: + name: Log calls + env: + WORKING_DIRECTORY: utils/call_stacks_analysis/ + runs-on: ubuntu-latest + steps: + - name: Clone the git repo + uses: actions/checkout@v4.1.1 + + - name: Generate log calls' diff + working-directory: ${{ env.WORKING_DIRECTORY }} + run: | + ./log_call_all_generate.py + git diff > log_calls.diff + echo "length=$(cat log_calls.diff | wc -l)" >> $GITHUB_OUTPUT + id: log_calls_diff + + - name: Upload artifacts + if: steps.log_calls_diff.outputs.length != '0' + uses: actions/upload-artifact@v3 + with: + name: log_calls_diff + path: | + ${{ env.WORKING_DIRECTORY }}/log_calls.diff + + - name: Exit code + run: | + [ "${{steps.log_calls_diff.outputs.length}}" != '0' ] && exit 1 + exit 0 diff --git a/.github/workflows/scans.yml b/.github/workflows/scans.yml index 644d2baf1fc..fc7ab815547 100644 --- a/.github/workflows/scans.yml +++ b/.github/workflows/scans.yml @@ -32,3 +32,6 @@ jobs: call-stack-usage: uses: ./.github/workflows/scan_stack_usage.yml name: Stack usage + call-log-calls: + uses: ./.github/workflows/scan_log_calls.yml + name: Log calls From f8b4c9dfb9c1a0fcc7dcc474f5ae02c8047ae216 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 16 Feb 2024 08:49:07 +0100 Subject: [PATCH 092/182] common: log w/ errno handled internally Alternative implementation that keeps max stack consumption on the same level as it was before new logging solution. Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 59 +++++++++++++++------ src/core/log_internal.h | 78 ++++++++-------------------- src/test/core_log/core_log.c | 4 +- utils/call_stacks_analysis/README.md | 2 +- 4 files changed, 70 insertions(+), 73 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 1575bfb1553..732b8dd83da 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -6,6 +6,14 @@ * via user defined function */ +/* + * Note: The undef below is critical to use the XSI-compliant version of + * the strerror_r(3) instead of the GNU-specific. Otherwise, the produced + * error string may not end up in the log buffer. + */ +#undef _GNU_SOURCE +#include + #include #include #include @@ -13,12 +21,12 @@ #ifdef ATOMIC_OPERATIONS_SUPPORTED #include #endif /* ATOMIC_OPERATIONS_SUPPORTED */ -#include #include #include "log_internal.h" #include "log_default.h" #include "last_error_msg.h" +#include "core_assert.h" /* * Default levels of the logging thresholds @@ -186,11 +194,28 @@ core_log_get_threshold(enum core_log_threshold threshold, static void inline core_log_va(char *buf, size_t buf_len, enum core_log_level level, - const char *file_name, int line_no, const char *function_name, - const char *message_format, va_list arg) + int errnum, const char *file_name, int line_no, + const char *function_name, const char *message_format, va_list arg) { - if (vsnprintf(buf, buf_len, message_format, arg) < 0) { - return; + int msg_len = vsnprintf(buf, buf_len, message_format, arg); + if (msg_len < 0) + goto end; + + if (errnum != NO_ERRNO) { + char *msg_ptr = buf + msg_len; + size_t buf_len_left = buf_len - (size_t)msg_len; + + /* Check if the longest possible error string can fit */ + if (buf_len_left < _CORE_LOG_MAX_ERRNO_MSG) { + goto end; + } + + /* Ask for the error string */ + /* + * If it fails, the best thing to do is to at least pass + * the log message as is. + */ + (void) strerror_r(errnum, msg_ptr, buf_len_left); } /* @@ -199,40 +224,44 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, * performed in the case of the CORE_LOG_TO_LAST macro. Sorry. */ if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) { - return; + goto end; } if (0 == Core_log_function) { - return; + goto end; } ((core_log_function *)Core_log_function)(Core_log_function_context, level, file_name, line_no, function_name, buf); + +end: + if (errnum != NO_ERRNO) + errno = errnum; } void -core_log(enum core_log_level level, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...) +core_log(enum core_log_level level, int errnum, const char *file_name, + int line_no, const char *function_name, const char *message_format, ...) { char message[1024] = ""; va_list arg; va_start(arg, message_format); - core_log_va(message, sizeof(message), level, file_name, line_no, - function_name, message_format, arg); + core_log_va(message, sizeof(message), level, errnum, file_name, + line_no, function_name, message_format, arg); va_end(arg); } void -core_log_to_last(const char *file_name, int line_no, const char *function_name, - const char *message_format, ...) +core_log_to_last(int errnum, const char *file_name, int line_no, + const char *function_name, const char *message_format, ...) { char *last_error = (char *)last_error_msg_get(); va_list arg; va_start(arg, message_format); core_log_va(last_error, CORE_LAST_ERROR_MSG_MAXPRINT, - CORE_LOG_LEVEL_ERROR, file_name, line_no, function_name, - message_format, arg); + CORE_LOG_LEVEL_ERROR, errnum, file_name, line_no, + function_name, message_format, arg); va_end(arg); } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 6385438cb96..459e7847eae 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -9,7 +9,6 @@ #define CORE_LOG_INTERNAL_H #include -#include #include #include @@ -119,18 +118,21 @@ core_log_error_translate(int ret) return 0; } -void core_log(enum core_log_level level, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...); +#define NO_ERRNO (-1) + +void core_log(enum core_log_level level, int errnum, const char *file_name, + int line_no, const char *function_name, + const char *message_format, ...); /* Only error messages can last. So, no level has to be specified. */ -void core_log_to_last(const char *file_name, int line_no, +void core_log_to_last(int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...); -#define _CORE_LOG(level, format, ...) \ +#define _CORE_LOG(level, errnum, format, ...) \ do { \ if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ - core_log(level, __FILE__, __LINE__, __func__, \ - format, ##__VA_ARGS__); \ + core_log(level, errnum, __FILE__, __LINE__, \ + __func__, format, ##__VA_ARGS__); \ } \ } while (0) @@ -138,73 +140,44 @@ void core_log_to_last(const char *file_name, int line_no, * Can't check the logging level here when logging to the last error message. * Since the log message has to be generated anyway. */ -#define CORE_LOG_TO_LAST(format, ...) \ - core_log_to_last(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__) - -/* - * Required to handle both variants' return types. - * The ideal solution would be to force using one variant or another. - */ -#ifdef _GNU_SOURCE -#define _CORE_LOG_STRERROR_R(buf, buf_len, out) \ - do { \ - char *ret = strerror_r(errno, (buf), (buf_len)); \ - *(out) = ret; \ - } while (0) -#else -#define _CORE_LOG_STRERROR_R(buf, buf_len, out) \ - do { \ - int ret = strerror_r(errno, (buf), (buf_len)); \ - (void) ret; \ - *(out) = buf; \ - } while (0) -#endif - -#define _CORE_LOG_STRERROR(buf, buf_len, out) \ - do { \ - int oerrno = errno; \ - _CORE_LOG_STRERROR_R((buf), (buf_len), (out)); \ - errno = oerrno; \ - } while (0) +#define CORE_LOG_TO_LAST(errnum, format, ...) \ + core_log_to_last(errnum, __FILE__, __LINE__, __func__, \ + format, ##__VA_ARGS__) /* The value fine-tuned to accommodate all possible errno message strings. */ #define _CORE_LOG_MAX_ERRNO_MSG 50 #define _CORE_LOG_W_ERRNO(level, format, ...) \ - do { \ - char buf[_CORE_LOG_MAX_ERRNO_MSG]; \ - char *error_str; \ - _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERRNO_MSG, &error_str); \ - _CORE_LOG(level, format ": %s", ##__VA_ARGS__, error_str); \ - } while (0) + _CORE_LOG(level, errno, format ": ", ##__VA_ARGS__) /* * Set of macros that should be used as the primary API for logging. * Direct call to log shall be used only in exceptional, corner cases. */ #define CORE_LOG_DEBUG(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_DEBUG, NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_INFO(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_INFO, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_INFO, NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_NOTICE(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_NOTICE, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_NOTICE, NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_WARNING(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_WARNING, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_WARNING, NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_ERROR(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_ERROR, NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_FATAL(format, ...) \ do { \ - _CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__); \ + _CORE_LOG(CORE_LOG_LEVEL_FATAL, NO_ERRNO, \ + format, ##__VA_ARGS__); \ abort(); \ } while (0) #define CORE_LOG_ALWAYS(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) + _CORE_LOG(CORE_LOG_LEVEL_ALWAYS, NO_ERRNO, format, ##__VA_ARGS__) /* * 'With errno' macros' flavours. Append string describing the current errno @@ -231,15 +204,10 @@ void core_log_to_last(const char *file_name, int line_no, */ #define CORE_LOG_ERROR_LAST(format, ...) \ - CORE_LOG_TO_LAST(format, ##__VA_ARGS__) + CORE_LOG_TO_LAST(NO_ERRNO, format, ##__VA_ARGS__) #define CORE_LOG_ERROR_W_ERRNO_LAST(format, ...) \ - do { \ - char buf[_CORE_LOG_MAX_ERRNO_MSG]; \ - char *error_str; \ - _CORE_LOG_STRERROR(buf, _CORE_LOG_MAX_ERRNO_MSG, &error_str); \ - CORE_LOG_TO_LAST(format ": %s", ##__VA_ARGS__, error_str); \ - } while (0) + CORE_LOG_TO_LAST(errno, format ": ", ##__VA_ARGS__); /* Aliases */ diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c index 2e2701eda98..1ee04f27f4c 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log/core_log.c @@ -100,8 +100,8 @@ static int Total_TLS_message_num; */ #define TOTAL_TLS_MESSAGE_NUM_EXPECTED 311 -FUNC_MOCK(core_log_to_last, void, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...) +FUNC_MOCK(core_log_to_last, void, int errnum, const char *file_name, + int line_no, const char *function_name, const char *message_format, ...) FUNC_MOCK_RUN_DEFAULT { char buf[BIG_BUF_SIZE] = ""; va_list arg; diff --git a/utils/call_stacks_analysis/README.md b/utils/call_stacks_analysis/README.md index c47af9a7e7d..ee4446dc0c0 100644 --- a/utils/call_stacks_analysis/README.md +++ b/utils/call_stacks_analysis/README.md @@ -15,7 +15,7 @@ ./make_extra.py && \ ./make_cflow.sh && \ ./make_call_stacks.py --filter-api-file examples/api_filter.txt \ - --filter-lower-limit 8192 --dump-all-stacks + --filter-lower-limit 11296 --dump-all-stacks ``` If succesfull, it produces: From 1058be5b3a455fd001669e998917bc9361f6f12f Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 16 Feb 2024 22:37:35 +0100 Subject: [PATCH 093/182] common: fix coverity issue 1976787 Adapt LOG() macro for proper usage in context of if() statement without brackets {}. https://coverityent.devtools.intel.com/prod8/#/project-view/26102/10909?selectedIssue=1976787 Signed-off-by: Tomasz Gromadzki --- src/core/out.h | 10 +++++++++- src/core/util.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/out.h b/src/core/out.h index 033dd18ce82..6a1f089261a 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -53,7 +53,15 @@ out_log_discard(const char *file, int line, const char *func, int level, } while (0) #else -#define LOG(level, ...) SUPPRESS_UNUSED(__VA_ARGS__) +/* + * 'do { ... } while()' is required for a proper interpretation of + * SUPPRESS_UNUSED(__VA_ARGS__) in the context of if() statement + * without brackets {}, especially in the situation when '...' expands + * to more than one argument in '__VA_ARGS__' list + */ +#define LOG(level, ...) do { \ + SUPPRESS_UNUSED(__VA_ARGS__); \ + } while (0) #endif void out_init(const char *log_prefix, const char *log_level_var, diff --git a/src/core/util.h b/src/core/util.h index 52d591fd7bd..179fc9a3f35 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -319,7 +319,7 @@ char *util_concat_str(const char *s1, const char *s2); #define GLUE_I(A, B) A##B /* macro for suppresing errors from unused variables (up to 9) */ -#define SUPPRESS_UNUSED(...)\ +#define SUPPRESS_UNUSED(...) \ GLUE(SUPPRESS_ARG_, COUNT(__VA_ARGS__))(__VA_ARGS__) #define SUPPRESS_ARG_1(X) (void) (X) #define SUPPRESS_ARG_2(X, ...) SUPPRESS_ARG_1(X); SUPPRESS_ARG_1(__VA_ARGS__) From 6ec6c45bd919d7d19a924e200112d2bc29d8382d Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 19 Feb 2024 09:57:53 -0500 Subject: [PATCH 094/182] common: stop using subprocess with shell=True https://bandit.readthedocs.io/en/latest/plugins/b602_subprocess_popen_with_shell_equals_true.html Signed-off-by: Jan Michalski --- utils/call_stacks_analysis/log_call_all_generate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py index 84a93c10de3..e8d06356457 100755 --- a/utils/call_stacks_analysis/log_call_all_generate.py +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -84,8 +84,7 @@ def file_should_be_ignored(file: str) -> bool: return False def extract_all_calls(func: str) -> List[Dict]: - cmd = f'cd {TOP}; grep -Irn {func}' - returned_output = subprocess.check_output(cmd, shell=True) + returned_output = subprocess.check_output(['grep', '-Irn', func], cwd=TOP) string = returned_output.decode("utf-8") calls = [] total = 0 From 8c1c62ac354e3ea688eb1f497acf7db718950606 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 20 Feb 2024 06:24:54 +0100 Subject: [PATCH 095/182] common: separate tests for max expected log message size Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 2 +- src/core/log_internal.h | 8 +++ src/test/Makefile | 2 +- src/test/core_log/.gitignore | 2 - src/test/core_log_max/.gitignore | 1 + src/test/{core_log => core_log_max}/Makefile | 6 +- src/test/{core_log => core_log_max}/TESTS.py | 6 +- .../{core_log => core_log_max}/call_all.c | 5 ++ .../call_all.c.generated | 0 .../{core_log => core_log_max}/call_all.h | 0 .../core_log_max.c} | 62 ++++++++++++++++++- .../log_call_all_generate.py | 17 +++-- 12 files changed, 90 insertions(+), 21 deletions(-) delete mode 100644 src/test/core_log/.gitignore create mode 100644 src/test/core_log_max/.gitignore rename src/test/{core_log => core_log_max}/Makefile (60%) rename src/test/{core_log => core_log_max}/TESTS.py (80%) rename src/test/{core_log => core_log_max}/call_all.c (85%) rename src/test/{core_log => core_log_max}/call_all.c.generated (100%) rename src/test/{core_log => core_log_max}/call_all.h (100%) rename src/test/{core_log/core_log.c => core_log_max/core_log_max.c} (68%) diff --git a/src/core/log.c b/src/core/log.c index 732b8dd83da..a2d15803878 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -243,7 +243,7 @@ void core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...) { - char message[1024] = ""; + char message[_CORE_LOG_MSG_MAXPRINT] = ""; va_list arg; va_start(arg, message_format); diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 459e7847eae..24ef908ba9a 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -107,6 +107,14 @@ void core_log_init(void); void core_log_fini(void); +/* + * The actual maximum expected log line is 407. + * An additional byte is used to detect buffer overflow in core_log tests. + * If the actual max message length is equal to 408, it means we have a buffer + * overflow. + */ +#define _CORE_LOG_MSG_MAXPRINT 408 /* maximum expected log line + 1 */ + static inline int core_log_error_translate(int ret) { diff --git a/src/test/Makefile b/src/test/Makefile index 786c7fce13b..d6e982904de 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -108,7 +108,7 @@ OBJ_TESTS = \ OTHER_TESTS = \ arch_flags\ - core_log\ + core_log_max\ checksum\ compat_incompat_features\ ctl_prefault\ diff --git a/src/test/core_log/.gitignore b/src/test/core_log/.gitignore deleted file mode 100644 index 001feb0f84e..00000000000 --- a/src/test/core_log/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -core_log -call_all diff --git a/src/test/core_log_max/.gitignore b/src/test/core_log_max/.gitignore new file mode 100644 index 00000000000..94e5728aea0 --- /dev/null +++ b/src/test/core_log_max/.gitignore @@ -0,0 +1 @@ +core_log_max diff --git a/src/test/core_log/Makefile b/src/test/core_log_max/Makefile similarity index 60% rename from src/test/core_log/Makefile rename to src/test/core_log_max/Makefile index 4eb6aac574b..d4196489148 100644 --- a/src/test/core_log/Makefile +++ b/src/test/core_log_max/Makefile @@ -1,12 +1,12 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024, Intel Corporation -TARGET = core_log -OBJS = core_log.o call_all.o +TARGET = core_log_max +OBJS = core_log_max.o call_all.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n LIBPMEMCORE=y include ../Makefile.inc -LDFLAGS += $(call extract_funcs, core_log.c) +LDFLAGS += $(call extract_funcs, core_log_max.c) diff --git a/src/test/core_log/TESTS.py b/src/test/core_log_max/TESTS.py similarity index 80% rename from src/test/core_log/TESTS.py rename to src/test/core_log_max/TESTS.py index e1acac9d831..89e60b44a73 100755 --- a/src/test/core_log/TESTS.py +++ b/src/test/core_log_max/TESTS.py @@ -14,7 +14,7 @@ class CORE_LOG(t.BaseTest): test_type = t.Short def run(self, ctx): - ctx.exec('core_log', self.test_case) + ctx.exec('core_log_max', self.test_case) class TEST0(CORE_LOG): @@ -23,3 +23,7 @@ class TEST0(CORE_LOG): class TEST1(CORE_LOG): test_case = 'test_ERR_W_ERRNO' + + +class TEST2(CORE_LOG): + test_case = 'test_CORE_LOG' diff --git a/src/test/core_log/call_all.c b/src/test/core_log_max/call_all.c similarity index 85% rename from src/test/core_log/call_all.c rename to src/test/core_log_max/call_all.c index 313ed8354fc..e8978a97736 100644 --- a/src/test/core_log/call_all.c +++ b/src/test/core_log_max/call_all.c @@ -18,4 +18,9 @@ static size_t _zu = SIZE_MAX; static void *_p = (void *)UINT64_MAX; static uintmax_t _ju = UINTMAX_MAX; +/* + * Prevent abort() from CORE_LOG_FATAL() + */ +#define abort() do {; } while (0) + #include "call_all.c.generated" diff --git a/src/test/core_log/call_all.c.generated b/src/test/core_log_max/call_all.c.generated similarity index 100% rename from src/test/core_log/call_all.c.generated rename to src/test/core_log_max/call_all.c.generated diff --git a/src/test/core_log/call_all.h b/src/test/core_log_max/call_all.h similarity index 100% rename from src/test/core_log/call_all.h rename to src/test/core_log_max/call_all.h diff --git a/src/test/core_log/core_log.c b/src/test/core_log_max/core_log_max.c similarity index 68% rename from src/test/core_log/core_log.c rename to src/test/core_log_max/core_log_max.c index 1ee04f27f4c..2037479ad04 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log_max/core_log_max.c @@ -2,12 +2,13 @@ /* Copyright 2024, Intel Corporation */ /* - * core_log.c -- unit test for core_log + * core_log_max.c -- unit test to verify max size of log buffers */ #undef _GNU_SOURCE #include #include +#include #include "log_internal.h" #include "last_error_msg.h" @@ -109,6 +110,8 @@ FUNC_MOCK(core_log_to_last, void, int errnum, const char *file_name, int ret = vsnprintf(buf, BIG_BUF_SIZE, message_format, arg); UT_ASSERT(ret > 0); UT_ASSERTeq(ret, strlen(buf)); + if (errnum != NO_ERRNO) + ret += _CORE_LOG_MAX_ERRNO_MSG; if (ret > Max_TLS_message_len) { Max_TLS_message_len = ret; strncpy(The_longest_TLS_message, buf, BIG_BUF_SIZE); @@ -129,16 +132,69 @@ test_ERR_W_ERRNO(const struct test_case *tc, int argc, char *argv[]) call_all_CORE_LOG_ERROR_W_ERRNO_LAST(MAX_STRERROR_NUM); call_all_ERR_W_ERRNO(MAX_STRERROR_NUM); - UT_OUT("%s", The_longest_TLS_message); + UT_OUT("The_longest_TLS_message: %s", The_longest_TLS_message); UT_ASSERTeq(Total_TLS_message_num, TOTAL_TLS_MESSAGE_NUM_EXPECTED); UT_ASSERTeq(Max_TLS_message_len + 1, CORE_LAST_ERROR_MSG_MAXPRINT); return NO_ARGS_CONSUMED; } +#define TOTAL_MESSAGE_NUM_EXPECTED 212 +static int Max_message_len = 0; +static int Total_message_num = 0; +static char The_longest_message[BIG_BUF_SIZE]; + +FUNC_MOCK(core_log, void, enum core_log_level level, int errnum, + const char *file_name, int line_no, const char *function_name, + const char *message_format, ...) + FUNC_MOCK_RUN_DEFAULT { + char buf[BIG_BUF_SIZE] = ""; + va_list arg; + va_start(arg, message_format); + int ret = vsnprintf(buf, BIG_BUF_SIZE, message_format, arg); + UT_ASSERT(ret > 0); + UT_ASSERTeq(ret, strlen(buf)); + if (errnum != NO_ERRNO) + ret += _CORE_LOG_MAX_ERRNO_MSG; + + if (ret > Max_message_len) { + Max_message_len = ret; + strncpy(The_longest_message, buf, BIG_BUF_SIZE); + } + ++Total_message_num; + return; + } +FUNC_MOCK_END + +static int +test_CORE_LOG(const struct test_case *tc, int argc, char *argv[]) +{ + Max_message_len = 0; + Total_message_num = 0; + + call_all_CORE_LOG_WARNING(); + call_all_CORE_LOG_WARNING_W_ERRNO(MAX_STRERROR_NUM); + call_all_CORE_LOG_ERROR(); + call_all_CORE_LOG_ERROR_W_ERRNO(MAX_STRERROR_NUM); + call_all_CORE_LOG_FATAL(); + call_all_CORE_LOG_FATAL_W_ERRNO(MAX_STRERROR_NUM); + + UT_OUT("The_longest_message: %s", The_longest_message); +/* + * + 1 for '\0' and another + * + 1 as a means for detecting too-long log messages. + * Please see _CORE_LOG_MSG_MAXPRINT for details. + */ + UT_ASSERTeq(Max_message_len + 2, _CORE_LOG_MSG_MAXPRINT); + UT_ASSERTeq(Total_message_num, TOTAL_MESSAGE_NUM_EXPECTED); + + return NO_ARGS_CONSUMED; +} + static struct test_case test_cases[] = { TEST_CASE(test_CORE_LOG_MAX_ERRNO_MSG), TEST_CASE(test_ERR_W_ERRNO), + TEST_CASE(test_CORE_LOG), }; #define NTESTS ARRAY_SIZE(test_cases) @@ -146,7 +202,7 @@ static struct test_case test_cases[] = { int main(int argc, char *argv[]) { - START(argc, argv, "core_log"); + START(argc, argv, "core_log_max"); UT_COMPILE_ERROR_ON(sizeof(PATH) != 128); diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py index e8d06356457..251f7be5df7 100755 --- a/utils/call_stacks_analysis/log_call_all_generate.py +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -12,8 +12,8 @@ DEBUG = False PARSER_DEBUG = False -TOP = '../../' -OUTPUT_PATH = TOP + 'src/test/core_log/' +TOP = '../../src/' +OUTPUT_PATH = TOP + 'test/core_log_max/' OUTPUT_C = OUTPUT_PATH + 'call_all.c.generated' NOTICE = """/* @@ -68,13 +68,10 @@ def extract_append_code(file_name: str, start_line: int, code: str) -> str: return code IGNORE_FILES = [ - '.git/', - 'src/core/log_internal.h', - 'src/libpmem2/', - 'src/libpmempool/', - 'src/test/', - 'utils/', - 'CODING_STYLE.md', + 'core/log_internal.h', + 'libpmem2/', + 'libpmempool/', + 'test/', ] def file_should_be_ignored(file: str) -> bool: @@ -363,7 +360,7 @@ def generate_call(file, func: str, call: Dict) -> str: args = ', ' + ', '.join(call['args']) else: args = '' - file.write(f'\t// {call["file"]}:{call["line"]}\n') + file.write(f'\t// src/{call["file"]}:{call["line"]}\n') file.write(f'\t{func}("{call["format_string"]}"{args});\n') def generate_func_with_errno(func: str, calls: List[Dict]) -> None: From c314f24512f10b1b4abcfab7154eab7c2658f422 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 21 Feb 2024 13:05:34 +0100 Subject: [PATCH 096/182] common: restore original out_common() buffer size The buffer size affect only the debug build. Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/out.c b/src/core/out.c index 68fe54000d5..907391a387f 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -22,7 +22,7 @@ #include "log_internal.h" #include "last_error_msg.h" -#define MAXPRINT CORE_LAST_ERROR_MSG_MAXPRINT +#define MAXPRINT 8192 static const char *Log_prefix; static int Log_level; From 2362b7b11ecbe030899cf246bf7c8fc949a3099a Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 21 Feb 2024 11:24:39 -0500 Subject: [PATCH 097/182] common: add some Bandit exclusions Signed-off-by: Jan Michalski --- utils/call_stacks_analysis/log_call_all_generate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py index e8d06356457..71828cc5711 100755 --- a/utils/call_stacks_analysis/log_call_all_generate.py +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024, Intel Corporation -import subprocess +import subprocess # nosec B304 import json import re @@ -84,7 +84,16 @@ def file_should_be_ignored(file: str) -> bool: return False def extract_all_calls(func: str) -> List[Dict]: - returned_output = subprocess.check_output(['grep', '-Irn', func], cwd=TOP) + # XXX The grep call could be replaced by os.walk() call + for loops over + # all lines of all files + re.search(). + # In the meantime: + # B607: Starting a process with a partial executable path - ignored since it + # is normal way of accessing system utilities. + # B603: subprocess call - check for execution of untrusted input - there is + # no way around it. Theoretically, some bad actor could inject faulty grep + # in the head of the PATH which will lead to us parsing whatever they could + # benefit from. So, do not commit the produced code automatically. + returned_output = subprocess.check_output(['grep', '-Irn', func], cwd=TOP) # nosec B607, B603 string = returned_output.decode("utf-8") calls = [] total = 0 From 28364337d1f367365a9c2a062fdee7d191659bbc Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 22 Feb 2024 11:39:15 +0100 Subject: [PATCH 098/182] common: introduce logging level HARK CORE_LOG_HARK together with CORE_LOG_LEVEL_HARK are used for messages that should always be visible in the logging system like library version number, Valgrind compilation status and other basic library information. Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 4 ++-- src/core/log_default.c | 17 ++++---------- src/core/log_internal.h | 12 ++++------ src/core/out.c | 31 +++++++++++-------------- src/include/libpmemobj/log.h | 19 ++++++++------- src/libpmempool/replica.c | 10 ++++---- src/libpmempool/sync.c | 6 ++--- src/libpmempool/transform.c | 4 ++-- src/test/traces/custom_file0.log.match | 2 +- src/test/traces/redir_stderr2.log.match | 2 +- src/test/traces/redir_stderr3.log.match | 2 +- src/test/traces/redir_stderr4.log.match | 2 +- src/test/traces/redir_stderr5.log.match | 2 +- src/test/traces/traces.c | 2 +- src/test/unittest/ut_log.c | 4 +--- 15 files changed, 52 insertions(+), 67 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index a2d15803878..0d636b9ba90 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -36,7 +36,7 @@ #define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_LEVEL_WARNING #else #define CORE_LOG_THRESHOLD_DEFAULT CORE_LOG_LEVEL_WARNING -#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_DISABLED +#define CORE_LOG_THRESHOLD_AUX_DEFAULT CORE_LOG_LEVEL_HARK #endif /* @@ -148,7 +148,7 @@ core_log_set_threshold(enum core_log_threshold threshold, threshold != CORE_LOG_THRESHOLD_AUX) return EINVAL; - if (level < CORE_LOG_DISABLED || level > CORE_LOG_LEVEL_DEBUG) + if (level < CORE_LOG_LEVEL_HARK || level > CORE_LOG_LEVEL_DEBUG) return EINVAL; #ifdef ATOMIC_OPERATIONS_SUPPORTED diff --git a/src/core/log_default.c b/src/core/log_default.c index e19c394589c..8728c51f91e 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -22,7 +22,8 @@ #include "os.h" #include "util.h" -static const char log_level_names[6][9] = { +static const char log_level_names[CORE_LOG_LEVEL_MAX][9] = { + [CORE_LOG_LEVEL_HARK] = "*HARK* ", [CORE_LOG_LEVEL_FATAL] = "*FATAL* ", [CORE_LOG_LEVEL_ERROR] = "*ERROR* ", [CORE_LOG_LEVEL_WARNING] = "*WARN* ", @@ -32,6 +33,7 @@ static const char log_level_names[6][9] = { }; static const int log_level_syslog_severity[] = { + [CORE_LOG_LEVEL_HARK] = LOG_NOTICE, [CORE_LOG_LEVEL_FATAL] = LOG_CRIT, [CORE_LOG_LEVEL_ERROR] = LOG_ERR, [CORE_LOG_LEVEL_WARNING] = LOG_WARNING, @@ -105,15 +107,6 @@ core_log_default_function(void *context, enum core_log_level level, char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; const char file_info_error[] = "[file info error]: "; - bool is_always = false; - - if (CORE_LOG_DISABLED == level) - return; - - if (level == CORE_LOG_LEVEL_ALWAYS) { - is_always = true; - level = CORE_LOG_LEVEL_NOTICE; - } if (file_name) { /* extract base_file_name */ @@ -136,12 +129,12 @@ core_log_default_function(void *context, enum core_log_level level, log_level_names[level], file_info, message); /* - * Since the CORE_LOG_LEVEL_ALWAYS level messages convey pretty mundane + * Since the CORE_LOG_LEVEL_HARK level messages convey pretty mundane * information regarding the libraries versions etc. it has been decided * to print them out to the syslog and under no circumstances to stderr * to keep it clean for potentially more critical information. */ - if (is_always) { + if (level == CORE_LOG_LEVEL_HARK) { return; } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 24ef908ba9a..1720b4fc656 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -22,8 +22,8 @@ extern "C" { #endif enum core_log_level { - /* all messages will be suppressed */ - CORE_LOG_DISABLED = -1, + /* only basic library info */ + CORE_LOG_LEVEL_HARK, /* an error that causes the library to stop working immediately */ CORE_LOG_LEVEL_FATAL, /* an error that causes the library to stop working properly */ @@ -36,11 +36,9 @@ enum core_log_level { CORE_LOG_LEVEL_INFO, /* debug info e.g. write operation dump */ CORE_LOG_LEVEL_DEBUG, + CORE_LOG_LEVEL_MAX }; -/* Not meant to be used directly. */ -#define CORE_LOG_LEVEL_ALWAYS (CORE_LOG_DISABLED - 1) - enum core_log_threshold { /* * the main threshold level - the logging messages above this level @@ -184,8 +182,8 @@ void core_log_to_last(int errnum, const char *file_name, int line_no, abort(); \ } while (0) -#define CORE_LOG_ALWAYS(format, ...) \ - _CORE_LOG(CORE_LOG_LEVEL_ALWAYS, NO_ERRNO, format, ##__VA_ARGS__) +#define CORE_LOG_HARK(format, ...) \ + _CORE_LOG(CORE_LOG_LEVEL_HARK, NO_ERRNO, format, ##__VA_ARGS__) /* * 'With errno' macros' flavours. Append string describing the current errno diff --git a/src/core/out.c b/src/core/out.c index 907391a387f..e6922ab4f90 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -31,14 +31,15 @@ static unsigned Log_alignment; #ifdef DEBUG static const enum core_log_level level_to_core_log_level[5] = { - [0] = CORE_LOG_DISABLED, + [0] = CORE_LOG_LEVEL_HARK, [1] = CORE_LOG_LEVEL_ERROR, [2] = CORE_LOG_LEVEL_NOTICE, [3] = CORE_LOG_LEVEL_INFO, [4] = CORE_LOG_LEVEL_DEBUG, }; -static const int core_log_level_to_level[6] = { +static const int core_log_level_to_level[CORE_LOG_LEVEL_MAX] = { + [CORE_LOG_LEVEL_HARK] = 1, [CORE_LOG_LEVEL_FATAL] = 1, [CORE_LOG_LEVEL_ERROR] = 1, [CORE_LOG_LEVEL_WARNING] = 2, @@ -55,13 +56,7 @@ out_legacy(void *context, enum core_log_level core_level, const char *file_name, { SUPPRESS_UNUSED(context); - int level; - if (core_level == CORE_LOG_LEVEL_ALWAYS) { - level = 1; /* traditionally used for this kind of messages */ - } else { - level = core_log_level_to_level[core_level]; - } - + int level = core_log_level_to_level[core_level]; out_log(file_name, line_no, function_name, level, "%s", message); } #endif /* DEBUG */ @@ -161,15 +156,15 @@ out_init(const char *log_prefix, const char *log_level_var, #ifdef DEBUG static char namepath[PATH_MAX]; - CORE_LOG_ALWAYS("pid %d: program: %s", getpid(), + CORE_LOG_HARK("pid %d: program: %s", getpid(), util_getexecname(namepath, PATH_MAX)); #endif - CORE_LOG_ALWAYS("%s version %d.%d", log_prefix, major_version, + CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version, minor_version); static __attribute__((used)) const char *version_msg = "src version: " SRCVERSION; - CORE_LOG_ALWAYS("%s", version_msg); + CORE_LOG_HARK("%s", version_msg); #if VG_PMEMCHECK_ENABLED /* * Attribute "used" to prevent compiler from optimizing out the variable @@ -177,32 +172,32 @@ out_init(const char *log_prefix, const char *log_level_var, */ static __attribute__((used)) const char *pmemcheck_msg = "compiled with support for Valgrind pmemcheck"; - CORE_LOG_ALWAYS("%s", pmemcheck_msg); + CORE_LOG_HARK("%s", pmemcheck_msg); #endif /* VG_PMEMCHECK_ENABLED */ #if VG_HELGRIND_ENABLED static __attribute__((used)) const char *helgrind_msg = "compiled with support for Valgrind helgrind"; - CORE_LOG_ALWAYS("%s", helgrind_msg); + CORE_LOG_HARK("%s", helgrind_msg); #endif /* VG_HELGRIND_ENABLED */ #if VG_MEMCHECK_ENABLED static __attribute__((used)) const char *memcheck_msg = "compiled with support for Valgrind memcheck"; - CORE_LOG_ALWAYS("%s", memcheck_msg); + CORE_LOG_HARK("%s", memcheck_msg); #endif /* VG_MEMCHECK_ENABLED */ #if VG_DRD_ENABLED static __attribute__((used)) const char *drd_msg = "compiled with support for Valgrind drd"; - CORE_LOG_ALWAYS("%s", drd_msg); + CORE_LOG_HARK("%s", drd_msg); #endif /* VG_DRD_ENABLED */ #if SDS_ENABLED static __attribute__((used)) const char *shutdown_state_msg = "compiled with support for shutdown state"; - CORE_LOG_ALWAYS("%s", shutdown_state_msg); + CORE_LOG_HARK("%s", shutdown_state_msg); #endif #if NDCTL_ENABLED static __attribute__((used)) const char *ndctl_ge_63_msg = "compiled with libndctl 63+"; - CORE_LOG_ALWAYS("%s", ndctl_ge_63_msg); + CORE_LOG_HARK("%s", ndctl_ge_63_msg); #endif last_error_msg_init(); diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index 4a0be3966ce..64f1d7855e7 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -13,13 +13,13 @@ extern "C" { #endif /* - * Available log levels. Log levels (except for PMEMOBJ_LOG_DISABLED) are used - * in the logging API calls to indicate logging message severity. Log levels are - * also used to define thresholds for the logging. + * Available log levels. Log levels are used in the logging API calls + * to indicate logging message severity. Log levels are also used + * to define thresholds for the logging. */ enum pmemobj_log_level { - /* all messages will be suppressed */ - PMEMOBJ_LOG_DISABLED = -1, + /* only basic library info */ + PMEMOBJ_LOG_LEVEL_HARK, /* an error that causes the library to stop working immediately */ PMEMOBJ_LOG_LEVEL_FATAL, /* an error that causes the library to stop working properly */ @@ -57,7 +57,7 @@ enum pmemobj_log_threshold { * enum pmemobj_log_level level); * * enum log_level { - * PMEMOBJ_LOG_DISABLED, + * PMEMOBJ_LOG_LEVEL_HARK, * PMEMOBJ_LOG_LEVEL_FATAL, * PMEMOBJ_LOG_LEVEL_ERROR, * PMEMOBJ_LOG_LEVEL_WARNING, @@ -78,15 +78,16 @@ enum pmemobj_log_threshold { * Available thresholds are: * - PMEMOBJ_LOG_THRESHOLD - the main threshold used to filter out undesired * logging messages. Messages on a higher level than the primary threshold - * level are ignored. PMEMOBJ_LOG_DISABLED shall be used to suppress logging. + * level are ignored. PMEMOBJ_LOG_LEVEL_HARK shall be used to suppress + * logging. * The default value is PMEMOBJ_LOG_WARNING. * - PMEMOBJ_LOG_THRESHOLD_AUX - the auxiliary threshold intended for use inside * the logging function (please see log_get_threshold(3)). The logging * function may or may not take this threshold into consideration. The default - * value is PMEMOBJ_LOG_DISABLED. + * value is PMEMOBJ_LOG_LEVEL_HARK. * * Available threshold levels are defined by enum log_level: - * - PMEMOBJ_LOG_DISABLED - all messages will be suppressed + * - PMEMOBJ_LOG_LEVEL_HARK - only basic library info * - PMEMOBJ_LOG_LEVEL_FATAL - an error that causes the library to stop working * immediately * - PMEMOBJ_LOG_LEVEL_ERROR - an error that causes the library to stop working diff --git a/src/libpmempool/replica.c b/src/libpmempool/replica.c index 1cfb00473cd..1a90bb6cbbf 100644 --- a/src/libpmempool/replica.c +++ b/src/libpmempool/replica.c @@ -806,7 +806,7 @@ replica_part_badblocks_recovery_file_read(struct part_health_status *part_hs) os_fclose(recovery_file); - CORE_LOG_ALWAYS("bad blocks read from the recovery file -- '%s'", path); + CORE_LOG_HARK("bad blocks read from the recovery file -- '%s'", path); return 0; @@ -928,7 +928,7 @@ replica_badblocks_recovery_files_read(struct pool_set *set, continue; } - CORE_LOG_ALWAYS( + CORE_LOG_HARK( "reading bad blocks from the recovery file -- '%s'", part_hs->recovery_file_name); @@ -1280,7 +1280,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, */ if (!dry_run) { - CORE_LOG_ALWAYS( + CORE_LOG_HARK( "removing all bad block recovery files..."); ret = replica_remove_all_recovery_files(set_hs); if (ret < 0) { @@ -1289,7 +1289,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, return -1; } } else { - CORE_LOG_ALWAYS( + CORE_LOG_HARK( "all bad block recovery files would be removed"); } @@ -1360,7 +1360,7 @@ replica_badblocks_check_or_clear(struct pool_set *set, if (dry_run) { /* dry-run - do nothing */ - CORE_LOG_ALWAYS("bad blocks would be cleared"); + CORE_LOG_HARK("bad blocks would be cleared"); return 0; } diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index ad1bedd2bb8..6379d13e26d 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -819,7 +819,7 @@ sync_badblocks_data(struct pool_set *set, struct poolset_health_status *set_hs) sync_mark_replica_no_badblocks(r, set_hs); } - CORE_LOG_ALWAYS("all bad blocks have been fixed"); + CORE_LOG_HARK("all bad blocks have been fixed"); if (replica_remove_all_recovery_files(set_hs)) { CORE_LOG_ERROR("removing bad block recovery files failed"); @@ -1326,7 +1326,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* check if poolset is broken; if not, nothing to do */ if (replica_is_poolset_healthy(set_hs)) { - CORE_LOG_ALWAYS("poolset is healthy"); + CORE_LOG_HARK("poolset is healthy"); goto out; } } else { @@ -1348,7 +1348,7 @@ replica_sync(struct pool_set *set, struct poolset_health_status *s_hs, /* in dry-run mode we can stop here */ if (is_dry_run(flags)) { - CORE_LOG_ALWAYS("Sync in dry-run mode finished successfully"); + CORE_LOG_HARK("Sync in dry-run mode finished successfully"); goto out; } diff --git a/src/libpmempool/transform.c b/src/libpmempool/transform.c index b0785b02c7f..be9f9fad81d 100644 --- a/src/libpmempool/transform.c +++ b/src/libpmempool/transform.c @@ -920,7 +920,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - CORE_LOG_ALWAYS( + CORE_LOG_HARK( "falling back to the input poolset succeeded"); } ret = -1; @@ -938,7 +938,7 @@ replica_transform(struct pool_set *set_in, struct pool_set *set_out, CORE_LOG_ERROR( "falling back to the input poolset failed"); } else { - CORE_LOG_ALWAYS( + CORE_LOG_HARK( "falling back to the input poolset succeeded"); } ret = -1; diff --git a/src/test/traces/custom_file0.log.match b/src/test/traces/custom_file0.log.match index a3733783de9..8247d4a062f 100644 --- a/src/test/traces/custom_file0.log.match +++ b/src/test/traces/custom_file0.log.match @@ -8,7 +8,7 @@ $(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) compiled with support for shutdown state $(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <3> $(nW) $(nW) -$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR $(nW) <2> $(nW) $(nW) Log level WARNING $(nW) <3> $(nW) $(nW) Log level INFO diff --git a/src/test/traces/redir_stderr2.log.match b/src/test/traces/redir_stderr2.log.match index 79271cadab2..e0792eb7238 100644 --- a/src/test/traces/redir_stderr2.log.match +++ b/src/test/traces/redir_stderr2.log.match @@ -7,5 +7,5 @@ $(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck $(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) compiled with support for shutdown state $(nW) <1> $(nW) $(nW) compiled with libndctl 63+ -$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/traces/redir_stderr3.log.match b/src/test/traces/redir_stderr3.log.match index dfee35a04d7..1522078c9fe 100644 --- a/src/test/traces/redir_stderr3.log.match +++ b/src/test/traces/redir_stderr3.log.match @@ -7,6 +7,6 @@ $(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck $(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) compiled with support for shutdown state $(nW) <1> $(nW) $(nW) compiled with libndctl 63+ -$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR $(nW) <2> $(nW) $(nW) Log level WARNING diff --git a/src/test/traces/redir_stderr4.log.match b/src/test/traces/redir_stderr4.log.match index 15cb460f06a..be7f3829c7b 100644 --- a/src/test/traces/redir_stderr4.log.match +++ b/src/test/traces/redir_stderr4.log.match @@ -8,7 +8,7 @@ $(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) compiled with support for shutdown state $(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <3> $(nW) $(nW) -$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR $(nW) <2> $(nW) $(nW) Log level WARNING $(nW) <3> $(nW) $(nW) Log level INFO diff --git a/src/test/traces/redir_stderr5.log.match b/src/test/traces/redir_stderr5.log.match index a3733783de9..8247d4a062f 100644 --- a/src/test/traces/redir_stderr5.log.match +++ b/src/test/traces/redir_stderr5.log.match @@ -8,7 +8,7 @@ $(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) compiled with support for shutdown state $(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <3> $(nW) $(nW) -$(nW) <1> $(nW) $(nW) Log level ALWAYS +$(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR $(nW) <2> $(nW) $(nW) Log level WARNING $(nW) <3> $(nW) $(nW) Log level INFO diff --git a/src/test/traces/traces.c b/src/test/traces/traces.c index 05e08499026..c2286260e2d 100644 --- a/src/test/traces/traces.c +++ b/src/test/traces/traces.c @@ -24,7 +24,7 @@ main(int argc, char *argv[]) /* Execute test */ common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); - CORE_LOG_ALWAYS("Log level ALWAYS"); + CORE_LOG_HARK("Log level HARK"); CORE_LOG_ERROR("Log level ERROR"); CORE_LOG_WARNING("Log level WARNING"); LOG(3, "Log level INFO"); diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c index bd6fa87ba37..a3773e00cde 100644 --- a/src/test/unittest/ut_log.c +++ b/src/test/unittest/ut_log.c @@ -10,6 +10,7 @@ #include "out.h" static const int core_log_level_to_out_level[] = { + [CORE_LOG_LEVEL_HARK] = 1, [CORE_LOG_LEVEL_FATAL] = 1, [CORE_LOG_LEVEL_ERROR] = 1, [CORE_LOG_LEVEL_WARNING] = 2, @@ -22,9 +23,6 @@ void ut_log_function(void *context, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message) { - if (level == CORE_LOG_LEVEL_ALWAYS) - level = CORE_LOG_LEVEL_ERROR; - out_log(file_name, line_no, function_name, core_log_level_to_out_level[(int)level], "%s", message); } From f7442b1cc915d1347cd408c5768a50686a0da4ec Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 22 Feb 2024 17:37:16 +0100 Subject: [PATCH 099/182] common: print basic lib info when new logging function is set Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 17 +++++++++++++++-- src/core/out.c | 17 +++++++++-------- src/test/arch_flags/log0.log.match | 21 ++++++++++++--------- src/test/out_err/traces0.log.match | 3 +++ src/test/traces/custom_file0.log.match | 3 +++ src/test/traces/redir_stderr2.log.match | 3 +++ src/test/traces/redir_stderr3.log.match | 3 +++ src/test/traces/redir_stderr4.log.match | 3 +++ src/test/traces/redir_stderr5.log.match | 3 +++ src/test/util_poolset/grep0.log.match | 3 +++ src/test/util_poolset/grep1.log.match | 3 +++ src/test/util_poolset/grep2.log.match | 3 +++ src/test/util_poolset/grep3.log.match | 3 +++ src/test/util_poolset/grep4.log.match | 3 +++ src/test/util_poolset/grep5.log.match | 3 +++ src/test/util_poolset/grep6.log.match | 3 +++ src/test/util_poolset/grep7.log.match | 3 +++ 17 files changed, 78 insertions(+), 19 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 0d636b9ba90..d6071476d35 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -103,6 +103,17 @@ core_log_fini() core_log_default_fini(); } +static void +core_log_lib_info(void) +{ + CORE_LOG_HARK("src version: " SRCVERSION); +#if SDS_ENABLED + CORE_LOG_HARK("compiled with support for shutdown state"); +#endif +#if NDCTL_ENABLED + CORE_LOG_HARK("compiled with libndctl 63+"); +#endif +} /* * core_log_set_function -- set the log function pointer either to * a user-provided function pointer or to the default logging function. @@ -127,10 +138,12 @@ core_log_set_function(core_log_function *log_function, void *context) core_log_function_old, (uintptr_t)log_function)) return EAGAIN; if (__sync_bool_compare_and_swap(&Core_log_function_context, - context_old, context)) + context_old, context)) { + core_log_lib_info(); return 0; + } - __sync_bool_compare_and_swap(&Core_log_function, + (void) __sync_bool_compare_and_swap(&Core_log_function, (uintptr_t)log_function, core_log_function_old); return EAGAIN; diff --git a/src/core/out.c b/src/core/out.c index e6922ab4f90..54003a5382e 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -133,13 +133,6 @@ out_init(const char *log_prefix, const char *log_level_var, abort(); } } - - if (log_level != NULL || log_file != NULL) { - ret = core_log_set_function(out_legacy, NULL); - if (ret) { - CORE_LOG_FATAL("Cannot set legacy log function"); - } - } #endif /* DEBUG */ char *log_alignment = os_getenv("PMDK_LOG_ALIGN"); @@ -154,11 +147,19 @@ out_init(const char *log_prefix, const char *log_level_var, else setlinebuf(Out_fp); +#ifdef DEBUG + if (log_level != NULL || log_file != NULL) { + ret = core_log_set_function(out_legacy, NULL); + if (ret) { + CORE_LOG_FATAL("Cannot set legacy log function"); + } + } +#endif /* DEBUG */ #ifdef DEBUG static char namepath[PATH_MAX]; CORE_LOG_HARK("pid %d: program: %s", getpid(), util_getexecname(namepath, PATH_MAX)); -#endif +#endif /* DEBUG */ CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version, minor_version); diff --git a/src/test/arch_flags/log0.log.match b/src/test/arch_flags/log0.log.match index 6328efe7c15..6335703f5f0 100644 --- a/src/test/arch_flags/log0.log.match +++ b/src/test/arch_flags/log0.log.match @@ -1,12 +1,15 @@ -: <1> [$(nW) out_init]$(W)pid $(nW): program: $(nW) -: <1> [$(nW) out_init]$(W)arch_flags version 0.0 -: <1> [$(nW) out_init]$(W)src version: $(nW) -$(OPT): <1> [$(nW) out_init]$(W)compiled with support for Valgrind pmemcheck -$(OPT): <1> [$(nW) out_init]$(W)compiled with support for Valgrind helgrind -$(OPT): <1> [$(nW) out_init]$(W)compiled with support for Valgrind memcheck -$(OPT): <1> [$(nW) out_init]$(W)compiled with support for Valgrind drd -$(OPT): <1> [$(nW) out_init]$(W)compiled with support for shutdown state -$(OPT): <1> [$(nW) out_init]$(W)compiled with libndctl 63+ +: <1> [$(*)]$(W)src version: $(nW) +$(OPT): <1> [$(*)]$(W)compiled with support for shutdown state +$(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ +: <1> [$(*)]$(W)pid $(nW): program: $(nW) +: <1> [$(*)]$(W)arch_flags version 0.0 +: <1> [$(*)]$(W)src version: $(nW) +$(OPT): <1> [$(*)]$(W)compiled with support for Valgrind pmemcheck +$(OPT): <1> [$(*)]$(W)compiled with support for Valgrind helgrind +$(OPT): <1> [$(*)]$(W)compiled with support for Valgrind memcheck +$(OPT): <1> [$(*)]$(W)compiled with support for Valgrind drd +$(OPT): <1> [$(*)]$(W)compiled with support for shutdown state +$(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ : <3> [$(nW) util_mmap_init] : <1> [$(nW) util_check_arch_flags]$(W)invalid machine value : <1> [$(nW) util_check_arch_flags]$(W)invalid machine_class value diff --git a/src/test/out_err/traces0.log.match b/src/test/out_err/traces0.log.match index 0e34ec94875..f4a016acc1d 100644 --- a/src/test/out_err/traces0.log.match +++ b/src/test/out_err/traces0.log.match @@ -1,3 +1,6 @@ +: <1> [$(*)]$(W)src version: $(nW) +$(OPT): <1> [$(*)]$(W)compiled with support for shutdown state +$(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ : <1> [out.c:$(N) out_init]$(W)pid $(N): program: $(nW) : <1> [out.c:$(N) out_init]$(W)trace version 1.0 : <1> [out.c:$(N) out_init]$(W)src version: $(nW) diff --git a/src/test/traces/custom_file0.log.match b/src/test/traces/custom_file0.log.match index 8247d4a062f..f5fc05bbbb5 100644 --- a/src/test/traces/custom_file0.log.match +++ b/src/test/traces/custom_file0.log.match @@ -1,3 +1,6 @@ +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 $(nW) <1> $(nW) $(nW) src version: $(nW) diff --git a/src/test/traces/redir_stderr2.log.match b/src/test/traces/redir_stderr2.log.match index e0792eb7238..1b1da1d81dc 100644 --- a/src/test/traces/redir_stderr2.log.match +++ b/src/test/traces/redir_stderr2.log.match @@ -1,3 +1,6 @@ +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 $(nW) <1> $(nW) $(nW) src version: $(nW) diff --git a/src/test/traces/redir_stderr3.log.match b/src/test/traces/redir_stderr3.log.match index 1522078c9fe..c71f0ff5d27 100644 --- a/src/test/traces/redir_stderr3.log.match +++ b/src/test/traces/redir_stderr3.log.match @@ -1,3 +1,6 @@ +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 $(nW) <1> $(nW) $(nW) src version: $(nW) diff --git a/src/test/traces/redir_stderr4.log.match b/src/test/traces/redir_stderr4.log.match index be7f3829c7b..48b1f776812 100644 --- a/src/test/traces/redir_stderr4.log.match +++ b/src/test/traces/redir_stderr4.log.match @@ -1,3 +1,6 @@ +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 $(nW) <1> $(nW) $(nW) src version: $(nW) diff --git a/src/test/traces/redir_stderr5.log.match b/src/test/traces/redir_stderr5.log.match index 8247d4a062f..f5fc05bbbb5 100644 --- a/src/test/traces/redir_stderr5.log.match +++ b/src/test/traces/redir_stderr5.log.match @@ -1,3 +1,6 @@ +$(nW) <1> $(nW) $(nW) src version: $(nW) +$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 $(nW) <1> $(nW) $(nW) src version: $(nW) diff --git a/src/test/util_poolset/grep0.log.match b/src/test/util_poolset/grep0.log.match index 6790b813cff..bfdcdb162bb 100644 --- a/src/test/util_poolset/grep0.log.match +++ b/src/test/util_poolset/grep0.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep1.log.match b/src/test/util_poolset/grep1.log.match index 7dcf42462b5..739d49f8239 100644 --- a/src/test/util_poolset/grep1.log.match +++ b/src/test/util_poolset/grep1.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep2.log.match b/src/test/util_poolset/grep2.log.match index 6d25e56c110..4d9565f6890 100644 --- a/src/test/util_poolset/grep2.log.match +++ b/src/test/util_poolset/grep2.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep3.log.match b/src/test/util_poolset/grep3.log.match index 96b81b9b3b7..e65f9966f51 100644 --- a/src/test/util_poolset/grep3.log.match +++ b/src/test/util_poolset/grep3.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep4.log.match b/src/test/util_poolset/grep4.log.match index 96b81b9b3b7..e65f9966f51 100644 --- a/src/test/util_poolset/grep4.log.match +++ b/src/test/util_poolset/grep4.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep5.log.match b/src/test/util_poolset/grep5.log.match index 96b81b9b3b7..e65f9966f51 100644 --- a/src/test/util_poolset/grep5.log.match +++ b/src/test/util_poolset/grep5.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep6.log.match b/src/test/util_poolset/grep6.log.match index 536bfdc581b..cacd9c26dae 100644 --- a/src/test/util_poolset/grep6.log.match +++ b/src/test/util_poolset/grep6.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 src version: $(nW) diff --git a/src/test/util_poolset/grep7.log.match b/src/test/util_poolset/grep7.log.match index 712b6a897dd..b89d04ba9fb 100644 --- a/src/test/util_poolset/grep7.log.match +++ b/src/test/util_poolset/grep7.log.match @@ -1,3 +1,6 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 src version: $(nW) From 52912343e3529903e9cc1545c11660186aafadf1 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 06:46:21 +0100 Subject: [PATCH 100/182] common: start PMem tests at 6:00 pm to get results early next day PMem tests required about 14h30m for execution. With execution started at noon results are practically available at the end of working day. Signed-off-by: Tomasz Gromadzki --- .github/workflows/pmem_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pmem_tests.yml b/.github/workflows/pmem_tests.yml index 6fb36e89d0f..a2857e91b19 100644 --- a/.github/workflows/pmem_tests.yml +++ b/.github/workflows/pmem_tests.yml @@ -6,8 +6,8 @@ name: PMEM tests on: workflow_dispatch: schedule: - # run this job at 00:00 UTC every day - - cron: '0 0 * * *' + # run this job at 18:00 UTC every day + - cron: '0 18 * * *' jobs: # Test the default build with the basic test suite. From 1916db29dca09fc111a63cead0cdd8d0c94a36bf Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 09:17:02 +0100 Subject: [PATCH 101/182] common: initialize Out_fp before any other log operations Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 67 +++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index 54003a5382e..12b4e4225e7 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -83,32 +83,15 @@ out_init(const char *log_prefix, const char *log_level_var, Log_prefix = log_prefix; -#ifdef DEBUG - char *log_level; - char *log_file; - int log_level_cropped = 0; - int ret; - - if ((log_level = os_getenv(log_level_var)) != NULL) { - Log_level = atoi(log_level); - if (Log_level < 0) { - Log_level = 0; - } - if (Log_level <= OUT_MAX_LEVEL) { - log_level_cropped = Log_level; - } else { - log_level_cropped = OUT_MAX_LEVEL; - } - } - - if (log_level != NULL) { - ret = core_log_set_threshold(CORE_LOG_THRESHOLD, - level_to_core_log_level[log_level_cropped]); - if (ret) { - CORE_LOG_FATAL("Cannot set log threshold"); - } + char *log_alignment = os_getenv("PMDK_LOG_ALIGN"); + if (log_alignment) { + int align = atoi(log_alignment); + if (align > 0) + Log_alignment = (unsigned)align; } +#ifdef DEBUG + char *log_file; if ((log_file = os_getenv(log_file_var)) != NULL && log_file[0] != '\0') { @@ -135,19 +118,36 @@ out_init(const char *log_prefix, const char *log_level_var, } #endif /* DEBUG */ - char *log_alignment = os_getenv("PMDK_LOG_ALIGN"); - if (log_alignment) { - int align = atoi(log_alignment); - if (align > 0) - Log_alignment = (unsigned)align; - } - if (Out_fp == NULL) Out_fp = stderr; else setlinebuf(Out_fp); #ifdef DEBUG + char *log_level; + int log_level_cropped = 0; + int ret; + + if ((log_level = os_getenv(log_level_var)) != NULL) { + Log_level = atoi(log_level); + if (Log_level < 0) { + Log_level = 0; + } + if (Log_level <= OUT_MAX_LEVEL) { + log_level_cropped = Log_level; + } else { + log_level_cropped = OUT_MAX_LEVEL; + } + } + + if (log_level != NULL) { + ret = core_log_set_threshold(CORE_LOG_THRESHOLD, + level_to_core_log_level[log_level_cropped]); + if (ret) { + CORE_LOG_FATAL("Cannot set log threshold"); + } + } + if (log_level != NULL || log_file != NULL) { ret = core_log_set_function(out_legacy, NULL); if (ret) { @@ -155,11 +155,16 @@ out_init(const char *log_prefix, const char *log_level_var, } } #endif /* DEBUG */ + +/* + * Print library info + */ #ifdef DEBUG static char namepath[PATH_MAX]; CORE_LOG_HARK("pid %d: program: %s", getpid(), util_getexecname(namepath, PATH_MAX)); #endif /* DEBUG */ + CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version, minor_version); From a609ece4fdda0185284a98ee4b9b786375cabe17 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 09:27:12 +0100 Subject: [PATCH 102/182] common: remove redundant log messages Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 13 ------------- src/test/arch_flags/log0.log.match | 2 -- src/test/out_err/traces0.log.match | 3 --- src/test/traces/custom_file0.log.match | 15 ++++++--------- src/test/traces/redir_stderr2.log.match | 15 ++++++--------- src/test/traces/redir_stderr3.log.match | 15 ++++++--------- src/test/traces/redir_stderr4.log.match | 15 ++++++--------- src/test/traces/redir_stderr5.log.match | 15 ++++++--------- src/test/util_poolset/grep0.log.match | 3 --- src/test/util_poolset/grep1.log.match | 3 --- src/test/util_poolset/grep10.log.match | 6 +++--- src/test/util_poolset/grep2.log.match | 3 --- src/test/util_poolset/grep3.log.match | 3 --- src/test/util_poolset/grep4.log.match | 3 --- src/test/util_poolset/grep5.log.match | 3 --- src/test/util_poolset/grep6.log.match | 3 --- 16 files changed, 33 insertions(+), 87 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index 12b4e4225e7..d1b9785c9e2 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -168,9 +168,6 @@ out_init(const char *log_prefix, const char *log_level_var, CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version, minor_version); - static __attribute__((used)) const char *version_msg = - "src version: " SRCVERSION; - CORE_LOG_HARK("%s", version_msg); #if VG_PMEMCHECK_ENABLED /* * Attribute "used" to prevent compiler from optimizing out the variable @@ -195,16 +192,6 @@ out_init(const char *log_prefix, const char *log_level_var, "compiled with support for Valgrind drd"; CORE_LOG_HARK("%s", drd_msg); #endif /* VG_DRD_ENABLED */ -#if SDS_ENABLED - static __attribute__((used)) const char *shutdown_state_msg = - "compiled with support for shutdown state"; - CORE_LOG_HARK("%s", shutdown_state_msg); -#endif -#if NDCTL_ENABLED - static __attribute__((used)) const char *ndctl_ge_63_msg = - "compiled with libndctl 63+"; - CORE_LOG_HARK("%s", ndctl_ge_63_msg); -#endif last_error_msg_init(); } diff --git a/src/test/arch_flags/log0.log.match b/src/test/arch_flags/log0.log.match index 6335703f5f0..bb87a7f820b 100644 --- a/src/test/arch_flags/log0.log.match +++ b/src/test/arch_flags/log0.log.match @@ -8,8 +8,6 @@ $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind pmemcheck $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind helgrind $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind memcheck $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind drd -$(OPT): <1> [$(*)]$(W)compiled with support for shutdown state -$(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ : <3> [$(nW) util_mmap_init] : <1> [$(nW) util_check_arch_flags]$(W)invalid machine value : <1> [$(nW) util_check_arch_flags]$(W)invalid machine_class value diff --git a/src/test/out_err/traces0.log.match b/src/test/out_err/traces0.log.match index f4a016acc1d..b9b09809d4f 100644 --- a/src/test/out_err/traces0.log.match +++ b/src/test/out_err/traces0.log.match @@ -3,13 +3,10 @@ $(OPT): <1> [$(*)]$(W)compiled with support for shutdown state $(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ : <1> [out.c:$(N) out_init]$(W)pid $(N): program: $(nW) : <1> [out.c:$(N) out_init]$(W)trace version 1.0 -: <1> [out.c:$(N) out_init]$(W)src version: $(nW) $(OPT): <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind pmemcheck $(OPT): <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind helgrind $(OPT): <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind memcheck $(OPT): <1> [out.c:$(N) out_init]$(W)compiled with support for Valgrind drd -$(OPT): <1> [out.c:$(N) out_init]$(W)compiled with support for shutdown state -$(OPT): <1> [out.c:$(N) out_init]$(W)compiled with libndctl 63+ : <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #1 $(OPT): <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: Success $(OPX): <1> [out_err$(nW).c:$(N) $(nW)main]$(W)ERR #2: No error: 0 diff --git a/src/test/traces/custom_file0.log.match b/src/test/traces/custom_file0.log.match index f5fc05bbbb5..e04efd9f8c0 100644 --- a/src/test/traces/custom_file0.log.match +++ b/src/test/traces/custom_file0.log.match @@ -1,15 +1,12 @@ $(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 -$(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <3> $(nW) $(nW) $(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/traces/redir_stderr2.log.match b/src/test/traces/redir_stderr2.log.match index 1b1da1d81dc..1de6b64ad75 100644 --- a/src/test/traces/redir_stderr2.log.match +++ b/src/test/traces/redir_stderr2.log.match @@ -1,14 +1,11 @@ $(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 -$(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/traces/redir_stderr3.log.match b/src/test/traces/redir_stderr3.log.match index c71f0ff5d27..a2d55384538 100644 --- a/src/test/traces/redir_stderr3.log.match +++ b/src/test/traces/redir_stderr3.log.match @@ -1,15 +1,12 @@ $(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 -$(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR $(nW) <2> $(nW) $(nW) Log level WARNING diff --git a/src/test/traces/redir_stderr4.log.match b/src/test/traces/redir_stderr4.log.match index 48b1f776812..140b9d37046 100644 --- a/src/test/traces/redir_stderr4.log.match +++ b/src/test/traces/redir_stderr4.log.match @@ -1,15 +1,12 @@ $(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 -$(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <3> $(nW) $(nW) $(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/traces/redir_stderr5.log.match b/src/test/traces/redir_stderr5.log.match index f5fc05bbbb5..e04efd9f8c0 100644 --- a/src/test/traces/redir_stderr5.log.match +++ b/src/test/traces/redir_stderr5.log.match @@ -1,15 +1,12 @@ $(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for shutdown state +$(OPT)$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ $(nW) <1> $(nW) $(nW) pid $(N): program: $(nW) $(nW) <1> $(nW) $(nW) ut version 1.0 -$(nW) <1> $(nW) $(nW) src version: $(nW) -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck -$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd -$(nW) <1> $(nW) $(nW) compiled with support for shutdown state -$(nW) <1> $(nW) $(nW) compiled with libndctl 63+ +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind pmemcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind helgrind +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind memcheck +$(OPT)$(nW) <1> $(nW) $(nW) compiled with support for Valgrind drd $(nW) <3> $(nW) $(nW) $(nW) <1> $(nW) $(nW) Log level HARK $(nW) <1> $(nW) $(nW) Log level ERROR diff --git a/src/test/util_poolset/grep0.log.match b/src/test/util_poolset/grep0.log.match index bfdcdb162bb..441bee9364a 100644 --- a/src/test/util_poolset/grep0.log.match +++ b/src/test/util_poolset/grep0.log.match @@ -3,13 +3,10 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ open "$(nW)/testset0": No such file or directory cannot create pool set -- '$(nW)/testset0' $(OPT)Cannot read device usc - ndctl is not available diff --git a/src/test/util_poolset/grep1.log.match b/src/test/util_poolset/grep1.log.match index 739d49f8239..370ed3dee53 100644 --- a/src/test/util_poolset/grep1.log.match +++ b/src/test/util_poolset/grep1.log.match @@ -3,13 +3,10 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ open "$(nW)/testset0": No such file or directory cannot open pool set -- '$(nW)/testset0' invalid major version (0) diff --git a/src/test/util_poolset/grep10.log.match b/src/test/util_poolset/grep10.log.match index f7d99cc936f..091561cbf37 100644 --- a/src/test/util_poolset/grep10.log.match +++ b/src/test/util_poolset/grep10.log.match @@ -1,12 +1,12 @@ +src version: $(nW) +$(OPT)compiled with support for shutdown state +$(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ invalid checksum of pool header wrong pool type: "ERRORXX" pool version 99 (library expects 1) diff --git a/src/test/util_poolset/grep2.log.match b/src/test/util_poolset/grep2.log.match index 4d9565f6890..63958613a09 100644 --- a/src/test/util_poolset/grep2.log.match +++ b/src/test/util_poolset/grep2.log.match @@ -3,13 +3,10 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)/util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ invalid checksum of pool header header check failed - part #1 wrong pool type: "ERRORXX" diff --git a/src/test/util_poolset/grep3.log.match b/src/test/util_poolset/grep3.log.match index e65f9966f51..4849bc225db 100644 --- a/src/test/util_poolset/grep3.log.match +++ b/src/test/util_poolset/grep3.log.match @@ -3,10 +3,7 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ diff --git a/src/test/util_poolset/grep4.log.match b/src/test/util_poolset/grep4.log.match index e65f9966f51..4849bc225db 100644 --- a/src/test/util_poolset/grep4.log.match +++ b/src/test/util_poolset/grep4.log.match @@ -3,10 +3,7 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ diff --git a/src/test/util_poolset/grep5.log.match b/src/test/util_poolset/grep5.log.match index e65f9966f51..4849bc225db 100644 --- a/src/test/util_poolset/grep5.log.match +++ b/src/test/util_poolset/grep5.log.match @@ -3,10 +3,7 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ diff --git a/src/test/util_poolset/grep6.log.match b/src/test/util_poolset/grep6.log.match index cacd9c26dae..dd61ea30a0d 100644 --- a/src/test/util_poolset/grep6.log.match +++ b/src/test/util_poolset/grep6.log.match @@ -3,13 +3,10 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 -src version: $(nW) $(OPT)compiled with support for Valgrind pmemcheck $(OPT)compiled with support for Valgrind helgrind $(OPT)compiled with support for Valgrind memcheck $(OPT)compiled with support for Valgrind drd -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ cannot mix directories and files in a set cannot create pool set -- '$(nW)/testset2' cannot mix directories and files in a set From 15de5c060d01fd35df5bffc0d536f982b37235a6 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 10:38:44 +0100 Subject: [PATCH 103/182] common: update generated file to reflect latest changes Signed-off-by: Tomasz Gromadzki --- src/test/core_log_max/call_all.c.generated | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/core_log_max/call_all.c.generated b/src/test/core_log_max/call_all.c.generated index 15552125ed5..f44cbd7e251 100644 --- a/src/test/core_log_max/call_all.c.generated +++ b/src/test/core_log_max/call_all.c.generated @@ -687,9 +687,9 @@ call_all_CORE_LOG_FATAL(void) CORE_LOG_FATAL("os_thread_key_create"); // src/core/last_error_msg.c:78 CORE_LOG_FATAL("os_tls_set"); - // src/core/out.c:113 + // src/core/out.c:147 CORE_LOG_FATAL("Cannot set log threshold"); - // src/core/out.c:145 + // src/core/out.c:154 CORE_LOG_FATAL("Cannot set legacy log function"); // src/core/sys_util.h:108 CORE_LOG_FATAL("os_rwlock_init"); @@ -1000,7 +1000,7 @@ call_all_ERR_W_ERRNO(int errnum) // src/common/vecq.h:68 ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/core/out.c:126 + // src/core/out.c:104 ERR_W_ERRNO("snprintf"); UT_ASSERTeq(errno, errnum); // src/core/ravl.c:167 From 9ce89e430cb482dc7811f1fe8d130013cbf567ea Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 12:58:43 +0100 Subject: [PATCH 104/182] common: run coverage scan in paralel w/ Ubuntu build To get all results in a shorter time Signed-off-by: Tomasz Gromadzki --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a5fc9edd42..3460bcc149a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,6 +70,6 @@ jobs: name: Ubuntu coverage_scan: - needs: call-ubuntu + needs: [src_checkers, basic_build] uses: ./.github/workflows/scan_coverage.yml name: Coverage From 4fd9deb3f12ef2d012bd96f4b6f7f28fcee87b6c Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 26 Feb 2024 08:32:21 +0100 Subject: [PATCH 105/182] common: missing header file stdarg.h added The file originally has been included in out.h, and is no longer there after new core_log impelmentation. In majority of builds it was included via valgrind.h, but it is not valid for builds with `make EXTRA_CFLAGS=-DVG_MEMCHECK_ENABLED=0` Signed-off-by: Tomasz Gromadzki --- src/libpmemobj/tx.c | 1 + src/libpmempool/check_util.c | 1 + src/libpmempool/feature.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index 13b6d77901f..bdb9f18b075 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -7,6 +7,7 @@ #include #include +#include #include "queue.h" #include "ravl.h" diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index d1afc6c44fd..9688194a0f7 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -7,6 +7,7 @@ #include #include +#include #include "out.h" #include "libpmempool.h" diff --git a/src/libpmempool/feature.c b/src/libpmempool/feature.c index d9698dbe787..3716b0cb262 100644 --- a/src/libpmempool/feature.c +++ b/src/libpmempool/feature.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "libpmempool.h" #include "util_pmem.h" From 7ff96168a25d4b4efd6430929a6bb4baea2d0fa2 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 26 Feb 2024 16:11:04 +0100 Subject: [PATCH 106/182] common: inrease total stack usage limit causes by new logging function Signed-off-by: Tomasz Gromadzki --- .github/workflows/scan_stack_usage.yml | 6 +++--- utils/call_stacks_analysis/README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scan_stack_usage.yml b/.github/workflows/scan_stack_usage.yml index 93f36f59608..09d882fc3ed 100644 --- a/.github/workflows/scan_stack_usage.yml +++ b/.github/workflows/scan_stack_usage.yml @@ -52,13 +52,13 @@ jobs: ./make_extra.py ./make_cflow.sh # The lower limit comes up from the DAOS memory requirements. - # 16kB - 4kB - 1kB = ~11kB + # 16kB - 4kB - 768B = 11520B # 16kB = Stack allocated for a single Argobot's ULT # 4kB = a maximum DAOS' stack usage up to calling a PMDK API calls - # 1kB = safety margin + # 768B = safety margin # ~ = Some OSes, e.g. Ubuntu 22.04, generate call stacks of size # a little bit over the exact limit which is not deemed a problem at the moment. - ./make_call_stacks.py --filter-api-file examples/api_filter.txt --filter-lower-limit 11296 + ./make_call_stacks.py --filter-api-file examples/api_filter.txt --filter-lower-limit 11520 - name: List per-function stack usage for all call stacks of interest working-directory: ${{ env.CALL_STACKS_TOOLS_PATH }} diff --git a/utils/call_stacks_analysis/README.md b/utils/call_stacks_analysis/README.md index ee4446dc0c0..4933254effd 100644 --- a/utils/call_stacks_analysis/README.md +++ b/utils/call_stacks_analysis/README.md @@ -15,7 +15,7 @@ ./make_extra.py && \ ./make_cflow.sh && \ ./make_call_stacks.py --filter-api-file examples/api_filter.txt \ - --filter-lower-limit 11296 --dump-all-stacks + --filter-lower-limit 11520 --dump-all-stacks ``` If succesfull, it produces: From 6b911a6cc8d621715ce040374b9b6608096f3b16 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 06:27:25 +0100 Subject: [PATCH 107/182] common: exclude line number from generated file Line numer may change what causes `git diff` to produce non-empty output in Scan-Log calls GHA. It should be enough to monitor total number of CORE_LOG... call and ordered list of it. Exact position in the file can not be ensured. Print non-empty log_calls.diff to GHA log Signed-off-by: Tomasz Gromadzki --- .github/workflows/scan_log_calls.yml | 7 +- src/test/core_log_max/call_all.c.generated | 1046 ++++++++--------- .../log_call_all_generate.py | 6 +- 3 files changed, 531 insertions(+), 528 deletions(-) diff --git a/.github/workflows/scan_log_calls.yml b/.github/workflows/scan_log_calls.yml index fd257236a4b..dde2334ff35 100644 --- a/.github/workflows/scan_log_calls.yml +++ b/.github/workflows/scan_log_calls.yml @@ -24,13 +24,16 @@ jobs: echo "length=$(cat log_calls.diff | wc -l)" >> $GITHUB_OUTPUT id: log_calls_diff + - name: Non-empty diff + if: steps.log_calls_diff.outputs.length != '0' + run: cat ${{ env.WORKING_DIRECTORY }}/log_calls.diff + - name: Upload artifacts if: steps.log_calls_diff.outputs.length != '0' uses: actions/upload-artifact@v3 with: name: log_calls_diff - path: | - ${{ env.WORKING_DIRECTORY }}/log_calls.diff + path: ${{ env.WORKING_DIRECTORY }}/log_calls.diff - name: Exit code run: | diff --git a/src/test/core_log_max/call_all.c.generated b/src/test/core_log_max/call_all.c.generated index f44cbd7e251..6c38ba31d31 100644 --- a/src/test/core_log_max/call_all.c.generated +++ b/src/test/core_log_max/call_all.c.generated @@ -10,782 +10,782 @@ call_all_CORE_LOG_ERROR_LAST(void) void call_all_ERR_WO_ERRNO(void) { - // src/common/ctl.c:215 + // src/common/ctl.c ERR_WO_ERRNO("read queries require non-NULL argument"); - // src/common/ctl.c:231 + // src/common/ctl.c ERR_WO_ERRNO("write queries require non-NULL argument"); - // src/common/ctl.c:278 + // src/common/ctl.c ERR_WO_ERRNO("invalid query"); - // src/common/ctl.c:302 + // src/common/ctl.c ERR_WO_ERRNO("invalid query entry point %s", _s); - // src/common/ctl.c:374 + // src/common/ctl.c ERR_WO_ERRNO("failed to parse query %s", _s); - // src/common/ctl.c:436 + // src/common/ctl.c ERR_WO_ERRNO("Config file too large"); - // src/common/ctl.c:562 + // src/common/ctl.c ERR_WO_ERRNO("invalid destination size %zu", _zu); - // src/common/file.c:111 + // src/common/file.c ERR_WO_ERRNO("invalid (NULL) path"); - // src/common/file.c:182 + // src/common/file.c ERR_WO_ERRNO("file size (%ld) too big to be represented in 64-bit signed integer", _ld); - // src/common/file.c:409 + // src/common/file.c ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); - // src/common/file.c:415 + // src/common/file.c ERR_WO_ERRNO("invalid size (%zu) for os_off_t", _zu); - // src/common/file.c:485 + // src/common/file.c ERR_WO_ERRNO("stat \"%s\": negative size", _s); - // src/common/file.c:491 + // src/common/file.c ERR_WO_ERRNO("size %zu smaller than %zu", _zu, _zu); - // src/common/mmap.c:287 + // src/common/mmap.c ERR_WO_ERRNO("duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu", _p, _zu); - // src/common/mmap.c:308 + // src/common/mmap.c ERR_WO_ERRNO("Cannot find DAX device region id"); - // src/common/mmap.c:336 + // src/common/mmap.c ERR_WO_ERRNO("invalid munmap length, must be non-zero and page aligned"); - // src/common/mmap_posix.c:90 + // src/common/mmap_posix.c ERR_WO_ERRNO("end of address space reached"); - // src/common/pool_hdr.c:116 + // src/common/pool_hdr.c ERR_WO_ERRNO("invalid reserved values"); - // src/common/pool_hdr.c:121 + // src/common/pool_hdr.c ERR_WO_ERRNO("invalid machine value"); - // src/common/pool_hdr.c:126 + // src/common/pool_hdr.c ERR_WO_ERRNO("invalid data value"); - // src/common/pool_hdr.c:131 + // src/common/pool_hdr.c ERR_WO_ERRNO("invalid machine_class value"); - // src/common/pool_hdr.c:136 + // src/common/pool_hdr.c ERR_WO_ERRNO("invalid alignment_desc value"); - // src/common/pool_hdr.c:173 + // src/common/pool_hdr.c ERR_WO_ERRNO("unsafe to continue due to unknown incompat features: %#x", _u); - // src/common/pool_hdr.c:182 + // src/common/pool_hdr.c ERR_WO_ERRNO("switching to read-only mode due to unknown ro_compat features: %#x", _u); - // src/common/set.c:1066 + // src/common/set.c ERR_WO_ERRNO("unable to load part %s", _s); - // src/common/set.c:1105 + // src/common/set.c ERR_WO_ERRNO("failed to load parts from directory %s", _s); - // src/common/set.c:1302 + // src/common/set.c ERR_WO_ERRNO("Remote replicas are no longer supported. This functionality is deprecated."); - // src/common/set.c:1339 + // src/common/set.c ERR_WO_ERRNO("%s [%s:%d]", _s, _s, _d); - // src/common/set.c:1357 + // src/common/set.c ERR_WO_ERRNO("cannot load part files from directories"); - // src/common/set.c:1511 + // src/common/set.c ERR_WO_ERRNO("file size does not match config: %s, %zu != %zu", _s, _zu, _zu); - // src/common/set.c:1609 + // src/common/set.c ERR_WO_ERRNO("size must be zero for device dax"); - // src/common/set.c:1643 + // src/common/set.c ERR_WO_ERRNO("file is not a poolset file and its size (%zu) is smaller than %zu", _zu, _zu); - // src/common/set.c:1680 + // src/common/set.c ERR_WO_ERRNO("poolset file options (%u) do not match incompat feature flags (%#x)", _u, _u); - // src/common/set.c:1708 + // src/common/set.c ERR_WO_ERRNO("Non-empty file detected"); - // src/common/set.c:1816 + // src/common/set.c ERR_WO_ERRNO("invalid major version (0)"); - // src/common/set.c:1823 + // src/common/set.c ERR_WO_ERRNO("wrong pool type: \"%.8s\"", _8s); - // src/common/set.c:1830 + // src/common/set.c ERR_WO_ERRNO("pool version %d (library expects %d)", _d, _d); - // src/common/set.c:1833 + // src/common/set.c ERR_WO_ERRNO("Please run the pmdk-convert utility to upgrade the pool."); - // src/common/set.c:1858 + // src/common/set.c ERR_WO_ERRNO("invalid checksum of pool header"); - // src/common/set.c:1866 + // src/common/set.c ERR_WO_ERRNO("wrong architecture flags"); - // src/common/set.c:1874 + // src/common/set.c ERR_WO_ERRNO("wrong pool set UUID"); - // src/common/set.c:1884 + // src/common/set.c ERR_WO_ERRNO("wrong part UUID"); - // src/common/set.c:1891 + // src/common/set.c ERR_WO_ERRNO("incompatible pool format"); - // src/common/set.c:1900 + // src/common/set.c ERR_WO_ERRNO("incompatible feature flags"); - // src/common/set.c:2253 + // src/common/set.c ERR_WO_ERRNO("cannot extend pool by 0 bytes"); - // src/common/set.c:2258 + // src/common/set.c ERR_WO_ERRNO("extending the pool by appending parts with headers is not supported!"); - // src/common/set.c:2266 + // src/common/set.c ERR_WO_ERRNO("exceeded reservation size"); - // src/common/set.c:2275 + // src/common/set.c ERR_WO_ERRNO("unable to append a new part to the pool"); - // src/common/set.c:2290 + // src/common/set.c ERR_WO_ERRNO("cannot open the new part"); - // src/common/set.c:2300 + // src/common/set.c ERR_WO_ERRNO("cannot map the new part"); - // src/common/set.c:2310 + // src/common/set.c ERR_WO_ERRNO("new part cannot be mapped with MAP_SYNC"); - // src/common/set.c:2313 + // src/common/set.c ERR_WO_ERRNO("new part mapped with MAP_SYNC"); - // src/common/set.c:2356 + // src/common/set.c ERR_WO_ERRNO("file contains bad blocks -- '%s'", _s); - // src/common/set.c:2390 + // src/common/set.c ERR_WO_ERRNO("file %s already exists", _s); - // src/common/set.c:2407 + // src/common/set.c ERR_WO_ERRNO("the NOHDRS poolset option is not supported for local poolsets"); - // src/common/set.c:2414 + // src/common/set.c ERR_WO_ERRNO("pool attributes are not supported for poolsets without headers (with the NOHDRS option)"); - // src/common/set.c:2421 + // src/common/set.c ERR_WO_ERRNO("directory based pools are not supported for poolsets with headers (without SINGLEHDR option)"); - // src/common/set.c:2428 + // src/common/set.c ERR_WO_ERRNO("reservation pool size %zu smaller than %zu", _zu, _zu); - // src/common/set.c:2436 + // src/common/set.c ERR_WO_ERRNO("cannot create a new part in provided directories"); - // src/common/set.c:2455 + // src/common/set.c ERR_WO_ERRNO("pool set contains bad blocks and cannot be created, run 'pmempool create --clear-bad-blocks' utility to clear bad blocks and create a pool"); - // src/common/set.c:2463 + // src/common/set.c ERR_WO_ERRNO("net pool size %zu smaller than %zu", _zu, _zu); - // src/common/set.c:2470 + // src/common/set.c ERR_WO_ERRNO("replication not supported"); - // src/common/set.c:257 + // src/common/set.c ERR_WO_ERRNO("unable to map at requested address %p", _p); - // src/common/set.c:2633 + // src/common/set.c ERR_WO_ERRNO("pool mapping failed - address space reservation too small"); - // src/common/set.c:2806 + // src/common/set.c ERR_WO_ERRNO("wrong replica UUID"); - // src/common/set.c:2862 + // src/common/set.c ERR_WO_ERRNO("device dax cannot be mapped privately"); - // src/common/set.c:2877 + // src/common/set.c ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:2900 + // src/common/set.c ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:3018 + // src/common/set.c ERR_WO_ERRNO("device dax cannot be mapped privately"); - // src/common/set.c:3038 + // src/common/set.c ERR_WO_ERRNO("error: a bad block recovery file exists, run 'pmempool sync --bad-blocks' utility to try to recover the pool"); - // src/common/set.c:3064 + // src/common/set.c ERR_WO_ERRNO("pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool -- '%s'", _s); - // src/common/set.c:3215 + // src/common/set.c ERR_WO_ERRNO("util_poolset_parse failed -- '%s'", _s); - // src/common/set.c:476 + // src/common/set.c ERR_WO_ERRNO("size autodetection is supported only for device dax"); - // src/common/set.c:732 + // src/common/set.c ERR_WO_ERRNO("cannot mix directories and files in a set"); - // src/common/set.c:758 + // src/common/set.c ERR_WO_ERRNO("cannot mix directories and files in a set"); - // src/common/set.c:768 + // src/common/set.c ERR_WO_ERRNO("cannot resolve realpath of new directory"); - // src/common/set.c:780 + // src/common/set.c ERR_WO_ERRNO("cannot use the same directory twice"); - // src/common/set.c:877 + // src/common/set.c ERR_WO_ERRNO("replica #%u part %u %smapped with MAP_SYNC", _u, _u, _s); - // src/common/set.c:887 + // src/common/set.c ERR_WO_ERRNO("replica #%u part %u header %smapped with MAP_SYNC", _u, _u, _s); - // src/common/set.c:916 + // src/common/set.c ERR_WO_ERRNO("either all the parts must be Device DAX or none"); - // src/common/set.c:926 + // src/common/set.c ERR_WO_ERRNO("Multiple DAX devices with alignment other than 4KB. Use the SINGLEHDR poolset option."); - // src/common/set.c:945 + // src/common/set.c ERR_WO_ERRNO("both SINGLEHDR and NOHDR poolset options used at the same time"); - // src/common/set_badblocks.c:120 + // src/common/set_badblocks.c ERR_WO_ERRNO("clearing bad blocks in the pool file failed -- '%s'", _s); - // src/common/set_badblocks.c:46 + // src/common/set_badblocks.c ERR_WO_ERRNO("checking the pool file for bad blocks failed -- '%s'", _s); - // src/common/set_badblocks.c:53 + // src/common/set_badblocks.c ERR_WO_ERRNO("part file contains bad blocks -- '%s'", _s); - // src/common/shutdown_state.c:101 + // src/common/shutdown_state.c ERR_WO_ERRNO("cannot read uuid of %d", _d); - // src/common/shutdown_state.c:232 + // src/common/shutdown_state.c ERR_WO_ERRNO("an ADR failure was detected, the pool might be corrupted"); - // src/common/shutdown_state.c:77 + // src/common/shutdown_state.c ERR_WO_ERRNO("Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207"); - // src/common/shutdown_state.c:87 + // src/common/shutdown_state.c ERR_WO_ERRNO("cannot read uuid of %d", _d); - // src/libpmem/libpmem.c:56 + // src/libpmem/libpmem.c ERR_WO_ERRNO("libpmem major version mismatch (need %u, found %u)", _u, _u); - // src/libpmem/libpmem.c:63 + // src/libpmem/libpmem.c ERR_WO_ERRNO("libpmem minor version mismatch (need %u, found %u)", _u, _u); - // src/libpmem/pmem.c:413 + // src/libpmem/pmem.c ERR_WO_ERRNO("invalid flag specified %x", _u); - // src/libpmem/pmem.c:420 + // src/libpmem/pmem.c ERR_WO_ERRNO("flag unsupported for Device DAX %x", _u); - // src/libpmem/pmem.c:429 + // src/libpmem/pmem.c ERR_WO_ERRNO("unable to read Device DAX size"); - // src/libpmem/pmem.c:434 + // src/libpmem/pmem.c ERR_WO_ERRNO("Device DAX length must be either 0 or the exact size of the device: %zu", _zu); - // src/libpmem/pmem.c:446 + // src/libpmem/pmem.c ERR_WO_ERRNO("invalid file length %zu", _zu); - // src/libpmem/pmem.c:457 + // src/libpmem/pmem.c ERR_WO_ERRNO("non-zero 'len' not allowed without PMEM_FILE_CREATE"); - // src/libpmem/pmem.c:464 + // src/libpmem/pmem.c ERR_WO_ERRNO("zero 'len' not allowed with PMEM_FILE_CREATE"); - // src/libpmem/pmem.c:470 + // src/libpmem/pmem.c ERR_WO_ERRNO("PMEM_FILE_TMPFILE not allowed without PMEM_FILE_CREATE"); - // src/libpmem/pmem.c:513 + // src/libpmem/pmem.c ERR_WO_ERRNO("stat %s: negative size", _s); - // src/libpmem/pmem.c:588 + // src/libpmem/pmem.c ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmem/pmem.c:619 + // src/libpmem/pmem.c ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmem/pmem.c:651 + // src/libpmem/pmem.c ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmemobj/alloc_class.c:231 + // src/libpmemobj/alloc_class.c ERR_WO_ERRNO("unable to register allocation class"); - // src/libpmemobj/heap.c:1051 + // src/libpmemobj/heap.c ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/heap.c:1167 + // src/libpmemobj/heap.c ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/heap.c:1410 + // src/libpmemobj/heap.c ERR_WO_ERRNO("at least one automatic arena must exist"); - // src/libpmemobj/heap.c:1605 + // src/libpmemobj/heap.c ERR_WO_ERRNO("mapped region smaller than the heap size"); - // src/libpmemobj/heap.c:1787 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid header's checksum"); - // src/libpmemobj/heap.c:1792 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid signature"); - // src/libpmemobj/heap.c:1810 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid zone size"); - // src/libpmemobj/heap.c:1825 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid chunk type"); - // src/libpmemobj/heap.c:1830 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: unknown chunk type"); - // src/libpmemobj/heap.c:1835 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid chunk flags"); - // src/libpmemobj/heap.c:1852 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid zone magic"); - // src/libpmemobj/heap.c:1868 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: chunk sizes mismatch"); - // src/libpmemobj/heap.c:1884 + // src/libpmemobj/heap.c ERR_WO_ERRNO("heap: invalid heap size"); - // src/libpmemobj/heap.c:768 + // src/libpmemobj/heap.c ERR_WO_ERRNO("lost runtime tracking info of %u run due to OOM", _u); - // src/libpmemobj/libpmemobj.c:52 + // src/libpmemobj/libpmemobj.c ERR_WO_ERRNO("libpmemobj major version mismatch (need %u, found %u)", _u, _u); - // src/libpmemobj/libpmemobj.c:59 + // src/libpmemobj/libpmemobj.c ERR_WO_ERRNO("libpmemobj minor version mismatch (need %u, found %u)", _u, _u); - // src/libpmemobj/memops.c:575 + // src/libpmemobj/memops.c ERR_WO_ERRNO("Capacity insufficient"); - // src/libpmemobj/memops.c:586 + // src/libpmemobj/memops.c ERR_WO_ERRNO("Buffer currently used"); - // src/libpmemobj/memops.c:691 + // src/libpmemobj/memops.c ERR_WO_ERRNO("no extend function present"); - // src/libpmemobj/obj.c:1036 + // src/libpmemobj/obj.c ERR_WO_ERRNO("%s variable must be a positive integer", _s); - // src/libpmemobj/obj.c:1065 + // src/libpmemobj/obj.c ERR_WO_ERRNO("Layout too long"); - // src/libpmemobj/obj.c:1114 + // src/libpmemobj/obj.c ERR_WO_ERRNO("initialization of replica #%u failed", _u); - // src/libpmemobj/obj.c:1134 + // src/libpmemobj/obj.c ERR_WO_ERRNO("pool initialization failed"); - // src/libpmemobj/obj.c:1184 + // src/libpmemobj/obj.c ERR_WO_ERRNO("invalid run_id %lu", _lu); - // src/libpmemobj/obj.c:1246 + // src/libpmemobj/obj.c ERR_WO_ERRNO("read-only mode is not supported"); - // src/libpmemobj/obj.c:1279 + // src/libpmemobj/obj.c ERR_WO_ERRNO("initialization of replica #%u failed", _u); - // src/libpmemobj/obj.c:1319 + // src/libpmemobj/obj.c ERR_WO_ERRNO("inconsistent replica #%u", _u); - // src/libpmemobj/obj.c:1405 + // src/libpmemobj/obj.c ERR_WO_ERRNO("pool initialization failed"); - // src/libpmemobj/obj.c:1537 + // src/libpmemobj/obj.c ERR_WO_ERRNO("critnib_remove for pools_ht"); - // src/libpmemobj/obj.c:1541 + // src/libpmemobj/obj.c ERR_WO_ERRNO("critnib_remove for pools_tree"); - // src/libpmemobj/obj.c:1724 + // src/libpmemobj/obj.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/obj.c:1767 + // src/libpmemobj/obj.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/obj.c:1798 + // src/libpmemobj/obj.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/obj.c:1804 + // src/libpmemobj/obj.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/obj.c:1843 + // src/libpmemobj/obj.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/obj.c:1921 + // src/libpmemobj/obj.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/obj.c:2298 + // src/libpmemobj/obj.c ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmemobj/obj.c:2316 + // src/libpmemobj/obj.c ERR_WO_ERRNO("invalid flags 0x%x", _u); - // src/libpmemobj/obj.c:2418 + // src/libpmemobj/obj.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/obj.c:2424 + // src/libpmemobj/obj.c ERR_WO_ERRNO("requested size cannot equals zero"); - // src/libpmemobj/obj.c:2560 + // src/libpmemobj/obj.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/obj.c:2669 + // src/libpmemobj/obj.c ERR_WO_ERRNO("Not all PMEMoids belong to the provided pool"); - // src/libpmemobj/obj.c:2739 + // src/libpmemobj/obj.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/obj.c:773 + // src/libpmemobj/obj.c ERR_WO_ERRNO("invalid checksum of pool descriptor"); - // src/libpmemobj/obj.c:780 + // src/libpmemobj/obj.c ERR_WO_ERRNO("wrong layout (\"%s\"), pool created with layout \"%s\"", _s, _s); - // src/libpmemobj/obj.c:788 + // src/libpmemobj/obj.c ERR_WO_ERRNO("unaligned heap: off %lu", _lu); - // src/libpmemobj/palloc.c:196 + // src/libpmemobj/palloc.c ERR_WO_ERRNO("no allocation class for size %lu bytes", _lu); - // src/libpmemobj/palloc.c:211 + // src/libpmemobj/palloc.c ERR_WO_ERRNO("allocation class not suitable for size %lu bytes", _lu); - // src/libpmemobj/palloc.c:275 + // src/libpmemobj/palloc.c ERR_WO_ERRNO("invalid operation or heap corruption"); - // src/libpmemobj/pmalloc.c:237 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("unit size must be evenly divisible by alignment"); - // src/libpmemobj/pmalloc.c:243 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("alignment cannot be larger than 2 megabytes"); - // src/libpmemobj/pmalloc.c:261 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("invalid header type"); - // src/libpmemobj/pmalloc.c:268 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("no available free allocation class identifier"); - // src/libpmemobj/pmalloc.c:278 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("class id outside of the allowed range"); - // src/libpmemobj/pmalloc.c:286 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("attempted to overwrite an allocation class"); - // src/libpmemobj/pmalloc.c:344 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("invalid header type"); - // src/libpmemobj/pmalloc.c:369 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("class id outside of the allowed range"); - // src/libpmemobj/pmalloc.c:380 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("class with the given id does not exist"); - // src/libpmemobj/pmalloc.c:459 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("incorrect size for extend, must be larger than %lu", _lu); - // src/libpmemobj/pmalloc.c:511 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("incorrect grow size, must be 0 or larger than %lu", _lu); - // src/libpmemobj/pmalloc.c:576 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("cannot change max arena number"); - // src/libpmemobj/pmalloc.c:642 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); - // src/libpmemobj/pmalloc.c:680 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); - // src/libpmemobj/pmalloc.c:687 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("incorrect arena state, must be 0 or 1"); - // src/libpmemobj/pmalloc.c:719 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); - // src/libpmemobj/pmalloc.c:767 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("arena id outside of the allowed range: <1,%u>", _u); - // src/libpmemobj/pmalloc.c:919 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("invalid arena assignment type"); - // src/libpmemobj/pmalloc.c:969 + // src/libpmemobj/pmalloc.c ERR_WO_ERRNO("number of default arenas can't be 0"); - // src/libpmemobj/stats.c:74 + // src/libpmemobj/stats.c ERR_WO_ERRNO("invalid enable type"); - // src/libpmemobj/sync.c:43 + // src/libpmemobj/sync.c ERR_WO_ERRNO("error initializing lock"); - // src/libpmemobj/sync.c:50 + // src/libpmemobj/sync.c ERR_WO_ERRNO("error setting lock runid"); - // src/libpmemobj/tx.c:1236 + // src/libpmemobj/tx.c ERR_WO_ERRNO("snapshot size too large"); - // src/libpmemobj/tx.c:1243 + // src/libpmemobj/tx.c ERR_WO_ERRNO("object outside of heap"); - // src/libpmemobj/tx.c:1383 + // src/libpmemobj/tx.c ERR_WO_ERRNO("out of memory"); - // src/libpmemobj/tx.c:1410 + // src/libpmemobj/tx.c ERR_WO_ERRNO("object outside of pool"); - // src/libpmemobj/tx.c:1448 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1456 + // src/libpmemobj/tx.c ERR_WO_ERRNO("object outside of pool"); - // src/libpmemobj/tx.c:1493 + // src/libpmemobj/tx.c ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1531 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1539 + // src/libpmemobj/tx.c ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1576 + // src/libpmemobj/tx.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1607 + // src/libpmemobj/tx.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1638 + // src/libpmemobj/tx.c ERR_WO_ERRNO("allocation with size 0"); - // src/libpmemobj/tx.c:1645 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1714 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1722 + // src/libpmemobj/tx.c ERR_WO_ERRNO("cannot duplicate NULL string"); - // src/libpmemobj/tx.c:1772 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1780 + // src/libpmemobj/tx.c ERR_WO_ERRNO("cannot duplicate NULL string"); - // src/libpmemobj/tx.c:1831 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1842 + // src/libpmemobj/tx.c ERR_WO_ERRNO("invalid pool uuid"); - // src/libpmemobj/tx.c:1914 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:1959 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/tx.c:2208 + // src/libpmemobj/tx.c ERR_WO_ERRNO("invalid cache size, must be between 0 and max alloc size"); - // src/libpmemobj/tx.c:2232 + // src/libpmemobj/tx.c ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - // src/libpmemobj/tx.c:2247 + // src/libpmemobj/tx.c ERR_WO_ERRNO("tx.cache.threshold parameter is deprecated"); - // src/libpmemobj/tx.c:513 + // src/libpmemobj/tx.c ERR_WO_ERRNO("Unrecognized lock type"); - // src/libpmemobj/tx.c:550 + // src/libpmemobj/tx.c ERR_WO_ERRNO("Unrecognized lock type"); - // src/libpmemobj/tx.c:588 + // src/libpmemobj/tx.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/tx.c:617 + // src/libpmemobj/tx.c ERR_WO_ERRNO("out of memory"); - // src/libpmemobj/tx.c:633 + // src/libpmemobj/tx.c ERR_WO_ERRNO("requested size too large"); - // src/libpmemobj/tx.c:647 + // src/libpmemobj/tx.c ERR_WO_ERRNO("pmemobj_tx_free failed"); - // src/libpmemobj/tx.c:665 + // src/libpmemobj/tx.c ERR_WO_ERRNO("pmemobj_tx_free failed"); - // src/libpmemobj/tx.c:682 + // src/libpmemobj/tx.c ERR_WO_ERRNO("Buffer from a different pool"); - // src/libpmemobj/tx.c:739 + // src/libpmemobj/tx.c ERR_WO_ERRNO("nested transaction for different pool"); - // src/libpmemobj/tx.c:865 + // src/libpmemobj/tx.c ERR_WO_ERRNO("unknown flags 0x%lx", _lu); - // src/libpmemobj/ulog.c:245 + // src/libpmemobj/ulog.c ERR_WO_ERRNO("cannot auto reserve next ulog"); - // src/tools/pmempool/output.c:779 + // src/tools/pmempool/output.c ERR_WO_ERRNO("snprintf for incompat features: %d", _d); } void call_all_CORE_LOG_WARNING(void) { - // src/common/file.c:263 + // src/common/file.c CORE_LOG_WARNING("requested size of write goes beyond the file length, %zu > %zu", _zu, _zu); - // src/common/file.c:326 + // src/common/file.c CORE_LOG_WARNING("requested size of write goes beyond the file length, %zu > %zu", _zu, _zu); - // src/common/file.c:380 + // src/common/file.c CORE_LOG_WARNING("requested size of read goes beyond the file length, %zu > %zu", _zu, _zu); - // src/common/mmap.c:54 + // src/common/mmap.c CORE_LOG_WARNING("Invalid PMEM_MMAP_HINT"); - // src/common/mmap.c:56 + // src/common/mmap.c CORE_LOG_WARNING("No /proc, PMEM_MMAP_HINT ignored"); - // src/common/set.c:2002 + // src/common/set.c CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); - // src/common/set.c:2649 + // src/common/set.c CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); - // src/common/set.c:2897 + // src/common/set.c CORE_LOG_WARNING("pool set contains bad blocks, ignoring"); - // src/common/set.c:2955 + // src/common/set.c CORE_LOG_WARNING("cannot open the part -- \"%s\"", _s); - // src/common/set.c:3060 + // src/common/set.c CORE_LOG_WARNING("pool set contains bad blocks, ignoring -- '%s'", _s); - // src/common/set.c:428 + // src/common/set.c CORE_LOG_WARNING("file permissions changed during pool initialization, file: %s (%o)", _s, _u); - // src/common/shutdown_state.c:206 + // src/common/shutdown_state.c CORE_LOG_WARNING("incorrect checksum - SDS will be reinitialized"); - // src/common/shutdown_state.c:219 + // src/common/shutdown_state.c CORE_LOG_WARNING("the pool was not closed - SDS will be reinitialized"); - // src/common/shutdown_state.c:226 + // src/common/shutdown_state.c CORE_LOG_WARNING("an ADR failure was detected but the pool was closed - SDS will be reinitialized"); - // src/libpmemobj/heap.c:1192 + // src/libpmemobj/heap.c CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); - // src/libpmemobj/heap.c:1204 + // src/libpmemobj/heap.c CORE_LOG_WARNING("failed to allocate memory block runtime tracking info"); - // src/libpmemobj/memops.c:352 + // src/libpmemobj/memops.c CORE_LOG_WARNING("out of memory - unable to track entries"); - // src/libpmemobj/palloc.c:307 + // src/libpmemobj/palloc.c CORE_LOG_WARNING("unable to track runtime chunk state"); } void call_all_CORE_LOG_ERROR(void) { - // src/common/bad_blocks.c:152 + // src/common/bad_blocks.c CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); - // src/common/bad_blocks.c:161 + // src/common/bad_blocks.c CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); - // src/common/bad_blocks.c:210 + // src/common/bad_blocks.c CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", _s); - // src/common/bad_blocks.c:217 + // src/common/bad_blocks.c CORE_LOG_ERROR("pmem2_badblock_clear -- %s", _s); - // src/common/bad_blocks.c:255 + // src/common/bad_blocks.c CORE_LOG_ERROR("counting bad blocks failed -- '%s'", _s); - // src/common/bad_blocks.c:260 + // src/common/bad_blocks.c CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", _s, _d); - // src/common/ctl.c:238 + // src/common/ctl.c CORE_LOG_ERROR("Invalid arguments"); - // src/common/file.c:212 + // src/common/file.c CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:218 + // src/common/file.c CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:250 + // src/common/file.c CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:256 + // src/common/file.c CORE_LOG_ERROR("offset beyond file length, %ju > %ju", _ju, _ju); - // src/common/file.c:272 + // src/common/file.c CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:307 + // src/common/file.c CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/file.c:320 + // src/common/file.c CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:335 + // src/common/file.c CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:361 + // src/common/file.c CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/file.c:374 + // src/common/file.c CORE_LOG_ERROR("cannot determine file length \"%s\"", _s); - // src/common/file.c:389 + // src/common/file.c CORE_LOG_ERROR("failed to map entire file \"%s\"", _s); - // src/common/file.c:547 + // src/common/file.c CORE_LOG_ERROR("failed to open file \"%s\"", _s); - // src/common/file_posix.c:115 + // src/common/file_posix.c CORE_LOG_ERROR("Cannot open file %s", _s); - // src/common/mmap.c:94 + // src/common/mmap.c CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/os_deep_linux.c:127 + // src/common/os_deep_linux.c CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); - // src/common/os_deep_linux.c:156 + // src/common/os_deep_linux.c CORE_LOG_ERROR("deep_flush not supported"); - // src/common/os_deep_linux.c:159 + // src/common/os_deep_linux.c CORE_LOG_ERROR("invalid dax_region id %u", _u); - // src/common/os_deep_linux.c:166 + // src/common/os_deep_linux.c CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", _u); - // src/common/os_deep_linux.c:175 + // src/common/os_deep_linux.c CORE_LOG_ERROR("pmem_msync(%p, %lu)", _p, _lu); - // src/common/os_deep_linux.c:38 + // src/common/os_deep_linux.c CORE_LOG_ERROR("deep_flush not supported"); - // src/common/os_deep_linux.c:42 + // src/common/os_deep_linux.c CORE_LOG_ERROR("cannot write to deep_flush in region %u", _u); - // src/common/set.c:1053 + // src/common/set.c CORE_LOG_ERROR("cannot read size of file (%s) in a poolset directory", _s); - // src/common/set.c:1484 + // src/common/set.c CORE_LOG_ERROR("failed to create file: %s", _s); - // src/common/set.c:1494 + // src/common/set.c CORE_LOG_ERROR("failed to open file: %s", _s); - // src/common/set.c:183 + // src/common/set.c CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/set.c:1964 + // src/common/set.c CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/set.c:1972 + // src/common/set.c CORE_LOG_ERROR("pool mapping failed - replica #%u part #0", _u); - // src/common/set.c:2016 + // src/common/set.c CORE_LOG_ERROR("usable space mapping failed - part #%d", _d); - // src/common/set.c:2085 + // src/common/set.c CORE_LOG_ERROR("header mapping failed - part #%d", _d); - // src/common/set.c:2093 + // src/common/set.c CORE_LOG_ERROR("header creation failed - part #%d", _d); - // src/common/set.c:2130 + // src/common/set.c CORE_LOG_ERROR("replica #%u map failed", _u); - // src/common/set.c:2139 + // src/common/set.c CORE_LOG_ERROR("replica #%u headers initialization failed", _u); - // src/common/set.c:2398 + // src/common/set.c CORE_LOG_ERROR("cannot create pool set -- '%s'", _s); - // src/common/set.c:2445 + // src/common/set.c CORE_LOG_ERROR("failed to check pool set for bad blocks -- '%s'", _s); - // src/common/set.c:2485 + // src/common/set.c CORE_LOG_ERROR("cannot generate pool set UUID"); - // src/common/set.c:2497 + // src/common/set.c CORE_LOG_ERROR("cannot generate pool set part UUID"); - // src/common/set.c:2524 + // src/common/set.c CORE_LOG_ERROR("replica #%u creation failed", _u); - // src/common/set.c:2591 + // src/common/set.c CORE_LOG_ERROR("cannot find a contiguous region of given size"); - // src/common/set.c:2601 + // src/common/set.c CORE_LOG_ERROR("pool mapping failed - replica #%u part #0", _u); - // src/common/set.c:2615 + // src/common/set.c CORE_LOG_ERROR("header mapping failed - part #%d", _d); - // src/common/set.c:2662 + // src/common/set.c CORE_LOG_ERROR("usable space mapping failed - part #%d", _d); - // src/common/set.c:2793 + // src/common/set.c CORE_LOG_ERROR("header check failed - part #%d", _d); - // src/common/set.c:2823 + // src/common/set.c CORE_LOG_ERROR("ADR failure detected"); - // src/common/set.c:2883 + // src/common/set.c CORE_LOG_ERROR("an error occurred when checking whether recovery file exists."); - // src/common/set.c:2890 + // src/common/set.c CORE_LOG_ERROR("failed to check pool set for bad blocks"); - // src/common/set.c:2916 + // src/common/set.c CORE_LOG_ERROR("replica #%u open failed", _u); - // src/common/set.c:2963 + // src/common/set.c CORE_LOG_ERROR("header mapping failed -- \"%s\"", _s); - // src/common/set.c:3007 + // src/common/set.c CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); - // src/common/set.c:3030 + // src/common/set.c CORE_LOG_ERROR("reading compat features failed"); - // src/common/set.c:3045 + // src/common/set.c CORE_LOG_ERROR("an error occurred when checking whether recovery file exists."); - // src/common/set.c:3052 + // src/common/set.c CORE_LOG_ERROR("failed to check pool set for bad blocks -- '%s'", _s); - // src/common/set.c:3079 + // src/common/set.c CORE_LOG_ERROR("replica #%u open failed", _u); - // src/common/set.c:3316 + // src/common/set.c CORE_LOG_ERROR("os_part_deep_common(%p, %p, %lu)", _p, _p, _lu); - // src/common/set.c:343 + // src/common/set.c CORE_LOG_ERROR("replica open failed: replica %u", _u); - // src/common/set_badblocks.c:213 + // src/common/set_badblocks.c CORE_LOG_ERROR("allocating name of bad block recovery file failed"); - // src/common/set_badblocks.c:86 + // src/common/set_badblocks.c CORE_LOG_ERROR("%i pool file(s) contain bad blocks", _d); - // src/common/shutdown_state.c:80 + // src/common/shutdown_state.c CORE_LOG_ERROR("cannot read unsafe shutdown count for %d", _d); - // src/common/uuid.c:24 + // src/common/uuid.c CORE_LOG_ERROR("invalid buffer for uuid string"); - // src/common/uuid.c:29 + // src/common/uuid.c CORE_LOG_ERROR("invalid uuid structure"); - // src/common/uuid.c:42 + // src/common/uuid.c CORE_LOG_ERROR("snprintf(uuid): %d", _d); - // src/common/uuid.c:60 + // src/common/uuid.c CORE_LOG_ERROR("invalid uuid string"); - // src/common/uuid.c:66 + // src/common/uuid.c CORE_LOG_ERROR("invalid uuid string"); - // src/common/uuid.c:79 + // src/common/uuid.c CORE_LOG_ERROR("sscanf(uuid)"); - // src/common/uuid_linux.c:31 + // src/common/uuid_linux.c CORE_LOG_ERROR("open(uuid)"); - // src/common/uuid_linux.c:37 + // src/common/uuid_linux.c CORE_LOG_ERROR("read(uuid)"); - // src/core/util_posix.c:52 + // src/core/util_posix.c CORE_LOG_ERROR("stat failed for %s", _s); - // src/core/util_posix.c:62 + // src/core/util_posix.c CORE_LOG_ERROR("stat failed for %s", _s); - // src/libpmem/pmem.c:480 + // src/libpmem/pmem.c CORE_LOG_ERROR("failed to create temporary file at \"%s\"", _s); - // src/libpmem/pmem_posix.c:61 + // src/libpmem/pmem_posix.c CORE_LOG_ERROR("can't track mapped region"); - // src/libpmemobj/heap.c:1327 + // src/libpmemobj/heap.c CORE_LOG_ERROR("cannot decrease max number of arenas"); - // src/libpmemobj/lane.c:417 + // src/libpmemobj/lane.c CORE_LOG_ERROR("lane %lu internal redo failed: %d", _lu, _d); - // src/libpmemobj/list.c:564 + // src/libpmemobj/list.c CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:603 + // src/libpmemobj/list.c CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:731 + // src/libpmemobj/list.c CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:765 + // src/libpmemobj/list.c CORE_LOG_ERROR("pmemobj_mutex_lock failed"); - // src/libpmemobj/list.c:842 + // src/libpmemobj/list.c CORE_LOG_ERROR("list_mutexes_lock failed"); - // src/libpmemobj/obj.c:105 + // src/libpmemobj/obj.c CORE_LOG_ERROR("unable to parse config stored in %s environment variable", _s); - // src/libpmemobj/obj.c:1090 + // src/libpmemobj/obj.c CORE_LOG_ERROR("cannot create pool or pool set"); - // src/libpmemobj/obj.c:1127 + // src/libpmemobj/obj.c CORE_LOG_ERROR("creation of pool descriptor failed"); - // src/libpmemobj/obj.c:116 + // src/libpmemobj/obj.c CORE_LOG_ERROR("unable to parse config stored in %s file (from %s environment variable)", _s, _s); - // src/libpmemobj/obj.c:1189 + // src/libpmemobj/obj.c CORE_LOG_ERROR("lane_check"); - // src/libpmemobj/obj.c:1198 + // src/libpmemobj/obj.c CORE_LOG_ERROR("heap_check"); - // src/libpmemobj/obj.c:1238 + // src/libpmemobj/obj.c CORE_LOG_ERROR("cannot open pool or pool set"); - // src/libpmemobj/obj.c:1375 + // src/libpmemobj/obj.c CORE_LOG_ERROR("descriptor check of replica #%u failed", _u); - // src/libpmemobj/obj.c:2438 + // src/libpmemobj/obj.c CORE_LOG_ERROR("obj_realloc_root failed"); - // src/libpmemobj/obj.c:90 + // src/libpmemobj/obj.c CORE_LOG_ERROR("ctl_new"); - // src/tools/pmempool/common.c:1307 + // src/tools/pmempool/common.c CORE_LOG_ERROR("cannot open pool set -- '%s'", _s); } void call_all_CORE_LOG_FATAL(void) { - // src/common/set.c:221 + // src/common/set.c CORE_LOG_FATAL("munmap: %s", _s); - // src/common/set.c:2220 + // src/common/set.c CORE_LOG_FATAL("cannot add a new part to the replica info"); - // src/common/util_pmem.h:30 + // src/common/util_pmem.h CORE_LOG_FATAL("pmem_msync"); - // src/core/alloc.c:62 + // src/core/alloc.c CORE_LOG_FATAL("unknown allocation type"); - // src/core/core_assert.h:39 + // src/core/core_assert.h CORE_LOG_FATAL("assertion failure: %s", _s); - // src/core/core_assert.h:45 + // src/core/core_assert.h CORE_LOG_FATAL("assertion failure: %s (%s = %s)", _s, _s, _s); - // src/core/last_error_msg.c:37 + // src/core/last_error_msg.c CORE_LOG_FATAL("os_thread_key_create"); - // src/core/last_error_msg.c:78 + // src/core/last_error_msg.c CORE_LOG_FATAL("os_tls_set"); - // src/core/out.c:147 + // src/core/out.c CORE_LOG_FATAL("Cannot set log threshold"); - // src/core/out.c:154 + // src/core/out.c CORE_LOG_FATAL("Cannot set legacy log function"); - // src/core/sys_util.h:108 + // src/core/sys_util.h CORE_LOG_FATAL("os_rwlock_init"); - // src/core/sys_util.h:123 + // src/core/sys_util.h CORE_LOG_FATAL("os_rwlock_rdlock"); - // src/core/sys_util.h:138 + // src/core/sys_util.h CORE_LOG_FATAL("os_rwlock_wrlock"); - // src/core/sys_util.h:153 + // src/core/sys_util.h CORE_LOG_FATAL("os_rwlock_unlock"); - // src/core/sys_util.h:168 + // src/core/sys_util.h CORE_LOG_FATAL("os_rwlock_destroy"); - // src/core/sys_util.h:197 + // src/core/sys_util.h CORE_LOG_FATAL("os_spin_destroy"); - // src/core/sys_util.h:211 + // src/core/sys_util.h CORE_LOG_FATAL("os_spin_lock"); - // src/core/sys_util.h:226 + // src/core/sys_util.h CORE_LOG_FATAL("os_spin_unlock"); - // src/core/sys_util.h:239 + // src/core/sys_util.h CORE_LOG_FATAL("os_semaphore_init"); - // src/core/sys_util.h:249 + // src/core/sys_util.h CORE_LOG_FATAL("os_semaphore_destroy"); - // src/core/sys_util.h:266 + // src/core/sys_util.h CORE_LOG_FATAL("os_semaphore_wait"); - // src/core/sys_util.h:282 + // src/core/sys_util.h CORE_LOG_FATAL("os_semaphore_trywait"); - // src/core/sys_util.h:294 + // src/core/sys_util.h CORE_LOG_FATAL("os_semaphore_post"); - // src/core/sys_util.h:301 + // src/core/sys_util.h CORE_LOG_FATAL("os_cond_init"); - // src/core/sys_util.h:308 + // src/core/sys_util.h CORE_LOG_FATAL("os_cond_destroy"); - // src/core/sys_util.h:31 + // src/core/sys_util.h CORE_LOG_FATAL("os_mutex_init"); - // src/core/sys_util.h:46 + // src/core/sys_util.h CORE_LOG_FATAL("os_mutex_destroy"); - // src/core/sys_util.h:61 + // src/core/sys_util.h CORE_LOG_FATAL("os_mutex_lock"); - // src/core/sys_util.h:77 + // src/core/sys_util.h CORE_LOG_FATAL("os_mutex_trylock"); - // src/core/sys_util.h:93 + // src/core/sys_util.h CORE_LOG_FATAL("os_mutex_unlock"); - // src/libpmem/pmem.c:362 + // src/libpmem/pmem.c CORE_LOG_FATAL("util_bool_compare_and_swap32"); - // src/libpmem/pmem.c:915 + // src/libpmem/pmem.c CORE_LOG_FATAL("invalid flush function address"); - // src/libpmemobj/lane.c:105 + // src/libpmemobj/lane.c CORE_LOG_FATAL("os_tls_key_create"); - // src/libpmemobj/lane.c:43 + // src/libpmemobj/lane.c CORE_LOG_FATAL("critnib_new"); - // src/libpmemobj/lane.c:483 + // src/libpmemobj/lane.c CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/lane.c:499 + // src/libpmemobj/lane.c CORE_LOG_FATAL("critnib_insert"); - // src/libpmemobj/lane.c:555 + // src/libpmemobj/lane.c CORE_LOG_FATAL("lane_release"); - // src/libpmemobj/lane.c:560 + // src/libpmemobj/lane.c CORE_LOG_FATAL("util_bool_compare_and_swap64"); - // src/libpmemobj/lane.c:80 + // src/libpmemobj/lane.c CORE_LOG_FATAL("os_tls_set"); - // src/libpmemobj/memblock.c:1106 + // src/libpmemobj/memblock.c CORE_LOG_FATAL("failed to initialize valgrind state"); - // src/libpmemobj/memblock.c:1146 + // src/libpmemobj/memblock.c CORE_LOG_FATAL("failed to initialize valgrind state"); - // src/libpmemobj/memblock.c:1466 + // src/libpmemobj/memblock.c CORE_LOG_FATAL("possible zone chunks metadata corruption"); - // src/libpmemobj/obj.c:148 + // src/libpmemobj/obj.c CORE_LOG_FATAL("critnib_new for pools_ht"); - // src/libpmemobj/obj.c:156 + // src/libpmemobj/obj.c CORE_LOG_FATAL("critnib_new for pools_tree"); - // src/libpmemobj/obj.c:211 + // src/libpmemobj/obj.c CORE_LOG_FATAL("error: %s", _s); - // src/libpmemobj/obj.c:252 + // src/libpmemobj/obj.c CORE_LOG_FATAL("pmem_msync"); - // src/libpmemobj/palloc.c:304 + // src/libpmemobj/palloc.c CORE_LOG_FATAL("duplicate runtime chunk state, possible double free"); - // src/libpmemobj/sync.h:102 + // src/libpmemobj/sync.h CORE_LOG_FATAL("pmemobj_mutex_unlock"); - // src/libpmemobj/sync.h:87 + // src/libpmemobj/sync.h CORE_LOG_FATAL("pmemobj_mutex_lock"); - // src/libpmemobj/tx.c:1049 + // src/libpmemobj/tx.c CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); - // src/libpmemobj/tx.c:1053 + // src/libpmemobj/tx.c CORE_LOG_FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); - // src/libpmemobj/tx.c:161 + // src/libpmemobj/tx.c CORE_LOG_FATAL("%s called outside of transaction", _s); - // src/libpmemobj/tx.c:272 + // src/libpmemobj/tx.c CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:284 + // src/libpmemobj/tx.c CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:321 + // src/libpmemobj/tx.c CORE_LOG_FATAL("Malloc"); - // src/libpmemobj/tx.c:574 + // src/libpmemobj/tx.c CORE_LOG_FATAL("invalid state of ranges tree"); - // src/libpmemobj/tx.c:769 + // src/libpmemobj/tx.c CORE_LOG_FATAL("Invalid stage %d to begin new transaction", _d); - // src/libpmemobj/tx.c:807 + // src/libpmemobj/tx.c CORE_LOG_FATAL("transaction callback is already set, old %p new %p old_arg %p new_arg %p", _p, _p, _p, _p); } @@ -799,304 +799,304 @@ void call_all_ERR_W_ERRNO(int errnum) { errno = errnum; - // src/common/bad_blocks.c:142 + // src/common/bad_blocks.c ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/bad_blocks.c:200 + // src/common/bad_blocks.c ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/bad_blocks.c:63 + // src/common/bad_blocks.c ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:132 + // src/common/ctl.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:142 + // src/common/ctl.c ERR_W_ERRNO("strtok_r"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:400 + // src/common/ctl.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:445 + // src/common/ctl.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/ctl.c:479 + // src/common/ctl.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:126 + // src/common/file.c ERR_W_ERRNO("stat"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:143 + // src/common/file.c ERR_W_ERRNO("open"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:206 + // src/common/file.c ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:244 + // src/common/file.c ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:40 + // src/common/file.c ERR_W_ERRNO("os_access \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:430 + // src/common/file.c ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:435 + // src/common/file.c ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); UT_ASSERTeq(errno, errnum); - // src/common/file.c:440 + // src/common/file.c ERR_W_ERRNO("flock \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:469 + // src/common/file.c ERR_W_ERRNO("open \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:474 + // src/common/file.c ERR_W_ERRNO("flock \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/file.c:507 + // src/common/file.c ERR_W_ERRNO("flock unlock"); UT_ASSERTeq(errno, errnum); - // src/common/file.c:94 + // src/common/file.c ERR_W_ERRNO("fstat"); UT_ASSERTeq(errno, errnum); - // src/common/file_posix.c:158 + // src/common/file_posix.c ERR_W_ERRNO("stat \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:104 + // src/common/mmap.c ERR_W_ERRNO("mmap %zu bytes", _zu); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:126 + // src/common/mmap.c ERR_W_ERRNO("munmap"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:155 + // src/common/mmap.c ERR_W_ERRNO("mprotect: PROT_READ"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:184 + // src/common/mmap.c ERR_W_ERRNO("mprotect: PROT_READ|PROT_WRITE"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:213 + // src/common/mmap.c ERR_W_ERRNO("mprotect: PROT_NONE"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:297 + // src/common/mmap.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:360 + // src/common/mmap.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/mmap.c:375 + // src/common/mmap.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/mmap_posix.c:141 + // src/common/mmap_posix.c ERR_W_ERRNO("mmap MAP_ANONYMOUS"); UT_ASSERTeq(errno, errnum); - // src/common/mmap_posix.c:43 + // src/common/mmap_posix.c ERR_W_ERRNO("%s", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1027 + // src/common/set.c ERR_W_ERRNO("fs_new: \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1060 + // src/common/set.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1139 + // src/common/set.c ERR_W_ERRNO("no directories in replica"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1156 + // src/common/set.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1196 + // src/common/set.c ERR_W_ERRNO("lseek %d", _d); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1202 + // src/common/set.c ERR_W_ERRNO("dup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1208 + // src/common/set.c ERR_W_ERRNO("fdopen %d", _d); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1219 + // src/common/set.c ERR_W_ERRNO("Reading poolset file"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1226 + // src/common/set.c ERR_W_ERRNO("Malloc for pool set"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1232 + // src/common/set.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1404 + // src/common/set.c ERR_W_ERRNO("Malloc for pool set"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1410 + // src/common/set.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1419 + // src/common/set.c ERR_W_ERRNO("Malloc for pool set replica"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1503 + // src/common/set.c ERR_W_ERRNO("posix_fallocate \"%s\", %zu", _s, _zu); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1573 + // src/common/set.c ERR_W_ERRNO("open: path \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1632 + // src/common/set.c ERR_W_ERRNO("read %d", _d); UT_ASSERTeq(errno, errnum); - // src/common/set.c:1756 + // src/common/set.c ERR_W_ERRNO("fstat"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:195 + // src/common/set.c ERR_W_ERRNO("mmap: %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:2212 + // src/common/set.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:252 + // src/common/set.c ERR_W_ERRNO("mmap: %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:283 + // src/common/set.c ERR_W_ERRNO("munmap: %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:3013 + // src/common/set.c ERR_W_ERRNO("no parts in replicas"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:3144 + // src/common/set.c ERR_W_ERRNO("read"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:3208 + // src/common/set.c ERR_W_ERRNO("open: path \"%s\"", _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:369 + // src/common/set.c ERR_W_ERRNO("unlink %s failed (part %u, replica %u)", _s, _u, _u); UT_ASSERTeq(errno, errnum); - // src/common/set.c:422 + // src/common/set.c ERR_W_ERRNO("fstat %d %s", _d, _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:435 + // src/common/set.c ERR_W_ERRNO("chmod %u/%u/%s", _u, _u, _s); UT_ASSERTeq(errno, errnum); - // src/common/set.c:518 + // src/common/set.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:622 + // src/common/set.c ERR_W_ERRNO("Strdup"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:648 + // src/common/set.c ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:841 + // src/common/set.c ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/set.c:849 + // src/common/set.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/set_badblocks.c:171 + // src/common/set_badblocks.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/common/shutdown_state.c:95 + // src/common/shutdown_state.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/common/vec.h:62 + // src/common/vec.h ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/common/vecq.h:68 + // src/common/vecq.h ERR_W_ERRNO("Realloc"); UT_ASSERTeq(errno, errnum); - // src/core/out.c:104 + // src/core/out.c ERR_W_ERRNO("snprintf"); UT_ASSERTeq(errno, errnum); - // src/core/ravl.c:167 + // src/core/ravl.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/core/ravl.c:51 + // src/core/ravl.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:181 + // src/core/sys_util.h ERR_W_ERRNO("os_spin_init"); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:138 + // src/core/util_posix.c ERR_W_ERRNO("open"); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:49 + // src/core/util_posix.c ERR_W_ERRNO("stat failed for %s", _s); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:59 + // src/core/util_posix.c ERR_W_ERRNO("stat failed for %s", _s); UT_ASSERTeq(errno, errnum); - // src/core/util_posix.c:99 + // src/core/util_posix.c ERR_W_ERRNO("mkstemp"); UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:280 + // src/libpmem/pmem.c ERR_W_ERRNO("msync"); UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:487 + // src/libpmem/pmem.c ERR_W_ERRNO("open %s", _s); UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:500 + // src/libpmem/pmem.c ERR_W_ERRNO("ftruncate"); UT_ASSERTeq(errno, errnum); - // src/libpmem/pmem.c:506 + // src/libpmem/pmem.c ERR_W_ERRNO("posix_fallocate"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/critnib.c:279 + // src/libpmemobj/critnib.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/critnib.c:316 + // src/libpmemobj/critnib.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/heap.c:187 + // src/libpmemobj/heap.c ERR_W_ERRNO("heap: arena malloc error"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:267 + // src/libpmemobj/lane.c ERR_W_ERRNO("Malloc of volatile lanes"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:276 + // src/libpmemobj/lane.c ERR_W_ERRNO("Malloc for lane locks"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:289 + // src/libpmemobj/lane.c ERR_W_ERRNO("lane_init"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/list.c:473 + // src/libpmemobj/list.c ERR_W_ERRNO("palloc_reserve"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:116 + // src/libpmemobj/memops.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:177 + // src/libpmemobj/memops.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/memops.c:90 + // src/libpmemobj/memops.c ERR_W_ERRNO("Zalloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:662 + // src/libpmemobj/obj.c ERR_W_ERRNO("lane_boot"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:667 + // src/libpmemobj/obj.c ERR_W_ERRNO("lane_recover_and_section_boot"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:725 + // src/libpmemobj/obj.c ERR_W_ERRNO("palloc_init"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:964 + // src/libpmemobj/obj.c ERR_W_ERRNO("critnib_insert to pools_ht"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:969 + // src/libpmemobj/obj.c ERR_W_ERRNO("critnib_insert to pools_tree"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:984 + // src/libpmemobj/obj.c ERR_W_ERRNO("ravl_new_sized"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/stats.c:124 + // src/libpmemobj/stats.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:499 + // src/libpmemobj/tx.c ERR_W_ERRNO("pmemobj_mutex_lock"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:508 + // src/libpmemobj/tx.c ERR_W_ERRNO("pmemobj_rwlock_wrlock"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:776 + // src/libpmemobj/tx.c ERR_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:945 + // src/libpmemobj/tx.c ERR_W_ERRNO("explicit transaction abort"); UT_ASSERTeq(errno, errnum); } @@ -1105,7 +1105,7 @@ void call_all_CORE_LOG_WARNING_W_ERRNO(int errnum) { errno = errnum; - // src/common/set.c:2955 + // src/common/set.c CORE_LOG_WARNING_W_ERRNO("cannot open the part -- \"%s\"", _s); UT_ASSERTeq(errno, errnum); } @@ -1114,25 +1114,25 @@ void call_all_CORE_LOG_ERROR_W_ERRNO(int errnum) { errno = errnum; - // src/common/os_deep_linux.c:156 + // src/common/os_deep_linux.c CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); UT_ASSERTeq(errno, errnum); - // src/common/os_deep_linux.c:38 + // src/common/os_deep_linux.c CORE_LOG_ERROR_W_ERRNO("deep_flush not supported"); UT_ASSERTeq(errno, errnum); - // src/common/uuid_linux.c:31 + // src/common/uuid_linux.c CORE_LOG_ERROR_W_ERRNO("open(uuid)"); UT_ASSERTeq(errno, errnum); - // src/common/uuid_linux.c:37 + // src/common/uuid_linux.c CORE_LOG_ERROR_W_ERRNO("read(uuid)"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:1189 + // src/libpmemobj/obj.c CORE_LOG_ERROR_W_ERRNO("lane_check"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:1198 + // src/libpmemobj/obj.c CORE_LOG_ERROR_W_ERRNO("heap_check"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:90 + // src/libpmemobj/obj.c CORE_LOG_ERROR_W_ERRNO("ctl_new"); UT_ASSERTeq(errno, errnum); } @@ -1141,106 +1141,106 @@ void call_all_CORE_LOG_FATAL_W_ERRNO(int errnum) { errno = errnum; - // src/common/set.c:221 + // src/common/set.c CORE_LOG_FATAL_W_ERRNO("munmap: %s", _s); UT_ASSERTeq(errno, errnum); - // src/common/util_pmem.h:30 + // src/common/util_pmem.h CORE_LOG_FATAL_W_ERRNO("pmem_msync"); UT_ASSERTeq(errno, errnum); - // src/core/last_error_msg.c:37 + // src/core/last_error_msg.c CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); UT_ASSERTeq(errno, errnum); - // src/core/last_error_msg.c:78 + // src/core/last_error_msg.c CORE_LOG_FATAL_W_ERRNO("os_tls_set"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:108 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_rwlock_init"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:123 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_rwlock_rdlock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:138 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_rwlock_wrlock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:153 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_rwlock_unlock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:168 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_rwlock_destroy"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:197 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_spin_destroy"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:211 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_spin_lock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:226 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_spin_unlock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:239 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_semaphore_init"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:249 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_semaphore_destroy"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:266 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_semaphore_wait"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:282 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_semaphore_trywait"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:294 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_semaphore_post"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:301 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_cond_init"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:308 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_cond_destroy"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:31 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:46 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:61 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:77 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); UT_ASSERTeq(errno, errnum); - // src/core/sys_util.h:93 + // src/core/sys_util.h CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:105 + // src/libpmemobj/lane.c CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/lane.c:80 + // src/libpmemobj/lane.c CORE_LOG_FATAL_W_ERRNO("os_tls_set"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:148 + // src/libpmemobj/obj.c CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:156 + // src/libpmemobj/obj.c CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/obj.c:252 + // src/libpmemobj/obj.c CORE_LOG_FATAL_W_ERRNO("pmem_msync"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/sync.h:102 + // src/libpmemobj/sync.h CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/sync.h:87 + // src/libpmemobj/sync.h CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:272 + // src/libpmemobj/tx.c CORE_LOG_FATAL_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:284 + // src/libpmemobj/tx.c CORE_LOG_FATAL_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); - // src/libpmemobj/tx.c:321 + // src/libpmemobj/tx.c CORE_LOG_FATAL_W_ERRNO("Malloc"); UT_ASSERTeq(errno, errnum); } diff --git a/utils/call_stacks_analysis/log_call_all_generate.py b/utils/call_stacks_analysis/log_call_all_generate.py index 1a9d918f0bd..d4a2b7924d1 100755 --- a/utils/call_stacks_analysis/log_call_all_generate.py +++ b/utils/call_stacks_analysis/log_call_all_generate.py @@ -116,7 +116,7 @@ def extract_all_calls(func: str) -> List[Dict]: code = extract_append_code(file, int(line_no), code) call = { 'file': file, - 'line': line_no, + 'line_no': line_no, 'code': code } calls.append(call) @@ -124,7 +124,7 @@ def extract_all_calls(func: str) -> List[Dict]: bad_line('An unexpected line format', line) # sort calls by file and line def key_func(a: Dict) -> str: - return a['file'] + a['line'] + return a['file'] + a['line_no'] calls.sort(key=key_func) print(f'[{func}] total: {total}, included: {len(calls)}') return calls @@ -369,7 +369,7 @@ def generate_call(file, func: str, call: Dict) -> str: args = ', ' + ', '.join(call['args']) else: args = '' - file.write(f'\t// src/{call["file"]}:{call["line"]}\n') + file.write(f'\t// src/{call["file"]}\n') file.write(f'\t{func}("{call["format_string"]}"{args});\n') def generate_func_with_errno(func: str, calls: List[Dict]) -> None: From bbe8082b3cfa46ca34b171266b850ec9d0fe3280 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 27 Feb 2024 18:12:35 +0100 Subject: [PATCH 108/182] common: remove core_log_to_last (#6030) common: replace core_log_to_last() by core_log w/ new level Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 42 ++++++++++------------------ src/core/log_internal.h | 11 ++++---- src/test/core_log_max/core_log_max.c | 35 ++++++++--------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index d6071476d35..6f440020ebc 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -214,16 +214,13 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, if (msg_len < 0) goto end; - if (errnum != NO_ERRNO) { + if ((size_t)msg_len < buf_len - 1 && errnum != NO_ERRNO) { + /* + * Ask for the error string right after the already printed + * message. + */ char *msg_ptr = buf + msg_len; size_t buf_len_left = buf_len - (size_t)msg_len; - - /* Check if the longest possible error string can fit */ - if (buf_len_left < _CORE_LOG_MAX_ERRNO_MSG) { - goto end; - } - - /* Ask for the error string */ /* * If it fails, the best thing to do is to at least pass * the log message as is. @@ -236,13 +233,11 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, * the CORE_LOG() macro it has to be done here again since it is not * performed in the case of the CORE_LOG_TO_LAST macro. Sorry. */ - if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) { + if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) goto end; - } - if (0 == Core_log_function) { + if (0 == Core_log_function) goto end; - } ((core_log_function *)Core_log_function)(Core_log_function_context, level, file_name, line_no, function_name, buf); @@ -257,24 +252,17 @@ core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...) { char message[_CORE_LOG_MSG_MAXPRINT] = ""; - va_list arg; - - va_start(arg, message_format); - core_log_va(message, sizeof(message), level, errnum, file_name, - line_no, function_name, message_format, arg); - va_end(arg); -} + char *buf = message; + size_t buf_len = sizeof(message); + if (level == CORE_LOG_LEVEL_ERROR_LAST) { + level = CORE_LOG_LEVEL_ERROR; + buf = (char *)last_error_msg_get(); + buf_len = CORE_LAST_ERROR_MSG_MAXPRINT; + } -void -core_log_to_last(int errnum, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...) -{ - char *last_error = (char *)last_error_msg_get(); va_list arg; - va_start(arg, message_format); - core_log_va(last_error, CORE_LAST_ERROR_MSG_MAXPRINT, - CORE_LOG_LEVEL_ERROR, errnum, file_name, line_no, + core_log_va(buf, buf_len, level, errnum, file_name, line_no, function_name, message_format, arg); va_end(arg); } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 1720b4fc656..8f78558426a 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -39,6 +39,9 @@ enum core_log_level { CORE_LOG_LEVEL_MAX }; +#define CORE_LOG_LEVEL_ERROR_LAST ((enum core_log_level) \ + (CORE_LOG_LEVEL_ERROR + CORE_LOG_LEVEL_MAX)) + enum core_log_threshold { /* * the main threshold level - the logging messages above this level @@ -130,10 +133,6 @@ void core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...); -/* Only error messages can last. So, no level has to be specified. */ -void core_log_to_last(int errnum, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...); - #define _CORE_LOG(level, errnum, format, ...) \ do { \ if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ @@ -147,8 +146,8 @@ void core_log_to_last(int errnum, const char *file_name, int line_no, * Since the log message has to be generated anyway. */ #define CORE_LOG_TO_LAST(errnum, format, ...) \ - core_log_to_last(errnum, __FILE__, __LINE__, __func__, \ - format, ##__VA_ARGS__) + core_log(CORE_LOG_LEVEL_ERROR_LAST, errnum, __FILE__, __LINE__, \ + __func__, format, ##__VA_ARGS__) /* The value fine-tuned to accommodate all possible errno message strings. */ #define _CORE_LOG_MAX_ERRNO_MSG 50 diff --git a/src/test/core_log_max/core_log_max.c b/src/test/core_log_max/core_log_max.c index 2037479ad04..c1dcc2875ca 100644 --- a/src/test/core_log_max/core_log_max.c +++ b/src/test/core_log_max/core_log_max.c @@ -101,26 +101,6 @@ static int Total_TLS_message_num; */ #define TOTAL_TLS_MESSAGE_NUM_EXPECTED 311 -FUNC_MOCK(core_log_to_last, void, int errnum, const char *file_name, - int line_no, const char *function_name, const char *message_format, ...) - FUNC_MOCK_RUN_DEFAULT { - char buf[BIG_BUF_SIZE] = ""; - va_list arg; - va_start(arg, message_format); - int ret = vsnprintf(buf, BIG_BUF_SIZE, message_format, arg); - UT_ASSERT(ret > 0); - UT_ASSERTeq(ret, strlen(buf)); - if (errnum != NO_ERRNO) - ret += _CORE_LOG_MAX_ERRNO_MSG; - if (ret > Max_TLS_message_len) { - Max_TLS_message_len = ret; - strncpy(The_longest_TLS_message, buf, BIG_BUF_SIZE); - } - ++Total_TLS_message_num; - return; - } -FUNC_MOCK_END - static int test_ERR_W_ERRNO(const struct test_case *tc, int argc, char *argv[]) { @@ -157,11 +137,20 @@ FUNC_MOCK(core_log, void, enum core_log_level level, int errnum, if (errnum != NO_ERRNO) ret += _CORE_LOG_MAX_ERRNO_MSG; - if (ret > Max_message_len) { - Max_message_len = ret; + if (level == CORE_LOG_LEVEL_ERROR_LAST) { + if (ret > Max_TLS_message_len) { + Max_TLS_message_len = ret; + strncpy(The_longest_TLS_message, buf, + BIG_BUF_SIZE); + } + ++Total_TLS_message_num; + } else { + if (ret > Max_message_len) { + Max_message_len = ret; strncpy(The_longest_message, buf, BIG_BUF_SIZE); + } + ++Total_message_num; } - ++Total_message_num; return; } FUNC_MOCK_END From 212969390a0fa1bd511e518f16737f173d258d87 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 15:29:32 +0100 Subject: [PATCH 109/182] common: disable out_* functions in release build Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 22 +++++++++++----------- src/core/out.h | 2 -- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index d1b9785c9e2..9773b8667b3 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -22,6 +22,8 @@ #include "log_internal.h" #include "last_error_msg.h" +#ifdef DEBUG + #define MAXPRINT 8192 static const char *Log_prefix; @@ -29,7 +31,6 @@ static int Log_level; static FILE *Out_fp; static unsigned Log_alignment; -#ifdef DEBUG static const enum core_log_level level_to_core_log_level[5] = { [0] = CORE_LOG_LEVEL_HARK, [1] = CORE_LOG_LEVEL_ERROR, @@ -72,7 +73,8 @@ out_init(const char *log_prefix, const char *log_level_var, int minor_version) { /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(log_level_var, log_file_var); + SUPPRESS_UNUSED(log_prefix, log_level_var, log_file_var, major_version, + minor_version); static int once; @@ -81,6 +83,7 @@ out_init(const char *log_prefix, const char *log_level_var, return; once++; +#ifdef DEBUG Log_prefix = log_prefix; char *log_alignment = os_getenv("PMDK_LOG_ALIGN"); @@ -90,7 +93,6 @@ out_init(const char *log_prefix, const char *log_level_var, Log_alignment = (unsigned)align; } -#ifdef DEBUG char *log_file; if ((log_file = os_getenv(log_file_var)) != NULL && log_file[0] != '\0') { @@ -116,14 +118,12 @@ out_init(const char *log_prefix, const char *log_level_var, abort(); } } -#endif /* DEBUG */ if (Out_fp == NULL) Out_fp = stderr; else setlinebuf(Out_fp); -#ifdef DEBUG char *log_level; int log_level_cropped = 0; int ret; @@ -154,16 +154,12 @@ out_init(const char *log_prefix, const char *log_level_var, CORE_LOG_FATAL("Cannot set legacy log function"); } } -#endif /* DEBUG */ - /* * Print library info */ -#ifdef DEBUG static char namepath[PATH_MAX]; CORE_LOG_HARK("pid %d: program: %s", getpid(), util_getexecname(namepath, PATH_MAX)); -#endif /* DEBUG */ CORE_LOG_HARK("%s version %d.%d", log_prefix, major_version, minor_version); @@ -192,7 +188,7 @@ out_init(const char *log_prefix, const char *log_level_var, "compiled with support for Valgrind drd"; CORE_LOG_HARK("%s", drd_msg); #endif /* VG_DRD_ENABLED */ - +#endif /* DEBUG */ last_error_msg_init(); } @@ -204,12 +200,15 @@ out_init(const char *log_prefix, const char *log_level_var, void out_fini(void) { +#ifdef DEBUG if (Out_fp != NULL && Out_fp != stderr) { fclose(Out_fp); Out_fp = stderr; } +#endif } +#ifdef DEBUG /* * out_print_func -- print function, goes to Out_fp (stderr by default) */ @@ -303,7 +302,7 @@ out_common(const char *file, int line, const char *func, int level, /* * out_log_va/out_log -- output a log line if Log_level >= level */ -void +static void out_log_va(const char *file, int line, const char *func, int level, const char *fmt, va_list ap) { @@ -323,3 +322,4 @@ out_log(const char *file, int line, const char *func, int level, va_end(ap); } +#endif /* DEBUG */ diff --git a/src/core/out.h b/src/core/out.h index 6a1f089261a..772d927aece 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -68,8 +68,6 @@ void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version); void out_fini(void); -void out_log_va(const char *file, int line, const char *func, int level, - const char *fmt, va_list ap); void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); From ad664ffc7a7efdf6fba793442d7dc81df7c7a195 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 28 Feb 2024 10:09:20 +0100 Subject: [PATCH 110/182] test: fix util_poolset test to work w/o ndctl Signed-off-by: Tomasz Gromadzki --- src/test/util_poolset/grep7.log.match | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/util_poolset/grep7.log.match b/src/test/util_poolset/grep7.log.match index b89d04ba9fb..c6a96c6a44f 100644 --- a/src/test/util_poolset/grep7.log.match +++ b/src/test/util_poolset/grep7.log.match @@ -3,9 +3,6 @@ $(OPT)compiled with support for shutdown state $(OPT)compiled with libndctl 63+ pid $(N): program: $(nW)util_poolset$(nW) ut version 1.0 -src version: $(nW) -$(OPT)compiled with support for shutdown state -$(OPT)compiled with libndctl 63+ the NOHDRS poolset option is not supported for local poolsets the NOHDRS poolset option is not supported for local poolsets the NOHDRS poolset option is not supported for local poolsets From 13c1deca7e4598ba8f5f338dec1b96528128aef8 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 28 Feb 2024 10:34:49 +0100 Subject: [PATCH 111/182] test: fix test for non-ndctl build Signed-off-by: Tomasz Gromadzki --- src/test/arch_flags/log0.log.match | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/arch_flags/log0.log.match b/src/test/arch_flags/log0.log.match index bb87a7f820b..f55300c8a02 100644 --- a/src/test/arch_flags/log0.log.match +++ b/src/test/arch_flags/log0.log.match @@ -3,7 +3,6 @@ $(OPT): <1> [$(*)]$(W)compiled with support for shutdown state $(OPT): <1> [$(*)]$(W)compiled with libndctl 63+ : <1> [$(*)]$(W)pid $(nW): program: $(nW) : <1> [$(*)]$(W)arch_flags version 0.0 -: <1> [$(*)]$(W)src version: $(nW) $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind pmemcheck $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind helgrind $(OPT): <1> [$(*)]$(W)compiled with support for Valgrind memcheck From abcccfdb8128a15ed2f5e6d9d08b744b97789033 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 23 Feb 2024 08:48:13 +0100 Subject: [PATCH 112/182] common: an option to run all tests from command line (debbuger) Signed-off-by: Tomasz Gromadzki --- src/test/unittest/unittest.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index a162667bb17..f865c2d07cc 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -624,6 +624,16 @@ TEST_CASE_PROCESS(int argc, char *argv[], if (argc < 2) UT_FATAL("usage: %s []", argv[0]); + if (strcmp("ALL", argv[1]) == 0) { + for (size_t i = 0; i < ntests; i++) { + int ret = test_cases[i].func(&test_cases[i], 0, NULL); + if (ret < 0) + UT_FATAL("Test %s return negative result", + test_cases[i].name); + } + return; + } + for (int i = 1; i < argc; i++) { char *str_test = argv[i]; const int args_off = i + 1; From 4f686a8c4534ab999e3996e38dd0a15934ae435b Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 27 Feb 2024 16:52:19 +0100 Subject: [PATCH 113/182] common: CORE_LOG_* macros UT implementation Signed-off-by: Tomasz Gromadzki --- src/test/Makefile | 1 + src/test/core_log_internal/.gitignore | 1 + src/test/core_log_internal/Makefile | 14 + src/test/core_log_internal/TESTS.py | 41 +++ .../core_log_internal/core_log_internal.c | 260 ++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 src/test/core_log_internal/.gitignore create mode 100644 src/test/core_log_internal/Makefile create mode 100755 src/test/core_log_internal/TESTS.py create mode 100644 src/test/core_log_internal/core_log_internal.c diff --git a/src/test/Makefile b/src/test/Makefile index d6e982904de..748d9fd6259 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -108,6 +108,7 @@ OBJ_TESTS = \ OTHER_TESTS = \ arch_flags\ + core_log_internal\ core_log_max\ checksum\ compat_incompat_features\ diff --git a/src/test/core_log_internal/.gitignore b/src/test/core_log_internal/.gitignore new file mode 100644 index 00000000000..69ac3b5a5ea --- /dev/null +++ b/src/test/core_log_internal/.gitignore @@ -0,0 +1 @@ +core_log_internal diff --git a/src/test/core_log_internal/Makefile b/src/test/core_log_internal/Makefile new file mode 100644 index 00000000000..221ebfd1f7b --- /dev/null +++ b/src/test/core_log_internal/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log_internal +OBJS = core_log_internal.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# `internal` is required for proper mock integration +LIBPMEMCORE=internal-nondebug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, core_log_internal.c) diff --git a/src/test/core_log_internal/TESTS.py b/src/test/core_log_internal/TESTS.py new file mode 100755 index 00000000000..a5c4706409d --- /dev/null +++ b/src/test/core_log_internal/TESTS.py @@ -0,0 +1,41 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +class CORE_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log_internal', self.test_case) + + +class TEST0(CORE_LOG): + test_case = 'test_CORE_LOG' + + +class TEST1(CORE_LOG): + test_case = 'test_CORE_LOG_ERROR_LAST' + + +class TEST2(CORE_LOG): + test_case = 'test_CORE_LOG_ERROR_W_ERRNO_LAST' + + +class TEST3(CORE_LOG): + test_case = 'test_CORE_LOG_W_ERRNO' + + +class TEST4(CORE_LOG): + test_case = 'test_CORE_LOG_TRESHOLD' + + +@t.require_build('nondebug') +class TEST5(CORE_LOG): + test_case = 'test_CORE_LOG_TRESHOLD_DEFAULT' diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c new file mode 100644 index 00000000000..67220f4ff4f --- /dev/null +++ b/src/test/core_log_internal/core_log_internal.c @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_internal.c -- unit test to CORE_LOG_... + */ + +#undef _GNU_SOURCE +#include +#include + +#include "unittest.h" +#include "log_internal.h" +#include "last_error_msg.h" + +#define NO_ARGS_CONSUMED 0 + +/* + * Prevent abort() from CORE_LOG_FATAL() + * Use mock_abort() instead. + * Use mock_abort() mock to monitor usage of abort() function + * inside CORE_LOG_FATAL(); + */ +#define abort() mock_abort() +void mock_abort(void); + +/* mock_abort() - mock for abort() function in CORE_LOG_FATAL() */ +static int Mock_abort_no_of_calls = 0; + +void +mock_abort(void) +{ + Mock_abort_no_of_calls++; +} + +/* core_log() - mock */ +static int Core_log_no_of_calls = 0; +static struct { + int initialized; + enum core_log_level level; + int errnum; + const char *file_name; + int line_no; + const char *function_name; + const char *message_format; +} Core_log_context; + +FUNC_MOCK(core_log, void, enum core_log_level level, int errnum, + const char *file_name, int line_no, const char *function_name, + const char *message_format, ...) +FUNC_MOCK_RUN_DEFAULT { + Core_log_no_of_calls++; + if (Core_log_context.initialized) { + UT_ASSERTeq(Core_log_context.level, level); + UT_ASSERTeq(Core_log_context.errnum, errnum); + UT_ASSERTeq(strcmp(Core_log_context.file_name, file_name), 0); + UT_ASSERTeq(Core_log_context.line_no, line_no); + UT_ASSERTeq(strcmp(Core_log_context.function_name, + function_name), 0); + UT_ASSERTeq(strcmp(Core_log_context.message_format, + message_format), 0); + } +} +FUNC_MOCK_END + +static enum core_log_level Core_log_default_threshold; + +#define CORE_LOG_UT_MESSAGE "Test message long 20Test message long 40" \ + "Test message long 60Test message long 80Test message long100" \ + "Test message long120Test message long140Test message long160" \ + "Test message long180Test message long200Test message long220" \ + "Test message long240Test message long260Test message long280" \ + "Test message long300Test message long320Test message long340" \ + "Test message long360Test message long380Test message long400 407" + +#define TEST_SETUP(MESSAGE_TO_TEST) \ + core_log_set_threshold(CORE_LOG_THRESHOLD, \ + Core_log_default_threshold); \ + Mock_abort_no_of_calls = 0; \ + Core_log_context.file_name = __FILE__; \ + Core_log_context.function_name = __func__; \ + Core_log_context.message_format = MESSAGE_TO_TEST; \ + Core_log_context.errnum = NO_ERRNO; \ + Core_log_context.initialized = 1 + +#define CORE_LOG_(LEVEL) CORE_LOG_##LEVEL +#define CORE_LOG_W_ERRNO_(LEVEL) CORE_LOG_##LEVEL##_W_ERRNO + +#define TEST_STEP_SETUP(LEVEL) \ + Core_log_context.level = CORE_LOG_LEVEL_##LEVEL; \ + Core_log_no_of_calls = 0; \ + Core_log_context.line_no = __LINE__ + +#define TEST_STEP(LEVEL, PASS) \ + TEST_STEP_SETUP(LEVEL); \ + CORE_LOG_(LEVEL)(CORE_LOG_UT_MESSAGE); \ + UT_ASSERTeq(Core_log_no_of_calls, PASS) + +#define TEST_STEP_W_ERRNO(LEVEL, ERRNUM) \ + TEST_STEP_SETUP(LEVEL); \ + Core_log_context.errnum = ERRNUM; \ + CORE_LOG_W_ERRNO_(LEVEL) (CORE_LOG_UT_MESSAGE) + +/* tests CORE_LOG_... with default threshold */ +static int +test_CORE_LOG(const struct test_case *tc, int argc, char *argv[]) +{ + TEST_SETUP(CORE_LOG_UT_MESSAGE); + TEST_STEP(HARK, 1); + UT_ASSERTeq(Mock_abort_no_of_calls, 0); + TEST_STEP(FATAL, 1); + UT_ASSERTeq(Mock_abort_no_of_calls, 1); + Mock_abort_no_of_calls = 0; + TEST_STEP(ERROR, 1); + TEST_STEP(WARNING, 1); + TEST_STEP(NOTICE, 0); + TEST_STEP(INFO, 0); + TEST_STEP(DEBUG, 0); + UT_ASSERTeq(Mock_abort_no_of_calls, 0); + return NO_ARGS_CONSUMED; +} + +/* Test for CORE_LOG_ERROR_LAST() */ +static int +test_CORE_LOG_ERROR_LAST(const struct test_case *tc, int argc, + char *argv[]) +{ + TEST_SETUP(CORE_LOG_UT_MESSAGE); + Core_log_no_of_calls = 0; + Core_log_context.level = CORE_LOG_LEVEL_ERROR_LAST; + Core_log_context.line_no = __LINE__ + 1; + CORE_LOG_ERROR_LAST(CORE_LOG_UT_MESSAGE); + UT_ASSERTeq(Core_log_no_of_calls, 1); + return NO_ARGS_CONSUMED; +} + +#define DUMMY_ERRNO 0xf00d + +/* Test for CORE_LOG_ERROR_W_ERRNO_LAST() w/ errno */ +static int +test_CORE_LOG_ERROR_W_ERRNO_LAST(const struct test_case *tc, int argc, \ + char *argv[]) +{ + TEST_SETUP(CORE_LOG_UT_MESSAGE ": "); + errno = DUMMY_ERRNO; + Core_log_no_of_calls = 0; + Core_log_context.errnum = DUMMY_ERRNO; + Core_log_context.level = CORE_LOG_LEVEL_ERROR_LAST; + Core_log_context.line_no = __LINE__ + 1; + CORE_LOG_ERROR_W_ERRNO_LAST(CORE_LOG_UT_MESSAGE); + UT_ASSERTeq(errno, DUMMY_ERRNO); + UT_ASSERTeq(Core_log_no_of_calls, 1); + errno = 0; + return NO_ARGS_CONSUMED; +} + +/* Test all macros that pass errno */ +static int +test_CORE_LOG_W_ERRNO(const struct test_case *tc, + int argc, char *argv[]) +{ + int errnum = DUMMY_ERRNO; + TEST_SETUP(CORE_LOG_UT_MESSAGE ": "); + Mock_abort_no_of_calls = 0; + errno = errnum; + TEST_STEP_W_ERRNO(FATAL, errnum); + UT_ASSERTeq(Mock_abort_no_of_calls, 1); + UT_ASSERTeq(errno, errnum); + errno = ++errnum; + TEST_STEP_W_ERRNO(ERROR, errnum); + UT_ASSERTeq(errno, errnum); + errno = ++errnum; + TEST_STEP_W_ERRNO(WARNING, errnum); + UT_ASSERTeq(errno, errnum); + UT_ASSERTeq(Mock_abort_no_of_calls, 1); + errno = 0; + return NO_ARGS_CONSUMED; +} + +#define CORE_LOG_TRESHOLD_STEP(LEVEL, ABORT_NO_OF_CALL, CORE_LOG_NO_OF_CALL) \ + do { \ + TEST_STEP_SETUP(LEVEL); \ + Mock_abort_no_of_calls = 0; \ + CORE_LOG_(LEVEL)(CORE_LOG_UT_MESSAGE); \ + UT_ASSERTeq(Mock_abort_no_of_calls, ABORT_NO_OF_CALL); \ + UT_ASSERTeq(Core_log_no_of_calls, CORE_LOG_NO_OF_CALL); \ + } while (0) + +#define CORE_LOG_TRESHOLD_STEP_ALL(HARK_PASS, FATAL_PASS, ERROR_PASS, \ + WARNING_PASS, NOTICE_PASS, INFO_PASS, DEBUG_PASS) \ + Mock_abort_no_of_calls = 0; \ + CORE_LOG_TRESHOLD_STEP(HARK, 0, HARK_PASS); \ + CORE_LOG_TRESHOLD_STEP(FATAL, 1, FATAL_PASS); \ + Mock_abort_no_of_calls = 0; \ + CORE_LOG_TRESHOLD_STEP(ERROR, 0, ERROR_PASS); \ + CORE_LOG_TRESHOLD_STEP(WARNING, 0, WARNING_PASS); \ + CORE_LOG_TRESHOLD_STEP(NOTICE, 0, NOTICE_PASS); \ + CORE_LOG_TRESHOLD_STEP(INFO, 0, INFO_PASS); \ + CORE_LOG_TRESHOLD_STEP(DEBUG, 0, DEBUG_PASS) + +/* Test all possible tresholds */ +static int +test_CORE_LOG_TRESHOLD(const struct test_case *tc, int argc, char *argv[]) +{ + TEST_SETUP(CORE_LOG_UT_MESSAGE); + Mock_abort_no_of_calls = 0; + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_HARK); + CORE_LOG_TRESHOLD_STEP_ALL(1, 0, 0, 0, 0, 0, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_FATAL); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 0, 0, 0, 0, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 1, 0, 0, 0, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_WARNING); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 1, 1, 0, 0, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_NOTICE); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 1, 1, 1, 0, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_INFO); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 1, 1, 1, 1, 0); + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_DEBUG); + CORE_LOG_TRESHOLD_STEP_ALL(1, 1, 1, 1, 1, 1, 1); + return NO_ARGS_CONSUMED; +} + +/* Validate the default threshold of the release build (no DEBUG set). */ +static int +test_CORE_LOG_TRESHOLD_DEFAULT(const struct test_case *tc, int argc, + char *argv[]) +{ + UT_ASSERTeq(Core_log_default_threshold, CORE_LOG_LEVEL_WARNING); + return NO_ARGS_CONSUMED; +} + +static struct test_case test_cases[] = { + TEST_CASE(test_CORE_LOG), + TEST_CASE(test_CORE_LOG_ERROR_LAST), + TEST_CASE(test_CORE_LOG_ERROR_W_ERRNO_LAST), + TEST_CASE(test_CORE_LOG_W_ERRNO), + TEST_CASE(test_CORE_LOG_TRESHOLD), + TEST_CASE(test_CORE_LOG_TRESHOLD_DEFAULT), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +/* Restore original abort() definition as it is defined in stdlib.h */ +#undef abort +extern void abort(void) __THROW __attribute__((__noreturn__)); + +#undef LOG_SET_PMEMCORE_FUNC +#define LOG_SET_PMEMCORE_FUNC + +int +main(int argc, char *argv[]) +{ + core_log_get_threshold(CORE_LOG_THRESHOLD, &Core_log_default_threshold); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + + START(argc, argv, "core_log"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} From 106675cbaa563d3716713eced948edf3112148dc Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 1 Mar 2024 14:29:05 +0100 Subject: [PATCH 114/182] test: skip run tests for static builds Signed-off-by: Tomasz Gromadzki --- src/test/core_log_internal/TESTS.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/core_log_internal/TESTS.py b/src/test/core_log_internal/TESTS.py index a5c4706409d..5e179c3968f 100755 --- a/src/test/core_log_internal/TESTS.py +++ b/src/test/core_log_internal/TESTS.py @@ -9,6 +9,7 @@ @g.require_granularity(g.ANY) +@t.require_build('nondebug') class CORE_LOG(t.BaseTest): test_type = t.Short @@ -36,6 +37,5 @@ class TEST4(CORE_LOG): test_case = 'test_CORE_LOG_TRESHOLD' -@t.require_build('nondebug') class TEST5(CORE_LOG): test_case = 'test_CORE_LOG_TRESHOLD_DEFAULT' From 3e5569da8e03a4f3f617b3e2af00fe5f5a570d3c Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 4 Mar 2024 22:37:54 -0500 Subject: [PATCH 115/182] common: core_log_set/get_threshold MT unit tests Signed-off-by: Jan Michalski --- src/core/log.c | 27 ++------ src/test/Makefile | 1 + src/test/core_log_mt/.gitignore | 1 + src/test/core_log_mt/Makefile | 12 ++++ src/test/core_log_mt/TESTS.py | 45 +++++++++++++ src/test/core_log_mt/core_log_mt.c | 105 +++++++++++++++++++++++++++++ 6 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 src/test/core_log_mt/.gitignore create mode 100644 src/test/core_log_mt/Makefile create mode 100755 src/test/core_log_mt/TESTS.py create mode 100644 src/test/core_log_mt/core_log_mt.c diff --git a/src/core/log.c b/src/core/log.c index 6f440020ebc..b85c6555c33 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -57,9 +57,6 @@ _Atomic void *Core_log_function_context; /* threshold levels */ -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ enum core_log_level Core_log_threshold[] = { CORE_LOG_THRESHOLD_DEFAULT, CORE_LOG_THRESHOLD_AUX_DEFAULT @@ -114,6 +111,7 @@ core_log_lib_info(void) CORE_LOG_HARK("compiled with libndctl 63+"); #endif } + /* * core_log_set_function -- set the log function pointer either to * a user-provided function pointer or to the default logging function. @@ -164,21 +162,15 @@ core_log_set_threshold(enum core_log_threshold threshold, if (level < CORE_LOG_LEVEL_HARK || level > CORE_LOG_LEVEL_DEBUG) return EINVAL; -#ifdef ATOMIC_OPERATIONS_SUPPORTED - atomic_store_explicit(&Log_threshold[threshold], level, - __ATOMIC_SEQ_CST); - return 0; -#else enum core_log_level level_old; - while (EAGAIN == core_log_get_threshold(threshold, &level_old)) - ; + (void) core_log_get_threshold(threshold, &level_old); - if (__sync_bool_compare_and_swap(&Core_log_threshold[threshold], - level_old, level)) - return 0; - else + if (!__sync_bool_compare_and_swap(&Core_log_threshold[threshold], + level_old, level)) { return EAGAIN; -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ + } + + return 0; } /* @@ -195,12 +187,7 @@ core_log_get_threshold(enum core_log_threshold threshold, if (level == NULL) return EINVAL; -#ifdef ATOMIC_OPERATIONS_SUPPORTED - *level = atomic_load_explicit(&Log_threshold[threshold], - __ATOMIC_SEQ_CST); -#else *level = Core_log_threshold[threshold]; -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ return 0; } diff --git a/src/test/Makefile b/src/test/Makefile index 748d9fd6259..9f01ff92b41 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -110,6 +110,7 @@ OTHER_TESTS = \ arch_flags\ core_log_internal\ core_log_max\ + core_log_mt\ checksum\ compat_incompat_features\ ctl_prefault\ diff --git a/src/test/core_log_mt/.gitignore b/src/test/core_log_mt/.gitignore new file mode 100644 index 00000000000..806ac7ab750 --- /dev/null +++ b/src/test/core_log_mt/.gitignore @@ -0,0 +1 @@ +core_log_mt diff --git a/src/test/core_log_mt/Makefile b/src/test/core_log_mt/Makefile new file mode 100644 index 00000000000..8df2f390710 --- /dev/null +++ b/src/test/core_log_mt/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log_mt +OBJS = core_log_mt.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +LIBPMEMCORE=nondebug + +include ../Makefile.inc diff --git a/src/test/core_log_mt/TESTS.py b/src/test/core_log_mt/TESTS.py new file mode 100755 index 00000000000..13a2377e89f --- /dev/null +++ b/src/test/core_log_mt/TESTS.py @@ -0,0 +1,45 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +@t.require_build('nondebug') +class CORE_LOG_MT(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log_mt', self.test_case) + + +class THRESHOLD(CORE_LOG_MT): + test_case = 'test_threshold' + + +class THRESHOLD_AUX(CORE_LOG_MT): + test_case = 'test_threshold_aux' + + +@t.require_valgrind_enabled('helgrind') +class TEST0(THRESHOLD): + pass + + +@t.require_valgrind_enabled('drd') +class TEST1(THRESHOLD): + pass + + +@t.require_valgrind_enabled('helgrind') +class TEST2(THRESHOLD_AUX): + pass + + +@t.require_valgrind_enabled('drd') +class TEST3(THRESHOLD_AUX): + pass diff --git a/src/test/core_log_mt/core_log_mt.c b/src/test/core_log_mt/core_log_mt.c new file mode 100644 index 00000000000..c69e7b714fd --- /dev/null +++ b/src/test/core_log_mt/core_log_mt.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_internal.c -- unit test to CORE_LOG_... + */ + +#include "unittest.h" +#include "log_internal.h" + +#define NO_ARGS_CONSUMED 0 + +#define THREADS_IN_GROUP 10 +#define TOTAL_THREADS (THREADS_IN_GROUP * 2) +#define OP_REDO 4096 + +struct test_threshold_helper_ctx { + enum core_log_threshold threshold; + enum core_log_level level; +} threshold_helper_ [TOTAL_THREADS]; + +static void * +test_threshold_helper_set(void *arg) +{ + struct test_threshold_helper_ctx *ctx = + (struct test_threshold_helper_ctx *)arg; + for (int i = 0; i < OP_REDO; ++i) { + core_log_set_threshold(ctx->threshold, ctx->level); + } + return NULL; +} + +static void * +test_threshold_helper_get(void *arg) +{ + struct test_threshold_helper_ctx *ctx = + (struct test_threshold_helper_ctx *)arg; + for (int i = 0; i < OP_REDO; ++i) { + core_log_get_threshold(ctx->threshold, &ctx->level); + } + (void) ctx->level; + return NULL; +} + +static void +test_threshold_helper(enum core_log_threshold threshold) +{ + os_thread_t threads[TOTAL_THREADS]; + + /* core_log_set_threshold() threads */ + for (int idx = 0; idx < THREADS_IN_GROUP; idx++) { + threshold_helper_[idx].threshold = threshold; + threshold_helper_[idx].level = + (enum core_log_level)(idx % CORE_LOG_LEVEL_MAX); + THREAD_CREATE(&threads[idx], 0, test_threshold_helper_set, + (void *)&threshold_helper_[idx]); + } + + /* core_log_get_threshold() threads */ + for (int idx = THREADS_IN_GROUP; idx < TOTAL_THREADS; idx++) { + threshold_helper_[idx].threshold = threshold; + THREAD_CREATE(&threads[idx], 0, test_threshold_helper_get, + (void *)&threshold_helper_[idx]); + } + + for (int idx = 0; idx < TOTAL_THREADS; idx++) { + void *retval; + THREAD_JOIN(&threads[idx], &retval); + } +} + +/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD, ...) in parallel. */ +static int +test_threshold(const struct test_case *tc, int argc, char *argv[]) +{ + test_threshold_helper(CORE_LOG_THRESHOLD); + return NO_ARGS_CONSUMED; +} + +/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD_AUX, ...) in parallel. */ +static int +test_threshold_aux(const struct test_case *tc, int argc, char *argv[]) +{ + test_threshold_helper(CORE_LOG_THRESHOLD_AUX); + return NO_ARGS_CONSUMED; +} + +/* + * A Valgrind tool external to the test binary is assumed to monitor + * the execution and assess synchronisation correctness. + */ +static struct test_case test_cases[] = { + TEST_CASE(test_threshold), + TEST_CASE(test_threshold_aux), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log_mt"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} From bc31e53289e29bb40cdea51872bea0f3ceb66117 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 28 Feb 2024 19:45:37 +0100 Subject: [PATCH 116/182] test: UT_ASSERTstreq() for strings comparison Signed-off-by: Tomasz Gromadzki --- src/test/unittest/unittest.h | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index f865c2d07cc..78d144a52d4 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -173,29 +173,35 @@ ut_log_function(void *context, enum core_log_level level, const char *file_name, /* * assertions... */ +#define UT_ASSERT_MSG(FORMAT, ...) \ + UT_FATAL("assertion failure: " FORMAT, ##__VA_ARGS__) /* assert a condition is true at runtime */ #define UT_ASSERT_rt(cnd)\ - ((void)((cnd) || (ut_fatal(__FILE__, __LINE__, __func__,\ - "assertion failure: %s", #cnd), 0))) + ((void)((cnd) || (UT_ASSERT_MSG("%s", #cnd), 0))) /* assertion with extra info printed if assertion fails at runtime */ #define UT_ASSERTinfo_rt(cnd, info) \ - ((void)((cnd) || (ut_fatal(__FILE__, __LINE__, __func__,\ - "assertion failure: %s (%s)", #cnd, info), 0))) + ((void)((cnd) || (UT_ASSERT_MSG("%s (%s)", #cnd, info), 0))) /* assert two integer values are equal at runtime */ -#define UT_ASSERTeq_rt(lhs, rhs)\ - ((void)(((lhs) == (rhs)) || (ut_fatal(__FILE__, __LINE__, __func__,\ - "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\ +#define UT_ASSERTeq_rt(lhs, rhs) \ + ((void)(((lhs) == (rhs)) || \ + (UT_ASSERT_MSG("%s (0x%llx) == %s (0x%llx)", #lhs, \ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)), 0))) /* assert two integer values are not equal at runtime */ -#define UT_ASSERTne_rt(lhs, rhs)\ - ((void)(((lhs) != (rhs)) || (ut_fatal(__FILE__, __LINE__, __func__,\ - "assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ +#define UT_ASSERTne_rt(lhs, rhs) \ + ((void)(((lhs) != (rhs)) || \ + (UT_ASSERT_MSG("%s (0x%llx) != %s (0x%llx)", #lhs, \ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)), 0))) +/* assert two strings are equal at runtime */ +#define UT_ASSERTstreq_rt(__s1, __s2) \ + ((void)((__s1 == NULL && __s2 == NULL) || \ + (strcmp(__s1, __s2) == 0) || \ + (UT_ASSERT_MSG("%s: \"%s\" != %s", #__s1, __s1, __s2), 0))) + #if defined(__CHECKER__) #define UT_COMPILE_ERROR_ON(cond) #define UT_ASSERT_COMPILE_ERROR_ON(cond) @@ -255,11 +261,18 @@ ut_log_function(void *context, enum core_log_level level, const char *file_name, #define UT_ASSERTrange(ptr, start, size)\ ((void)(((uintptr_t)(ptr) >= (uintptr_t)(start) &&\ (uintptr_t)(ptr) < (uintptr_t)(start) + (uintptr_t)(size)) ||\ - (ut_fatal(__FILE__, __LINE__, __func__,\ - "assert failure: %s (%p) is outside range [%s (%p), %s (%p))", #ptr,\ + (UT_ASSERT_MSG("%s (%p) is outside range [%s (%p), %s (%p))", #ptr,\ (void *)(ptr), #start, (void *)(start), #start"+"#size,\ (void *)((uintptr_t)(start) + (uintptr_t)(size))), 0))) +/* assert strings are equal */ +#define UT_ASSERTstreq(__s1, __s2) \ + do { \ + if (__builtin_constant_p(__s1)) \ + UT_FATAL("UT_ASSERTstreq the first param must not be " \ + "const"); \ + UT_ASSERTstreq_rt(__s1, __s2); \ + } while (0) /* * memory allocation... */ From 3ee560effb334db1ef606b6fb5b8658a7cfd72bb Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 26 Feb 2024 16:28:11 +0100 Subject: [PATCH 117/182] test: core_log_default_function UT implementation Signed-off-by: Tomasz Gromadzki --- src/core/log_default.c | 2 +- src/test/Makefile | 2 +- src/test/core_log_default_function/.gitignore | 1 + src/test/core_log_default_function/Makefile | 17 + src/test/core_log_default_function/TESTS.py | 40 +++ .../core_log_default_function.c | 300 ++++++++++++++++++ src/test/core_log_internal/Makefile | 4 +- 7 files changed, 363 insertions(+), 3 deletions(-) create mode 100644 src/test/core_log_default_function/.gitignore create mode 100644 src/test/core_log_default_function/Makefile create mode 100755 src/test/core_log_default_function/TESTS.py create mode 100644 src/test/core_log_default_function/core_log_default_function.c diff --git a/src/core/log_default.c b/src/core/log_default.c index 8728c51f91e..b761a85a49a 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -93,7 +93,7 @@ get_timestamp_prefix(char *buf, size_t buf_size) * are formatted and inserted in the message. * * ASSUMPTIONS: - * - level >= CORE_LOG_LEVEL_FATAL && level <= CORE_LOG_LEVEL_DEBUG + * - level >= CORE_LOG_LEVEL_HARK && level <= CORE_LOG_LEVEL_DEBUG * - level <= Core_log_threshold[LOG_THRESHOLD] * - file == NULL || (file != NULL && function != NULL) */ diff --git a/src/test/Makefile b/src/test/Makefile index 748d9fd6259..e39efaaa792 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -23,7 +23,6 @@ OBJ_TESTS = \ obj_many_size_allocs\ obj_realloc\ obj_sync\ - \ obj_action\ obj_alloc\ obj_badblock\ @@ -109,6 +108,7 @@ OBJ_TESTS = \ OTHER_TESTS = \ arch_flags\ core_log_internal\ + core_log_default_function\ core_log_max\ checksum\ compat_incompat_features\ diff --git a/src/test/core_log_default_function/.gitignore b/src/test/core_log_default_function/.gitignore new file mode 100644 index 00000000000..5c484fc37a8 --- /dev/null +++ b/src/test/core_log_default_function/.gitignore @@ -0,0 +1 @@ +core_log_default_function diff --git a/src/test/core_log_default_function/Makefile b/src/test/core_log_default_function/Makefile new file mode 100644 index 00000000000..9d0d328c3b2 --- /dev/null +++ b/src/test/core_log_default_function/Makefile @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log_default_function +OBJS = core_log_default_function.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# 'internal' is required for proper mock integration +# 'debug' is required for debug version of core/log.o that provides +# implementation of 'out_log()' that is used by 'ut_log_function()' + +LIBPMEMCORE=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, core_log_default_function.c) diff --git a/src/test/core_log_default_function/TESTS.py b/src/test/core_log_default_function/TESTS.py new file mode 100755 index 00000000000..939ae671dd9 --- /dev/null +++ b/src/test/core_log_default_function/TESTS.py @@ -0,0 +1,40 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +class CORE_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log_default_function', self.test_case) + + +class TEST0(CORE_LOG): + test_case = 'test_default_function' + + +class TEST1(CORE_LOG): + test_case = 'test_default_function_bad_file_name' + + +class TEST2(CORE_LOG): + test_case = 'test_default_function_short_file_name' + + +class TEST3(CORE_LOG): + test_case = 'test_default_function_no_file_name' + + +class TEST4(CORE_LOG): + test_case = 'test_default_function_no_function_name' + + +class TEST5(CORE_LOG): + test_case = 'test_default_function_bad_timestamp' diff --git a/src/test/core_log_default_function/core_log_default_function.c b/src/test/core_log_default_function/core_log_default_function.c new file mode 100644 index 00000000000..b685b4be806 --- /dev/null +++ b/src/test/core_log_default_function/core_log_default_function.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_default_function.c -- unit test for core_log_default_function + */ + +#undef _GNU_SOURCE +#include +#include +#include + +#include "unittest.h" +#include "log_internal.h" +#include "log_default.h" + +#define NO_ARGS_CONSUMED 0 + +#define MESSAGE_MOCK ((char *)0x24689753) +#define TIMESTAMP "DUMMY TIMESTAMP" +#define FILE_NAME "dummy.c" +#define FILE_NAME_W_PATH "dummy_path/dummy_path/" FILE_NAME +#define FILE_INFO_ERROR "[file info error]: " +#define FUNCTION_NAME "dummy_func()" +#define FILE_INFO FILE_NAME ": 123: " FUNCTION_NAME ": " +#define LINE_NO 1357 + +static const char log_level_names[CORE_LOG_LEVEL_MAX][9] = { + [CORE_LOG_LEVEL_HARK] = "*HARK* ", + [CORE_LOG_LEVEL_FATAL] = "*FATAL* ", + [CORE_LOG_LEVEL_ERROR] = "*ERROR* ", + [CORE_LOG_LEVEL_WARNING] = "*WARN* ", + [CORE_LOG_LEVEL_NOTICE] = "*NOTE* ", + [CORE_LOG_LEVEL_INFO] = "*INFO* ", + [CORE_LOG_LEVEL_DEBUG] = "*DEBUG* ", +}; + +static const int log_level_syslog_severity[] = { + [CORE_LOG_LEVEL_HARK] = LOG_NOTICE, + [CORE_LOG_LEVEL_FATAL] = LOG_CRIT, + [CORE_LOG_LEVEL_ERROR] = LOG_ERR, + [CORE_LOG_LEVEL_WARNING] = LOG_WARNING, + [CORE_LOG_LEVEL_NOTICE] = LOG_NOTICE, + [CORE_LOG_LEVEL_INFO] = LOG_INFO, + [CORE_LOG_LEVEL_DEBUG] = LOG_DEBUG, +}; + +static struct { + const char *exp_log_level_name; + const char *exp_file_info; +} Common; + +char *Strchr_ret; + +FUNC_MOCK(strrchr, char *, const char *__s, int __c) +FUNC_MOCK_RUN_DEFAULT { + UT_ASSERTeq(__c, '/'); + return Strchr_ret; +} +FUNC_MOCK_END + +static bool Os_clock_gettime_force_error; + +FUNC_MOCK(clock_gettime, int, clockid_t __clock_id, struct timespec *__tp) +FUNC_MOCK_RUN_DEFAULT { + if (Os_clock_gettime_force_error) + return -1; + return _FUNC_REAL(clock_gettime)(__clock_id, __tp); +} +FUNC_MOCK_END + +static struct { + const char *exp_file_name; + int ret; +} Snprintf; + +FUNC_MOCK(snprintf, int, char *__restrict __s, size_t __maxlen, + const char *__restrict __format, ...) +/* file info */ + FUNC_MOCK_RUN(0) { + va_list arg; + va_start(arg, __format); + UT_ASSERTstreq(__format, "%s: %3d: %s: "); + char *file_name = va_arg(arg, char *); + UT_ASSERTstreq(file_name, Snprintf.exp_file_name); + int line_no = va_arg(arg, int); + UT_ASSERTeq(line_no, LINE_NO); + char *function_name = va_arg(arg, char *); + UT_ASSERTstreq(function_name, FUNCTION_NAME); + /* Can we access the whole given buffer (*__s) */ + *(__s + __maxlen - 1) = '\0'; + va_end(arg); + + if (Snprintf.ret != 0) + return Snprintf.ret; + UT_ASSERT(sizeof(FILE_INFO) <= __maxlen); + strncpy(__s, FILE_INFO, __maxlen); + return sizeof(FILE_INFO) - 1; + } +/* get time prefix */ + FUNC_MOCK_RUN(1) { + UT_ASSERTstreq(__format, "%s.%06ld "); + UT_ASSERT(sizeof(TIMESTAMP) <= __maxlen); + strncpy(__s, TIMESTAMP, __maxlen); + return sizeof(TIMESTAMP) - 1; + } +FUNC_MOCK_RUN_DEFAULT { + UT_FATAL("Unexpected #%d sprintf: %s", RCOUNTER(snprintf), __format); +} +FUNC_MOCK_END + +static struct { + int exp__pri; +} Syslog; + +FUNC_MOCK(syslog, void, int __pri, const char *__fmt, ...) +FUNC_MOCK_RUN_DEFAULT { + UT_ASSERTeq(__pri, Syslog.exp__pri); + UT_ASSERTstreq(__fmt, "%s%s%s"); + va_list arg; + va_start(arg, __fmt); + char *log_level_name = va_arg(arg, char *); + UT_ASSERTstreq(log_level_name, Common.exp_log_level_name); + char *file_info = va_arg(arg, char *); + UT_ASSERTstreq(file_info, Common.exp_file_info); + char *message = va_arg(arg, char *); + UT_ASSERTeq(message, MESSAGE_MOCK); + va_end(arg); +} +FUNC_MOCK_END + +static struct { + char *exp_times_stamp; +} Fprintf; + +FUNC_MOCK(fprintf, int, FILE *__restrict __stream, const char *__restrict __fmt, + ...) +FUNC_MOCK_RUN_DEFAULT { + UT_ASSERTeq(__stream, stderr); + UT_ASSERTstreq(__fmt, "%s[%ld] %s%s%s\n"); + va_list arg; + va_start(arg, __fmt); + char *times_tamp = va_arg(arg, char *); + UT_ASSERTstreq(times_tamp, Fprintf.exp_times_stamp); + va_arg(arg, int); /* skip syscall(SYS_gettid) */ + char *log_level_name = va_arg(arg, char *); + UT_ASSERTstreq(log_level_name, Common.exp_log_level_name); + char *file_info = va_arg(arg, char *); + UT_ASSERTstreq(file_info, Common.exp_file_info); + char *message = va_arg(arg, char *); + UT_ASSERTeq(message, MESSAGE_MOCK); + va_end(arg); + return 0; +} +FUNC_MOCK_END + +/* Tests' helpers */ +#define TEST_SETUP() core_log_set_threshold(CORE_LOG_THRESHOLD_AUX, \ + CORE_LOG_LEVEL_DEBUG) + +#define TEST_STEP_SETUP(_LEVEL, _FILE_NAME_SHORT) \ + do { \ + FUNC_MOCK_RCOUNTER_SET(snprintf, 0); \ + FUNC_MOCK_RCOUNTER_SET(syslog, 0); \ + FUNC_MOCK_RCOUNTER_SET(fprintf, 0); \ + Strchr_ret = "/"_FILE_NAME_SHORT; \ + Common.exp_log_level_name = log_level_names[_LEVEL]; \ + Common.exp_file_info = FILE_INFO; \ + Snprintf.exp_file_name = _FILE_NAME_SHORT; \ + Snprintf.ret = 0; \ + Syslog.exp__pri = log_level_syslog_severity[_LEVEL]; \ + Fprintf.exp_times_stamp = TIMESTAMP; \ + } while (0) + +#define TEST_STEP_CHECK(_SNPRINTF, _FPRINTF) \ + do { \ + UT_ASSERTeq(RCOUNTER(syslog), 1); \ + UT_ASSERTeq(RCOUNTER(snprintf), _SNPRINTF); \ + UT_ASSERTeq(RCOUNTER(fprintf), _FPRINTF); \ + } while (0) + +/* basic test with a normal message pass through */ +static int +test_default_function(const struct test_case *tc, int argc, char *argv[]) +{ + TEST_SETUP(); + for (enum core_log_level treshold = CORE_LOG_LEVEL_HARK; + treshold < CORE_LOG_LEVEL_MAX; treshold++) { + core_log_set_threshold(CORE_LOG_THRESHOLD_AUX, treshold); + for (enum core_log_level level = CORE_LOG_LEVEL_HARK; + level < CORE_LOG_LEVEL_MAX; level++) { + TEST_STEP_SETUP(level, FILE_NAME); + core_log_default_function(NULL, level, FILE_NAME_W_PATH, + LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + if (level == CORE_LOG_LEVEL_HARK || level > treshold) + TEST_STEP_CHECK(1, 0); + else + TEST_STEP_CHECK(2, 1); + } + } + + return NO_ARGS_CONSUMED; +} + +/* test to check that information about a bad file is printed */ +static int +test_default_function_bad_file_name(const struct test_case *tc, int argc, + char *argv[]) +{ + TEST_SETUP(); + TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_INFO_ERROR); + Snprintf.ret = -1; + Common.exp_file_info = FILE_INFO_ERROR; + core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME_W_PATH, + LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + TEST_STEP_CHECK(2, 1); + + return NO_ARGS_CONSUMED; +} + +/* test to check that short file name (w/o path) is properly printed */ +static int +test_default_function_short_file_name(const struct test_case *tc, int argc, + char *argv[]) +{ + core_log_set_threshold(CORE_LOG_THRESHOLD_AUX, CORE_LOG_LEVEL_DEBUG); + TEST_SETUP(); + TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); + Strchr_ret = NULL; + core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, + LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + TEST_STEP_CHECK(2, 1); + + return NO_ARGS_CONSUMED; +} + +/* test to check no fileinfo when file_name is NULL */ +static int +test_default_function_no_file_name(const struct test_case *tc, int argc, + char *argv[]) +{ + TEST_SETUP(); + TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); + FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ + Common.exp_file_info = ""; + core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, + LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + TEST_STEP_CHECK(2, 1); + + return NO_ARGS_CONSUMED; +} + +/* test to check no fileinfo when file_name and function_name are NULL */ +static int +test_default_function_no_function_name(const struct test_case *tc, int argc, + char *argv[]) +{ + TEST_SETUP(); + TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); + FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ + Common.exp_file_info = ""; + core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, + LINE_NO, NULL, MESSAGE_MOCK); + TEST_STEP_CHECK(2, 1); + + return NO_ARGS_CONSUMED; +} + +/* test to check timestamp error */ +static int +test_default_function_bad_timestamp(const struct test_case *tc, int argc, + char *argv[]) +{ + TEST_SETUP(); + TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); + Os_clock_gettime_force_error = true; /* fail the file_info snprintf() */ + Fprintf.exp_times_stamp = "[time error] "; + core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, + LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + TEST_STEP_CHECK(1, 1); + + return NO_ARGS_CONSUMED; +} + +static struct test_case test_cases[] = { + TEST_CASE(test_default_function), + TEST_CASE(test_default_function_bad_file_name), + TEST_CASE(test_default_function_short_file_name), + TEST_CASE(test_default_function_no_file_name), + TEST_CASE(test_default_function_no_function_name), + TEST_CASE(test_default_function_bad_timestamp), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log_default_function"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} diff --git a/src/test/core_log_internal/Makefile b/src/test/core_log_internal/Makefile index 221ebfd1f7b..1fe8a911bd3 100644 --- a/src/test/core_log_internal/Makefile +++ b/src/test/core_log_internal/Makefile @@ -7,7 +7,9 @@ OBJS = core_log_internal.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n -# `internal` is required for proper mock integration +# 'internal' is required for proper mock integration +# 'nondebug' is required for proper execution of test_CORE_LOG_TRESHOLD_DEFAULT +# (use nondebug version of core/log.o) LIBPMEMCORE=internal-nondebug include ../Makefile.inc From bf0970149a6909dc18a408f2eb0360a91d06161b Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 29 Feb 2024 23:36:45 -0500 Subject: [PATCH 118/182] test: introduce core_log() unit tests Signed-off-by: Jan Michalski --- src/core/log_internal.h | 14 -- src/test/Makefile | 4 +- src/test/core_log/.gitignore | 1 + src/test/core_log/Makefile | 7 + src/test/core_log/Makefile.inc | 12 + src/test/core_log/TESTS.py | 47 ++++ src/test/core_log/core_log.c | 224 ++++++++++++++++++ src/test/core_log/core_log_common.c | 163 +++++++++++++ src/test/core_log/core_log_common.h | 62 +++++ .../core_log_internal/core_log_internal.c | 2 +- src/test/core_log_no_func/.gitignore | 1 + src/test/core_log_no_func/Makefile | 10 + src/test/core_log_no_func/TESTS.py | 27 +++ src/test/core_log_no_func/core_log_no_func.c | 67 ++++++ src/test/unittest/unittest.h | 2 +- 15 files changed, 626 insertions(+), 17 deletions(-) create mode 100644 src/test/core_log/.gitignore create mode 100644 src/test/core_log/Makefile create mode 100644 src/test/core_log/Makefile.inc create mode 100755 src/test/core_log/TESTS.py create mode 100644 src/test/core_log/core_log.c create mode 100644 src/test/core_log/core_log_common.c create mode 100644 src/test/core_log/core_log_common.h create mode 100644 src/test/core_log_no_func/.gitignore create mode 100644 src/test/core_log_no_func/Makefile create mode 100755 src/test/core_log_no_func/TESTS.py create mode 100644 src/test/core_log_no_func/core_log_no_func.c diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 8f78558426a..2d03c1b3fa4 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -83,20 +83,6 @@ typedef void core_log_function( int core_log_set_function(core_log_function *log_function, void *context); -/* pointer to the logging function */ -extern -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -uintptr_t Core_log_function; - -/* the logging function's context */ -extern -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -void *Core_log_function_context; - /* threshold levels */ extern #ifdef ATOMIC_OPERATIONS_SUPPORTED diff --git a/src/test/Makefile b/src/test/Makefile index 6e0107d44c0..0f96dc0167f 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -107,10 +107,12 @@ OBJ_TESTS = \ OTHER_TESTS = \ arch_flags\ - core_log_internal\ + core_log\ core_log_default_function\ + core_log_internal\ core_log_max\ core_log_mt\ + core_log_no_func\ checksum\ compat_incompat_features\ ctl_prefault\ diff --git a/src/test/core_log/.gitignore b/src/test/core_log/.gitignore new file mode 100644 index 00000000000..077e6928a11 --- /dev/null +++ b/src/test/core_log/.gitignore @@ -0,0 +1 @@ +core_log diff --git a/src/test/core_log/Makefile b/src/test/core_log/Makefile new file mode 100644 index 00000000000..0067f595c8d --- /dev/null +++ b/src/test/core_log/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log +OBJS = core_log.o core_log_common.o + +include ./Makefile.inc diff --git a/src/test/core_log/Makefile.inc b/src/test/core_log/Makefile.inc new file mode 100644 index 00000000000..7eb23ab70c0 --- /dev/null +++ b/src/test/core_log/Makefile.inc @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# 'internal' is required for proper mock integration +# 'debug' provides 'out_log()' required for 'ut_log_function()' +LIBPMEMCORE=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, ../core_log/core_log_common.c) diff --git a/src/test/core_log/TESTS.py b/src/test/core_log/TESTS.py new file mode 100755 index 00000000000..975d3d5cc73 --- /dev/null +++ b/src/test/core_log/TESTS.py @@ -0,0 +1,47 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'nondebug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('nondebug') +class CORE_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log', self.test_case) + + +class TEST0(CORE_LOG): + test_case = 'test_CORE_LOG_LEVEL_ERROR_LAST' + + +class TEST1(CORE_LOG): + test_case = 'test_vsnprintf_fail' + + +class TEST2(CORE_LOG): + test_case = 'test_NO_ERRNO' + + +class TEST3(CORE_LOG): + test_case = 'test_no_space_for_strerror_r' + + +class TEST4(CORE_LOG): + test_case = 'test_strerror_r_fail' + + +class TEST5(CORE_LOG): + test_case = 'test_level_gt_threshold' + + +class TEST6(CORE_LOG): + test_case = 'test_happy_day' diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c new file mode 100644 index 00000000000..3263668ca40 --- /dev/null +++ b/src/test/core_log/core_log.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log.c -- unit test for core_log() and core_log_va() + */ + +#include + +#include "last_error_msg.h" +#include "unittest.h" + +#include "core_log_common.h" + +/* tests */ + +/* + * Check: + * - CORE_LOG_LEVEL_ERROR_LAST -> CORE_LOG_LEVEL_ERROR + * - buf == last_error_msg_get(); + * - buf_len == CORE_LAST_ERROR_MSG_MAXPRINT + */ +static int +test_CORE_LOG_LEVEL_ERROR_LAST(const struct test_case *tc, int argc, + char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + reset_mocks(); + + /* set the expectations */ + Common.use_last_error_msg = true; + Vsnprintf_.ret = 0; /* empty but successful */ + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + + core_log(CORE_LOG_LEVEL_ERROR_LAST, NO_ERRNO, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - The log preparation stops after the failed vsnprintf() call. + * - The log function is not called. + */ +static int +test_vsnprintf_fail(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = -1; /* negative value if an output error */ + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + Common.use_last_error_msg = false; + + core_log(CORE_LOG_LEVEL_ERROR, NO_ERRNO, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), NOT_CALLED); + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - NO_ERRNO means no strerror_r() call. + * - The produced log message is passed to the log function. + */ +static int +test_NO_ERRNO(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = 0; /* leave a lot of space for the error string */ + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + Common.use_last_error_msg = false; + + core_log(CORE_LOG_LEVEL_ERROR, NO_ERRNO, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - fully fill the provided buffer in three ways: + * (1) exactly (`- 1` for the terminating null-byte) + * (2) one character too many (the null-byte would end up just after + * the actual buffer space) + * (3) two characters too many (no space for one character of the message and + * for the null-byte) + * - the strerror_r() is not called despite an errno is provided. + */ +static int +test_no_space_for_strerror_r(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + for (int i = _CORE_LOG_MSG_MAXPRINT - 1; + i <= _CORE_LOG_MSG_MAXPRINT + 1; ++i) { + test_no_space_for_strerror_r_helper(i); + } + + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - strerror_r() fails in two ways: + * (1) before glibc 2.13 + * (2) since glibc 2.13 + * - The produced log message is passed to the log function. + */ +static int +test_strerror_r_fail(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + test_strerror_r_fail_helper(true); + test_strerror_r_fail_helper(false); + + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - if level <= threshold: + * - the log function is called + * - else: + * - the log function is not called + */ +static int +test_level_gt_threshold(const struct test_case *tc, int argc, char *argv[]) +{ + for (enum core_log_level threshold = CORE_LOG_LEVEL_HARK; + threshold < CORE_LOG_LEVEL_MAX; ++threshold) { + core_log_set_threshold(CORE_LOG_THRESHOLD, threshold); + + for (enum core_log_level level = CORE_LOG_LEVEL_HARK; + level < CORE_LOG_LEVEL_MAX; ++level) { + bool log_function_called = (level <= threshold); + test_log_function_call_helper(level, + log_function_called); + } + } + + return NO_ARGS_CONSUMED; +} + +static int +test_happy_day(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = BASIC_MESSAGE_LEN; + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + Common.use_last_error_msg = true; + Strerror_r.exp__buf = LAST_ERROR_MSG_MOCK + Vsnprintf_.ret; + Strerror_r.exp__buflen = CORE_LAST_ERROR_MSG_MAXPRINT - + (size_t)Vsnprintf_.ret; + Strerror_r.error = EXIT_SUCCESS; + + core_log(CORE_LOG_LEVEL_ERROR_LAST, DUMMY_ERRNO1, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); + + return NO_ARGS_CONSUMED; +} + +static struct test_case test_cases[] = { + TEST_CASE(test_CORE_LOG_LEVEL_ERROR_LAST), + TEST_CASE(test_vsnprintf_fail), + TEST_CASE(test_NO_ERRNO), + TEST_CASE(test_no_space_for_strerror_r), + TEST_CASE(test_strerror_r_fail), + TEST_CASE(test_level_gt_threshold), + TEST_CASE(test_happy_day), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log"); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + openlog(NULL, LOG_NDELAY, LOG_USER); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + closelog(); + DONE(NULL); +} diff --git a/src/test/core_log/core_log_common.c b/src/test/core_log/core_log_common.c new file mode 100644 index 00000000000..8b804de46f2 --- /dev/null +++ b/src/test/core_log/core_log_common.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_common.c -- mocks and helpers common for core_log(_no_func) + */ + +#include "last_error_msg.h" +#include "unittest.h" + +#include "core_log_common.h" + +/* mocks */ + +struct common_ctx Common; +struct vsnprintf_ctx Vsnprintf_; +struct strerror_r_ctx Strerror_r; +struct log_function_ctx Log_function_; + +FUNC_MOCK(last_error_msg_get, const char *, void) +FUNC_MOCK_RUN_DEFAULT { + return LAST_ERROR_MSG_MOCK; +} +FUNC_MOCK_END + +FUNC_MOCK(vsnprintf, int, char *__restrict __s, size_t __maxlen, + const char *__restrict __format, va_list __arg) + FUNC_MOCK_RUN(VALIDATED_CALL) { + if (Common.use_last_error_msg) { + UT_ASSERTeq(__s, LAST_ERROR_MSG_MOCK); + UT_ASSERTeq(__maxlen, CORE_LAST_ERROR_MSG_MAXPRINT); + } else { + UT_ASSERTne(__s, LAST_ERROR_MSG_MOCK); + UT_ASSERTeq(__maxlen, _CORE_LOG_MSG_MAXPRINT); + } + UT_ASSERT(__format == MSG_FORMAT); + (void) __arg; + + return Vsnprintf_.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(vsnprintf)(__s, __maxlen, __format, __arg); +} +FUNC_MOCK_END + +FUNC_MOCK(__xpg_strerror_r, int, int __errnum, char *__buf, size_t __buflen) +FUNC_MOCK_RUN_DEFAULT { + UT_ASSERTeq(__errnum, DUMMY_ERRNO1); + UT_ASSERTeq(__buf, Strerror_r.exp__buf); + UT_ASSERTeq(__buflen, Strerror_r.exp__buflen); + + if (Strerror_r.error == EXIT_SUCCESS) { + return 0; + } + + if (Strerror_r.before_glibc_2_13) { + errno = Strerror_r.error; + return -1; + } else { + return Strerror_r.error; + } +} +FUNC_MOCK_END + +FUNC_MOCK(core_log_default_function, void, void *context, + enum core_log_level level, const char *file_name, const int line_no, + const char *function_name, const char *message) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(context, NULL); + UT_ASSERTeq(level, Log_function_.exp_level); + UT_ASSERTstreq(file_name, FILE_NAME); + UT_ASSERTeq(line_no, LINE_NO); + UT_ASSERTstreq(function_name, FUNC_NAME); + if (Common.use_last_error_msg) { + UT_ASSERTeq(message, LAST_ERROR_MSG_MOCK); + } else { + UT_ASSERTne(message, LAST_ERROR_MSG_MOCK); + } + return; + } +FUNC_MOCK_RUN_DEFAULT { + _FUNC_REAL(core_log_default_function)(context, level, file_name, + line_no, function_name, message); +} +FUNC_MOCK_END + +/* helpers */ + +void +reset_mocks(void) +{ + FUNC_MOCK_RCOUNTER_SET(last_error_msg_get, VALIDATED_CALL); + FUNC_MOCK_RCOUNTER_SET(vsnprintf, VALIDATED_CALL); + FUNC_MOCK_RCOUNTER_SET(__xpg_strerror_r, VALIDATED_CALL); + FUNC_MOCK_RCOUNTER_SET(core_log_default_function, VALIDATED_CALL); +} + +void +test_no_space_for_strerror_r_helper(int core_message_length) +{ + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = core_message_length; + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + Common.use_last_error_msg = false; + + core_log(CORE_LOG_LEVEL_ERROR, DUMMY_ERRNO1, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); +} + +void +test_strerror_r_fail_helper(bool before_glibc_2_13) +{ + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = BASIC_MESSAGE_LEN; + Log_function_.exp_level = CORE_LOG_LEVEL_ERROR; + Common.use_last_error_msg = true; + Strerror_r.exp__buf = LAST_ERROR_MSG_MOCK + Vsnprintf_.ret; + Strerror_r.exp__buflen = CORE_LAST_ERROR_MSG_MAXPRINT - + (size_t)Vsnprintf_.ret; + Strerror_r.error = DUMMY_ERRNO2; + Strerror_r.before_glibc_2_13 = before_glibc_2_13; + + core_log(CORE_LOG_LEVEL_ERROR_LAST, DUMMY_ERRNO1, FILE_NAME, LINE_NO, + FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); +} + +void +test_log_function_call_helper(enum core_log_level level, + bool log_function_called) +{ + reset_mocks(); + + /* set the expectations */ + Vsnprintf_.ret = BASIC_MESSAGE_LEN; + Log_function_.exp_level = level; + Common.use_last_error_msg = (level == CORE_LOG_LEVEL_ERROR_LAST); + + core_log(level, NO_ERRNO, FILE_NAME, LINE_NO, FUNC_NAME, MSG_FORMAT); + + /* check the call counters */ + UT_ASSERTeq(RCOUNTER(last_error_msg_get), + Common.use_last_error_msg ? CALLED : NOT_CALLED); + UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); + UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(core_log_default_function), + log_function_called ? CALLED : NOT_CALLED); +} diff --git a/src/test/core_log/core_log_common.h b/src/test/core_log/core_log_common.h new file mode 100644 index 00000000000..bb6307fee41 --- /dev/null +++ b/src/test/core_log/core_log_common.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* Copyright 2024, Intel Corporation */ + +/* + * core_log.c -- definitions for mocks and helpers common for core_log(_no_func) + */ + +#include + +#include "unittest.h" + +#define NO_ARGS_CONSUMED 0 + +#define FILE_NAME "dummy.c" +#define LINE_NO 1234 +#define FUNC_NAME "dummy_func" +#define MSG_FORMAT ((char *)0x0458f044) +#define LAST_ERROR_MSG_MOCK ((char *)0x1a547e58) +#define DUMMY_ERRNO1 500 +#define DUMMY_ERRNO2 (DUMMY_ERRNO1 + 1) +#define BASIC_MESSAGE_LEN 131 + +#define VALIDATED_CALL 127 +#define NOT_CALLED VALIDATED_CALL +#define CALLED (VALIDATED_CALL + 1) + +extern struct common_ctx { + bool use_last_error_msg; +} Common; + +extern struct vsnprintf_ctx { + int ret; +} Vsnprintf_; + +extern struct strerror_r_ctx { + char *exp__buf; + size_t exp__buflen; + bool before_glibc_2_13; + int error; +} Strerror_r; + +extern struct log_function_ctx { + enum core_log_level exp_level; +} Log_function_; + +/* mocks */ + +extern unsigned RCOUNTER(last_error_msg_get); +extern unsigned RCOUNTER(vsnprintf); +extern unsigned RCOUNTER(__xpg_strerror_r); +extern unsigned RCOUNTER(core_log_default_function); + +/* helpers */ + +void reset_mocks(void); + +void test_no_space_for_strerror_r_helper(int core_message_length); + +void test_strerror_r_fail_helper(bool before_glibc_2_13); + +void test_log_function_call_helper(enum core_log_level level, + bool call_log_function); diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c index 67220f4ff4f..6fd1af8d5a4 100644 --- a/src/test/core_log_internal/core_log_internal.c +++ b/src/test/core_log_internal/core_log_internal.c @@ -254,7 +254,7 @@ main(int argc, char *argv[]) core_log_get_threshold(CORE_LOG_THRESHOLD, &Core_log_default_threshold); core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); - START(argc, argv, "core_log"); + START(argc, argv, "core_log_internal"); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); DONE(NULL); } diff --git a/src/test/core_log_no_func/.gitignore b/src/test/core_log_no_func/.gitignore new file mode 100644 index 00000000000..18f74694106 --- /dev/null +++ b/src/test/core_log_no_func/.gitignore @@ -0,0 +1 @@ +core_log_no_func diff --git a/src/test/core_log_no_func/Makefile b/src/test/core_log_no_func/Makefile new file mode 100644 index 00000000000..cfa23ac02f5 --- /dev/null +++ b/src/test/core_log_no_func/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +vpath %.c ../core_log + +TARGET = core_log_no_func +OBJS = core_log_no_func.o core_log_common.o + +include ../core_log/Makefile.inc +INCS += -I../core_log diff --git a/src/test/core_log_no_func/TESTS.py b/src/test/core_log_no_func/TESTS.py new file mode 100755 index 00000000000..55c52d048d8 --- /dev/null +++ b/src/test/core_log_no_func/TESTS.py @@ -0,0 +1,27 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'nondebug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('nondebug') +class CORE_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log_no_func', self.test_case) + + +class TEST0(CORE_LOG): + test_case = 'test_no_log_function' + + +class TEST1(CORE_LOG): + test_case = 'test_no_log_function_CORE_LOG_LEVEL_ERROR_LAST' diff --git a/src/test/core_log_no_func/core_log_no_func.c b/src/test/core_log_no_func/core_log_no_func.c new file mode 100644 index 00000000000..4b64500f845 --- /dev/null +++ b/src/test/core_log_no_func/core_log_no_func.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_no_func.c -- unit test for core_log() and core_log_va() when + * no logging function is attached. + */ + +#include + +#include "unittest.h" +#include "core_log_common.h" + +/* tests */ + +/* + * Check: + * - if Core_log_function == 0: + * - the log function is not called + */ +static int +test_no_log_function(const struct test_case *tc, int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + test_log_function_call_helper(CORE_LOG_LEVEL_ERROR, + false /* log_function_called */); + + return NO_ARGS_CONSUMED; +} + +/* + * Check: + * - if Core_log_function == 0 and level == CORE_LOG_LEVEL_ERROR_LAST: + * - the log function is not called + */ +static int +test_no_log_function_CORE_LOG_LEVEL_ERROR_LAST(const struct test_case *tc, + int argc, char *argv[]) +{ + /* Pass the message all the way to the logging function. */ + core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + + test_log_function_call_helper(CORE_LOG_LEVEL_ERROR_LAST, + false /* log_function_called */); + + return NO_ARGS_CONSUMED; +} + +static struct test_case test_cases[] = { + TEST_CASE(test_no_log_function), + TEST_CASE(test_no_log_function_CORE_LOG_LEVEL_ERROR_LAST), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +#undef LOG_SET_PMEMCORE_FUNC +#define LOG_SET_PMEMCORE_FUNC + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log_no_func"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 78d144a52d4..a01a791e61f 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -559,7 +559,7 @@ int ut_thread_join(const char *file, int line, const char *func, #define FUNC_MOCK(name, ret_type, ...)\ _FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\ - static unsigned RCOUNTER(name);\ + unsigned RCOUNTER(name);\ ret_type __wrap_##name(__VA_ARGS__);\ ret_type __wrap_##name(__VA_ARGS__) {\ switch (util_fetch_and_add32(&RCOUNTER(name), 1)) { From def6b52b629fd8466ff6daa3edf80ec2ae4c33f3 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 5 Mar 2024 23:54:41 -0500 Subject: [PATCH 119/182] common: drop the logging context Signed-off-by: Jan Michalski --- src/core/log.c | 29 ++++--------------- src/core/log_default.c | 7 ++--- src/core/log_default.h | 5 ++-- src/core/log_internal.h | 4 +-- src/core/out.c | 6 ++-- src/include/libpmemobj/log.h | 12 ++------ src/libpmemobj/obj_log.c | 8 ++--- src/test/core_log/core_log.c | 2 +- src/test/core_log/core_log_common.c | 11 ++++--- .../core_log_default_function.c | 16 +++++----- .../core_log_internal/core_log_internal.c | 2 +- src/test/unittest/unittest.h | 6 ++-- src/test/unittest/ut_log.c | 2 +- 13 files changed, 36 insertions(+), 74 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index b85c6555c33..de18b7c04b4 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -50,12 +50,6 @@ _Atomic #endif /* ATOMIC_OPERATIONS_SUPPORTED */ uintptr_t Core_log_function = 0; -/* the logging function's context */ -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -void *Core_log_function_context; - /* threshold levels */ enum core_log_level Core_log_threshold[] = { CORE_LOG_THRESHOLD_DEFAULT, @@ -78,7 +72,7 @@ core_log_init() /* enable the default logging function */ core_log_default_init(); while (EAGAIN == - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL)) + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION)) ; } @@ -94,7 +88,6 @@ core_log_fini() * logging function. */ Core_log_function = 0; - Core_log_function_context = NULL; /* cleanup the default logging function */ core_log_default_fini(); @@ -117,7 +110,7 @@ core_log_lib_info(void) * a user-provided function pointer or to the default logging function. */ int -core_log_set_function(core_log_function *log_function, void *context) +core_log_set_function(core_log_function *log_function) { if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) @@ -126,25 +119,15 @@ core_log_set_function(core_log_function *log_function, void *context) #ifdef ATOMIC_OPERATIONS_SUPPORTED atomic_store_explicit(&Core_log_function, (uintptr_t)log_function, __ATOMIC_SEQ_CST); - atomic_store_explicit(&Core_log_function_context, context, - __ATOMIC_SEQ_CST); return 0; #else uintptr_t core_log_function_old = Core_log_function; - void *context_old = Core_log_function_context; - if (!__sync_bool_compare_and_swap(&Core_log_function, - core_log_function_old, (uintptr_t)log_function)) - return EAGAIN; - if (__sync_bool_compare_and_swap(&Core_log_function_context, - context_old, context)) { + if (__sync_bool_compare_and_swap(&Core_log_function, + core_log_function_old, (uintptr_t)log_function)) { core_log_lib_info(); return 0; } - - (void) __sync_bool_compare_and_swap(&Core_log_function, - (uintptr_t)log_function, core_log_function_old); return EAGAIN; - #endif /* ATOMIC_OPERATIONS_SUPPORTED */ } @@ -226,8 +209,8 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, if (0 == Core_log_function) goto end; - ((core_log_function *)Core_log_function)(Core_log_function_context, - level, file_name, line_no, function_name, buf); + ((core_log_function *)Core_log_function)(level, file_name, line_no, + function_name, buf); end: if (errnum != NO_ERRNO) diff --git a/src/core/log_default.c b/src/core/log_default.c index b761a85a49a..563844af97d 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -98,12 +98,9 @@ get_timestamp_prefix(char *buf, size_t buf_size) * - file == NULL || (file != NULL && function != NULL) */ void -core_log_default_function(void *context, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, - const char *message) +core_log_default_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message) { - SUPPRESS_UNUSED(context); - char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; const char file_info_error[] = "[file info error]: "; diff --git a/src/core/log_default.h b/src/core/log_default.h index c7bdde7023b..7583dce6905 100644 --- a/src/core/log_default.h +++ b/src/core/log_default.h @@ -8,9 +8,8 @@ #ifndef CORE_LOG_DEFAULT_H #define CORE_LOG_DEFAULT_H -void core_log_default_function(void *context, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, - const char *message); +void core_log_default_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message); void core_log_default_init(void); diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 2d03c1b3fa4..fb1a8bcf452 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -66,8 +66,6 @@ int core_log_get_threshold(enum core_log_threshold threshold, * the type used for defining logging functions */ typedef void core_log_function( - /* the context provided when setting the log function */ - void *context, /* the log level of the message */ enum core_log_level level, /* name of the source file where the message coming from */ @@ -81,7 +79,7 @@ typedef void core_log_function( #define CORE_LOG_USE_DEFAULT_FUNCTION (NULL) -int core_log_set_function(core_log_function *log_function, void *context); +int core_log_set_function(core_log_function *log_function); /* threshold levels */ extern diff --git a/src/core/out.c b/src/core/out.c index 9773b8667b3..f0bd95e4a08 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -52,11 +52,9 @@ static const int core_log_level_to_level[CORE_LOG_LEVEL_MAX] = { #define OUT_MAX_LEVEL 4 static void -out_legacy(void *context, enum core_log_level core_level, const char *file_name, +out_legacy(enum core_log_level core_level, const char *file_name, const int line_no, const char *function_name, const char *message) { - SUPPRESS_UNUSED(context); - int level = core_log_level_to_level[core_level]; out_log(file_name, line_no, function_name, level, "%s", message); } @@ -149,7 +147,7 @@ out_init(const char *log_prefix, const char *log_level_var, } if (log_level != NULL || log_file != NULL) { - ret = core_log_set_function(out_legacy, NULL); + ret = core_log_set_function(out_legacy); if (ret) { CORE_LOG_FATAL("Cannot set legacy log function"); } diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index 64f1d7855e7..43c0eaaecfe 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -153,8 +153,6 @@ int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, * the type used for defining logging functions */ typedef void pmemobj_log_function( - /* the context provided when setting the log function */ - void *context, /* the log level of the message */ enum pmemobj_log_level level, /* name of the source file where the message coming from */ @@ -176,7 +174,6 @@ typedef void pmemobj_log_function( * SYNOPSIS * * typedef void pmemobj_log_function( - * void *context, * enum pmemobj_log_level level, * const char *file_name, * const int line_no, @@ -184,18 +181,13 @@ typedef void pmemobj_log_function( * const char *message_format, * ...); * - * int pmemobj_log_set_function(pmemobj_log_function *log_function, - * void *context); + * int pmemobj_log_set_function(pmemobj_log_function *log_function); * * DESCRIPTION * pmemobj_log_set_function() allows choosing the function which will get all * the generated logging messages. The log_function can be either * PMEMOBJ_LOG_USE_DEFAULT_FUNCTION which will use the default logging function * (built into the library) or a pointer to a user-defined function. - * The context allows to pass an additional value which will be passed along - * with all the logging messages to the logging function. When the provided - * log_function is PMEMOBJ_LOG_USE_DEFAULT_FUNCTION the provided context is - * ignored. * * Parameters of a user-defined log function are as follow: * - level - the log level of the message @@ -228,7 +220,7 @@ typedef void pmemobj_log_function( * SEE ALSO * pmemobj_log_get_threshold(3), pmemobj_log_set_threshold(3). */ -int pmemobj_log_set_function(pmemobj_log_function *log_function, void *context); +int pmemobj_log_set_function(pmemobj_log_function *log_function); #ifdef __cplusplus } diff --git a/src/libpmemobj/obj_log.c b/src/libpmemobj/obj_log.c index 3984e9e5d5e..aad0ad0f11a 100644 --- a/src/libpmemobj/obj_log.c +++ b/src/libpmemobj/obj_log.c @@ -38,12 +38,8 @@ pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, * a user-provided function pointer or to the default logging function. */ int -pmemobj_log_set_function(pmemobj_log_function *log_function, void *context) +pmemobj_log_set_function(pmemobj_log_function *log_function) { - if (log_function == PMEMOBJ_LOG_USE_DEFAULT_FUNCTION) - context = NULL; - - int ret = core_log_set_function((core_log_function *)log_function, - context); + int ret = core_log_set_function((core_log_function *)log_function); return core_log_error_translate(ret); } diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c index 3263668ca40..75aa59891f6 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log/core_log.c @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) { START(argc, argv, "core_log"); - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION); openlog(NULL, LOG_NDELAY, LOG_USER); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); closelog(); diff --git a/src/test/core_log/core_log_common.c b/src/test/core_log/core_log_common.c index 8b804de46f2..d9dea37a68f 100644 --- a/src/test/core_log/core_log_common.c +++ b/src/test/core_log/core_log_common.c @@ -62,11 +62,10 @@ FUNC_MOCK_RUN_DEFAULT { } FUNC_MOCK_END -FUNC_MOCK(core_log_default_function, void, void *context, - enum core_log_level level, const char *file_name, const int line_no, - const char *function_name, const char *message) +FUNC_MOCK(core_log_default_function, void, enum core_log_level level, + const char *file_name, const int line_no, const char *function_name, + const char *message) FUNC_MOCK_RUN(VALIDATED_CALL) { - UT_ASSERTeq(context, NULL); UT_ASSERTeq(level, Log_function_.exp_level); UT_ASSERTstreq(file_name, FILE_NAME); UT_ASSERTeq(line_no, LINE_NO); @@ -79,8 +78,8 @@ FUNC_MOCK(core_log_default_function, void, void *context, return; } FUNC_MOCK_RUN_DEFAULT { - _FUNC_REAL(core_log_default_function)(context, level, file_name, - line_no, function_name, message); + _FUNC_REAL(core_log_default_function)(level, file_name, line_no, + function_name, message); } FUNC_MOCK_END diff --git a/src/test/core_log_default_function/core_log_default_function.c b/src/test/core_log_default_function/core_log_default_function.c index b685b4be806..01f9ba42b0f 100644 --- a/src/test/core_log_default_function/core_log_default_function.c +++ b/src/test/core_log_default_function/core_log_default_function.c @@ -190,7 +190,7 @@ test_default_function(const struct test_case *tc, int argc, char *argv[]) for (enum core_log_level level = CORE_LOG_LEVEL_HARK; level < CORE_LOG_LEVEL_MAX; level++) { TEST_STEP_SETUP(level, FILE_NAME); - core_log_default_function(NULL, level, FILE_NAME_W_PATH, + core_log_default_function(level, FILE_NAME_W_PATH, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); if (level == CORE_LOG_LEVEL_HARK || level > treshold) TEST_STEP_CHECK(1, 0); @@ -211,7 +211,7 @@ test_default_function_bad_file_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_INFO_ERROR); Snprintf.ret = -1; Common.exp_file_info = FILE_INFO_ERROR; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME_W_PATH, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME_W_PATH, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -227,7 +227,7 @@ test_default_function_short_file_name(const struct test_case *tc, int argc, TEST_SETUP(); TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); Strchr_ret = NULL; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -243,7 +243,7 @@ test_default_function_no_file_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ Common.exp_file_info = ""; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, NULL, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -259,8 +259,8 @@ test_default_function_no_function_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ Common.exp_file_info = ""; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, - LINE_NO, NULL, MESSAGE_MOCK); + core_log_default_function(CORE_LOG_LEVEL_DEBUG, NULL, LINE_NO, NULL, + MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); return NO_ARGS_CONSUMED; @@ -275,8 +275,8 @@ test_default_function_bad_timestamp(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); Os_clock_gettime_force_error = true; /* fail the file_info snprintf() */ Fprintf.exp_times_stamp = "[time error] "; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, - LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME, LINE_NO, + FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(1, 1); return NO_ARGS_CONSUMED; diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c index 6fd1af8d5a4..637cce50518 100644 --- a/src/test/core_log_internal/core_log_internal.c +++ b/src/test/core_log_internal/core_log_internal.c @@ -252,7 +252,7 @@ int main(int argc, char *argv[]) { core_log_get_threshold(CORE_LOG_THRESHOLD, &Core_log_default_threshold); - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION); START(argc, argv, "core_log_internal"); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index a01a791e61f..c13422871ee 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -122,19 +122,19 @@ void ut_err(const char *file, int line, const char *func, __attribute__((format(printf, 4, 5))); void -ut_log_function(void *context, enum core_log_level level, const char *file_name, +ut_log_function(enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message); #ifdef USE_LOG_PMEMCORE -#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL) +#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function) #else #define LOG_SET_PMEMCORE_FUNC #endif #ifdef USE_LOG_PMEMOBJ #define LOG_SET_PMEMOBJ_FUNC \ - pmemobj_log_set_function((pmemobj_log_function *)ut_log_function, NULL) + pmemobj_log_set_function((pmemobj_log_function *)ut_log_function) #else #define LOG_SET_PMEMOBJ_FUNC #endif diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c index a3773e00cde..8c03185fbbe 100644 --- a/src/test/unittest/ut_log.c +++ b/src/test/unittest/ut_log.c @@ -20,7 +20,7 @@ static const int core_log_level_to_out_level[] = { }; void -ut_log_function(void *context, enum core_log_level level, const char *file_name, +ut_log_function(enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message) { out_log(file_name, line_no, function_name, From 522f15119a7bdf83ce337ca8c748c4b24ffd23b2 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 7 Mar 2024 14:06:41 +0100 Subject: [PATCH 120/182] test: fix static variable for clang Signed-off-by: Tomasz Gromadzki --- src/test/core_log_default_function/core_log_default_function.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/core_log_default_function/core_log_default_function.c b/src/test/core_log_default_function/core_log_default_function.c index 01f9ba42b0f..66312b07d38 100644 --- a/src/test/core_log_default_function/core_log_default_function.c +++ b/src/test/core_log_default_function/core_log_default_function.c @@ -50,7 +50,7 @@ static struct { const char *exp_file_info; } Common; -char *Strchr_ret; +static char *Strchr_ret; FUNC_MOCK(strrchr, char *, const char *__s, int __c) FUNC_MOCK_RUN_DEFAULT { From e06c1625ca189ba3fed02f62e3a8c1f63e2e9186 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 6 Mar 2024 14:12:33 -0500 Subject: [PATCH 121/182] common: core_log_set/get_threshold MT unit tests (part 2) - make core_log_threshold_mt a dedicated test - keep Core_log_threshold available only via API - add _core_log_get_threshold_internal() calls Ref: #6035 Signed-off-by: Jan Michalski --- src/core/log.c | 16 +- src/core/log_default.c | 4 +- src/core/log_internal.h | 12 +- src/test/Makefile | 2 +- src/test/core_log_mt/.gitignore | 1 - src/test/core_log_mt/core_log_mt.c | 105 ------------ src/test/core_log_threshold_mt/.gitignore | 1 + .../Makefile | 4 +- .../TESTS.py | 6 +- .../core_log_threshold_mt.c | 158 ++++++++++++++++++ 10 files changed, 186 insertions(+), 123 deletions(-) delete mode 100644 src/test/core_log_mt/.gitignore delete mode 100644 src/test/core_log_mt/core_log_mt.c create mode 100644 src/test/core_log_threshold_mt/.gitignore rename src/test/{core_log_mt => core_log_threshold_mt}/Makefile (73%) rename src/test/{core_log_mt => core_log_threshold_mt}/TESTS.py (82%) create mode 100644 src/test/core_log_threshold_mt/core_log_threshold_mt.c diff --git a/src/core/log.c b/src/core/log.c index de18b7c04b4..9151cb8e3bb 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -51,7 +51,7 @@ _Atomic uintptr_t Core_log_function = 0; /* threshold levels */ -enum core_log_level Core_log_threshold[] = { +static enum core_log_level Core_log_threshold[] = { CORE_LOG_THRESHOLD_DEFAULT, CORE_LOG_THRESHOLD_AUX_DEFAULT }; @@ -146,6 +146,7 @@ core_log_set_threshold(enum core_log_threshold threshold, return EINVAL; enum core_log_level level_old; + /* fed with already validated arguments it can't fail */ (void) core_log_get_threshold(threshold, &level_old); if (!__sync_bool_compare_and_swap(&Core_log_threshold[threshold], @@ -175,6 +176,17 @@ core_log_get_threshold(enum core_log_threshold threshold, return 0; } +/* + * _core_log_get_threshold_internal -- a core_log_get_threshold variant + * optimized for performance and not affecting the stack size of all + * the functions using the CORE_LOG_* macros. + */ +volatile enum core_log_level +_core_log_get_threshold_internal() +{ + return Core_log_threshold[CORE_LOG_THRESHOLD]; +} + static void inline core_log_va(char *buf, size_t buf_len, enum core_log_level level, int errnum, const char *file_name, int line_no, @@ -203,7 +215,7 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, * the CORE_LOG() macro it has to be done here again since it is not * performed in the case of the CORE_LOG_TO_LAST macro. Sorry. */ - if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) + if (level > _core_log_get_threshold_internal()) goto end; if (0 == Core_log_function) diff --git a/src/core/log_default.c b/src/core/log_default.c index 563844af97d..7f1549efce5 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -104,6 +104,7 @@ core_log_default_function(enum core_log_level level, const char *file_name, char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; const char file_info_error[] = "[file info error]: "; + enum core_log_level threshold_aux; if (file_name) { /* extract base_file_name */ @@ -136,7 +137,8 @@ core_log_default_function(enum core_log_level level, const char *file_name, } /* secondary logging destination (CORE_LOG_THRESHOLD_AUX) */ - if (level <= Core_log_threshold[CORE_LOG_THRESHOLD_AUX]) { + (void) core_log_get_threshold(CORE_LOG_THRESHOLD_AUX, &threshold_aux); + if (level <= threshold_aux) { char times_tamp[45] = ""; get_timestamp_prefix(times_tamp, sizeof(times_tamp)); (void) fprintf(stderr, "%s[%ld] %s%s%s\n", times_tamp, diff --git a/src/core/log_internal.h b/src/core/log_internal.h index fb1a8bcf452..f058d871a0e 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -62,6 +62,8 @@ int core_log_set_threshold(enum core_log_threshold threshold, int core_log_get_threshold(enum core_log_threshold threshold, enum core_log_level *level); +volatile enum core_log_level _core_log_get_threshold_internal(void); + /* * the type used for defining logging functions */ @@ -81,13 +83,6 @@ typedef void core_log_function( int core_log_set_function(core_log_function *log_function); -/* threshold levels */ -extern -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -enum core_log_level Core_log_threshold[CORE_LOG_THRESHOLD_MAX]; - void core_log_init(void); void core_log_fini(void); @@ -119,7 +114,8 @@ void core_log(enum core_log_level level, int errnum, const char *file_name, #define _CORE_LOG(level, errnum, format, ...) \ do { \ - if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ + if (level <= \ + _core_log_get_threshold_internal()) { \ core_log(level, errnum, __FILE__, __LINE__, \ __func__, format, ##__VA_ARGS__); \ } \ diff --git a/src/test/Makefile b/src/test/Makefile index 0f96dc0167f..1bf789e4fac 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -111,8 +111,8 @@ OTHER_TESTS = \ core_log_default_function\ core_log_internal\ core_log_max\ - core_log_mt\ core_log_no_func\ + core_log_threshold_mt\ checksum\ compat_incompat_features\ ctl_prefault\ diff --git a/src/test/core_log_mt/.gitignore b/src/test/core_log_mt/.gitignore deleted file mode 100644 index 806ac7ab750..00000000000 --- a/src/test/core_log_mt/.gitignore +++ /dev/null @@ -1 +0,0 @@ -core_log_mt diff --git a/src/test/core_log_mt/core_log_mt.c b/src/test/core_log_mt/core_log_mt.c deleted file mode 100644 index c69e7b714fd..00000000000 --- a/src/test/core_log_mt/core_log_mt.c +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2024, Intel Corporation */ - -/* - * core_log_internal.c -- unit test to CORE_LOG_... - */ - -#include "unittest.h" -#include "log_internal.h" - -#define NO_ARGS_CONSUMED 0 - -#define THREADS_IN_GROUP 10 -#define TOTAL_THREADS (THREADS_IN_GROUP * 2) -#define OP_REDO 4096 - -struct test_threshold_helper_ctx { - enum core_log_threshold threshold; - enum core_log_level level; -} threshold_helper_ [TOTAL_THREADS]; - -static void * -test_threshold_helper_set(void *arg) -{ - struct test_threshold_helper_ctx *ctx = - (struct test_threshold_helper_ctx *)arg; - for (int i = 0; i < OP_REDO; ++i) { - core_log_set_threshold(ctx->threshold, ctx->level); - } - return NULL; -} - -static void * -test_threshold_helper_get(void *arg) -{ - struct test_threshold_helper_ctx *ctx = - (struct test_threshold_helper_ctx *)arg; - for (int i = 0; i < OP_REDO; ++i) { - core_log_get_threshold(ctx->threshold, &ctx->level); - } - (void) ctx->level; - return NULL; -} - -static void -test_threshold_helper(enum core_log_threshold threshold) -{ - os_thread_t threads[TOTAL_THREADS]; - - /* core_log_set_threshold() threads */ - for (int idx = 0; idx < THREADS_IN_GROUP; idx++) { - threshold_helper_[idx].threshold = threshold; - threshold_helper_[idx].level = - (enum core_log_level)(idx % CORE_LOG_LEVEL_MAX); - THREAD_CREATE(&threads[idx], 0, test_threshold_helper_set, - (void *)&threshold_helper_[idx]); - } - - /* core_log_get_threshold() threads */ - for (int idx = THREADS_IN_GROUP; idx < TOTAL_THREADS; idx++) { - threshold_helper_[idx].threshold = threshold; - THREAD_CREATE(&threads[idx], 0, test_threshold_helper_get, - (void *)&threshold_helper_[idx]); - } - - for (int idx = 0; idx < TOTAL_THREADS; idx++) { - void *retval; - THREAD_JOIN(&threads[idx], &retval); - } -} - -/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD, ...) in parallel. */ -static int -test_threshold(const struct test_case *tc, int argc, char *argv[]) -{ - test_threshold_helper(CORE_LOG_THRESHOLD); - return NO_ARGS_CONSUMED; -} - -/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD_AUX, ...) in parallel. */ -static int -test_threshold_aux(const struct test_case *tc, int argc, char *argv[]) -{ - test_threshold_helper(CORE_LOG_THRESHOLD_AUX); - return NO_ARGS_CONSUMED; -} - -/* - * A Valgrind tool external to the test binary is assumed to monitor - * the execution and assess synchronisation correctness. - */ -static struct test_case test_cases[] = { - TEST_CASE(test_threshold), - TEST_CASE(test_threshold_aux), -}; - -#define NTESTS ARRAY_SIZE(test_cases) - -int -main(int argc, char *argv[]) -{ - START(argc, argv, "core_log_mt"); - TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); - DONE(NULL); -} diff --git a/src/test/core_log_threshold_mt/.gitignore b/src/test/core_log_threshold_mt/.gitignore new file mode 100644 index 00000000000..c949af1fe1d --- /dev/null +++ b/src/test/core_log_threshold_mt/.gitignore @@ -0,0 +1 @@ +core_log_threshold_mt diff --git a/src/test/core_log_mt/Makefile b/src/test/core_log_threshold_mt/Makefile similarity index 73% rename from src/test/core_log_mt/Makefile rename to src/test/core_log_threshold_mt/Makefile index 8df2f390710..2c7ad36734d 100644 --- a/src/test/core_log_mt/Makefile +++ b/src/test/core_log_threshold_mt/Makefile @@ -1,8 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024, Intel Corporation -TARGET = core_log_mt -OBJS = core_log_mt.o +TARGET = core_log_threshold_mt +OBJS = core_log_threshold_mt.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n diff --git a/src/test/core_log_mt/TESTS.py b/src/test/core_log_threshold_mt/TESTS.py similarity index 82% rename from src/test/core_log_mt/TESTS.py rename to src/test/core_log_threshold_mt/TESTS.py index 13a2377e89f..2b94d1a250c 100755 --- a/src/test/core_log_mt/TESTS.py +++ b/src/test/core_log_threshold_mt/TESTS.py @@ -14,15 +14,15 @@ class CORE_LOG_MT(t.BaseTest): test_type = t.Short def run(self, ctx): - ctx.exec('core_log_mt', self.test_case) + ctx.exec('core_log_threshold_mt', self.test_case) class THRESHOLD(CORE_LOG_MT): - test_case = 'test_threshold' + test_case = 'test_threshold_set_get' class THRESHOLD_AUX(CORE_LOG_MT): - test_case = 'test_threshold_aux' + test_case = 'test_threshold_aux_set_get' @t.require_valgrind_enabled('helgrind') diff --git a/src/test/core_log_threshold_mt/core_log_threshold_mt.c b/src/test/core_log_threshold_mt/core_log_threshold_mt.c new file mode 100644 index 00000000000..39abf21c66e --- /dev/null +++ b/src/test/core_log_threshold_mt/core_log_threshold_mt.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_threshold_mt.c -- unit test for core_log_set/get_threshold() and + * CORE_LOG_X() since all of them may write/read thresholds in parallel. + */ + +#include "unittest.h" +#include "log_internal.h" + +#define NO_ARGS_CONSUMED 0 + +#define THREADS_IN_GROUP 10 +#define THREADS_SET_MIN 0 +#define THREADS_SET_MAX (THREADS_SET_MIN + THREADS_IN_GROUP) +#define THREADS_GET_MIN THREADS_SET_MAX +#define THREADS_GET_MAX (THREADS_GET_MIN + THREADS_IN_GROUP) +#define TOTAL_THREADS THREADS_GET_MAX + +#define OP_REDO 4096 + +struct helper_ctx { + enum core_log_threshold threshold; + int idx; +} helper_ctx_ [TOTAL_THREADS]; + +os_mutex_t mutex; +os_cond_t cond; +unsigned threads_waiting; + +static void * +helper_set(void *arg) +{ + struct helper_ctx *ctx = (struct helper_ctx *)arg; + os_mutex_lock(&mutex); + ++threads_waiting; + os_cond_wait(&cond, &mutex); + os_mutex_unlock(&mutex); + for (int i = 0; i < OP_REDO; ++i) { + /* + * a simple attempt to generate a different sequence of values + * for each of the threads + */ + enum core_log_level level = + (enum core_log_level)((i * (ctx->idx + 1)) % + CORE_LOG_LEVEL_MAX); + int ret = core_log_set_threshold(ctx->threshold, level); + UT_ASSERT(ret == 0 || ret == EAGAIN); + if (ret == EAGAIN) { + UT_OUT("ret == EAGAIN"); /* just out of curiosity */ + } + } + return NULL; +} + +static void * +helper_get(void *arg) +{ + struct helper_ctx *ctx = (struct helper_ctx *)arg; + os_mutex_lock(&mutex); + ++threads_waiting; + os_cond_wait(&cond, &mutex); + os_mutex_unlock(&mutex); + for (int i = 0; i < OP_REDO; ++i) { + enum core_log_level level; + int ret = core_log_get_threshold(ctx->threshold, &level); + UT_ASSERTeq(ret, 0); + level = _core_log_get_threshold_internal(); + } + return NULL; +} + +static void +helper(enum core_log_threshold threshold) +{ + os_thread_t threads[TOTAL_THREADS]; + + os_mutex_init(&mutex); + os_cond_init(&cond); + threads_waiting = 0; + + /* core_log_set_threshold() threads */ + for (int idx = THREADS_SET_MIN; idx < THREADS_SET_MAX; idx++) { + helper_ctx_[idx].threshold = threshold; + helper_ctx_[idx].idx = idx; + THREAD_CREATE(&threads[idx], 0, helper_set, + (void *)&helper_ctx_[idx]); + } + + /* core_log_get_threshold/_core_log_get_threshold_internal() threads */ + for (int idx = THREADS_GET_MIN; idx < THREADS_GET_MAX; idx++) { + helper_ctx_[idx].threshold = threshold; + THREAD_CREATE(&threads[idx], 0, helper_get, + (void *)&helper_ctx_[idx]); + } + + do { + os_mutex_lock(&mutex); + if (threads_waiting == TOTAL_THREADS) { + os_cond_broadcast(&cond); + os_mutex_unlock(&mutex); + break; + } + os_mutex_unlock(&mutex); + } while (1); + + for (int idx = 0; idx < TOTAL_THREADS; idx++) { + void *retval; + THREAD_JOIN(&threads[idx], &retval); + } + + os_cond_destroy(&cond); + os_mutex_destroy(&mutex); +} + +/* tests */ + +/* + * Run core_log_set/get_threshold(CORE_LOG_THRESHOLD, ...) and CORE_LOG_X() + * in parallel. + */ +static int +test_threshold_set_get(const struct test_case *tc, int argc, char *argv[]) +{ + helper(CORE_LOG_THRESHOLD); + return NO_ARGS_CONSUMED; +} + +/* + * Run core_log_set/get_threshold(CORE_LOG_THRESHOLD_AUX, ...) and CORE_LOG_X() + * in parallel. + */ +static int +test_threshold_aux_set_get(const struct test_case *tc, int argc, char *argv[]) +{ + helper(CORE_LOG_THRESHOLD_AUX); + return NO_ARGS_CONSUMED; +} + +/* + * A Valgrind tool external to the test binary is assumed to monitor + * the execution and assess synchronisation correctness. + */ +static struct test_case test_cases[] = { + TEST_CASE(test_threshold_set_get), + TEST_CASE(test_threshold_aux_set_get), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log_threshold_mt"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} From cad581946a1dfc9d13f711cf4cf96ffda0083d97 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 8 Mar 2024 08:26:16 +0100 Subject: [PATCH 122/182] test: skip core_log_default_function tests for static builds Signed-off-by: Tomasz Gromadzki --- src/test/core_log_default_function/Makefile | 1 - src/test/core_log_default_function/TESTS.py | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/core_log_default_function/Makefile b/src/test/core_log_default_function/Makefile index 9d0d328c3b2..f81b3907a37 100644 --- a/src/test/core_log_default_function/Makefile +++ b/src/test/core_log_default_function/Makefile @@ -10,7 +10,6 @@ BUILD_STATIC_NONDEBUG=n # 'internal' is required for proper mock integration # 'debug' is required for debug version of core/log.o that provides # implementation of 'out_log()' that is used by 'ut_log_function()' - LIBPMEMCORE=internal-debug include ../Makefile.inc diff --git a/src/test/core_log_default_function/TESTS.py b/src/test/core_log_default_function/TESTS.py index 939ae671dd9..5768e37434d 100755 --- a/src/test/core_log_default_function/TESTS.py +++ b/src/test/core_log_default_function/TESTS.py @@ -9,6 +9,9 @@ @g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') class CORE_LOG(t.BaseTest): test_type = t.Short From 1c2e3fff4ac02da4fa0ab4a652b3fdbfc643ce9c Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 7 Mar 2024 16:12:17 -0500 Subject: [PATCH 123/182] common: add core_log_set_function() MT unit test Signed-off-by: Jan Michalski --- src/core/log.c | 30 +--- src/test/Makefile | 1 + src/test/core_log_function_mt/.gitignore | 1 + src/test/core_log_function_mt/Makefile | 12 ++ src/test/core_log_function_mt/TESTS.py | 33 ++++ .../core_log_function_mt.c | 155 ++++++++++++++++++ src/test/core_log_threshold_mt/TESTS.py | 18 +- 7 files changed, 219 insertions(+), 31 deletions(-) create mode 100644 src/test/core_log_function_mt/.gitignore create mode 100644 src/test/core_log_function_mt/Makefile create mode 100755 src/test/core_log_function_mt/TESTS.py create mode 100644 src/test/core_log_function_mt/core_log_function_mt.c diff --git a/src/core/log.c b/src/core/log.c index 9151cb8e3bb..9f87da38523 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -18,9 +18,6 @@ #include #include #include -#ifdef ATOMIC_OPERATIONS_SUPPORTED -#include -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ #include #include "log_internal.h" @@ -40,15 +37,11 @@ #endif /* - * Core_log_function -- pointer to the logging function saved as uintptr_t to - * make it _Atomic, because function pointers cannot be _Atomic. By default it - * is core_log_default_function(), but could be a user-defined logging function + * Core_log_function -- pointer to the logging function. By default it is + * core_log_default_function(), but could be a user-defined logging function * provided via core_log_set_function(). */ -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -uintptr_t Core_log_function = 0; +static core_log_function *Core_log_function = NULL; /* threshold levels */ static enum core_log_level Core_log_threshold[] = { @@ -87,7 +80,7 @@ core_log_fini() * the previous value was the default logging function or a user * logging function. */ - Core_log_function = 0; + Core_log_function = NULL; /* cleanup the default logging function */ core_log_default_fini(); @@ -116,19 +109,13 @@ core_log_set_function(core_log_function *log_function) if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) log_function = core_log_default_function; -#ifdef ATOMIC_OPERATIONS_SUPPORTED - atomic_store_explicit(&Core_log_function, (uintptr_t)log_function, - __ATOMIC_SEQ_CST); - return 0; -#else - uintptr_t core_log_function_old = Core_log_function; + core_log_function *core_log_function_old = Core_log_function; if (__sync_bool_compare_and_swap(&Core_log_function, - core_log_function_old, (uintptr_t)log_function)) { + core_log_function_old, log_function)) { core_log_lib_info(); return 0; } return EAGAIN; -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ } /* @@ -218,11 +205,10 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, if (level > _core_log_get_threshold_internal()) goto end; - if (0 == Core_log_function) + if (NULL == Core_log_function) goto end; - ((core_log_function *)Core_log_function)(level, file_name, line_no, - function_name, buf); + Core_log_function(level, file_name, line_no, function_name, buf); end: if (errnum != NO_ERRNO) diff --git a/src/test/Makefile b/src/test/Makefile index 1bf789e4fac..0cfdff1d793 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -109,6 +109,7 @@ OTHER_TESTS = \ arch_flags\ core_log\ core_log_default_function\ + core_log_function_mt\ core_log_internal\ core_log_max\ core_log_no_func\ diff --git a/src/test/core_log_function_mt/.gitignore b/src/test/core_log_function_mt/.gitignore new file mode 100644 index 00000000000..b61c703b86f --- /dev/null +++ b/src/test/core_log_function_mt/.gitignore @@ -0,0 +1 @@ +core_log_function_mt diff --git a/src/test/core_log_function_mt/Makefile b/src/test/core_log_function_mt/Makefile new file mode 100644 index 00000000000..72273d7a269 --- /dev/null +++ b/src/test/core_log_function_mt/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = core_log_function_mt +OBJS = core_log_function_mt.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +LIBPMEMCORE=nondebug + +include ../Makefile.inc diff --git a/src/test/core_log_function_mt/TESTS.py b/src/test/core_log_function_mt/TESTS.py new file mode 100755 index 00000000000..d76d1d9ee88 --- /dev/null +++ b/src/test/core_log_function_mt/TESTS.py @@ -0,0 +1,33 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'nondebug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('nondebug') +class CORE_LOG_MT(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('core_log_function_mt', self.test_case) + + +class SET_CALL(CORE_LOG_MT): + test_case = 'test_function_set_call' + + +@t.require_valgrind_enabled('helgrind') +class TEST0(SET_CALL): + pass + + +@t.require_valgrind_enabled('drd') +class TEST1(SET_CALL): + pass diff --git a/src/test/core_log_function_mt/core_log_function_mt.c b/src/test/core_log_function_mt/core_log_function_mt.c new file mode 100644 index 00000000000..c318d5a6520 --- /dev/null +++ b/src/test/core_log_function_mt/core_log_function_mt.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * core_log_function_mt.c -- unit test for core_log_set_function() and + * core_log() since both of them may write/read the log function pointer in + * parallel. + */ + +#include "unittest.h" +#include "log_internal.h" + +#define NO_ARGS_CONSUMED 0 + +#define THREADS_IN_GROUP 10 +#define THREADS_SET_MIN 0 +#define THREADS_SET_MAX (THREADS_SET_MIN + THREADS_IN_GROUP) +#define THREADS_CALL_MIN THREADS_SET_MAX +#define THREADS_CALL_MAX (THREADS_CALL_MIN + THREADS_IN_GROUP) +#define TOTAL_THREADS THREADS_CALL_MAX + +#define OP_REDO 4096 + +#define LOG_FUNC(FUNC_NAME) \ +static void \ +FUNC_NAME(enum core_log_level level, const char *file_name, const int line_no, \ + const char *function_name, const char *message) \ +{ \ + SUPPRESS_UNUSED(level, file_name, line_no, function_name, message); \ +} + +LOG_FUNC(log_func0) +LOG_FUNC(log_func1) +LOG_FUNC(log_func2) +LOG_FUNC(log_func3) +LOG_FUNC(log_func4) +LOG_FUNC(log_func5) +LOG_FUNC(log_func6) +LOG_FUNC(log_func7) +LOG_FUNC(log_func8) +LOG_FUNC(log_func9) + +core_log_function *log_funcs[] = { + log_func0, + log_func1, + log_func2, + log_func3, + log_func4, + log_func5, + log_func6, + log_func7, + log_func8, + log_func9, +}; + +#define N_LOG_FUNCS ARRAY_SIZE(log_funcs) + +os_mutex_t mutex; +os_cond_t cond; +unsigned threads_waiting; + +static void * +helper_set(void *arg) +{ + uint64_t idx = (uint64_t)arg; + os_mutex_lock(&mutex); + ++threads_waiting; + os_cond_wait(&cond, &mutex); + os_mutex_unlock(&mutex); + for (uint64_t i = 0; i < OP_REDO; ++i) { + core_log_function *log_func = + log_funcs[(i * (idx + 1)) % N_LOG_FUNCS]; + int ret = core_log_set_function(log_func); + UT_ASSERT(ret == 0 || ret == EAGAIN); + if (ret == EAGAIN) { + UT_OUT("ret == EAGAIN"); /* just out of curiosity */ + } + } + return NULL; +} + +static void * +helper_call(void *arg) +{ + SUPPRESS_UNUSED(arg); + + os_mutex_lock(&mutex); + ++threads_waiting; + os_cond_wait(&cond, &mutex); + os_mutex_unlock(&mutex); + for (uint64_t i = 0; i < OP_REDO; ++i) { + core_log(CORE_LOG_LEVEL_ERROR, NO_ERRNO, "", 0, "", ""); + } + return NULL; +} + +/* tests */ + +/* Run core_log_set_function() and core_log() in parallel. */ +static int +test_function_set_call(const struct test_case *tc, int argc, char *argv[]) +{ + os_thread_t threads[TOTAL_THREADS]; + + os_mutex_init(&mutex); + os_cond_init(&cond); + threads_waiting = 0; + + /* core_log_set_function() threads */ + for (uint64_t idx = THREADS_SET_MIN; idx < THREADS_SET_MAX; idx++) { + THREAD_CREATE(&threads[idx], 0, helper_set, (void *)idx); + } + + /* core_log() threads */ + for (uint64_t idx = THREADS_CALL_MIN; idx < THREADS_CALL_MAX; idx++) { + THREAD_CREATE(&threads[idx], 0, helper_call, NULL); + } + + do { + os_mutex_lock(&mutex); + if (threads_waiting == TOTAL_THREADS) { + os_cond_broadcast(&cond); + os_mutex_unlock(&mutex); + break; + } + os_mutex_unlock(&mutex); + } while (1); + + for (uint64_t idx = 0; idx < TOTAL_THREADS; idx++) { + void *retval; + THREAD_JOIN(&threads[idx], &retval); + } + + os_cond_destroy(&cond); + os_mutex_destroy(&mutex); + return NO_ARGS_CONSUMED; +} + +/* + * A Valgrind tool external to the test binary is assumed to monitor + * the execution and assess synchronisation correctness. + */ +static struct test_case test_cases[] = { + TEST_CASE(test_function_set_call), +}; + +#define NTESTS ARRAY_SIZE(test_cases) + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "core_log_function_mt"); + TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); + DONE(NULL); +} diff --git a/src/test/core_log_threshold_mt/TESTS.py b/src/test/core_log_threshold_mt/TESTS.py index 2b94d1a250c..115e6d43afa 100755 --- a/src/test/core_log_threshold_mt/TESTS.py +++ b/src/test/core_log_threshold_mt/TESTS.py @@ -17,29 +17,29 @@ def run(self, ctx): ctx.exec('core_log_threshold_mt', self.test_case) -class THRESHOLD(CORE_LOG_MT): +class TEST0(CORE_LOG_MT): test_case = 'test_threshold_set_get' -class THRESHOLD_AUX(CORE_LOG_MT): - test_case = 'test_threshold_aux_set_get' - - @t.require_valgrind_enabled('helgrind') -class TEST0(THRESHOLD): +class TEST1(TEST0): pass @t.require_valgrind_enabled('drd') -class TEST1(THRESHOLD): +class TEST2(TEST0): pass +class TEST3(CORE_LOG_MT): + test_case = 'test_threshold_aux_set_get' + + @t.require_valgrind_enabled('helgrind') -class TEST2(THRESHOLD_AUX): +class TEST4(TEST3): pass @t.require_valgrind_enabled('drd') -class TEST3(THRESHOLD_AUX): +class TEST5(TEST3): pass From 139bd372a5efa38aef0fb61ac2b0db57fd53f7e9 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Fri, 8 Mar 2024 16:04:08 -0500 Subject: [PATCH 124/182] test: add core_log_function_mt no-valgrind test Signed-off-by: Jan Michalski --- src/test/core_log_function_mt/TESTS.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/core_log_function_mt/TESTS.py b/src/test/core_log_function_mt/TESTS.py index d76d1d9ee88..c15dc8d6b90 100755 --- a/src/test/core_log_function_mt/TESTS.py +++ b/src/test/core_log_function_mt/TESTS.py @@ -12,22 +12,19 @@ # The 'nondebug' build is chosen arbitrarily to ensure these tests are run only # once. No dynamic libraries are used nor .static_* builds are available. @t.require_build('nondebug') -class CORE_LOG_MT(t.BaseTest): +class TEST0(t.BaseTest): test_type = t.Short + test_case = 'test_function_set_call' def run(self, ctx): ctx.exec('core_log_function_mt', self.test_case) -class SET_CALL(CORE_LOG_MT): - test_case = 'test_function_set_call' - - @t.require_valgrind_enabled('helgrind') -class TEST0(SET_CALL): +class TEST1(TEST0): pass @t.require_valgrind_enabled('drd') -class TEST1(SET_CALL): +class TEST2(TEST0): pass From 9c33b7d22b81a5914356ef50f47554373ece9737 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 11 Mar 2024 12:15:19 -0400 Subject: [PATCH 125/182] common: update actions/checkout to v4 It seems the only thing changed between v3 and v4 is node20. v4.1.1 has been used in our ci before. It was unified to directly use v4 which will make our life easier since we would not need to update these workflows till v5. Ref: https://github.com/actions/checkout/releases/tag/v4.0.0 Signed-off-by: Jan Michalski --- .github/workflows/docker_rebuild.yml | 2 +- .github/workflows/main.yml | 4 ++-- .github/workflows/nightly.yml | 4 ++-- .github/workflows/pmem.io_doc_update.yml | 2 +- .github/workflows/pmem_ras.yml | 2 +- .github/workflows/pmem_test_matrix.yml | 2 +- .github/workflows/pmem_tests.yml | 6 +++--- .github/workflows/scan_bandit.yml | 2 +- .github/workflows/scan_codeql.yml | 2 +- .github/workflows/scan_coverage.yml | 2 +- .github/workflows/scan_coverity.yml | 2 +- .github/workflows/scan_documentation.yml | 2 +- .github/workflows/scan_log_calls.yml | 2 +- .github/workflows/scan_stack_usage.yml | 2 +- .github/workflows/scan_ubsan.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- 16 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker_rebuild.yml b/.github/workflows/docker_rebuild.yml index 6d0444f2d75..dd740fef3d2 100644 --- a/.github/workflows/docker_rebuild.yml +++ b/.github/workflows/docker_rebuild.yml @@ -37,7 +37,7 @@ jobs: - {OS: ubuntu, OS_VER: 22.04} steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Rebuild the image env: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3460bcc149a..0cfb74cc9e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: issues: read steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # required for `make check-license` to work properly fetch-depth: 50 @@ -53,7 +53,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: sudo apt-get -y install pandoc diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index dc846995648..b2b43cef8b1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -35,7 +35,7 @@ jobs: TEST_BUILD: [debug, nondebug] steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 50 @@ -66,7 +66,7 @@ jobs: ] steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 50 diff --git a/.github/workflows/pmem.io_doc_update.yml b/.github/workflows/pmem.io_doc_update.yml index 8dce6d866ad..147bfabd3f2 100644 --- a/.github/workflows/pmem.io_doc_update.yml +++ b/.github/workflows/pmem.io_doc_update.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: sudo apt-get install libndctl-dev libdaxctl-dev pandoc diff --git a/.github/workflows/pmem_ras.yml b/.github/workflows/pmem_ras.yml index 703f48278b9..9a041e24a54 100644 --- a/.github/workflows/pmem_ras.yml +++ b/.github/workflows/pmem_ras.yml @@ -44,7 +44,7 @@ jobs: steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Variables, such as $ras_runner are hidden on the controller platform as environmental variables. # 'sed' command is used to filter out IP addresses from the ansible output, it will show up as the 'ras_runner' instead. diff --git a/.github/workflows/pmem_test_matrix.yml b/.github/workflows/pmem_test_matrix.yml index e4b9d47cbe8..ccb032b74c4 100644 --- a/.github/workflows/pmem_test_matrix.yml +++ b/.github/workflows/pmem_test_matrix.yml @@ -29,7 +29,7 @@ jobs: build: [debug, nondebug] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test prepare uses: ./.github/actions/pmem_test_prepare diff --git a/.github/workflows/pmem_tests.yml b/.github/workflows/pmem_tests.yml index a2857e91b19..36899997ea8 100644 --- a/.github/workflows/pmem_tests.yml +++ b/.github/workflows/pmem_tests.yml @@ -48,7 +48,7 @@ jobs: build: [static_debug, static_nondebug] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test prepare uses: ./.github/actions/pmem_test_prepare @@ -67,7 +67,7 @@ jobs: runs-on: [self-hosted, rhel] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test prepare uses: ./.github/actions/pmem_test_prepare @@ -90,7 +90,7 @@ jobs: runs-on: [self-hosted, rhel] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test prepare uses: ./.github/actions/pmem_test_prepare diff --git a/.github/workflows/scan_bandit.yml b/.github/workflows/scan_bandit.yml index d803661a766..ead974e30fa 100644 --- a/.github/workflows/scan_bandit.yml +++ b/.github/workflows/scan_bandit.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Bandit run: sudo apt-get -y install bandit diff --git a/.github/workflows/scan_codeql.yml b/.github/workflows/scan_codeql.yml index c45a4e70bfa..fc3c7183dcc 100644 --- a/.github/workflows/scan_codeql.yml +++ b/.github/workflows/scan_codeql.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pmem/valgrind (including dependencies) run: | diff --git a/.github/workflows/scan_coverage.yml b/.github/workflows/scan_coverage.yml index 20de43538b6..521c0fd8cb1 100644 --- a/.github/workflows/scan_coverage.yml +++ b/.github/workflows/scan_coverage.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Pull the image run: cd $WORKDIR && ./pull-or-rebuild-image.sh diff --git a/.github/workflows/scan_coverity.yml b/.github/workflows/scan_coverity.yml index c87f5f7076e..4c1c5703046 100644 --- a/.github/workflows/scan_coverity.yml +++ b/.github/workflows/scan_coverity.yml @@ -30,7 +30,7 @@ jobs: CONFIG: ["OS=ubuntu OS_VER=22.04"] steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Pull or rebuild the image run: cd $WORKDIR && ${{ matrix.CONFIG }} ./pull-or-rebuild-image.sh diff --git a/.github/workflows/scan_documentation.yml b/.github/workflows/scan_documentation.yml index d35231c489e..16c4993ea4d 100644 --- a/.github/workflows/scan_documentation.yml +++ b/.github/workflows/scan_documentation.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install required packages run: | diff --git a/.github/workflows/scan_log_calls.yml b/.github/workflows/scan_log_calls.yml index dde2334ff35..406ce1275a5 100644 --- a/.github/workflows/scan_log_calls.yml +++ b/.github/workflows/scan_log_calls.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4 - name: Generate log calls' diff working-directory: ${{ env.WORKING_DIRECTORY }} diff --git a/.github/workflows/scan_stack_usage.yml b/.github/workflows/scan_stack_usage.yml index 09d882fc3ed..e133b31ce44 100644 --- a/.github/workflows/scan_stack_usage.yml +++ b/.github/workflows/scan_stack_usage.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: pmdk diff --git a/.github/workflows/scan_ubsan.yml b/.github/workflows/scan_ubsan.yml index 2c8427f222b..3693783ca22 100644 --- a/.github/workflows/scan_ubsan.yml +++ b/.github/workflows/scan_ubsan.yml @@ -28,7 +28,7 @@ jobs: build: ['debug', 'nondebug'] steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Pull the image run: cd $WORKDIR && ./pull-or-rebuild-image.sh diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index d92ac089b9c..7874483f567 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -27,7 +27,7 @@ jobs: TEST_BUILD: ['debug', 'nondebug'] steps: - name: Clone the git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 50 From 8015afb4417d8e8af813ae47b092df6d41689f30 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 11 Mar 2024 10:07:31 -0400 Subject: [PATCH 126/182] common: add parallel clang Main / Basic build Signed-off-by: Jan Michalski --- .github/workflows/main.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3460bcc149a..7e2e32e163c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,14 @@ jobs: basic_build: name: Basic build runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - CC: gcc + CXX: g++ + - CC: clang + CXX: clang++ steps: - name: Clone the git repo uses: actions/checkout@v3 @@ -61,6 +69,8 @@ jobs: - name: Build sources env: NDCTL_ENABLE: n # just to speed up the job + CC: ${{ matrix.CC }} + CXX: ${{ matrix.CXX }} run: make -j$(nproc) test From 580750a1dd4b017d11342f8bc04863c22d5a8d8f Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 11 Mar 2024 11:12:38 -0400 Subject: [PATCH 127/182] test: instroduce FUNC_MOCK_NONSTATIC and FUNC_MOCK_EXTERN Signed-off-by: Jan Michalski --- src/test/Makefile.inc | 2 +- src/test/core_log/core_log_common.c | 9 +++++---- src/test/core_log/core_log_common.h | 8 ++++---- src/test/unittest/README | 3 ++- src/test/unittest/unittest.h | 13 +++++++++++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index f9f635758e4..3d581ea6a83 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -455,7 +455,7 @@ endif PAREN=( extract_funcs = $(shell \ awk -F '[$(PAREN),]' \ - '/(FUNC_MOCK_RET_ALWAYS|FUNC_MOCK_RET_ALWAYS_VOID|FUNC_MOCK)\$(PAREN)[^,]/ \ + '/(FUNC_MOCK_RET_ALWAYS|FUNC_MOCK_RET_ALWAYS_VOID|FUNC_MOCK|FUNC_MOCK_NONSTATIC)\$(PAREN)[^,]/ \ { \ print "-Wl,--wrap=" $$2 \ }' $(1) ) diff --git a/src/test/core_log/core_log_common.c b/src/test/core_log/core_log_common.c index d9dea37a68f..727ce318fbf 100644 --- a/src/test/core_log/core_log_common.c +++ b/src/test/core_log/core_log_common.c @@ -17,13 +17,13 @@ struct vsnprintf_ctx Vsnprintf_; struct strerror_r_ctx Strerror_r; struct log_function_ctx Log_function_; -FUNC_MOCK(last_error_msg_get, const char *, void) +FUNC_MOCK_NONSTATIC(last_error_msg_get, const char *, void) FUNC_MOCK_RUN_DEFAULT { return LAST_ERROR_MSG_MOCK; } FUNC_MOCK_END -FUNC_MOCK(vsnprintf, int, char *__restrict __s, size_t __maxlen, +FUNC_MOCK_NONSTATIC(vsnprintf, int, char *__restrict __s, size_t __maxlen, const char *__restrict __format, va_list __arg) FUNC_MOCK_RUN(VALIDATED_CALL) { if (Common.use_last_error_msg) { @@ -43,7 +43,8 @@ FUNC_MOCK_RUN_DEFAULT { } FUNC_MOCK_END -FUNC_MOCK(__xpg_strerror_r, int, int __errnum, char *__buf, size_t __buflen) +FUNC_MOCK_NONSTATIC(__xpg_strerror_r, int, int __errnum, char *__buf, + size_t __buflen) FUNC_MOCK_RUN_DEFAULT { UT_ASSERTeq(__errnum, DUMMY_ERRNO1); UT_ASSERTeq(__buf, Strerror_r.exp__buf); @@ -62,7 +63,7 @@ FUNC_MOCK_RUN_DEFAULT { } FUNC_MOCK_END -FUNC_MOCK(core_log_default_function, void, enum core_log_level level, +FUNC_MOCK_NONSTATIC(core_log_default_function, void, enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message) FUNC_MOCK_RUN(VALIDATED_CALL) { diff --git a/src/test/core_log/core_log_common.h b/src/test/core_log/core_log_common.h index bb6307fee41..b2f6909af27 100644 --- a/src/test/core_log/core_log_common.h +++ b/src/test/core_log/core_log_common.h @@ -45,10 +45,10 @@ extern struct log_function_ctx { /* mocks */ -extern unsigned RCOUNTER(last_error_msg_get); -extern unsigned RCOUNTER(vsnprintf); -extern unsigned RCOUNTER(__xpg_strerror_r); -extern unsigned RCOUNTER(core_log_default_function); +FUNC_MOCK_EXTERN(last_error_msg_get); +FUNC_MOCK_EXTERN(vsnprintf); +FUNC_MOCK_EXTERN(__xpg_strerror_r); +FUNC_MOCK_EXTERN(core_log_default_function); /* helpers */ diff --git a/src/test/unittest/README b/src/test/unittest/README index c5c8fb9c6c6..ea50a92f6f6 100644 --- a/src/test/unittest/README +++ b/src/test/unittest/README @@ -6,7 +6,8 @@ This directory contains the unit test framework used by the Persistent Memory Development Kit unit tests. This framework provides a support for mock objects. To mock an interface use -FUNC_MOCK_RET_ALWAYS or FUNC_MOCK macros in the test code. +FUNC_MOCK_RET_ALWAYS, FUNC_MOCK_RET_ALWAYS_VOID, FUNC_MOCK or +FUNC_MOCK_NONSTATIC macros in the test code. The FUNC_MOCK_RET_ALWAYS is quite straightforward, it simply takes a function name and a value that the given function has to return. For example: diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index c13422871ee..645168b9171 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -557,13 +557,22 @@ int ut_thread_join(const char *file, int line, const char *func, #define FUNC_MOCK_RCOUNTER_SET(name, val)\ RCOUNTER(name) = val; -#define FUNC_MOCK(name, ret_type, ...)\ +#define _FUNC_MOCK(type, name, ret_type, ...)\ _FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\ - unsigned RCOUNTER(name);\ + type unsigned RCOUNTER(name);\ ret_type __wrap_##name(__VA_ARGS__);\ ret_type __wrap_##name(__VA_ARGS__) {\ switch (util_fetch_and_add32(&RCOUNTER(name), 1)) { +#define FUNC_MOCK(name, ret_type, ...) \ + _FUNC_MOCK(static, name, ret_type, ##__VA_ARGS__) + +#define FUNC_MOCK_NONSTATIC(name, ret_type, ...) \ + _FUNC_MOCK(, name, ret_type, ##__VA_ARGS__) + +#define FUNC_MOCK_EXTERN(name) \ + extern unsigned RCOUNTER(name) + #define FUNC_MOCK_DLLIMPORT(name, ret_type, ...)\ __declspec(dllimport) _FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\ static unsigned RCOUNTER(name);\ From ce041fc5d4eb9a366f3bcf782d2db49e3d6ade26 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 7 Mar 2024 15:08:23 -0500 Subject: [PATCH 128/182] test: don't configure the log function for PMEMOBJ... ... nor PMEMCORE. Signed-off-by: Jan Michalski --- src/core/out.h | 3 ++ src/test/Makefile.inc | 15 ++-------- src/test/core_log/Makefile.inc | 3 +- src/test/core_log_default_function/Makefile | 4 +-- src/test/core_log_function_mt/Makefile | 2 +- .../core_log_internal/core_log_internal.c | 3 -- src/test/core_log_no_func/core_log_no_func.c | 3 -- src/test/core_log_threshold_mt/Makefile | 2 +- src/test/unittest/Makefile | 3 +- src/test/unittest/unittest.h | 25 +---------------- src/test/unittest/ut_log.c | 28 ------------------- 11 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 src/test/unittest/ut_log.c diff --git a/src/core/out.h b/src/core/out.h index 772d927aece..d4fc989d38f 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -68,8 +68,11 @@ void out_init(const char *log_prefix, const char *log_level_var, const char *log_file_var, int major_version, int minor_version); void out_fini(void); + +#ifdef DEBUG void out_log(const char *file, int line, const char *func, int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); +#endif #ifdef __cplusplus } diff --git a/src/test/Makefile.inc b/src/test/Makefile.inc index f9f635758e4..0da5eee2186 100644 --- a/src/test/Makefile.inc +++ b/src/test/Makefile.inc @@ -385,13 +385,11 @@ endif ifeq ($(LIBPMEMCORE), y) LIBPMEM=y -USE_LOG_PMEMCORE=y OBJS += $(LIBS_DIR)/debug/libpmemcore.a INCS += -I$(TOP)/src/core endif ifeq ($(LIBPMEMCORE), internal-nondebug) -USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/nondebug/core/alloc.o\ $(TOP)/src/nondebug/core/fs_posix.o\ @@ -410,7 +408,6 @@ INCS += -I$(TOP)/src/core endif ifeq ($(LIBPMEMCORE), internal-debug) -USE_LOG_PMEMCORE=y OBJS +=\ $(TOP)/src/debug/core/alloc.o\ $(TOP)/src/debug/core/fs_posix.o\ @@ -531,19 +528,13 @@ CFLAGS += -DFAULT_INJECTION=1 CXXFLAGS += -DFAULT_INJECTION=1 endif -ifeq ($(USE_LOG_PMEMCORE),y) -CFLAGS += -DUSE_LOG_PMEMCORE -endif - ifeq ($(USE_LOG_PMEMOBJ),y) CFLAGS += -DUSE_LOG_PMEMOBJ endif -# USE_LOG_PMEMCORE != y means the binary is built without directly linking with -# core units which are required by libut.a (ut_log.c to be exact). -# In case the binary is built with directly linking with core units it is -# assumed the following are among them already. -ifneq ($(USE_LOG_PMEMCORE),y) +# LIBPMEMCORE == '' means the binary is built without directly linking with +# core units which are required whenever test makes use of core utils. +ifeq ($(LIBPMEMCORE),) OBJS += $(TOP)/src/debug/core/out.o OBJS += $(TOP)/src/debug/core/last_error_msg.o OBJS += $(TOP)/src/debug/core/log.o diff --git a/src/test/core_log/Makefile.inc b/src/test/core_log/Makefile.inc index 7eb23ab70c0..1e2ecb614bb 100644 --- a/src/test/core_log/Makefile.inc +++ b/src/test/core_log/Makefile.inc @@ -4,8 +4,7 @@ BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n -# 'internal' is required for proper mock integration -# 'debug' provides 'out_log()' required for 'ut_log_function()' +# required for proper mock integration LIBPMEMCORE=internal-debug include ../Makefile.inc diff --git a/src/test/core_log_default_function/Makefile b/src/test/core_log_default_function/Makefile index f81b3907a37..6857d30cb99 100644 --- a/src/test/core_log_default_function/Makefile +++ b/src/test/core_log_default_function/Makefile @@ -7,9 +7,7 @@ OBJS = core_log_default_function.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n -# 'internal' is required for proper mock integration -# 'debug' is required for debug version of core/log.o that provides -# implementation of 'out_log()' that is used by 'ut_log_function()' +# required for proper mock integration LIBPMEMCORE=internal-debug include ../Makefile.inc diff --git a/src/test/core_log_function_mt/Makefile b/src/test/core_log_function_mt/Makefile index 72273d7a269..4029f83a0ac 100644 --- a/src/test/core_log_function_mt/Makefile +++ b/src/test/core_log_function_mt/Makefile @@ -7,6 +7,6 @@ OBJS = core_log_function_mt.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n -LIBPMEMCORE=nondebug +LIBPMEMCORE=y include ../Makefile.inc diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c index 637cce50518..948a4aea915 100644 --- a/src/test/core_log_internal/core_log_internal.c +++ b/src/test/core_log_internal/core_log_internal.c @@ -245,9 +245,6 @@ static struct test_case test_cases[] = { #undef abort extern void abort(void) __THROW __attribute__((__noreturn__)); -#undef LOG_SET_PMEMCORE_FUNC -#define LOG_SET_PMEMCORE_FUNC - int main(int argc, char *argv[]) { diff --git a/src/test/core_log_no_func/core_log_no_func.c b/src/test/core_log_no_func/core_log_no_func.c index 4b64500f845..d3672c3ca70 100644 --- a/src/test/core_log_no_func/core_log_no_func.c +++ b/src/test/core_log_no_func/core_log_no_func.c @@ -55,9 +55,6 @@ static struct test_case test_cases[] = { #define NTESTS ARRAY_SIZE(test_cases) -#undef LOG_SET_PMEMCORE_FUNC -#define LOG_SET_PMEMCORE_FUNC - int main(int argc, char *argv[]) { diff --git a/src/test/core_log_threshold_mt/Makefile b/src/test/core_log_threshold_mt/Makefile index 2c7ad36734d..545331e97fc 100644 --- a/src/test/core_log_threshold_mt/Makefile +++ b/src/test/core_log_threshold_mt/Makefile @@ -7,6 +7,6 @@ OBJS = core_log_threshold_mt.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n -LIBPMEMCORE=nondebug +LIBPMEMCORE=y include ../Makefile.inc diff --git a/src/test/unittest/Makefile b/src/test/unittest/Makefile index 59e580e3ac4..6244049d16b 100644 --- a/src/test/unittest/Makefile +++ b/src/test/unittest/Makefile @@ -16,8 +16,7 @@ vpath %.h $(TOP)/src/core TARGET_UT = libut.a OBJS_UT = ut.o ut_alloc.o ut_file.o ut_pthread.o ut_signal.o ut_backtrace.o\ - os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o\ - ut_log.o + os_posix.o os_thread_posix.o util.o alloc.o rand.o ut_fh.o ut_mt.o CFLAGS = -I$(TOP)/src/include CFLAGS += -I$(TOP)/src/common diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index c13422871ee..dfcf9d195b9 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -121,32 +121,9 @@ void ut_err(const char *file, int line, const char *func, const char *fmt, ...) __attribute__((format(printf, 4, 5))); -void -ut_log_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, - const char *message); - -#ifdef USE_LOG_PMEMCORE -#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function) -#else -#define LOG_SET_PMEMCORE_FUNC -#endif - -#ifdef USE_LOG_PMEMOBJ -#define LOG_SET_PMEMOBJ_FUNC \ - pmemobj_log_set_function((pmemobj_log_function *)ut_log_function) -#else -#define LOG_SET_PMEMOBJ_FUNC -#endif - /* indicate the start of the test */ #define START(argc, argv, ...)\ - do {\ - ut_start(__FILE__, __LINE__, __func__, argc, argv,\ - __VA_ARGS__);\ - LOG_SET_PMEMCORE_FUNC; \ - LOG_SET_PMEMOBJ_FUNC; \ - } while (0) + ut_start(__FILE__, __LINE__, __func__, argc, argv, __VA_ARGS__) /* normal exit from test */ #define DONE(...)\ diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c deleted file mode 100644 index 8c03185fbbe..00000000000 --- a/src/test/unittest/ut_log.c +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2024, Intel Corporation */ - -/* - * ut_log.c -- unit test log function - * - */ - -#include "unittest.h" -#include "out.h" - -static const int core_log_level_to_out_level[] = { - [CORE_LOG_LEVEL_HARK] = 1, - [CORE_LOG_LEVEL_FATAL] = 1, - [CORE_LOG_LEVEL_ERROR] = 1, - [CORE_LOG_LEVEL_WARNING] = 2, - [CORE_LOG_LEVEL_NOTICE] = 3, - [CORE_LOG_LEVEL_INFO] = 4, - [CORE_LOG_LEVEL_DEBUG] = 4, -}; - -void -ut_log_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, const char *message) -{ - out_log(file_name, line_no, function_name, - core_log_level_to_out_level[(int)level], "%s", message); -} From 6f2c54a9c764ecc8ee59e6ffea71e4cc62888281 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 11 Mar 2024 12:41:48 -0400 Subject: [PATCH 129/182] test: exclude core_log* from pmemcheck and/or memcheck Signed-off-by: Jan Michalski --- src/test/core_log/TESTS.py | 1 + src/test/core_log_default_function/TESTS.py | 1 + src/test/core_log_function_mt/TESTS.py | 1 + src/test/core_log_internal/TESTS.py | 1 + src/test/core_log_max/TESTS.py | 1 + src/test/core_log_no_func/TESTS.py | 1 + src/test/core_log_threshold_mt/TESTS.py | 1 + 7 files changed, 7 insertions(+) diff --git a/src/test/core_log/TESTS.py b/src/test/core_log/TESTS.py index 975d3d5cc73..8b509638e2c 100755 --- a/src/test/core_log/TESTS.py +++ b/src/test/core_log/TESTS.py @@ -9,6 +9,7 @@ @g.require_granularity(g.ANY) +@t.require_valgrind_disabled('pmemcheck') # The 'nondebug' build is chosen arbitrarily to ensure these tests are run only # once. No dynamic libraries are used nor .static_* builds are available. @t.require_build('nondebug') diff --git a/src/test/core_log_default_function/TESTS.py b/src/test/core_log_default_function/TESTS.py index 5768e37434d..5121a713337 100755 --- a/src/test/core_log_default_function/TESTS.py +++ b/src/test/core_log_default_function/TESTS.py @@ -9,6 +9,7 @@ @g.require_granularity(g.ANY) +@t.require_valgrind_disabled('pmemcheck') # The 'debug' build is chosen arbitrarily to ensure these tests are run only # once. No dynamic libraries are used nor .static_* builds are available. @t.require_build('debug') diff --git a/src/test/core_log_function_mt/TESTS.py b/src/test/core_log_function_mt/TESTS.py index c15dc8d6b90..56c93227f9f 100755 --- a/src/test/core_log_function_mt/TESTS.py +++ b/src/test/core_log_function_mt/TESTS.py @@ -9,6 +9,7 @@ @g.require_granularity(g.ANY) +@t.require_valgrind_disabled('pmemcheck', 'memcheck') # The 'nondebug' build is chosen arbitrarily to ensure these tests are run only # once. No dynamic libraries are used nor .static_* builds are available. @t.require_build('nondebug') diff --git a/src/test/core_log_internal/TESTS.py b/src/test/core_log_internal/TESTS.py index 5e179c3968f..4db34d21f22 100755 --- a/src/test/core_log_internal/TESTS.py +++ b/src/test/core_log_internal/TESTS.py @@ -10,6 +10,7 @@ @g.require_granularity(g.ANY) @t.require_build('nondebug') +@t.require_valgrind_disabled('pmemcheck') class CORE_LOG(t.BaseTest): test_type = t.Short diff --git a/src/test/core_log_max/TESTS.py b/src/test/core_log_max/TESTS.py index 89e60b44a73..c09cc5fc4da 100755 --- a/src/test/core_log_max/TESTS.py +++ b/src/test/core_log_max/TESTS.py @@ -10,6 +10,7 @@ @g.require_granularity(g.ANY) @t.require_build('nondebug') +@t.require_valgrind_disabled('pmemcheck') class CORE_LOG(t.BaseTest): test_type = t.Short diff --git a/src/test/core_log_no_func/TESTS.py b/src/test/core_log_no_func/TESTS.py index 55c52d048d8..b058118966c 100755 --- a/src/test/core_log_no_func/TESTS.py +++ b/src/test/core_log_no_func/TESTS.py @@ -9,6 +9,7 @@ @g.require_granularity(g.ANY) +@t.require_valgrind_disabled('pmemcheck') # The 'nondebug' build is chosen arbitrarily to ensure these tests are run only # once. No dynamic libraries are used nor .static_* builds are available. @t.require_build('nondebug') diff --git a/src/test/core_log_threshold_mt/TESTS.py b/src/test/core_log_threshold_mt/TESTS.py index 115e6d43afa..fffa0d7faf9 100755 --- a/src/test/core_log_threshold_mt/TESTS.py +++ b/src/test/core_log_threshold_mt/TESTS.py @@ -10,6 +10,7 @@ @g.require_granularity(g.ANY) @t.require_build('nondebug') +@t.require_valgrind_disabled('pmemcheck', 'memcheck') class CORE_LOG_MT(t.BaseTest): test_type = t.Short From eb5bec0c63ad7dc970e3bed885136029e6a6bffc Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Mon, 11 Mar 2024 11:20:36 -0400 Subject: [PATCH 130/182] test: add missing static (clang fix) Signed-off-by: Jan Michalski --- src/test/core_log_function_mt/core_log_function_mt.c | 8 ++++---- src/test/core_log_threshold_mt/core_log_threshold_mt.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/core_log_function_mt/core_log_function_mt.c b/src/test/core_log_function_mt/core_log_function_mt.c index c318d5a6520..afacd31d313 100644 --- a/src/test/core_log_function_mt/core_log_function_mt.c +++ b/src/test/core_log_function_mt/core_log_function_mt.c @@ -40,7 +40,7 @@ LOG_FUNC(log_func7) LOG_FUNC(log_func8) LOG_FUNC(log_func9) -core_log_function *log_funcs[] = { +static core_log_function *log_funcs[] = { log_func0, log_func1, log_func2, @@ -55,9 +55,9 @@ core_log_function *log_funcs[] = { #define N_LOG_FUNCS ARRAY_SIZE(log_funcs) -os_mutex_t mutex; -os_cond_t cond; -unsigned threads_waiting; +static os_mutex_t mutex; +static os_cond_t cond; +static unsigned threads_waiting; static void * helper_set(void *arg) diff --git a/src/test/core_log_threshold_mt/core_log_threshold_mt.c b/src/test/core_log_threshold_mt/core_log_threshold_mt.c index 39abf21c66e..eb854e968c5 100644 --- a/src/test/core_log_threshold_mt/core_log_threshold_mt.c +++ b/src/test/core_log_threshold_mt/core_log_threshold_mt.c @@ -20,14 +20,14 @@ #define OP_REDO 4096 -struct helper_ctx { +static struct helper_ctx { enum core_log_threshold threshold; int idx; } helper_ctx_ [TOTAL_THREADS]; -os_mutex_t mutex; -os_cond_t cond; -unsigned threads_waiting; +static os_mutex_t mutex; +static os_cond_t cond; +static unsigned threads_waiting; static void * helper_set(void *arg) From 9a96de07b85c39aca55004b3ecbd7e15e99b99b6 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 11 Mar 2024 20:53:49 +0100 Subject: [PATCH 131/182] test: UT for core_log_set_function() Signed-off-by: Tomasz Gromadzki --- src/test/core_log/TESTS.py | 4 +++ src/test/core_log/core_log.c | 41 ++++++++++++++++++++++++++--- src/test/core_log/core_log_common.c | 29 ++++++++++++++++++++ src/test/core_log/core_log_common.h | 5 ++++ 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/test/core_log/TESTS.py b/src/test/core_log/TESTS.py index 8b509638e2c..c84ad1578e3 100755 --- a/src/test/core_log/TESTS.py +++ b/src/test/core_log/TESTS.py @@ -46,3 +46,7 @@ class TEST5(CORE_LOG): class TEST6(CORE_LOG): test_case = 'test_happy_day' + + +class TEST7(CORE_LOG): + test_case = 'test_set_custom_function' diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c index 75aa59891f6..5801f02ef0c 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log/core_log.c @@ -2,7 +2,8 @@ /* Copyright 2024, Intel Corporation */ /* - * core_log.c -- unit test for core_log() and core_log_va() + * core_log.c -- unit test for core_log(), core_log_va() and + * core_log_set_function() */ #include @@ -172,11 +173,25 @@ test_level_gt_threshold(const struct test_case *tc, int argc, char *argv[]) } static int -test_happy_day(const struct test_case *tc, int argc, char *argv[]) +test_happy_day_helper(core_log_function *log_function) { /* Pass the message all the way to the logging function. */ core_log_set_threshold(CORE_LOG_THRESHOLD, CORE_LOG_LEVEL_ERROR); + /* + * Disable the validation as custom_log_function() may be called from + * core_log_set_function(). + */ + if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) { + FUNC_MOCK_RCOUNTER_SET(core_log_default_function, + NOT_VALIDATED_CALL); + } else { + FUNC_MOCK_RCOUNTER_SET(custom_log_function, + NOT_VALIDATED_CALL); + } + + core_log_set_function(log_function); + reset_mocks(); /* set the expectations */ @@ -195,11 +210,30 @@ test_happy_day(const struct test_case *tc, int argc, char *argv[]) UT_ASSERTeq(RCOUNTER(last_error_msg_get), CALLED); UT_ASSERTeq(RCOUNTER(vsnprintf), CALLED); UT_ASSERTeq(RCOUNTER(__xpg_strerror_r), CALLED); - UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); + if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) { + UT_ASSERTeq(RCOUNTER(core_log_default_function), CALLED); + UT_ASSERTeq(RCOUNTER(custom_log_function), NOT_CALLED); + } else { + UT_ASSERTeq(RCOUNTER(core_log_default_function), NOT_CALLED); + UT_ASSERTeq(RCOUNTER(custom_log_function), CALLED); + } return NO_ARGS_CONSUMED; } +static int +test_happy_day(const struct test_case *tc, int argc, char *argv[]) +{ + return test_happy_day_helper(CORE_LOG_USE_DEFAULT_FUNCTION); +} + +/* Happy day scenario with custom logging function */ +static int +test_set_custom_function(const struct test_case *tc, int argc, char *argv[]) +{ + return test_happy_day_helper(custom_log_function); +} + static struct test_case test_cases[] = { TEST_CASE(test_CORE_LOG_LEVEL_ERROR_LAST), TEST_CASE(test_vsnprintf_fail), @@ -208,6 +242,7 @@ static struct test_case test_cases[] = { TEST_CASE(test_strerror_r_fail), TEST_CASE(test_level_gt_threshold), TEST_CASE(test_happy_day), + TEST_CASE(test_set_custom_function), }; #define NTESTS ARRAY_SIZE(test_cases) diff --git a/src/test/core_log/core_log_common.c b/src/test/core_log/core_log_common.c index 727ce318fbf..63c1f7c1651 100644 --- a/src/test/core_log/core_log_common.c +++ b/src/test/core_log/core_log_common.c @@ -84,6 +84,34 @@ FUNC_MOCK_RUN_DEFAULT { } FUNC_MOCK_END +FUNC_MOCK_NONSTATIC(custom_log_function, void, enum core_log_level level, + const char *file_name, const int line_no, const char *function_name, + const char *message) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(level, Log_function_.exp_level); + UT_ASSERTstreq(file_name, FILE_NAME); + UT_ASSERTeq(line_no, LINE_NO); + UT_ASSERTstreq(function_name, FUNC_NAME); + if (Common.use_last_error_msg) { + UT_ASSERTeq(message, LAST_ERROR_MSG_MOCK); + } else { + UT_ASSERTne(message, LAST_ERROR_MSG_MOCK); + } + return; + } +FUNC_MOCK_RUN_DEFAULT { + _FUNC_REAL(custom_log_function)(level, file_name, line_no, + function_name, message); +} +FUNC_MOCK_END + +void +custom_log_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message) +{ + SUPPRESS_UNUSED(level, file_name, line_no, function_name, message); +} + /* helpers */ void @@ -93,6 +121,7 @@ reset_mocks(void) FUNC_MOCK_RCOUNTER_SET(vsnprintf, VALIDATED_CALL); FUNC_MOCK_RCOUNTER_SET(__xpg_strerror_r, VALIDATED_CALL); FUNC_MOCK_RCOUNTER_SET(core_log_default_function, VALIDATED_CALL); + FUNC_MOCK_RCOUNTER_SET(custom_log_function, VALIDATED_CALL); } void diff --git a/src/test/core_log/core_log_common.h b/src/test/core_log/core_log_common.h index b2f6909af27..c07c2384ef6 100644 --- a/src/test/core_log/core_log_common.h +++ b/src/test/core_log/core_log_common.h @@ -23,6 +23,7 @@ #define VALIDATED_CALL 127 #define NOT_CALLED VALIDATED_CALL #define CALLED (VALIDATED_CALL + 1) +#define NOT_VALIDATED_CALL 0 extern struct common_ctx { bool use_last_error_msg; @@ -49,6 +50,7 @@ FUNC_MOCK_EXTERN(last_error_msg_get); FUNC_MOCK_EXTERN(vsnprintf); FUNC_MOCK_EXTERN(__xpg_strerror_r); FUNC_MOCK_EXTERN(core_log_default_function); +FUNC_MOCK_EXTERN(custom_log_function); /* helpers */ @@ -60,3 +62,6 @@ void test_strerror_r_fail_helper(bool before_glibc_2_13); void test_log_function_call_helper(enum core_log_level level, bool call_log_function); + +void custom_log_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message); From d412c3656b968f0e701511203e6602d9151c82f8 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 31 Oct 2023 13:35:35 +0100 Subject: [PATCH 132/182] common: remove obsolete headers files Signed-off-by: Tomasz Gromadzki --- src/libpmem2/badblocks_ndctl.c | 1 - src/libpmem2/usc_ndctl.c | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libpmem2/badblocks_ndctl.c b/src/libpmem2/badblocks_ndctl.c index 35a914e9566..c7a8b4dd582 100644 --- a/src/libpmem2/badblocks_ndctl.c +++ b/src/libpmem2/badblocks_ndctl.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "libpmem2.h" #include "pmem2_utils.h" diff --git a/src/libpmem2/usc_ndctl.c b/src/libpmem2/usc_ndctl.c index 9ce2097274f..72cf9df3c02 100644 --- a/src/libpmem2/usc_ndctl.c +++ b/src/libpmem2/usc_ndctl.c @@ -5,7 +5,6 @@ * usc_ndctl.c -- pmem2 usc function for platforms using ndctl */ #include -#include #include #include #include From 00a2fed203e097301328203ed88594430071870a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 21 Nov 2023 07:52:26 +0100 Subject: [PATCH 133/182] common: remove unsupported FreeBSD related define Signed-off-by: Tomasz Gromadzki --- src/core/valgrind_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/valgrind_internal.h b/src/core/valgrind_internal.h index 5e203bb823a..ecbc741ef8f 100644 --- a/src/core/valgrind_internal.h +++ b/src/core/valgrind_internal.h @@ -8,7 +8,7 @@ #ifndef PMDK_VALGRIND_INTERNAL_H #define PMDK_VALGRIND_INTERNAL_H 1 -#if !defined(__FreeBSD__) && !defined(__riscv) && !defined(__loongarch64) +#if !defined(__riscv) && !defined(__loongarch64) #ifndef VALGRIND_ENABLED #define VALGRIND_ENABLED 1 #endif From 7c1fffd1c86eaf8a1ae1c0755e1820b0bcbd5c0e Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Thu, 14 Mar 2024 14:35:48 -0400 Subject: [PATCH 134/182] common: add log.h to libpmemobj.h Signed-off-by: Jan Michalski --- src/include/libpmemobj.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/include/libpmemobj.h b/src/include/libpmemobj.h index e1fd75aa634..d4a5becbb48 100644 --- a/src/include/libpmemobj.h +++ b/src/include/libpmemobj.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2020, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * libpmemobj.h -- definitions of libpmemobj entry points @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include From 559d3ed2e61e0380f01d87a79d61158eccba0653 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 8 Mar 2024 14:37:40 +0100 Subject: [PATCH 135/182] doc: logging function documentation --- doc/Makefile | 3 +- doc/libpmemobj/.gitignore | 3 + doc/libpmemobj/pmemobj_log_get_threshold.3.md | 56 +++++++ doc/libpmemobj/pmemobj_log_set_function.3.md | 109 +++++++++++++ doc/libpmemobj/pmemobj_log_set_threshold.3.md | 104 +++++++++++++ src/include/libpmemobj/log.h | 146 +----------------- 6 files changed, 278 insertions(+), 143 deletions(-) create mode 100644 doc/libpmemobj/pmemobj_log_get_threshold.3.md create mode 100644 doc/libpmemobj/pmemobj_log_set_function.3.md create mode 100644 doc/libpmemobj/pmemobj_log_set_threshold.3.md diff --git a/doc/Makefile b/doc/Makefile index 764a1409c03..48f5b37d030 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # @@ -18,6 +18,7 @@ MANPAGES_3_MD = libpmem/pmem_flush.3.md libpmem/pmem_is_pmem.3.md libpmem/pmem_m libpmemobj/pmemobj_list_insert.3.md libpmemobj/pmemobj_memcpy_persist.3.md libpmemobj/pmemobj_mutex_zero.3.md \ libpmemobj/pmemobj_open.3.md libpmemobj/pmemobj_root.3.md libpmemobj/pmemobj_tx_begin.3.md libpmemobj/pmemobj_tx_add_range.3.md \ libpmemobj/pmemobj_tx_alloc.3.md libpmemobj/pobj_layout_begin.3.md libpmemobj/pobj_list_head.3.md libpmemobj/toid_declare.3.md \ + libpmemobj/pmemobj_log_get_threshold.3.md libpmemobj/pmemobj_log_set_function.3.md libpmemobj/pmemobj_log_set_threshold.3.md \ libpmempool/pmempool_check_init.3.md libpmempool/pmempool_feature_query.3.md libpmempool/pmempool_rm.3.md libpmempool/pmempool_sync.3.md MANPAGES_1_MD = pmempool/pmempool.1.md pmempool/pmempool-info.1.md pmempool/pmempool-create.1.md \ diff --git a/doc/libpmemobj/.gitignore b/doc/libpmemobj/.gitignore index 19523dae4f9..f0e1a6f0f43 100644 --- a/doc/libpmemobj/.gitignore +++ b/doc/libpmemobj/.gitignore @@ -5,6 +5,9 @@ pmemobj_alloc.3 pmemobj_ctl_get.3 pmemobj_first.3 pmemobj_list_insert.3 +pmemobj_log_get_threshold.3 +pmemobj_log_set_function.3 +pmemobj_log_set_threshold.3 pmemobj_memcpy_persist.3 pmemobj_mutex_zero.3 pmemobj_open.3 diff --git a/doc/libpmemobj/pmemobj_log_get_threshold.3.md b/doc/libpmemobj/pmemobj_log_get_threshold.3.md new file mode 100644 index 00000000000..0fafe5c8f4e --- /dev/null +++ b/doc/libpmemobj/pmemobj_log_get_threshold.3.md @@ -0,0 +1,56 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmemobj_log_get_threshold.3.html"] +title: "libpmemobj | PMDK" +header: "pmemobj API version 2.3" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmemobj_log_get_threshold.3 -- get the logging threshold value) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmemobj_log_get_threshold** - get the logging threshold value + +# SYNOPSIS # + +```c + #include + + int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level *value); +``` + +# DESCRIPTION # + +**pmemobj_log_get_threshold**() gets the current *value* of the *threshold*. +See **pmemobj_log_set_threshold**(3) for available thresholds and values. + +# RETURN VALUE # + +On success, **pmemobj_log_get_threshold**() function returns 0 and writes into +*value* the current value of the *threshold*. On failure, it returns +a non-zero value and sets errno. In case of failure, the *value* contents is undefined. + +# ERRORS # + +**pmemobj_log_get_threshold**() can fail with the following errors: + + - EINVAL - *threshold* is not **PMEMOBJ_LOG_THRESHOLD** nor **PMEMOBJ_LOG_THRESHOLD_AUX** + - EINVAL - *value* is NULL + +# SEE ALSO # + +**pmemobj_log_set_function**(3), **pmemobj_log_set_threshold**(3). diff --git a/doc/libpmemobj/pmemobj_log_set_function.3.md b/doc/libpmemobj/pmemobj_log_set_function.3.md new file mode 100644 index 00000000000..642c7231a34 --- /dev/null +++ b/doc/libpmemobj/pmemobj_log_set_function.3.md @@ -0,0 +1,109 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmemobj_log_set_function.3.html"] +title: "libpmemobj | PMDK" +header: "pmemobj API version 2.3" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmemobj_log_set_function.3 -- set the logging function) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[THE DEFAULT LOGGING FUNCTION](#the-default-logging-function)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[NOTE](#note)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmemobj_log_set_function**() - set the logging function + +# SYNOPSIS # + +```c + #include + + typedef void pmemobj_log_function( + enum pmemobj_log_level level, + const char *file_name, + const int line_no, + const char *function_name, + const char *message); + + int pmemobj_log_set_function(pmemobj_log_function *log_function); +``` + +# DESCRIPTION # + +**pmemobj_log_set_function**() allows choosing the function which will get all +the generated logging messages. The *log_function* can be either +**PMEMOBJ_LOG_USE_DEFAULT_FUNCTION** which will use the default logging function +(built into the library) or a pointer to a user-defined function. + +The parameters of a user-defined log function are as follows: + + - *level* - the log level of the message (see **pmemobj_log_set_threshold**(3) + for available log levels) + - *file_name* - name of the source file where the message is coming from. + It could be set to NULL and in such case, neither *line_no* nor *function_name* + are provided. + - *line_no* - the source file line where the message is coming from + - *function_name* - the function name where the message is coming from + - *message* - the message string + +# THE DEFAULT LOGGING FUNCTION # + +The library provides the default logging function which writes messages to +**syslog**(3) and to **stderr**(3). This function is enabled during library +initialization and can be restored using **PMEMOBJ_LOG_USE_DEFAULT_FUNCTION** value +as the *log_function* argument. + +The default logging function sinks all the logging messages into **syslog**(3) +unconditionally. Additionally, it sinks a logging message into **stderr**(3) +if its logging level is not less severe than indicated by +the **PMEMOBJ_LOG_THRESHOLD_AUX** threshold's value and it is not of level +**PMEMOBJ_LOG_LEVEL_HARK**. + +Note that the **PMEMOBJ_LOG_THRESHOLD** threshold's value applies to +the default logging function. Please see the notes below. + +# RETURN VALUE # + +**pmemobj_log_set_function**() function returns 0 on success or returns +a non-zero value and sets errno on failure. On failure, the logging +function remains unchanged. + +# ERRORS # + +**pmemobj_log_set_function**() can set the following errno values on fail: + + - EAGAIN - multiple threads attempted to change the logging function concurrently. + A retry may fix the problem. This error is not expected when the function is + called from just one thread at a time. + +# NOTE # + +The logging messages of level less severe than indicated by +the **PMEMOBJ_LOG_THRESHOLD** threshold's value won't make it to the logging function +no matter whether the logging function is the default logging function or user-provided. + +The user-defined function must be thread-safe. + +The library will call user defined function before returning from **pmemobj_log_set_function**() +to deliver basic information about the library: + + - "src version: 2.y.z" + - "compiled with support for shutdown state" + - "compiled with libndctl 63+" + +# SEE ALSO # + +**pmemobj_log_get_threshold**(3), **pmemobj_log_set_threshold**(3). diff --git a/doc/libpmemobj/pmemobj_log_set_threshold.3.md b/doc/libpmemobj/pmemobj_log_set_threshold.3.md new file mode 100644 index 00000000000..d174aa780c8 --- /dev/null +++ b/doc/libpmemobj/pmemobj_log_set_threshold.3.md @@ -0,0 +1,104 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmemobj_log_set_threshold.3.html"] +title: "libpmemobj | PMDK" +header: "pmemobj API version 2.3" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmemobj_log_set_threshold.3 -- set the logging threshold value) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmemobj_log_set_threshold** - set the logging threshold value + +# SYNOPSIS # + +```c + #include + + enum pmemobj_log_level { + PMEMOBJ_LOG_LEVEL_HARK, + PMEMOBJ_LOG_LEVEL_FATAL, + PMEMOBJ_LOG_LEVEL_ERROR, + PMEMOBJ_LOG_LEVEL_WARNING, + PMEMOBJ_LOG_LEVEL_NOTICE, + PMEMOBJ_LOG_LEVEL_INFO, + PMEMOBJ_LOG_LEVEL_DEBUG + }; + + enum pmemobj_log_threshold { + PMEMOBJ_LOG_THRESHOLD, + PMEMOBJ_LOG_THRESHOLD_AUX + }; + + int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, + enum pmemobj_log_level value); +``` + +# DESCRIPTION # + +**pmemobj_log_set_threshold**() sets the logging threshold value. + +Available thresholds are: + + - **PMEMOBJ_LOG_THRESHOLD** - the main threshold used to filter out undesired + logging messages. Messages less severe than indicated by this threshold's + value are ignored so they won't make it to the logging function + (please see **pmemobj_log_set_function**(3)). + The default value is **PMEMOBJ_LOG_WARNING**. + - **PMEMOBJ_LOG_THRESHOLD_AUX** - the auxiliary threshold intended for use inside + the logging function (please see **pmemobj_log_get_threshold**(3)). A custom + logging function may or may not take this threshold into consideration depending + on the developer's needs. For the default logging function behaviour please see + **pmemobj_log_set_function**(3). The initial value of this threshold is + **PMEMOBJ_LOG_LEVEL_HARK**. + +Available threshold values are defined by enum *pmemobj_log_level*. +They are listed in descending order of severity: + + - **PMEMOBJ_LOG_LEVEL_HARK** - only basic library info. Shall be used to + effectively suppress the logging since it is used just for a few messages + when the program is started and whenever a new logging function is set. + Please see **pmemobj_log_set_function**(3). + - **PMEMOBJ_LOG_LEVEL_FATAL** - an error that causes the program to stop working + immediately. Sorry. + - **PMEMOBJ_LOG_LEVEL_ERROR** - an error that causes the current operation or transaction to fail + - **PMEMOBJ_LOG_LEVEL_WARNING** - an unexpected situation that does NOT + cause the current operation to fail + - **PMEMOBJ_LOG_LEVEL_NOTICE** - non-massive info mainly related to public API + function completions + - **PMEMOBJ_LOG_LEVEL_INFO** - massive info e.g. every write operation indication + - **PMEMOBJ_LOG_LEVEL_DEBUG** - debug info e.g. write operation dump + +# RETURN VALUE # + +**pmemobj_log_set_threshold**() function returns 0 on success or returns +a non-zero value and sets errno on failure. On failure, the *threshold* value remains unchanged. + +# ERRORS # + +**pmemobj_log_set_threshold**() can set the following errno values on fail: + + - EINVAL - *threshold* is not **PMEMOBJ_LOG_THRESHOLD** nor + **PMEMOBJ_LOG_THRESHOLD_AUX** + - EINVAL - *value* is not defined by enum *pmemobj_log_level* type + - EAGAIN - multiple threads attempted to change the *threshold* value concurrently. + A retry may fix the problem. This error is not expected when the function is + called from just one thread at a time. + +# SEE ALSO # + +**pmemobj_log_get_threshold**(3), **pmemobj_log_set_function**(3). diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index 43c0eaaecfe..caa7abf7d48 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -49,105 +49,16 @@ enum pmemobj_log_threshold { }; /* - * pmemobj_log_set_threshold - set the logging threshold level - * - * SYNOPSIS - * - * int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, - * enum pmemobj_log_level level); - * - * enum log_level { - * PMEMOBJ_LOG_LEVEL_HARK, - * PMEMOBJ_LOG_LEVEL_FATAL, - * PMEMOBJ_LOG_LEVEL_ERROR, - * PMEMOBJ_LOG_LEVEL_WARNING, - * PMEMOBJ_LOG_LEVEL_NOTICE, - * PMEMOBJ_LOG_LEVEL_INFO, - * PMEMOBJ_LOG_LEVEL_DEBUG, - * }; - * - * enum log_threshold { - * PMEMOBJ_LOG_THRESHOLD, - * PMEMOBJ_LOG_THRESHOLD_AUX, - * PMEMOBJ_LOG_THRESHOLD_MAX - * }; - * - * DESCRIPTION - * pmemobj_log_set_threshold() sets the logging threshold level. - * - * Available thresholds are: - * - PMEMOBJ_LOG_THRESHOLD - the main threshold used to filter out undesired - * logging messages. Messages on a higher level than the primary threshold - * level are ignored. PMEMOBJ_LOG_LEVEL_HARK shall be used to suppress - * logging. - * The default value is PMEMOBJ_LOG_WARNING. - * - PMEMOBJ_LOG_THRESHOLD_AUX - the auxiliary threshold intended for use inside - * the logging function (please see log_get_threshold(3)). The logging - * function may or may not take this threshold into consideration. The default - * value is PMEMOBJ_LOG_LEVEL_HARK. - * - * Available threshold levels are defined by enum log_level: - * - PMEMOBJ_LOG_LEVEL_HARK - only basic library info - * - PMEMOBJ_LOG_LEVEL_FATAL - an error that causes the library to stop working - * immediately - * - PMEMOBJ_LOG_LEVEL_ERROR - an error that causes the library to stop working - * properly - * - PMEMOBJ_LOG_LEVEL_WARNING - an error that could be handled in the upper - * level - * - PMEMOBJ_LOG_LEVEL_NOTICE - non-massive info mainly related to public API - * function completions - * - PMEMOBJ_LOG_LEVEL_INFO - massive info e.g. every write operation indication - * - PMEMOBJ_LOG_LEVEL_DEBUG - debug info e.g. write operation dump - * - * THE DEFAULT LOGGING FUNCTION - * The default logging function writes messages to syslog(3) and to stderr(3), - * where syslog(3) is the primary destination (PMEMOBJ_LOG_THRESHOLD applies) - * whereas stderr(3) is the secondary destination (PMEMOBJ_LOG_THRESHOLD_AUX - * applies). - * - * RETURN VALUE - * pmemobj_log_set_threshold() function returns 0 on success or returns - * a non-zero value and sets errno on failure. - * - * ERRORS - * pmemobj_log_set_threshold() can set the following errno values on fail: - * - EINVAL - threshold is not PMEMOBJ_LOG_THRESHOLD nor - * PMEMOBJ_LOG_THRESHOLD_AUX - * - EINVAL - level is not a value defined by enum log_level type - * - EAGAIN - a temporary error occurred, the retry may fix the problem - * - * SEE ALSO - * pmemobj_log_get_threshold(3), pmemobj_log_set_function(3). + * pmemobj_log_set_threshold - set the logging threshold value */ int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, - enum pmemobj_log_level level); + enum pmemobj_log_level value); /* - * pmemobj_log_get_threshold - get the logging threshold level - * - * SYNOPSIS - * - * int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, - * enum pmemobj_log_level *level); - * - * DESCRIPTION - * pmemobj_log_get_threshold() gets the current level of the threshold. - * See pmemobj_log_set_threshold(3) for available thresholds and levels. - * - * RETURN VALUE - * pmemobj_log_get_threshold() function returns 0 on success or returns - * a non-zero value and sets errno on failure. - * - * ERRORS - * pmemobj_log_get_threshold() can fail with the following errors: - * - EINVAL - threshold is not CORE_LOG_THRESHOLD nor CORE_LOG_THRESHOLD_AUX - * - EINVAL - *level is NULL - * - * SEE ALSO - * pmemobj_log_set_function(3), pmemobj_log_set_threshold(3). + * pmemobj_log_get_threshold - get the logging threshold value */ int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, - enum pmemobj_log_level *level); + enum pmemobj_log_level *value); /* * the type used for defining logging functions @@ -170,55 +81,6 @@ typedef void pmemobj_log_function( /* * pmemobj_log_set_function - set the logging function - * - * SYNOPSIS - * - * typedef void pmemobj_log_function( - * enum pmemobj_log_level level, - * const char *file_name, - * const int line_no, - * const char *function_name, - * const char *message_format, - * ...); - * - * int pmemobj_log_set_function(pmemobj_log_function *log_function); - * - * DESCRIPTION - * pmemobj_log_set_function() allows choosing the function which will get all - * the generated logging messages. The log_function can be either - * PMEMOBJ_LOG_USE_DEFAULT_FUNCTION which will use the default logging function - * (built into the library) or a pointer to a user-defined function. - * - * Parameters of a user-defined log function are as follow: - * - level - the log level of the message - * - file_name - name of the source file where the message coming from. It could - * be set to NULL and - * in such case neither line_no nor function_name are provided. - * - line_no - the source file line where the message coming from - * - function_name - the function name where the message coming from - * - message_format - printf(3)-like format string of the message - * - "..." - additional arguments of the message format string - * - * THE DEFAULT LOGGING FUNCTION - * The initial value of the logging function is CORE_LOG_USE_DEFAULT_FUNCTION. - * This function writes messages to syslog(3) (the primary destination) and to - * stderr(3) (the secondary destination). - * - * RETURN VALUE - * pmemobj_log_set_function() function returns 0 on success or returns - * a non-zero value and sets errno on failure. - * - * ERRORS - * - EAGAIN - a temporary error occurred, the retry may fix the problem - * - * NOTE - * The logging messages on the levels above the CORE_LOG_THRESHOLD level won't - * trigger the logging function. - * - * The user defined function must be thread-safe. - * - * SEE ALSO - * pmemobj_log_get_threshold(3), pmemobj_log_set_threshold(3). */ int pmemobj_log_set_function(pmemobj_log_function *log_function); From c24892f7bcbbc4234ff3613b2564be289749d8d6 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 29 Nov 2023 18:46:50 -0500 Subject: [PATCH 136/182] pmemobj: introduce fuses against ill-considered use of NDCTL_ENABLE=n Signed-off-by: Jan Michalski --- ChangeLog | 2 ++ src/libpmemobj/Makefile | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 664a1a061c5..b199c775169 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ XXX * Version 2.1.0 This release + - introduces fuses against ill-considered use of NDCTL_ENABLE=n + - PMEMOBJ_IGNORE_DIRTY_SHUTDOWN and PMEMOBJ_IGNORE_BAD_BLOCKS are required to acknowledge the understanding of what production-critical functions are missing for the build without NDCTL - does not allow opening pmem pool without unsafe shoutdown counter if not explicitly disabled - remove support for build time define NO_LIBPTHREAD diff --git a/src/libpmemobj/Makefile b/src/libpmemobj/Makefile index 44ad0cc4933..62c242b4c4d 100644 --- a/src/libpmemobj/Makefile +++ b/src/libpmemobj/Makefile @@ -37,6 +37,28 @@ SOURCE +=\ include ../Makefile.inc +ifeq ($(OS_DIMM),none) + NOT_RECOMMENDED = Continuing the build without NDCTL is highly NOT recommended for production quality systems. + RAS_SUFFIX = Please see https://www.intel.com/content/www/us/en/developer/articles/technical/build-pmem-apps-with-ras.html for more info on RAS features. + PMEMOBJ_IGNORE_DIRTY_SHUTDOWN ?= n + ifneq ($(PMEMOBJ_IGNORE_DIRTY_SHUTDOWN),y) + $(info Libpmemobj without NDCTL cannot detect dirty shutdowns. This may result in silent data corruption.) + $(info $(NOT_RECOMMENDED)) + $(info If you understand the consequences for consistency of your data please set PMEMOBJ_IGNORE_DIRTY_SHUTDOWN=y to silence this error.) + $(info $(RAS_SUFFIX)) + $(error ) + endif + + PMEMOBJ_IGNORE_BAD_BLOCKS ?= n + ifneq ($(PMEMOBJ_IGNORE_BAD_BLOCKS),y) + $(info Libpmemobj without NDCTL cannot detect bad blocks up front. This may result in SIGBUS at runtime.) + $(info $(NOT_RECOMMENDED)) + $(info If you understand the consequences for the behaviour of your application at runtime please set PMEMOBJ_IGNORE_BAD_BLOCKS=y to silence this error.) + $(info $(RAS_SUFFIX)) + $(error ) + endif +endif + CFLAGS += -DUSE_LIBDL -D_PMEMOBJ_INTRNL $(LIBNDCTL_CFLAGS) LIBS += -pthread -lpmem $(LIBDL) $(LIBNDCTL_LIBS) From 44a4f3643b8f150fefde5c19f2418b62281f8de5 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 29 Nov 2023 18:56:31 -0500 Subject: [PATCH 137/182] common: use PMEMOBJ_IGNORE_*=y when necessary Signed-off-by: Jan Michalski --- .github/workflows/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8eec8cb57bb..76cafb5b014 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,12 +39,16 @@ jobs: - name: Check licenses env: NDCTL_ENABLE: n # just to speed up the job + PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: y # not recommended for production + PMEMOBJ_IGNORE_BAD_BLOCKS: y # not recommended for production run: make -j$(nproc) check-license - name: Check style env: CSTYLE_FAIL_IF_CLANG_FORMAT_MISSING: 1 NDCTL_ENABLE: n # just to speed up the job + PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: y # not recommended for production + PMEMOBJ_IGNORE_BAD_BLOCKS: y # not recommended for production run: make -j$(nproc) cstyle @@ -69,6 +73,8 @@ jobs: - name: Build sources env: NDCTL_ENABLE: n # just to speed up the job + PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: y # not recommended for production + PMEMOBJ_IGNORE_BAD_BLOCKS: y # not recommended for production CC: ${{ matrix.CC }} CXX: ${{ matrix.CXX }} run: make -j$(nproc) test From e0bc1f3367549b2f1eba2fa09988e573c737daa0 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 12 Mar 2024 14:47:35 +0100 Subject: [PATCH 138/182] obj: synchronize pmemobj_log API with core_log API Signed-off-by: Tomasz Gromadzki --- src/include/libpmemobj/log.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index caa7abf7d48..657819f018a 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -45,7 +45,6 @@ enum pmemobj_log_threshold { * function */ PMEMOBJ_LOG_THRESHOLD_AUX, - PMEMOBJ_LOG_THRESHOLD_MAX }; /* @@ -72,10 +71,8 @@ typedef void pmemobj_log_function( const int line_no, /* the function name where the message coming from */ const char *function_name, - /* printf(3)-like format string of the message */ - const char *message_format, - /* additional arguments of the message format string */ - ...); + /* message */ + const char *message); #define PMEMOBJ_LOG_USE_DEFAULT_FUNCTION (NULL) From a056f434eb1cd03198de7766c7befe4a16ff0d56 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 12 Mar 2024 08:27:01 +0100 Subject: [PATCH 139/182] test: pmemobj_log_function UT implementation Signed-off-by: Tomasz Gromadzki --- src/test/Makefile | 1 + src/test/obj_log_function/.gitignore | 1 + src/test/obj_log_function/Makefile | 14 + src/test/obj_log_function/TESTS.py | 47 ++++ src/test/obj_log_function/obj_log_function.c | 273 +++++++++++++++++++ 5 files changed, 336 insertions(+) create mode 100644 src/test/obj_log_function/.gitignore create mode 100644 src/test/obj_log_function/Makefile create mode 100755 src/test/obj_log_function/TESTS.py create mode 100644 src/test/obj_log_function/obj_log_function.c diff --git a/src/test/Makefile b/src/test/Makefile index 0cfdff1d793..87f07d65dda 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -62,6 +62,7 @@ OBJ_TESTS = \ obj_list_valgrind\ obj_list_macro\ obj_locks\ + obj_log_function\ obj_mem\ obj_memblock\ obj_memcheck\ diff --git a/src/test/obj_log_function/.gitignore b/src/test/obj_log_function/.gitignore new file mode 100644 index 00000000000..c72c292afa2 --- /dev/null +++ b/src/test/obj_log_function/.gitignore @@ -0,0 +1 @@ +obj_log_function diff --git a/src/test/obj_log_function/Makefile b/src/test/obj_log_function/Makefile new file mode 100644 index 00000000000..47df9a23129 --- /dev/null +++ b/src/test/obj_log_function/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = obj_log_function +OBJS = obj_log_function.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMOBJ=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, obj_log_function.c) diff --git a/src/test/obj_log_function/TESTS.py b/src/test/obj_log_function/TESTS.py new file mode 100755 index 00000000000..c80912fc7b5 --- /dev/null +++ b/src/test/obj_log_function/TESTS.py @@ -0,0 +1,47 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class OBJ_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('obj_log_function', self.test_case) + + +class TEST0(OBJ_LOG): + test_case = 'test_log_set_function' + + +class TEST1(OBJ_LOG): + test_case = 'test_log_set_function_EAGAIN' + + +class TEST2(OBJ_LOG): + test_case = 'test_log_set_treshold' + + +class TEST3(OBJ_LOG): + test_case = 'test_log_set_treshold_EAGAIN' + + +class TEST4(OBJ_LOG): + test_case = 'test_log_set_treshold_EINVAL' + + +class TEST5(OBJ_LOG): + test_case = 'test_log_get_treshold' + + +class TEST6(OBJ_LOG): + test_case = 'test_log_get_treshold_EAGAIN' diff --git a/src/test/obj_log_function/obj_log_function.c b/src/test/obj_log_function/obj_log_function.c new file mode 100644 index 00000000000..cdf86d692bf --- /dev/null +++ b/src/test/obj_log_function/obj_log_function.c @@ -0,0 +1,273 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * obj_log_function.c -- unit test for obj_log_function + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmemobj/log.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +/* + * *** pmemobj_log_set_function() tests *** + */ +#define PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK ((pmemobj_log_function *) 0xA1C5D68F) + +/* Mock */ +static struct { + int ret; +} Core_log_set_function; + +FUNC_MOCK(core_log_set_function, int, core_log_function *log_function) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq((void *)log_function, + (void *)PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); + return Core_log_set_function.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_set_function)(log_function); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_set_function_helper(int error) +{ + errno = NO_ERRNO; + Core_log_set_function.ret = error == NO_ERRNO ? 0: error; + FUNC_MOCK_RCOUNTER_SET(core_log_set_function, VALIDATED_CALL); + int ret = pmemobj_log_set_function(PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(errno, NO_ERRNO); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_set_function), CALLED); + + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_set_function is called with proper argument + * - if pmemobj_log_set_function return 0 (no error) + * - no errno is set + */ +static int +test_log_set_function(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_function_helper(NO_ERRNO); +} + +/* + * core_log_set_function() with EAGAIN error + * Check: + * - if core_log_set_function is called with proper argument + * - if pmemobj_log_set_function return 1 (error via errno) + * - errno is set to EAGAIN + */ +static int +test_log_set_function_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_function_helper(EAGAIN); +} + +/* + * *** pmemobj_log_set_treshold() tests *** + */ +static enum core_log_threshold core_tresholds[] = { + CORE_LOG_THRESHOLD, + CORE_LOG_THRESHOLD_AUX +}; + +static enum core_log_level core_levels[] = { + CORE_LOG_LEVEL_HARK, + CORE_LOG_LEVEL_FATAL, + CORE_LOG_LEVEL_ERROR, + CORE_LOG_LEVEL_WARNING, + CORE_LOG_LEVEL_NOTICE, + CORE_LOG_LEVEL_INFO, + CORE_LOG_LEVEL_DEBUG +}; + +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level exp_level; + int ret; +} Core_log_set_treshold; + +FUNC_MOCK(core_log_set_threshold, int, enum core_log_threshold threshold, + enum core_log_level level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_set_treshold.exp_threshold); + UT_ASSERTeq(level, Core_log_set_treshold.exp_level); + return Core_log_set_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_set_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_set_treshold_helper(int error) +{ + errno = NO_ERRNO; + Core_log_set_treshold.ret = error == NO_ERRNO ? 0: error; + for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; + treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { + Core_log_set_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmemobj_log_level level = PMEMOBJ_LOG_LEVEL_HARK; + level <= PMEMOBJ_LOG_LEVEL_DEBUG; level++) { + Core_log_set_treshold.exp_level = core_levels[level]; + FUNC_MOCK_RCOUNTER_SET(core_log_set_threshold, + VALIDATED_CALL); + int ret = pmemobj_log_set_threshold(treshold, level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(errno, NO_ERRNO); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_set_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_set_treshold is called with proper arguments + * - if pmemobj_log_set_treshold return 0 (no error) + * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_set_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(NO_ERRNO); +} + +/* Check pmemobj_log_set_threshold EAGAIN error handling. */ +static int +test_log_set_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EAGAIN); +} + +/* Check pmemobj_log_set_threshold EINVAL error handling. */ +static int +test_log_set_treshold_EINVAL(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EINVAL); +} + +/* + * *** pmemobj_log_get_treshold() tests *** + */ +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level level; + int ret; +} Core_log_get_treshold; + +FUNC_MOCK(core_log_get_threshold, int, enum core_log_threshold threshold, + enum core_log_level *level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_get_treshold.exp_threshold); + if (Core_log_get_treshold.ret == 0) + *level = Core_log_get_treshold.level; + return Core_log_get_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_get_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_get_treshold_helper(int error) +{ + errno = NO_ERRNO; + Core_log_get_treshold.ret = error == NO_ERRNO ? 0: error; + for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; + treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { + Core_log_get_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmemobj_log_level exp_level = PMEMOBJ_LOG_LEVEL_HARK; + exp_level <= PMEMOBJ_LOG_LEVEL_DEBUG; exp_level++) { + enum pmemobj_log_level level; + Core_log_get_treshold.level = core_levels[exp_level]; + FUNC_MOCK_RCOUNTER_SET(core_log_get_threshold, + VALIDATED_CALL); + int ret = pmemobj_log_get_threshold(treshold, &level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(level, exp_level); + UT_ASSERTeq(errno, NO_ERRNO); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_get_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_get_treshold is called with proper arguments + * - if pmemobj_log_get_treshold return 0 (no error) + * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_get_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(NO_ERRNO); +} + +/* Check pmemobj_log_get_threshold EAGAIN error handling. */ +static int +test_log_get_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(EAGAIN); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_set_function), + TEST_CASE(test_log_set_function_EAGAIN), + TEST_CASE(test_log_set_treshold), + TEST_CASE(test_log_set_treshold_EAGAIN), + TEST_CASE(test_log_set_treshold_EINVAL), + TEST_CASE(test_log_get_treshold), + TEST_CASE(test_log_get_treshold_EAGAIN), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "obj_log_function"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} From cd79eb526a9f81cdc5fd0728c50bff90acff2281 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 14 Mar 2024 08:14:45 +0100 Subject: [PATCH 140/182] test: rename obj_log_function to obj_log_set_function Signed-off-by: Tomasz Gromadzki --- src/test/Makefile | 2 +- src/test/obj_log_function/.gitignore | 1 - src/test/obj_log_set_function/.gitignore | 1 + .../{obj_log_function => obj_log_set_function}/Makefile | 6 +++--- .../{obj_log_function => obj_log_set_function}/TESTS.py | 2 +- .../obj_log_set_function.c} | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 src/test/obj_log_function/.gitignore create mode 100644 src/test/obj_log_set_function/.gitignore rename src/test/{obj_log_function => obj_log_set_function}/Makefile (64%) rename src/test/{obj_log_function => obj_log_set_function}/TESTS.py (94%) rename src/test/{obj_log_function/obj_log_function.c => obj_log_set_function/obj_log_set_function.c} (98%) diff --git a/src/test/Makefile b/src/test/Makefile index 87f07d65dda..e36632d0754 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -62,7 +62,7 @@ OBJ_TESTS = \ obj_list_valgrind\ obj_list_macro\ obj_locks\ - obj_log_function\ + obj_log_set_function\ obj_mem\ obj_memblock\ obj_memcheck\ diff --git a/src/test/obj_log_function/.gitignore b/src/test/obj_log_function/.gitignore deleted file mode 100644 index c72c292afa2..00000000000 --- a/src/test/obj_log_function/.gitignore +++ /dev/null @@ -1 +0,0 @@ -obj_log_function diff --git a/src/test/obj_log_set_function/.gitignore b/src/test/obj_log_set_function/.gitignore new file mode 100644 index 00000000000..4d9074233de --- /dev/null +++ b/src/test/obj_log_set_function/.gitignore @@ -0,0 +1 @@ +obj_log_set_function diff --git a/src/test/obj_log_function/Makefile b/src/test/obj_log_set_function/Makefile similarity index 64% rename from src/test/obj_log_function/Makefile rename to src/test/obj_log_set_function/Makefile index 47df9a23129..f3a26da93da 100644 --- a/src/test/obj_log_function/Makefile +++ b/src/test/obj_log_set_function/Makefile @@ -1,8 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024, Intel Corporation -TARGET = obj_log_function -OBJS = obj_log_function.o +TARGET = obj_log_set_function +OBJS = obj_log_set_function.o BUILD_STATIC_DEBUG=n BUILD_STATIC_NONDEBUG=n @@ -11,4 +11,4 @@ BUILD_STATIC_NONDEBUG=n LIBPMEMOBJ=internal-debug include ../Makefile.inc -LDFLAGS += $(call extract_funcs, obj_log_function.c) +LDFLAGS += $(call extract_funcs, obj_log_set_function.c) diff --git a/src/test/obj_log_function/TESTS.py b/src/test/obj_log_set_function/TESTS.py similarity index 94% rename from src/test/obj_log_function/TESTS.py rename to src/test/obj_log_set_function/TESTS.py index c80912fc7b5..2965e56b1ff 100755 --- a/src/test/obj_log_function/TESTS.py +++ b/src/test/obj_log_set_function/TESTS.py @@ -16,7 +16,7 @@ class OBJ_LOG(t.BaseTest): test_type = t.Short def run(self, ctx): - ctx.exec('obj_log_function', self.test_case) + ctx.exec('obj_log_set_function', self.test_case) class TEST0(OBJ_LOG): diff --git a/src/test/obj_log_function/obj_log_function.c b/src/test/obj_log_set_function/obj_log_set_function.c similarity index 98% rename from src/test/obj_log_function/obj_log_function.c rename to src/test/obj_log_set_function/obj_log_set_function.c index cdf86d692bf..49faadbedbc 100644 --- a/src/test/obj_log_function/obj_log_function.c +++ b/src/test/obj_log_set_function/obj_log_set_function.c @@ -2,7 +2,7 @@ /* Copyright 2024, Intel Corporation */ /* - * obj_log_function.c -- unit test for obj_log_function + * obj_log_set_function.c -- unit test for pmemobj_log_set_function */ #include "unittest.h" @@ -267,7 +267,7 @@ static struct test_case test_cases[] = { int main(int argc, char *argv[]) { - START(argc, argv, "obj_log_function"); + START(argc, argv, "obj_log_set_function"); TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); DONE(NULL); } From 0ad2b2baf39fa7cafbbcdc32cd0b86bc7f68aea0 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 14 Mar 2024 08:27:30 +0100 Subject: [PATCH 141/182] test: split pmemobj_log* tests to separate folders Signed-off-by: Tomasz Gromadzki --- src/test/Makefile | 2 + src/test/obj_log_get_treshold/.gitignore | 1 + src/test/obj_log_get_treshold/Makefile | 14 ++ src/test/obj_log_get_treshold/TESTS.py | 27 +++ .../obj_log_get_treshold.c | 116 +++++++++++ src/test/obj_log_set_function/TESTS.py | 20 -- .../obj_log_set_function.c | 186 +----------------- src/test/obj_log_set_treshold/.gitignore | 1 + src/test/obj_log_set_treshold/Makefile | 14 ++ src/test/obj_log_set_treshold/TESTS.py | 31 +++ .../obj_log_set_treshold.c | 121 ++++++++++++ 11 files changed, 329 insertions(+), 204 deletions(-) create mode 100644 src/test/obj_log_get_treshold/.gitignore create mode 100644 src/test/obj_log_get_treshold/Makefile create mode 100755 src/test/obj_log_get_treshold/TESTS.py create mode 100644 src/test/obj_log_get_treshold/obj_log_get_treshold.c create mode 100644 src/test/obj_log_set_treshold/.gitignore create mode 100644 src/test/obj_log_set_treshold/Makefile create mode 100755 src/test/obj_log_set_treshold/TESTS.py create mode 100644 src/test/obj_log_set_treshold/obj_log_set_treshold.c diff --git a/src/test/Makefile b/src/test/Makefile index e36632d0754..961172eac35 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -62,7 +62,9 @@ OBJ_TESTS = \ obj_list_valgrind\ obj_list_macro\ obj_locks\ + obj_log_get_treshold\ obj_log_set_function\ + obj_log_set_treshold\ obj_mem\ obj_memblock\ obj_memcheck\ diff --git a/src/test/obj_log_get_treshold/.gitignore b/src/test/obj_log_get_treshold/.gitignore new file mode 100644 index 00000000000..72cb85ece1c --- /dev/null +++ b/src/test/obj_log_get_treshold/.gitignore @@ -0,0 +1 @@ +obj_log_get_treshold diff --git a/src/test/obj_log_get_treshold/Makefile b/src/test/obj_log_get_treshold/Makefile new file mode 100644 index 00000000000..8629483392b --- /dev/null +++ b/src/test/obj_log_get_treshold/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = obj_log_get_treshold +OBJS = obj_log_get_treshold.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMOBJ=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, obj_log_get_treshold.c) diff --git a/src/test/obj_log_get_treshold/TESTS.py b/src/test/obj_log_get_treshold/TESTS.py new file mode 100755 index 00000000000..47094061bf6 --- /dev/null +++ b/src/test/obj_log_get_treshold/TESTS.py @@ -0,0 +1,27 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class OBJ_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('obj_log_get_treshold', self.test_case) + + +class TEST0(OBJ_LOG): + test_case = 'test_log_get_treshold' + + +class TEST1(OBJ_LOG): + test_case = 'test_log_get_treshold_EAGAIN' diff --git a/src/test/obj_log_get_treshold/obj_log_get_treshold.c b/src/test/obj_log_get_treshold/obj_log_get_treshold.c new file mode 100644 index 00000000000..3dcf79707f5 --- /dev/null +++ b/src/test/obj_log_get_treshold/obj_log_get_treshold.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * obj_log_get_treshold.c -- unit test for pmemobj_log_get_treshold + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmemobj/log.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +static enum core_log_threshold core_tresholds[] = { + CORE_LOG_THRESHOLD, + CORE_LOG_THRESHOLD_AUX +}; + +static enum core_log_level core_levels[] = { + CORE_LOG_LEVEL_HARK, + CORE_LOG_LEVEL_FATAL, + CORE_LOG_LEVEL_ERROR, + CORE_LOG_LEVEL_WARNING, + CORE_LOG_LEVEL_NOTICE, + CORE_LOG_LEVEL_INFO, + CORE_LOG_LEVEL_DEBUG +}; + +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level level; + int ret; +} Core_log_get_treshold; + +FUNC_MOCK(core_log_get_threshold, int, enum core_log_threshold threshold, + enum core_log_level *level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_get_treshold.exp_threshold); + if (Core_log_get_treshold.ret == 0) + *level = Core_log_get_treshold.level; + return Core_log_get_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_get_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_get_treshold_helper(int error) +{ + errno = 0; + Core_log_get_treshold.ret = error == NO_ERRNO ? 0 : error; + for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; + treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { + Core_log_get_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmemobj_log_level exp_level = PMEMOBJ_LOG_LEVEL_HARK; + exp_level <= PMEMOBJ_LOG_LEVEL_DEBUG; exp_level++) { + enum pmemobj_log_level level; + Core_log_get_treshold.level = core_levels[exp_level]; + FUNC_MOCK_RCOUNTER_SET(core_log_get_threshold, + VALIDATED_CALL); + int ret = pmemobj_log_get_threshold(treshold, &level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(level, exp_level); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_get_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_get_treshold is called with proper arguments + * - if pmemobj_log_get_treshold return 0 (no error) + * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_get_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(NO_ERRNO); +} + +/* Check pmemobj_log_get_threshold EAGAIN error handling. */ +static int +test_log_get_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(EAGAIN); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_get_treshold), + TEST_CASE(test_log_get_treshold_EAGAIN), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "obj_log_get_treshold"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} diff --git a/src/test/obj_log_set_function/TESTS.py b/src/test/obj_log_set_function/TESTS.py index 2965e56b1ff..7d59355dd63 100755 --- a/src/test/obj_log_set_function/TESTS.py +++ b/src/test/obj_log_set_function/TESTS.py @@ -25,23 +25,3 @@ class TEST0(OBJ_LOG): class TEST1(OBJ_LOG): test_case = 'test_log_set_function_EAGAIN' - - -class TEST2(OBJ_LOG): - test_case = 'test_log_set_treshold' - - -class TEST3(OBJ_LOG): - test_case = 'test_log_set_treshold_EAGAIN' - - -class TEST4(OBJ_LOG): - test_case = 'test_log_set_treshold_EINVAL' - - -class TEST5(OBJ_LOG): - test_case = 'test_log_get_treshold' - - -class TEST6(OBJ_LOG): - test_case = 'test_log_get_treshold_EAGAIN' diff --git a/src/test/obj_log_set_function/obj_log_set_function.c b/src/test/obj_log_set_function/obj_log_set_function.c index 49faadbedbc..bf95b03f690 100644 --- a/src/test/obj_log_set_function/obj_log_set_function.c +++ b/src/test/obj_log_set_function/obj_log_set_function.c @@ -14,9 +14,6 @@ #define VALIDATED_CALL 127 #define CALLED (VALIDATED_CALL + 1) -/* - * *** pmemobj_log_set_function() tests *** - */ #define PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK ((pmemobj_log_function *) 0xA1C5D68F) /* Mock */ @@ -39,13 +36,12 @@ FUNC_MOCK_END static int test_log_set_function_helper(int error) { - errno = NO_ERRNO; - Core_log_set_function.ret = error == NO_ERRNO ? 0: error; + errno = 0; + Core_log_set_function.ret = error == NO_ERRNO ? 0 : error; FUNC_MOCK_RCOUNTER_SET(core_log_set_function, VALIDATED_CALL); int ret = pmemobj_log_set_function(PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); if (error == NO_ERRNO) { UT_ASSERTeq(ret, 0); - UT_ASSERTeq(errno, NO_ERRNO); } else { UT_ASSERTeq(ret, 1); UT_ASSERTeq(errno, error); @@ -81,187 +77,9 @@ test_log_set_function_EAGAIN(const struct test_case *tc, int argc, char *argv[]) return test_log_set_function_helper(EAGAIN); } -/* - * *** pmemobj_log_set_treshold() tests *** - */ -static enum core_log_threshold core_tresholds[] = { - CORE_LOG_THRESHOLD, - CORE_LOG_THRESHOLD_AUX -}; - -static enum core_log_level core_levels[] = { - CORE_LOG_LEVEL_HARK, - CORE_LOG_LEVEL_FATAL, - CORE_LOG_LEVEL_ERROR, - CORE_LOG_LEVEL_WARNING, - CORE_LOG_LEVEL_NOTICE, - CORE_LOG_LEVEL_INFO, - CORE_LOG_LEVEL_DEBUG -}; - -/* Mock */ -static struct { - enum core_log_threshold exp_threshold; - enum core_log_level exp_level; - int ret; -} Core_log_set_treshold; - -FUNC_MOCK(core_log_set_threshold, int, enum core_log_threshold threshold, - enum core_log_level level) - FUNC_MOCK_RUN(VALIDATED_CALL) { - UT_ASSERTeq(threshold, Core_log_set_treshold.exp_threshold); - UT_ASSERTeq(level, Core_log_set_treshold.exp_level); - return Core_log_set_treshold.ret; - } -FUNC_MOCK_RUN_DEFAULT { - return _FUNC_REAL(core_log_set_threshold)(threshold, level); -} -FUNC_MOCK_END - -/* Helper */ -static int -test_log_set_treshold_helper(int error) -{ - errno = NO_ERRNO; - Core_log_set_treshold.ret = error == NO_ERRNO ? 0: error; - for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; - treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { - Core_log_set_treshold.exp_threshold = core_tresholds[treshold]; - for (enum pmemobj_log_level level = PMEMOBJ_LOG_LEVEL_HARK; - level <= PMEMOBJ_LOG_LEVEL_DEBUG; level++) { - Core_log_set_treshold.exp_level = core_levels[level]; - FUNC_MOCK_RCOUNTER_SET(core_log_set_threshold, - VALIDATED_CALL); - int ret = pmemobj_log_set_threshold(treshold, level); - if (error == NO_ERRNO) { - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(errno, NO_ERRNO); - } else { - UT_ASSERTeq(ret, 1); - UT_ASSERTeq(errno, error); - } - UT_ASSERTeq(RCOUNTER(core_log_set_threshold), CALLED); - /* no need to test the error path for all values */ - if (error != NO_ERRNO) - return NO_ARGS_CONSUMED; - } - } - return NO_ARGS_CONSUMED; -} - -/* Tests */ -/* - * Check: - * - if core_log_set_treshold is called with proper arguments - * - if pmemobj_log_set_treshold return 0 (no error) - * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL - * - no errno is set - */ -static int -test_log_set_treshold(const struct test_case *tc, int argc, char *argv[]) -{ - return test_log_set_treshold_helper(NO_ERRNO); -} - -/* Check pmemobj_log_set_threshold EAGAIN error handling. */ -static int -test_log_set_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) -{ - return test_log_set_treshold_helper(EAGAIN); -} - -/* Check pmemobj_log_set_threshold EINVAL error handling. */ -static int -test_log_set_treshold_EINVAL(const struct test_case *tc, int argc, char *argv[]) -{ - return test_log_set_treshold_helper(EINVAL); -} - -/* - * *** pmemobj_log_get_treshold() tests *** - */ -/* Mock */ -static struct { - enum core_log_threshold exp_threshold; - enum core_log_level level; - int ret; -} Core_log_get_treshold; - -FUNC_MOCK(core_log_get_threshold, int, enum core_log_threshold threshold, - enum core_log_level *level) - FUNC_MOCK_RUN(VALIDATED_CALL) { - UT_ASSERTeq(threshold, Core_log_get_treshold.exp_threshold); - if (Core_log_get_treshold.ret == 0) - *level = Core_log_get_treshold.level; - return Core_log_get_treshold.ret; - } -FUNC_MOCK_RUN_DEFAULT { - return _FUNC_REAL(core_log_get_threshold)(threshold, level); -} -FUNC_MOCK_END - -/* Helper */ -static int -test_log_get_treshold_helper(int error) -{ - errno = NO_ERRNO; - Core_log_get_treshold.ret = error == NO_ERRNO ? 0: error; - for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; - treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { - Core_log_get_treshold.exp_threshold = core_tresholds[treshold]; - for (enum pmemobj_log_level exp_level = PMEMOBJ_LOG_LEVEL_HARK; - exp_level <= PMEMOBJ_LOG_LEVEL_DEBUG; exp_level++) { - enum pmemobj_log_level level; - Core_log_get_treshold.level = core_levels[exp_level]; - FUNC_MOCK_RCOUNTER_SET(core_log_get_threshold, - VALIDATED_CALL); - int ret = pmemobj_log_get_threshold(treshold, &level); - if (error == NO_ERRNO) { - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(level, exp_level); - UT_ASSERTeq(errno, NO_ERRNO); - } else { - UT_ASSERTeq(ret, 1); - UT_ASSERTeq(errno, error); - } - UT_ASSERTeq(RCOUNTER(core_log_get_threshold), CALLED); - /* no need to test the error path for all values */ - if (error != NO_ERRNO) - return NO_ARGS_CONSUMED; - } - } - return NO_ARGS_CONSUMED; -} - -/* Tests */ -/* - * Check: - * - if core_log_get_treshold is called with proper arguments - * - if pmemobj_log_get_treshold return 0 (no error) - * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL - * - no errno is set - */ -static int -test_log_get_treshold(const struct test_case *tc, int argc, char *argv[]) -{ - return test_log_get_treshold_helper(NO_ERRNO); -} - -/* Check pmemobj_log_get_threshold EAGAIN error handling. */ -static int -test_log_get_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) -{ - return test_log_get_treshold_helper(EAGAIN); -} - static struct test_case test_cases[] = { TEST_CASE(test_log_set_function), TEST_CASE(test_log_set_function_EAGAIN), - TEST_CASE(test_log_set_treshold), - TEST_CASE(test_log_set_treshold_EAGAIN), - TEST_CASE(test_log_set_treshold_EINVAL), - TEST_CASE(test_log_get_treshold), - TEST_CASE(test_log_get_treshold_EAGAIN), }; int diff --git a/src/test/obj_log_set_treshold/.gitignore b/src/test/obj_log_set_treshold/.gitignore new file mode 100644 index 00000000000..bc77b806407 --- /dev/null +++ b/src/test/obj_log_set_treshold/.gitignore @@ -0,0 +1 @@ +obj_log_set_treshold diff --git a/src/test/obj_log_set_treshold/Makefile b/src/test/obj_log_set_treshold/Makefile new file mode 100644 index 00000000000..d36f662524a --- /dev/null +++ b/src/test/obj_log_set_treshold/Makefile @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = obj_log_set_treshold +OBJS = obj_log_set_treshold.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMOBJ=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, obj_log_set_treshold.c) diff --git a/src/test/obj_log_set_treshold/TESTS.py b/src/test/obj_log_set_treshold/TESTS.py new file mode 100755 index 00000000000..5d9b2416f83 --- /dev/null +++ b/src/test/obj_log_set_treshold/TESTS.py @@ -0,0 +1,31 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class OBJ_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('obj_log_set_treshold', self.test_case) + + +class TEST0(OBJ_LOG): + test_case = 'test_log_set_treshold' + + +class TEST1(OBJ_LOG): + test_case = 'test_log_set_treshold_EAGAIN' + + +class TEST2(OBJ_LOG): + test_case = 'test_log_set_treshold_EINVAL' diff --git a/src/test/obj_log_set_treshold/obj_log_set_treshold.c b/src/test/obj_log_set_treshold/obj_log_set_treshold.c new file mode 100644 index 00000000000..4f9aeec3ed3 --- /dev/null +++ b/src/test/obj_log_set_treshold/obj_log_set_treshold.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * obj_log_set_treshold.c -- unit test for pmemobj_log_set_treshold + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmemobj/log.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +static enum core_log_threshold core_tresholds[] = { + CORE_LOG_THRESHOLD, + CORE_LOG_THRESHOLD_AUX +}; + +static enum core_log_level core_levels[] = { + CORE_LOG_LEVEL_HARK, + CORE_LOG_LEVEL_FATAL, + CORE_LOG_LEVEL_ERROR, + CORE_LOG_LEVEL_WARNING, + CORE_LOG_LEVEL_NOTICE, + CORE_LOG_LEVEL_INFO, + CORE_LOG_LEVEL_DEBUG +}; + +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level exp_level; + int ret; +} Core_log_set_treshold; + +FUNC_MOCK(core_log_set_threshold, int, enum core_log_threshold threshold, + enum core_log_level level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_set_treshold.exp_threshold); + UT_ASSERTeq(level, Core_log_set_treshold.exp_level); + return Core_log_set_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_set_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_set_treshold_helper(int error) +{ + errno = 0; + Core_log_set_treshold.ret = error == NO_ERRNO ? 0 : error; + for (enum pmemobj_log_threshold treshold = PMEMOBJ_LOG_THRESHOLD; + treshold <= PMEMOBJ_LOG_THRESHOLD_AUX; treshold++) { + Core_log_set_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmemobj_log_level level = PMEMOBJ_LOG_LEVEL_HARK; + level <= PMEMOBJ_LOG_LEVEL_DEBUG; level++) { + Core_log_set_treshold.exp_level = core_levels[level]; + FUNC_MOCK_RCOUNTER_SET(core_log_set_threshold, + VALIDATED_CALL); + int ret = pmemobj_log_set_threshold(treshold, level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_set_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_set_treshold is called with proper arguments + * - if pmemobj_log_set_treshold return 0 (no error) + * - if each PMEMOBJ_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_set_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(NO_ERRNO); +} + +/* Check pmemobj_log_set_threshold EAGAIN error handling. */ +static int +test_log_set_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EAGAIN); +} + +/* Check pmemobj_log_set_threshold EINVAL error handling. */ +static int +test_log_set_treshold_EINVAL(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EINVAL); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_set_treshold), + TEST_CASE(test_log_set_treshold_EAGAIN), + TEST_CASE(test_log_set_treshold_EINVAL), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "obj_log_set_treshold"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} From 3d531e6760dc952665244fba2cd1d9d8ff914670 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Mon, 18 Mar 2024 11:45:54 +0100 Subject: [PATCH 142/182] doc: add an exception and a macro --- doc/Makefile | 3 ++- doc/libpmemobj/pmemobj_log_use_default_function.3 | 1 + utils/check_docs/exceptions.txt | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 doc/libpmemobj/pmemobj_log_use_default_function.3 diff --git a/doc/Makefile b/doc/Makefile index 48f5b37d030..232e721abf6 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -65,7 +65,8 @@ MANPAGES_3_DUMMY = libpmem/pmem_drain.3 libpmem/pmem_has_hw_drain.3 libpmem/pmem libpmemobj/pmemobj_check_version.3 libpmemobj/pmemobj_check.3 libpmemobj/pmemobj_errormsg.3 libpmemobj/pmemobj_set_funcs.3 \ libpmemobj/pmemobj_reserve.3 libpmemobj/pmemobj_xreserve.3 libpmemobj/pmemobj_defer_free.3 libpmemobj/pmemobj_set_value.3 libpmemobj/pmemobj_publish.3 libpmemobj/pmemobj_tx_publish.3 libpmemobj/pmemobj_tx_xpublish.3 libpmemobj/pmemobj_cancel.3 libpmemobj/pobj_reserve_new.3 libpmemobj/pobj_reserve_alloc.3 libpmemobj/pobj_xreserve_new.3 libpmemobj/pobj_xreserve_alloc.3 \ libpmemobj/tx_xstrdup.3 libpmemobj/tx_xwcsdup.3 libpmemobj/tx_xfree.3 \ - libpmemobj/pmemobj_defrag.3 libpmemobj/pmemobj_get_user_data.3 libpmemobj/pmemobj_set_user_data.3 libpmemobj/pmemobj_tx_get_user_data.3 libpmemobj/pmemobj_tx_set_user_data.3 libpmemobj/pmemobj_tx_get_failure_behavior.3 libpmemobj/pmemobj_tx_set_failure_behavior.3 + libpmemobj/pmemobj_defrag.3 libpmemobj/pmemobj_get_user_data.3 libpmemobj/pmemobj_set_user_data.3 libpmemobj/pmemobj_tx_get_user_data.3 libpmemobj/pmemobj_tx_set_user_data.3 libpmemobj/pmemobj_tx_get_failure_behavior.3 libpmemobj/pmemobj_tx_set_failure_behavior.3 \ + libpmemobj/pmemobj_log_use_default_function.3 MANPAGES_WEBDIR_LINUX = web_linux diff --git a/doc/libpmemobj/pmemobj_log_use_default_function.3 b/doc/libpmemobj/pmemobj_log_use_default_function.3 new file mode 100644 index 00000000000..fef4f379b5a --- /dev/null +++ b/doc/libpmemobj/pmemobj_log_use_default_function.3 @@ -0,0 +1 @@ +.so pmemobj_log_set_function.3 diff --git a/utils/check_docs/exceptions.txt b/utils/check_docs/exceptions.txt index f7c93fae46c..0b10129bdb7 100644 --- a/utils/check_docs/exceptions.txt +++ b/utils/check_docs/exceptions.txt @@ -27,6 +27,7 @@ libpmemobj_atomic_base_h pobj_xalloc_valid_flags libpmemobj_atomic_h libpmemobj_iterator_base_h +libpmemobj_log_h libpmemobj_pool_base_h pmemobj_min_pool pmemobj_min_part From 9e40ec7ee146eadfcea66bf82da2f2ad96703fdf Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 19 Mar 2024 15:02:05 -0400 Subject: [PATCH 143/182] common: check_license remove unused code Signed-off-by: Jan Michalski --- utils/check_license/check-headers.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/utils/check_license/check-headers.sh b/utils/check_license/check-headers.sh index c3fd36a9bed..3b0fe72bc7f 100755 --- a/utils/check_license/check-headers.sh +++ b/utils/check_license/check-headers.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2023, Intel Corporation +# Copyright 2016-2024, Intel Corporation # check-headers.sh - check copyright and license in source files @@ -26,7 +26,6 @@ shift PATTERN=`mktemp` TMP=`mktemp` TMP2=`mktemp` -TEMPFILE=`mktemp` rm -f $PATTERN $TMP $TMP2 if [ "$1" == "-h" -o "$1" == "--help" ]; then @@ -99,9 +98,6 @@ for file in $FILES ; do # git is called with -C flag so filepaths should be relative to SOURCE_ROOT src_path="${SOURCE_ROOT}/$file" [ ! -f $src_path ] && continue - # ensure that file is UTF-8 encoded - ENCODING=`file -b --mime-encoding $src_path` - iconv -f $ENCODING -t "UTF-8" $src_path > $TEMPFILE if ! grep -q "SPDX-License-Identifier: $LICENSE" $src_path; then echo "$src_path:1: no $LICENSE SPDX tag found " >&2 @@ -179,7 +175,7 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path` RV=1 fi done -rm -f $TMP $TMP2 $TEMPFILE +rm -f $TMP $TMP2 $(dirname "$0")/check-ms-license.pl $FILES From 8792d61ddadab35ce4e3dd23c2be2916049a8547 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 19 Mar 2024 15:31:19 -0400 Subject: [PATCH 144/182] common: check_license fix the year's line number Signed-off-by: Jan Michalski --- utils/check_license/check-headers.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/check_license/check-headers.sh b/utils/check_license/check-headers.sh index 3b0fe72bc7f..6fc14cd56f5 100755 --- a/utils/check_license/check-headers.sh +++ b/utils/check_license/check-headers.sh @@ -146,7 +146,7 @@ for file in $FILES ; do s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path` if [ -z "$YEARS" ]; then - echo >&2 "$src_path:1: No copyright years found" + echo >&2 "$src_path:2: No copyright years found" RV=1 continue fi @@ -167,7 +167,7 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path` else NEW=$COMMIT_FIRST-$COMMIT_LAST fi - echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2 + echo "$file:2: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2 RV=1 fi else From e17af64826b628d8c0802d7bd3b449675e94cc74 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 19 Mar 2024 15:33:41 -0400 Subject: [PATCH 145/182] common: check_license fix single year range error message --- utils/check_license/check-headers.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/check_license/check-headers.sh b/utils/check_license/check-headers.sh index 6fc14cd56f5..b863a386efa 100755 --- a/utils/check_license/check-headers.sh +++ b/utils/check_license/check-headers.sh @@ -167,6 +167,9 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path` else NEW=$COMMIT_FIRST-$COMMIT_LAST fi + if [ $HEADER_FIRST == $HEADER_LAST ]; then + YEARS=$HEADER_LAST + fi echo "$file:2: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2 RV=1 fi From 9edb75776fba296303ff98797dd0daac22dcfdb8 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 19 Mar 2024 16:24:23 -0400 Subject: [PATCH 146/182] common: allow check_license to apply proposed changes - assuming the source is not dirty Signed-off-by: Jan Michalski --- utils/check_license/check-headers.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/check_license/check-headers.sh b/utils/check_license/check-headers.sh index b863a386efa..e53f1baa4ce 100755 --- a/utils/check_license/check-headers.sh +++ b/utils/check_license/check-headers.sh @@ -46,6 +46,12 @@ else SHALLOW_CLONE=0 fi +if [ $($GIT diff | wc -l) -gt 0 ]; then + DIRTY_SOURCE=1 +else + DIRTY_SOURCE=0 +fi + VERBOSE=0 CHECK_ALL=0 while [ "$1" != "" ]; do @@ -171,6 +177,9 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path` YEARS=$HEADER_LAST fi echo "$file:2: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2 + if [ $DIRTY_SOURCE -eq 0 ]; then + sed -i "s/\(Copyright\) $YEARS\(, Intel Corporation\)/\1 $NEW\2/" $src_path + fi RV=1 fi else @@ -187,5 +196,10 @@ if [ $RV -eq 0 ]; then echo "Copyright headers are OK." else echo "Error(s) in copyright headers found!" >&2 + if [ $DIRTY_SOURCE -eq 0 ]; then + echo "Please see the proposed changes to fix the found issues." >&2 + else + echo "Since the source is dirty no changes have been proposed." >&2 + fi fi exit $RV From c045462c1f0fd4791c00b4c91c7bb304a5e55fb8 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 19 Mar 2024 16:52:30 -0400 Subject: [PATCH 147/182] common: Main / Check license add upload step --- .github/workflows/main.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76cafb5b014..e2eef50cc19 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,12 +36,30 @@ jobs: sudo pip install flake8 sudo apt-get install clang-format-14 - - name: Check licenses + - name: Check license + id: check_license + continue-on-error: true env: NDCTL_ENABLE: n # just to speed up the job PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: y # not recommended for production PMEMOBJ_IGNORE_BAD_BLOCKS: y # not recommended for production - run: make -j$(nproc) check-license + run: | + make -j$(nproc) check-license || true + git diff > /tmp/check-license.diff + [ $(cat /tmp/check-license.diff | wc -l ) -gt 0 ] && exit 1 + exit 0 + + - name: Upload check license diff + if: steps.check_license.outcome != 'success' + uses: actions/upload-artifact@v4 + with: + name: check-license.diff + path: /tmp/check-license.diff + + - name: Check license - Exit code + run: | + [ "${{steps.check_license.outcome}}" != "success" ] && exit 1 + exit 0 - name: Check style env: From 204bdff42152515550ec85e2ec9794bdd2be4023 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 15 Mar 2024 07:24:31 +0100 Subject: [PATCH 148/182] pmem: add pmem_log_[get/set]_treshold functions + UT --- src/include/libpmem.h | 53 +++++++- src/libpmem/libpmem.c | 24 ++++ src/test/Makefile | 2 + src/test/pmem_log_get_treshold/.gitignore | 1 + src/test/pmem_log_get_treshold/Makefile | 20 +++ src/test/pmem_log_get_treshold/TESTS.py | 27 ++++ .../pmem_log_get_treshold.c | 116 +++++++++++++++++ src/test/pmem_log_set_treshold/.gitignore | 1 + src/test/pmem_log_set_treshold/Makefile | 15 +++ src/test/pmem_log_set_treshold/TESTS.py | 31 +++++ .../pmem_log_set_treshold.c | 121 ++++++++++++++++++ 11 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 src/test/pmem_log_get_treshold/.gitignore create mode 100644 src/test/pmem_log_get_treshold/Makefile create mode 100755 src/test/pmem_log_get_treshold/TESTS.py create mode 100644 src/test/pmem_log_get_treshold/pmem_log_get_treshold.c create mode 100644 src/test/pmem_log_set_treshold/.gitignore create mode 100644 src/test/pmem_log_set_treshold/Makefile create mode 100755 src/test/pmem_log_set_treshold/TESTS.py create mode 100644 src/test/pmem_log_set_treshold/pmem_log_set_treshold.c diff --git a/src/include/libpmem.h b/src/include/libpmem.h index a1201889644..ad1a11c6e7f 100644 --- a/src/include/libpmem.h +++ b/src/include/libpmem.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2023, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ /* * libpmem.h -- definitions of libpmem entry points @@ -91,6 +91,57 @@ const char *pmem_check_version(unsigned major_required, const char *pmem_errormsg(void); +/* + * Available log levels. Log levels are used in the logging API calls + * to indicate logging message severity. Log levels are also used + * to define thresholds for the logging. + */ +enum pmem_log_level { + /* only basic library info */ + PMEM_LOG_LEVEL_HARK, + /* an error that causes the program to stop working immediately */ + PMEM_LOG_LEVEL_FATAL, + /* an error that causes the current operation to fail */ + PMEM_LOG_LEVEL_ERROR, + /* + * an unexpected situation that does NOT cause + * the current operation to fail + */ + PMEM_LOG_LEVEL_WARNING, + /* non-massive info mainly related to public API function completions */ + PMEM_LOG_LEVEL_NOTICE, + /* massive info e.g. every write operation indication */ + PMEM_LOG_LEVEL_INFO, + /* debug info e.g. write operation dump */ + PMEM_LOG_LEVEL_DEBUG, +}; + +enum pmem_log_threshold { + /* + * the main threshold level - the logging messages less severe than + * indicated by this threshold's value won't trigger the logging + * functions + */ + PMEM_LOG_THRESHOLD, + /* + * the auxiliary threshold level - may or may not be used by the logging + * function + */ + PMEM_LOG_THRESHOLD_AUX, +}; + +/* + * pmem_log_set_threshold - set the logging threshold value + */ +int pmem_log_set_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level value); + +/* + * pmem_log_get_threshold - get the logging threshold value + */ +int pmem_log_get_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level *value); + #ifdef __cplusplus } #endif diff --git a/src/libpmem/libpmem.c b/src/libpmem/libpmem.c index d2705f67cfb..514ee05d022 100644 --- a/src/libpmem/libpmem.c +++ b/src/libpmem/libpmem.c @@ -96,3 +96,27 @@ pmem_errormsg(void) { return pmem_errormsgU(); } + +/* + * pmem_log_set_threshold -- set the logging threshold value + */ +int +pmem_log_set_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level value) +{ + int ret = core_log_set_threshold((enum core_log_threshold)threshold, + (enum core_log_level)value); + return core_log_error_translate(ret); +} + +/* + * pmem_log_get_threshold -- get the logging level threshold value + */ +int +pmem_log_get_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level *value) +{ + int ret = core_log_get_threshold((enum core_log_threshold)threshold, + (enum core_log_level *)value); + return core_log_error_translate(ret); +} diff --git a/src/test/Makefile b/src/test/Makefile index 961172eac35..a3558c3f6eb 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -161,6 +161,8 @@ PMEM_TESTS = \ pmem_include\ pmem_is_pmem\ pmem_is_pmem_posix\ + pmem_log_get_treshold\ + pmem_log_set_treshold\ pmem_map_file\ pmem_has_auto_flush\ pmem_deep_persist\ diff --git a/src/test/pmem_log_get_treshold/.gitignore b/src/test/pmem_log_get_treshold/.gitignore new file mode 100644 index 00000000000..39976e5d27f --- /dev/null +++ b/src/test/pmem_log_get_treshold/.gitignore @@ -0,0 +1 @@ +pmem_log_get_treshold diff --git a/src/test/pmem_log_get_treshold/Makefile b/src/test/pmem_log_get_treshold/Makefile new file mode 100644 index 00000000000..5db71427838 --- /dev/null +++ b/src/test/pmem_log_get_treshold/Makefile @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + +# +# src/test/pmem_log_get_treshold/Makefile -- build pmem_log_get_treshold unit test +# + +TARGET = pmem_log_get_treshold +OBJS = pmem_log_get_treshold.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMCOMMON=internal-debug +LIBPMEM=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, pmem_log_get_treshold.c) diff --git a/src/test/pmem_log_get_treshold/TESTS.py b/src/test/pmem_log_get_treshold/TESTS.py new file mode 100755 index 00000000000..c01d1556353 --- /dev/null +++ b/src/test/pmem_log_get_treshold/TESTS.py @@ -0,0 +1,27 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class PMEM_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('pmem_log_get_treshold', self.test_case) + + +class TEST0(PMEM_LOG): + test_case = 'test_log_get_treshold' + + +class TEST1(PMEM_LOG): + test_case = 'test_log_get_treshold_EAGAIN' diff --git a/src/test/pmem_log_get_treshold/pmem_log_get_treshold.c b/src/test/pmem_log_get_treshold/pmem_log_get_treshold.c new file mode 100644 index 00000000000..1f96a71359f --- /dev/null +++ b/src/test/pmem_log_get_treshold/pmem_log_get_treshold.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * pmem_log_get_treshold.c -- unit test for pmem_log_get_treshold + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmem.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +static enum core_log_threshold core_tresholds[] = { + [PMEM_LOG_THRESHOLD] = CORE_LOG_THRESHOLD, + [PMEM_LOG_THRESHOLD_AUX] = CORE_LOG_THRESHOLD_AUX +}; + +static enum core_log_level core_levels[] = { + [PMEM_LOG_LEVEL_HARK] = CORE_LOG_LEVEL_HARK, + [PMEM_LOG_LEVEL_FATAL] = CORE_LOG_LEVEL_FATAL, + [PMEM_LOG_LEVEL_ERROR] = CORE_LOG_LEVEL_ERROR, + [PMEM_LOG_LEVEL_WARNING] = CORE_LOG_LEVEL_WARNING, + [PMEM_LOG_LEVEL_NOTICE] = CORE_LOG_LEVEL_NOTICE, + [PMEM_LOG_LEVEL_INFO] = CORE_LOG_LEVEL_INFO, + [PMEM_LOG_LEVEL_DEBUG] = CORE_LOG_LEVEL_DEBUG +}; + +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level level; + int ret; +} Core_log_get_treshold; + +FUNC_MOCK(core_log_get_threshold, int, enum core_log_threshold threshold, + enum core_log_level *level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_get_treshold.exp_threshold); + if (Core_log_get_treshold.ret == 0) + *level = Core_log_get_treshold.level; + return Core_log_get_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_get_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_get_treshold_helper(int error) +{ + errno = 0; + Core_log_get_treshold.ret = error == NO_ERRNO ? 0 : error; + for (enum pmem_log_threshold treshold = PMEM_LOG_THRESHOLD; + treshold <= PMEM_LOG_THRESHOLD_AUX; treshold++) { + Core_log_get_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmem_log_level exp_level = PMEM_LOG_LEVEL_HARK; + exp_level <= PMEM_LOG_LEVEL_DEBUG; exp_level++) { + enum pmem_log_level level; + Core_log_get_treshold.level = core_levels[exp_level]; + FUNC_MOCK_RCOUNTER_SET(core_log_get_threshold, + VALIDATED_CALL); + int ret = pmem_log_get_threshold(treshold, &level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(level, exp_level); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_get_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_get_treshold is called with proper arguments + * - if pmem_log_get_treshold return 0 (no error) + * - if each PMEM_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_get_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(NO_ERRNO); +} + +/* Check pmem_log_get_threshold EAGAIN error handling. */ +static int +test_log_get_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_get_treshold_helper(EAGAIN); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_get_treshold), + TEST_CASE(test_log_get_treshold_EAGAIN), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "pmem_log_get_treshold"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} diff --git a/src/test/pmem_log_set_treshold/.gitignore b/src/test/pmem_log_set_treshold/.gitignore new file mode 100644 index 00000000000..c56248dfa65 --- /dev/null +++ b/src/test/pmem_log_set_treshold/.gitignore @@ -0,0 +1 @@ +pmem_log_set_treshold diff --git a/src/test/pmem_log_set_treshold/Makefile b/src/test/pmem_log_set_treshold/Makefile new file mode 100644 index 00000000000..5e13b3cc238 --- /dev/null +++ b/src/test/pmem_log_set_treshold/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = pmem_log_set_treshold +OBJS = pmem_log_set_treshold.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMCOMMON=internal-debug +LIBPMEM=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, pmem_log_set_treshold.c) diff --git a/src/test/pmem_log_set_treshold/TESTS.py b/src/test/pmem_log_set_treshold/TESTS.py new file mode 100755 index 00000000000..781acaa44a2 --- /dev/null +++ b/src/test/pmem_log_set_treshold/TESTS.py @@ -0,0 +1,31 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class PMEM_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('pmem_log_set_treshold', self.test_case) + + +class TEST0(PMEM_LOG): + test_case = 'test_log_set_treshold' + + +class TEST1(PMEM_LOG): + test_case = 'test_log_set_treshold_EAGAIN' + + +class TEST2(PMEM_LOG): + test_case = 'test_log_set_treshold_EINVAL' diff --git a/src/test/pmem_log_set_treshold/pmem_log_set_treshold.c b/src/test/pmem_log_set_treshold/pmem_log_set_treshold.c new file mode 100644 index 00000000000..887ac02289a --- /dev/null +++ b/src/test/pmem_log_set_treshold/pmem_log_set_treshold.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * pmem_log_set_treshold.c -- unit test for pmem_log_set_treshold + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmem.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +static enum core_log_threshold core_tresholds[] = { + [PMEM_LOG_THRESHOLD] = CORE_LOG_THRESHOLD, + [PMEM_LOG_THRESHOLD_AUX] = CORE_LOG_THRESHOLD_AUX +}; + +static enum core_log_level core_levels[] = { + [PMEM_LOG_LEVEL_HARK] = CORE_LOG_LEVEL_HARK, + [PMEM_LOG_LEVEL_FATAL] = CORE_LOG_LEVEL_FATAL, + [PMEM_LOG_LEVEL_ERROR] = CORE_LOG_LEVEL_ERROR, + [PMEM_LOG_LEVEL_WARNING] = CORE_LOG_LEVEL_WARNING, + [PMEM_LOG_LEVEL_NOTICE] = CORE_LOG_LEVEL_NOTICE, + [PMEM_LOG_LEVEL_INFO] = CORE_LOG_LEVEL_INFO, + [PMEM_LOG_LEVEL_DEBUG] = CORE_LOG_LEVEL_DEBUG +}; + +/* Mock */ +static struct { + enum core_log_threshold exp_threshold; + enum core_log_level exp_level; + int ret; +} Core_log_set_treshold; + +FUNC_MOCK(core_log_set_threshold, int, enum core_log_threshold threshold, + enum core_log_level level) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq(threshold, Core_log_set_treshold.exp_threshold); + UT_ASSERTeq(level, Core_log_set_treshold.exp_level); + return Core_log_set_treshold.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_set_threshold)(threshold, level); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_set_treshold_helper(int error) +{ + errno = 0; + Core_log_set_treshold.ret = error == NO_ERRNO ? 0 : error; + for (enum pmem_log_threshold treshold = PMEM_LOG_THRESHOLD; + treshold <= PMEM_LOG_THRESHOLD_AUX; treshold++) { + Core_log_set_treshold.exp_threshold = core_tresholds[treshold]; + for (enum pmem_log_level level = PMEM_LOG_LEVEL_HARK; + level <= PMEM_LOG_LEVEL_DEBUG; level++) { + Core_log_set_treshold.exp_level = core_levels[level]; + FUNC_MOCK_RCOUNTER_SET(core_log_set_threshold, + VALIDATED_CALL); + int ret = pmem_log_set_threshold(treshold, level); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_set_threshold), CALLED); + /* no need to test the error path for all values */ + if (error != NO_ERRNO) + return NO_ARGS_CONSUMED; + } + } + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_set_treshold is called with proper arguments + * - if pmempmem_log_set_treshold return 0 (no error) + * - if each PMEM_LOG_LEVEL corespond to relevant CORE_LOG_LEVEL + * - no errno is set + */ +static int +test_log_set_treshold(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(NO_ERRNO); +} + +/* Check pmem_log_set_threshold EAGAIN error handling. */ +static int +test_log_set_treshold_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EAGAIN); +} + +/* Check pmem_log_set_threshold EINVAL error handling. */ +static int +test_log_set_treshold_EINVAL(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_treshold_helper(EINVAL); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_set_treshold), + TEST_CASE(test_log_set_treshold_EAGAIN), + TEST_CASE(test_log_set_treshold_EINVAL), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "pmem_log_set_treshold"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} From ef817684b71b9e52a58bfb06614c4ec7d0cbc44e Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Wed, 20 Mar 2024 09:03:42 +0100 Subject: [PATCH 149/182] pmem: add pmem_log_set_function function + UT --- src/include/libpmem.h | 22 +++++ src/libpmem/libpmem.c | 11 +++ src/test/Makefile | 1 + src/test/pmem_log_set_function/.gitignore | 1 + src/test/pmem_log_set_function/Makefile | 15 +++ src/test/pmem_log_set_function/TESTS.py | 27 ++++++ .../pmem_log_set_function.c | 91 +++++++++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 src/test/pmem_log_set_function/.gitignore create mode 100644 src/test/pmem_log_set_function/Makefile create mode 100755 src/test/pmem_log_set_function/TESTS.py create mode 100644 src/test/pmem_log_set_function/pmem_log_set_function.c diff --git a/src/include/libpmem.h b/src/include/libpmem.h index ad1a11c6e7f..5786cffd0af 100644 --- a/src/include/libpmem.h +++ b/src/include/libpmem.h @@ -142,6 +142,28 @@ int pmem_log_set_threshold(enum pmem_log_threshold threshold, int pmem_log_get_threshold(enum pmem_log_threshold threshold, enum pmem_log_level *value); +/* + * the type used for defining logging functions + */ +typedef void pmem_log_function( + /* the log level of the message */ + enum pmem_log_level level, + /* name of the source file where the message coming from */ + const char *file_name, + /* the source file line where the message coming from */ + const int line_no, + /* the function name where the message coming from */ + const char *function_name, + /* message */ + const char *message); + +#define PMEM_LOG_USE_DEFAULT_FUNCTION (NULL) + +/* + * pmem_log_set_function - set the logging function + */ +int pmem_log_set_function(pmem_log_function *log_function); + #ifdef __cplusplus } #endif diff --git a/src/libpmem/libpmem.c b/src/libpmem/libpmem.c index 514ee05d022..865deedf28f 100644 --- a/src/libpmem/libpmem.c +++ b/src/libpmem/libpmem.c @@ -120,3 +120,14 @@ pmem_log_get_threshold(enum pmem_log_threshold threshold, (enum core_log_level *)value); return core_log_error_translate(ret); } + +/* + * pmem_log_set_function -- set the log function pointer either to + * a user-provided function pointer or to the default logging function. + */ +int +pmem_log_set_function(pmem_log_function *log_function) +{ + int ret = core_log_set_function((core_log_function *)log_function); + return core_log_error_translate(ret); +} diff --git a/src/test/Makefile b/src/test/Makefile index a3558c3f6eb..0e9d87aa5c7 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -162,6 +162,7 @@ PMEM_TESTS = \ pmem_is_pmem\ pmem_is_pmem_posix\ pmem_log_get_treshold\ + pmem_log_set_function\ pmem_log_set_treshold\ pmem_map_file\ pmem_has_auto_flush\ diff --git a/src/test/pmem_log_set_function/.gitignore b/src/test/pmem_log_set_function/.gitignore new file mode 100644 index 00000000000..ee9f2a39097 --- /dev/null +++ b/src/test/pmem_log_set_function/.gitignore @@ -0,0 +1 @@ +pmem_log_set_function diff --git a/src/test/pmem_log_set_function/Makefile b/src/test/pmem_log_set_function/Makefile new file mode 100644 index 00000000000..ac703e1e285 --- /dev/null +++ b/src/test/pmem_log_set_function/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +TARGET = pmem_log_set_function +OBJS = pmem_log_set_function.o + +BUILD_STATIC_DEBUG=n +BUILD_STATIC_NONDEBUG=n + +# required for proper mock integration +LIBPMEMCOMMON=internal-debug +LIBPMEM=internal-debug + +include ../Makefile.inc +LDFLAGS += $(call extract_funcs, pmem_log_set_function.c) diff --git a/src/test/pmem_log_set_function/TESTS.py b/src/test/pmem_log_set_function/TESTS.py new file mode 100755 index 00000000000..0058a101a1a --- /dev/null +++ b/src/test/pmem_log_set_function/TESTS.py @@ -0,0 +1,27 @@ +#!../env.py +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation +# + + +import testframework as t +from testframework import granularity as g + + +@g.require_granularity(g.ANY) +# The 'debug' build is chosen arbitrarily to ensure these tests are run only +# once. No dynamic libraries are used nor .static_* builds are available. +@t.require_build('debug') +class PMEM_LOG(t.BaseTest): + test_type = t.Short + + def run(self, ctx): + ctx.exec('pmem_log_set_function', self.test_case) + + +class TEST0(PMEM_LOG): + test_case = 'test_log_set_function' + + +class TEST1(PMEM_LOG): + test_case = 'test_log_set_function_EAGAIN' diff --git a/src/test/pmem_log_set_function/pmem_log_set_function.c b/src/test/pmem_log_set_function/pmem_log_set_function.c new file mode 100644 index 00000000000..9f92d9cbd15 --- /dev/null +++ b/src/test/pmem_log_set_function/pmem_log_set_function.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * pmem_log_set_function.c -- unit test for pmem_log_set_function + */ + +#include "unittest.h" +#include "log_internal.h" +#include "libpmem.h" + +#define NO_ARGS_CONSUMED 0 + +#define VALIDATED_CALL 127 +#define CALLED (VALIDATED_CALL + 1) + +#define PMEM_LOG_CUSTOM_FUNCTION_MOCK ((pmem_log_function *) 0xA1C5D68F) + +/* Mock */ +static struct { + int ret; +} Core_log_set_function; + +FUNC_MOCK(core_log_set_function, int, core_log_function *log_function) + FUNC_MOCK_RUN(VALIDATED_CALL) { + UT_ASSERTeq((void *)log_function, + (void *)PMEM_LOG_CUSTOM_FUNCTION_MOCK); + return Core_log_set_function.ret; + } +FUNC_MOCK_RUN_DEFAULT { + return _FUNC_REAL(core_log_set_function)(log_function); +} +FUNC_MOCK_END + +/* Helper */ +static int +test_log_set_function_helper(int error) +{ + errno = 0; + Core_log_set_function.ret = error == NO_ERRNO ? 0 : error; + FUNC_MOCK_RCOUNTER_SET(core_log_set_function, VALIDATED_CALL); + int ret = pmem_log_set_function(PMEM_LOG_CUSTOM_FUNCTION_MOCK); + if (error == NO_ERRNO) { + UT_ASSERTeq(ret, 0); + } else { + UT_ASSERTeq(ret, 1); + UT_ASSERTeq(errno, error); + } + UT_ASSERTeq(RCOUNTER(core_log_set_function), CALLED); + + return NO_ARGS_CONSUMED; +} + +/* Tests */ +/* + * Check: + * - if core_log_set_function is called with proper argument + * - if pmem_log_set_function return 0 (no error) + * - no errno is set + */ +static int +test_log_set_function(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_function_helper(NO_ERRNO); +} + +/* + * core_log_set_function() with EAGAIN error + * Check: + * - if core_log_set_function is called with proper argument + * - if pmem_log_set_function return 1 (error via errno) + * - errno is set to EAGAIN + */ +static int +test_log_set_function_EAGAIN(const struct test_case *tc, int argc, char *argv[]) +{ + return test_log_set_function_helper(EAGAIN); +} + +static struct test_case test_cases[] = { + TEST_CASE(test_log_set_function), + TEST_CASE(test_log_set_function_EAGAIN), +}; + +int +main(int argc, char *argv[]) +{ + START(argc, argv, "pmem_log_set_function"); + TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); + DONE(NULL); +} From 478a79e6860506990cfa90413ffdbb40d5c48228 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 20 Mar 2024 15:30:54 +0100 Subject: [PATCH 150/182] test: suppress ERROR messages when irrelevant to the test result Suppress *ERROR* messages from stderr in tests that verify faulty situation based on function return value and errno value. These tests ignore stderr/stdout at all. This is to avoid a lot of unnecessary messages on the screen during tests execution. Signed-off-by: Tomasz Gromadzki --- src/test/obj_tx_locks/TEST1 | 4 ++-- src/test/out_err_mt/TEST1 | 4 ++-- src/test/out_err_mt/TEST2 | 4 ++-- src/test/util_ctl/TEST0 | 4 ++-- src/test/util_ctl/TEST1 | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/obj_tx_locks/TEST1 b/src/test/obj_tx_locks/TEST1 index 517832d1bb5..f0bbae0dedc 100755 --- a/src/test/obj_tx_locks/TEST1 +++ b/src/test/obj_tx_locks/TEST1 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2019, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # src/test/obj_tx_locks/TEST1 -- unit test for transaction locks @@ -21,6 +21,6 @@ require_valgrind 3.10 configure_valgrind drd force-enable setup -expect_normal_exit ./obj_tx_locks$EXESUFFIX $DIR/testfile1 m +expect_normal_exit ./obj_tx_locks$EXESUFFIX $DIR/testfile1 m 2>/dev/null pass diff --git a/src/test/out_err_mt/TEST1 b/src/test/out_err_mt/TEST1 index f1f557f211b..81f09de12c9 100755 --- a/src/test/out_err_mt/TEST1 +++ b/src/test/out_err_mt/TEST1 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2023, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # @@ -26,7 +26,7 @@ unset PMEM_LOG_FILE unset PMEMOBJ_LOG_FILE unset PMEMPOOL_LOG_FILE -expect_normal_exit ./out_err_mt$EXESUFFIX $DIR/testfile1 +expect_normal_exit ./out_err_mt$EXESUFFIX $DIR/testfile1 2>/dev/null check diff --git a/src/test/out_err_mt/TEST2 b/src/test/out_err_mt/TEST2 index 83bac1d3e38..fca512776bc 100755 --- a/src/test/out_err_mt/TEST2 +++ b/src/test/out_err_mt/TEST2 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2023, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # @@ -24,7 +24,7 @@ unset PMEMOBJ_LOG_LEVEL unset PMEM_LOG_FILE unset PMEMOBJ_LOG_FILE -expect_normal_exit ./out_err_mt$EXESUFFIX $DIR/testfile1 +expect_normal_exit ./out_err_mt$EXESUFFIX $DIR/testfile1 2>/dev/null check diff --git a/src/test/util_ctl/TEST0 b/src/test/util_ctl/TEST0 index f721eea18ce..15784dd7eb4 100755 --- a/src/test/util_ctl/TEST0 +++ b/src/test/util_ctl/TEST0 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2023, Intel Corporation +# Copyright 2016-2024, Intel Corporation . ../unittest/unittest.sh @@ -10,6 +10,6 @@ set_test_labels fault_injection setup expect_normal_exit\ - ./util_ctl$EXESUFFIX $DIR/testconfig + ./util_ctl$EXESUFFIX $DIR/testconfig 2>/dev/null pass diff --git a/src/test/util_ctl/TEST1 b/src/test/util_ctl/TEST1 index 9df1d2a6bda..981e27f1ea1 100755 --- a/src/test/util_ctl/TEST1 +++ b/src/test/util_ctl/TEST1 @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2023, Intel Corporation +# Copyright 2016-2024, Intel Corporation . ../unittest/unittest.sh @@ -12,6 +12,6 @@ configure_valgrind memcheck force-enable setup expect_normal_exit\ - ./util_ctl$EXESUFFIX $DIR/testconfig + ./util_ctl$EXESUFFIX $DIR/testconfig 2>/dev/null pass From e2d0ec76066ed58fbc9eaf437dc0deb86916142a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 6 Dec 2023 16:29:10 +0100 Subject: [PATCH 151/182] common: cleanup the way Valgrind is disabled in build Signed-off-by: Tomasz Gromadzki --- .github/workflows/scan_codeql.yml | 2 +- INSTALL.md | 7 +++++-- utils/gha-runners/build-pmdk.sh | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scan_codeql.yml b/.github/workflows/scan_codeql.yml index fc3c7183dcc..ce5a625834b 100644 --- a/.github/workflows/scan_codeql.yml +++ b/.github/workflows/scan_codeql.yml @@ -41,7 +41,7 @@ jobs: languages: cpp, python - name: Build PMDK - run: make EXTRA_CFLAGS=-DUSE_VALGRIND test -j$(nproc) + run: make test -j$(nproc) - name: CodeQL scan uses: github/codeql-action/analyze@v2 diff --git a/INSTALL.md b/INSTALL.md index a3f1baf19f9..035814792cf 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -114,8 +114,11 @@ By default, support for all tools is enabled. If you wish to disable it, supply make EXTRA_CFLAGS=-DVG_MEMCHECK_ENABLED=0 ``` -`VALGRIND_ENABLED` flag, when set to 0, disables all Valgrind tools -(drd, helgrind, memcheck and pmemcheck). +If you want to disable all Valgrind tools run: + +```sh +make VALGRIND=0 +``` The `SANITIZE` flag allows the libraries to be tested with various sanitizers. For example, to test the libraries with AddressSanitizer diff --git a/utils/gha-runners/build-pmdk.sh b/utils/gha-runners/build-pmdk.sh index 467acbff43a..84e2d4d5252 100755 --- a/utils/gha-runners/build-pmdk.sh +++ b/utils/gha-runners/build-pmdk.sh @@ -17,7 +17,7 @@ set -eo pipefail function build_pmdk { echo "********** make pmdk **********" cd ${PMDK_PATH} && make -j$(nproc) clean - cd ${PMDK_PATH} && make -j$(nproc) EXTRA_CFLAGS=-DUSE_VALGRIND + cd ${PMDK_PATH} && make -j$(nproc) echo "********** make pmdk test **********" cd ${PMDK_PATH}/ && make -j$(nproc) test } From 19ca6eed607ea57a3025344dd575f54ceb46cf52 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 28 Nov 2023 18:08:50 +0100 Subject: [PATCH 152/182] common: disable Valgrind tools when Valgrind is not enabled Disable all Valgrind tools when Valgrind is not enabled Use VALGRIND=0 env. var. to disable Valgrind in compilation Signed-off-by: Tomasz Gromadzki --- ChangeLog | 1 - INSTALL.md | 8 +------- src/benchmarks/Makefile | 7 ++++++- src/core/valgrind_internal.h | 7 ++++++- src/examples/Makefile.inc | 6 +++++- src/libpmem2/x86_64/memcpy/memcpy_avx.h | 5 ++++- src/libpmem2/x86_64/memcpy/memcpy_sse2.h | 5 ++++- src/libpmem2/x86_64/memset/memset_avx.h | 6 +++++- src/libpmem2/x86_64/memset/memset_sse2.h | 5 ++++- src/libpmemobj/heap.c | 2 ++ src/libpmemobj/heap.h | 4 +++- src/libpmemobj/obj.c | 2 +- src/libpmemobj/palloc.c | 10 ++++++++-- src/libpmemobj/palloc.h | 4 +++- src/test/unittest/Makefile | 5 +++++ utils/call_stacks_analysis/make_extra.py | 2 +- 16 files changed, 58 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index b199c775169..808e26f55df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,7 +17,6 @@ Mon Dec 4 2023 Oksana Sałyk - Reduces libpmemobj's stack usage below the 11kB threshold. - Fixing minor Coverity issues - Add a new toolset for stack usage analysis (https://github.com/pmem/pmdk/tree/master/utils/call_stacks_analysis) - Tue Aug 8 2023 Oksana Sałyk diff --git a/INSTALL.md b/INSTALL.md index 035814792cf..a8876d51c11 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -108,13 +108,7 @@ Both building and installation scripts are very flexible. To see additional opti ### Memory Management Tools The PMDK libraries support standard Valgrind DRD, Helgrind and Memcheck, as well as a PM-aware version of [Valgrind](https://github.com/pmem/valgrind). -By default, support for all tools is enabled. If you wish to disable it, supply the compiler with `VG_\_ENABLED` flag set to 0, for example: - -```sh -make EXTRA_CFLAGS=-DVG_MEMCHECK_ENABLED=0 -``` - -If you want to disable all Valgrind tools run: +By default, support for all tools is enabled. If you wish to disable it, supply the compiler with `VALGRIND` flag set to 0: ```sh make VALGRIND=0 diff --git a/src/benchmarks/Makefile b/src/benchmarks/Makefile index f70c4f17856..81691ccc765 100644 --- a/src/benchmarks/Makefile +++ b/src/benchmarks/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2023, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # src/benchmarks/Makefile -- build all benchmarks @@ -109,6 +109,11 @@ LDFLAGS += $(GCOV_LDFLAGS) LIBS += $(GCOV_LIBS) endif +ifeq ($(VALGRIND),0) +CFLAGS += -DVALGRIND_ENABLED=0 +CXXFLAGS += -DVALGRIND_ENABLED=0 +endif + ifneq ($(SANITIZE),) CXXFLAGS += -fsanitize=$(SANITIZE) LDFLAGS += -fsanitize=$(SANITIZE) diff --git a/src/core/valgrind_internal.h b/src/core/valgrind_internal.h index ecbc741ef8f..99dc553664a 100644 --- a/src/core/valgrind_internal.h +++ b/src/core/valgrind_internal.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2015-2023, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * valgrind_internal.h -- internal definitions for valgrind macros @@ -19,6 +19,11 @@ #define VG_HELGRIND_ENABLED 1 #define VG_MEMCHECK_ENABLED 1 #define VG_DRD_ENABLED 1 +#else +#define VG_PMEMCHECK_ENABLED 0 +#define VG_HELGRIND_ENABLED 0 +#define VG_MEMCHECK_ENABLED 0 +#define VG_DRD_ENABLED 0 #endif #if VG_PMEMCHECK_ENABLED || VG_HELGRIND_ENABLED || VG_MEMCHECK_ENABLED || \ diff --git a/src/examples/Makefile.inc b/src/examples/Makefile.inc index 3481e348a4e..ec9ca1a2e06 100644 --- a/src/examples/Makefile.inc +++ b/src/examples/Makefile.inc @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2015-2020, Intel Corporation +# Copyright 2015-2024, Intel Corporation # # examples/Makefile.inc -- build the Persistent Memory Development Kit examples @@ -23,6 +23,10 @@ CFLAGS += -fsanitize=$(SANITIZE) CXXFLAGS += -fsanitize=$(SANITIZE) LDFLAGS += -fsanitize=$(SANITIZE) endif +ifeq ($(VALGRIND),0) +CFLAGS += -DVALGRIND_ENABLED=0 +CXXFLAGS += -DVALGRIND_ENABLED=0 +endif INCS = -I$(INCDIR) -I. -I$(TOP_SRC)/examples $(OS_INCS) LIBS += $(OS_LIBS) $(LIBUUID) diff --git a/src/libpmem2/x86_64/memcpy/memcpy_avx.h b/src/libpmem2/x86_64/memcpy/memcpy_avx.h index 5d274035d95..6cb3c8fb88e 100644 --- a/src/libpmem2/x86_64/memcpy/memcpy_avx.h +++ b/src/libpmem2/x86_64/memcpy/memcpy_avx.h @@ -87,10 +87,13 @@ memmove_small_avx(char *dest, const char *src, size_t len, flush_fn flush) * path) in the optimized version. * libc's memcpy also does that, so we can't use it here. */ +#if VG_PMEMCHECK_ENABLED if (On_pmemcheck) { memmove_nodrain_generic(dest, src, len, PMEM2_F_MEM_NOFLUSH, NULL, NULL); - } else { + } else +#endif + { memmove_small_avx_noflush(dest, src, len); } diff --git a/src/libpmem2/x86_64/memcpy/memcpy_sse2.h b/src/libpmem2/x86_64/memcpy/memcpy_sse2.h index 4c56ca193c6..4012f33b712 100644 --- a/src/libpmem2/x86_64/memcpy/memcpy_sse2.h +++ b/src/libpmem2/x86_64/memcpy/memcpy_sse2.h @@ -103,10 +103,13 @@ memmove_small_sse2(char *dest, const char *src, size_t len, flush_fn flush) * path) in the optimized version. * libc's memcpy also does that, so we can't use it here. */ +#if VG_PMEMCHECK_ENABLED if (On_pmemcheck) { memmove_nodrain_generic(dest, src, len, PMEM2_F_MEM_NOFLUSH, NULL, NULL); - } else { + } else +#endif + { memmove_small_sse2_noflush(dest, src, len); } diff --git a/src/libpmem2/x86_64/memset/memset_avx.h b/src/libpmem2/x86_64/memset/memset_avx.h index f52e8cba736..1a5df0facc4 100644 --- a/src/libpmem2/x86_64/memset/memset_avx.h +++ b/src/libpmem2/x86_64/memset/memset_avx.h @@ -84,11 +84,15 @@ memset_small_avx(char *dest, __m256i ymm, size_t len, flush_fn flush) * path) in the optimized version. * libc's memset also does that, so we can't use it here. */ +#if VG_PMEMCHECK_ENABLED if (On_pmemcheck) { memset_nodrain_generic(dest, (uint8_t)m256_get2b(ymm), len, PMEM2_F_MEM_NOFLUSH, NULL, NULL); - } else { + } + else +#endif + { memset_small_avx_noflush(dest, ymm, len); } diff --git a/src/libpmem2/x86_64/memset/memset_sse2.h b/src/libpmem2/x86_64/memset/memset_sse2.h index 8654aa6c167..a160683fc45 100644 --- a/src/libpmem2/x86_64/memset/memset_sse2.h +++ b/src/libpmem2/x86_64/memset/memset_sse2.h @@ -91,10 +91,13 @@ memset_small_sse2(char *dest, __m128i xmm, size_t len, flush_fn flush) * path) in the optimized version. * libc's memset also does that, so we can't use it here. */ +#if VG_PMEMCHECK_ENABLED if (On_pmemcheck) { memset_nodrain_generic(dest, (uint8_t)_mm_cvtsi128_si32(xmm), len, PMEM2_F_MEM_NOFLUSH, NULL, NULL); - } else { + } else +#endif + { memset_small_sse2_noflush(dest, xmm, len); } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index d0b02f6fa18..64cc19f42d7 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -1240,6 +1240,7 @@ heap_get_bestfit_block(struct palloc_heap *heap, struct bucket *b, return 0; } +#if VG_MEMCHECK_ENABLED /* * heap_end -- returns first address after heap */ @@ -1252,6 +1253,7 @@ heap_end(struct palloc_heap *h) return &last_zone->chunks[last_zone->header.size_idx]; } +#endif /* VG_MEMCHECK_ENABLED */ /* * heap_arena_create -- create a new arena, push it to the vector diff --git a/src/libpmemobj/heap.h b/src/libpmemobj/heap.h index 455669aef9b..09278bad69e 100644 --- a/src/libpmemobj/heap.h +++ b/src/libpmemobj/heap.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2015-2022, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * heap.h -- internal definitions for heap @@ -83,7 +83,9 @@ void heap_foreach_object(struct palloc_heap *heap, object_callback cb, struct alloc_class_collection *heap_alloc_classes(struct palloc_heap *heap); +#if VG_MEMCHECK_ENABLED void *heap_end(struct palloc_heap *heap); +#endif /* VG_MEMCHECK_ENABLED */ unsigned heap_get_narenas_total(struct palloc_heap *heap); diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 90b69825c76..886e3f16cee 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -956,7 +956,7 @@ obj_runtime_init(PMEMobjpool *pop, int rdonly, int boot, unsigned nlanes) VALGRIND_DO_MAKE_MEM_NOACCESS(end, (char *)pop + pop->set->poolsize - (char *)end); } -#endif +#endif /* VG_MEMCHECK_ENABLED */ obj_pool_init(); diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index 7b2f7c8b3ff..852deca50e3 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -398,10 +398,14 @@ palloc_heap_action_on_process(struct palloc_heap *heap, act->m.m_ops->get_real_size(&act->m)); } } else if (act->new_state == MEMBLOCK_FREE) { +#if VG_MEMCHECK_ENABLED if (On_memcheck) { void *ptr = act->m.m_ops->get_user_data(&act->m); VALGRIND_DO_MEMPOOL_FREE(heap->layout, ptr); - } else if (On_pmemcheck) { + } +#endif /* VG_MEMCHECK_ENABLED */ +#if VG_PMEMCHECK_ENABLED + if (On_pmemcheck) { /* * The sync module, responsible for implementations of * persistent memory resident volatile variables, @@ -418,7 +422,7 @@ palloc_heap_action_on_process(struct palloc_heap *heap, size_t size = act->m.m_ops->get_real_size(&act->m); VALGRIND_REGISTER_PMEM_MAPPING(ptr, size); } - +#endif /* VG_PMEMCHECK_ENABLED */ STATS_SUB(heap->stats, persistent, heap_curr_allocated, act->m.m_ops->get_real_size(&act->m)); if (act->m.type == MEMORY_BLOCK_RUN) { @@ -1275,6 +1279,7 @@ palloc_init(void *heap_start, uint64_t heap_size, uint64_t *sizep, return heap_init(heap_start, heap_size, sizep, p_ops); } +#if VG_MEMCHECK_ENABLED /* * palloc_heap_end -- returns first address after heap */ @@ -1283,6 +1288,7 @@ palloc_heap_end(struct palloc_heap *h) { return heap_end(h); } +#endif /* VG_MEMCHECK_ENABLED */ /* * palloc_heap_check -- verifies heap state diff --git a/src/libpmemobj/palloc.h b/src/libpmemobj/palloc.h index 52a1f533d3f..31ddecd5595 100644 --- a/src/libpmemobj/palloc.h +++ b/src/libpmemobj/palloc.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2015-2022, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * palloc.h -- internal definitions for persistent allocator @@ -89,7 +89,9 @@ int palloc_buckets_init(struct palloc_heap *heap); int palloc_init(void *heap_start, uint64_t heap_size, uint64_t *sizep, struct pmem_ops *p_ops); +#if VG_MEMCHECK_ENABLED void *palloc_heap_end(struct palloc_heap *h); +#endif /* VG_MEMCHECK_ENABLED */ int palloc_heap_check(void *heap_start, uint64_t heap_size); void palloc_heap_cleanup(struct palloc_heap *heap); size_t palloc_heap(void *heap_start); diff --git a/src/test/unittest/Makefile b/src/test/unittest/Makefile index 6244049d16b..75242382d6c 100644 --- a/src/test/unittest/Makefile +++ b/src/test/unittest/Makefile @@ -72,6 +72,11 @@ LDFLAGS += $(GCOV_LDFLAGS) LIBS += $(GCOV_LIBS) endif +ifeq ($(VALGRIND),0) +CFLAGS += -DVALGRIND_ENABLED=0 +CXXFLAGS += -DVALGRIND_ENABLED=0 +endif + CFLAGS += $(EXTRA_CFLAGS) LIBS += $(LIBUTIL) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index 1177e69450a..d6352201716 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -22,7 +22,7 @@ def dict_extend(dict_, key, values): def inlines(calls: Calls) -> Calls: # common calls['core_init'] = ['util_init', 'core_log_init', 'out_init'] - calls['core_fini'] = ['out_fini'] + calls['core_fini'] = ['out_fini', 'core_log_fini'] calls['common_init'] = ['core_init', 'util_mmap_init'] calls['common_fini'] = ['util_mmap_fini', 'core_fini'] calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] From 2c76ea690abbbef896e4445ab7e16a61354b748a Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 7 Dec 2023 22:28:32 +0100 Subject: [PATCH 153/182] common: separate test to verify if Valgrind enabled in tests Signed-off-by: Tomasz Gromadzki --- src/test/Makefile | 3 ++- src/test/valgrind_check/.gitignore | 1 + src/test/valgrind_check/Makefile | 10 ++++++++++ src/test/valgrind_check/README | 7 +++++++ src/test/valgrind_check/TEST0 | 18 +++++++++++++++++ src/test/valgrind_check/valgrind_check.c | 25 ++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/test/valgrind_check/.gitignore create mode 100644 src/test/valgrind_check/Makefile create mode 100644 src/test/valgrind_check/README create mode 100755 src/test/valgrind_check/TEST0 create mode 100644 src/test/valgrind_check/valgrind_check.c diff --git a/src/test/Makefile b/src/test/Makefile index 0e9d87aa5c7..e7a9c78a889 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -150,7 +150,8 @@ OTHER_TESTS = \ util_uuid_generate\ util_vec\ util_vecq\ - log_errno + log_errno\ + valgrind_check ifeq ($(ARCH), x86_64) OTHER_TESTS += \ diff --git a/src/test/valgrind_check/.gitignore b/src/test/valgrind_check/.gitignore new file mode 100644 index 00000000000..15bae9bd64e --- /dev/null +++ b/src/test/valgrind_check/.gitignore @@ -0,0 +1 @@ +valgrind_check diff --git a/src/test/valgrind_check/Makefile b/src/test/valgrind_check/Makefile new file mode 100644 index 00000000000..b6d2a7129e8 --- /dev/null +++ b/src/test/valgrind_check/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +# +# src/test/valgrind_check/Makefile -- build valgrind_check unit test +# +TARGET = valgrind_check +OBJS = valgrind_check.o + +include ../Makefile.inc diff --git a/src/test/valgrind_check/README b/src/test/valgrind_check/README new file mode 100644 index 00000000000..ba3ee397cd5 --- /dev/null +++ b/src/test/valgrind_check/README @@ -0,0 +1,7 @@ +Persistent Memory Development Kit + +This is src/test/valgrind_check/README. + +This directory contains a unit test for Valgrind enabling. + +The program in valgrind_check.c verifies if Valgrind was enabled during build. diff --git a/src/test/valgrind_check/TEST0 b/src/test/valgrind_check/TEST0 new file mode 100755 index 00000000000..d7ffd137f8c --- /dev/null +++ b/src/test/valgrind_check/TEST0 @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +# +# src/test/valgrind_check/TEST0 -- unit test for valgrind_check +# + +. ../unittest/unittest.sh + +require_test_type short +require_valgrind + +setup + +expect_normal_exit ./valgrind_check$EXESUFFIX + +pass diff --git a/src/test/valgrind_check/valgrind_check.c b/src/test/valgrind_check/valgrind_check.c new file mode 100644 index 00000000000..b719be9a0b1 --- /dev/null +++ b/src/test/valgrind_check/valgrind_check.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2024, Intel Corporation */ + +/* + * valgrind_check.c -- unit test Valgrind enabled during build + * + * usage: valgrind_check + * + */ + +#include "valgrind_internal.h" + +#ifndef VALGRIND_ENABLED +#error Valgrind tools not properly configured +#endif + +int +main(int argc, char *argv[]) +{ +#if VALGRIND_ENABLED + return 0; +#else + return 1; +#endif +} From 12597f2a15971f5b440d084026ed2ba5b47e0db3 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 7 Dec 2023 22:36:39 +0100 Subject: [PATCH 154/182] common: check if Valgrind was enabled during biuld time Test is skipped if any Valgrind tool is required and Valgrind was not enabled during build (VALGRIND=0) Signed-off-by: Tomasz Gromadzki --- src/test/RUNTESTS.py | 8 ++++++-- src/test/unittest/unittest.sh | 11 +++++++++++ src/test/unittest/valgrind.py | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/test/RUNTESTS.py b/src/test/RUNTESTS.py index da27e155918..ccf4355f9aa 100755 --- a/src/test/RUNTESTS.py +++ b/src/test/RUNTESTS.py @@ -121,7 +121,9 @@ def run_tests(self): continue except futils.Skip as s: - self.msg.print('{}: SKIP: {}'.format(t, s)) + self.msg.print('{}: {}SKIP{}: {}'. + format(t, futils.Color.YELLOW, + futils.Color.END, s)) except futils.Fail as f: self._test_failed(t, c, f) @@ -130,7 +132,9 @@ def run_tests(self): self._test_passed(t) except futils.Skip as s: - self.msg.print('{}: SKIP: {}'.format(tc, s)) + self.msg.print('{}: {}SKIP{}: {}'. + format(tc, futils.Color.YELLOW, + futils.Color.END, s)) except futils.Fail as f: self._test_failed(tc, c, f) ret = 1 diff --git a/src/test/unittest/unittest.sh b/src/test/unittest/unittest.sh index fcc5d90bfc5..6208c044e4e 100644 --- a/src/test/unittest/unittest.sh +++ b/src/test/unittest/unittest.sh @@ -1475,6 +1475,17 @@ function require_valgrind() { exit 0 fi fi + + # Check if Valgrind is enabled in the test build + disable_exit_on_error + ../valgrind_check/valgrind_check + ret=$? + restore_exit_on_error + if [ $ret -ne 0 ]; then + msg=$(interactive_yellow STDOUT "SKIP:") + echo -e "$UNITTEST_NAME: $msg Valgrind is required but the Valgrind support has been disabled at compile time" + exit 0 + fi } # diff --git a/src/test/unittest/valgrind.py b/src/test/unittest/valgrind.py index abbc9723727..1af65357555 100644 --- a/src/test/unittest/valgrind.py +++ b/src/test/unittest/valgrind.py @@ -200,6 +200,14 @@ def _get_valgrind_exe(self, force_enable): else: raise futils.Skip('Valgrind not found') + try: + _ = sp.check_output('./valgrind_check/valgrind_check', + shell=True, universal_newlines=True, + stderr=sp.STDOUT) + except sp.CalledProcessError: + raise futils.Skip( + 'Valgrind is required but the Valgrind support has been disabled at compile time') # noqa: E501 + valgrind_bin = path.join(path.dirname(out), 'valgrind.bin') if path.isfile(valgrind_bin): return valgrind_bin From d0a979bb272d52505ed2cfe21fa5037849dfb1be Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 6 Dec 2023 16:34:55 +0100 Subject: [PATCH 155/182] common: add GHA test w/o Valgrind disable valgrind in builds that do not need them Signed-off-by: Tomasz Gromadzki --- .github/actions/pmem_test_prepare/action.yml | 5 +++++ .github/workflows/pmem_test_matrix.yml | 6 ++++++ .github/workflows/pmem_tests.yml | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/.github/actions/pmem_test_prepare/action.yml b/.github/actions/pmem_test_prepare/action.yml index 8a67800fcf4..2342444a309 100644 --- a/.github/actions/pmem_test_prepare/action.yml +++ b/.github/actions/pmem_test_prepare/action.yml @@ -9,6 +9,10 @@ inputs: description: Build with the fault injection capability required: false default: '0' + valgrind: + description: Build with Valgrind support + required: true + runs: using: composite steps: @@ -30,6 +34,7 @@ runs: - env: FAULT_INJECTION: ${{ inputs.fault_injection }} NDCTL_ENABLE: ${{ inputs.ndctl_enable }} + VALGRIND: ${{ inputs.valgrind }} run: | echo '::group::Build' $WORKDIR/build-pmdk.sh diff --git a/.github/workflows/pmem_test_matrix.yml b/.github/workflows/pmem_test_matrix.yml index ccb032b74c4..4b62b0c6788 100644 --- a/.github/workflows/pmem_test_matrix.yml +++ b/.github/workflows/pmem_test_matrix.yml @@ -9,6 +9,9 @@ on: force_enable: required: true type: string + valgrind: + required: true + type: string timeout_minutes: required: false type: number @@ -28,11 +31,14 @@ jobs: os: [rhel, opensuse] build: [debug, nondebug] + steps: - uses: actions/checkout@v4 - name: Test prepare uses: ./.github/actions/pmem_test_prepare + with: + valgrind: ${{ inputs.valgrind }} - name: Test run uses: ./.github/actions/pmem_test_run diff --git a/.github/workflows/pmem_tests.yml b/.github/workflows/pmem_tests.yml index 36899997ea8..6039698d986 100644 --- a/.github/workflows/pmem_tests.yml +++ b/.github/workflows/pmem_tests.yml @@ -12,11 +12,15 @@ on: jobs: # Test the default build with the basic test suite. Basic: + strategy: + matrix: + VALGRIND: [0, 1] uses: ./.github/workflows/pmem_test_matrix.yml with: # Exclude all Valgrind tests. All tests employing Valgrind tooling are run # in the dedicated workflows below. force_enable: '["none"]' + valgrind: ${{ matrix.VALGRIND }} # Test the default build with force-enabled Valgrind tooling for (persistent) @@ -25,6 +29,7 @@ jobs: uses: ./.github/workflows/pmem_test_matrix.yml with: force_enable: '["pmemcheck", "memcheck"]' + valgrind: 1 # Test the default build with force-enabled Valgrind tooling for thread error @@ -33,6 +38,7 @@ jobs: uses: ./.github/workflows/pmem_test_matrix.yml with: force_enable: '["drd", "helgrind"]' + valgrind: 1 # 9h = 7h20m (the longest workflow execution time) + ~20% leeway. timeout_minutes: 540 @@ -52,6 +58,8 @@ jobs: - name: Test prepare uses: ./.github/actions/pmem_test_prepare + with: + valgrid: 1 - name: Test run uses: ./.github/actions/pmem_test_run @@ -73,6 +81,7 @@ jobs: uses: ./.github/actions/pmem_test_prepare with: fault_injection: '1' + valgrind: 1 - name: Test run uses: ./.github/actions/pmem_test_run @@ -84,6 +93,8 @@ jobs: # By default, PMDK is built with NDCTL in order to provide RAS features. # This build is only viable as long as DAOS builds PMDK with NDCTL_ENABLE=n # https://github.com/daos-stack/pmdk/pull/12 + # It should be removed as soon as following PR is merged + # https://github.com/daos-stack/pmdk/pull/35 ndctl_enable_n: name: Without ndctl if: github.repository == 'pmem/pmdk' @@ -96,6 +107,7 @@ jobs: uses: ./.github/actions/pmem_test_prepare with: ndctl_enable: n + valgrind: 0 - name: Test run uses: ./.github/actions/pmem_test_run From cf1a192b4862fecec52778172bd3a8559082a424 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 20 Mar 2024 20:28:21 +0100 Subject: [PATCH 156/182] common: fix GHA builds w/o ndctl Signed-off-by: Tomasz Gromadzki --- .github/actions/pmem_test_prepare/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/pmem_test_prepare/action.yml b/.github/actions/pmem_test_prepare/action.yml index 2342444a309..e9ca0982590 100644 --- a/.github/actions/pmem_test_prepare/action.yml +++ b/.github/actions/pmem_test_prepare/action.yml @@ -34,6 +34,8 @@ runs: - env: FAULT_INJECTION: ${{ inputs.fault_injection }} NDCTL_ENABLE: ${{ inputs.ndctl_enable }} + PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: ${{ inputs.ndctl_enable == 'n' && 'y' || 'n' }} + PMEMOBJ_IGNORE_BAD_BLOCKS: ${{ inputs.ndctl_enable == 'n' && 'y' || 'n' }} VALGRIND: ${{ inputs.valgrind }} run: | echo '::group::Build' From 8188ab61152487e6264fe1d66b383db8924d7536 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 21 Mar 2024 09:40:13 +0100 Subject: [PATCH 157/182] common: increase GHA jobs names readability Signed-off-by: Tomasz Gromadzki --- .github/workflows/pmem_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pmem_tests.yml b/.github/workflows/pmem_tests.yml index 6039698d986..972e9eebe42 100644 --- a/.github/workflows/pmem_tests.yml +++ b/.github/workflows/pmem_tests.yml @@ -15,6 +15,7 @@ jobs: strategy: matrix: VALGRIND: [0, 1] + name: Basic ${{ matrix.VALGRIND == 0 && 'w/o Valgrind' || 'w/ Valgrind' }} uses: ./.github/workflows/pmem_test_matrix.yml with: # Exclude all Valgrind tests. All tests employing Valgrind tooling are run From 204e1ab0cfc986e9f43a72feb9cd5dc95d65e0cc Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 21 Mar 2024 08:29:13 +0100 Subject: [PATCH 158/182] common: include new logging functions in linkers files Signed-off-by: Tomasz Gromadzki --- src/libpmem/libpmem.link.in | 5 ++++- src/libpmemobj/libpmemobj.link.in | 2 +- src/test/scope/out2.log.match | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libpmem/libpmem.link.in b/src/libpmem/libpmem.link.in index 16673da952a..7dea4b1a6b8 100644 --- a/src/libpmem/libpmem.link.in +++ b/src/libpmem/libpmem.link.in @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2019, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # # src/libpmem.link -- linker link file for libpmem @@ -20,6 +20,9 @@ LIBPMEM_1.0 { pmem_has_hw_drain; pmem_check_version; pmem_errormsg; + pmem_log_get_threshold; + pmem_log_set_function; + pmem_log_set_threshold; pmem_memmove_persist; pmem_memcpy_persist; pmem_memset_persist; diff --git a/src/libpmemobj/libpmemobj.link.in b/src/libpmemobj/libpmemobj.link.in index 0bb0aea2e02..da9db4b9d57 100644 --- a/src/libpmemobj/libpmemobj.link.in +++ b/src/libpmemobj/libpmemobj.link.in @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2014-2020, Intel Corporation +# Copyright 2014-2024, Intel Corporation # # # src/libpmemobj.link -- linker link file for libpmemobj diff --git a/src/test/scope/out2.log.match b/src/test/scope/out2.log.match index 50225a08d30..20e7dda9247 100644 --- a/src/test/scope/out2.log.match +++ b/src/test/scope/out2.log.match @@ -10,6 +10,9 @@ pmem_has_auto_flush$(nW) pmem_has_hw_drain$(nW) $(OPT)pmem_inject_fault_at$(nW) pmem_is_pmem$(nW) +pmem_log_get_threshold$(nW) +pmem_log_set_function$(nW) +pmem_log_set_threshold$(nW) pmem_map_file$(nW) pmem_memcpy$(nW) pmem_memcpy_nodrain$(nW) From 7e879feea468d26854348c3dcb8d8176f1ccc3da Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 21 Mar 2024 08:29:13 +0100 Subject: [PATCH 159/182] common: include new logging functions in call_stacks_analysis Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_extra.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index d6352201716..bdc1e9cbe91 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -22,12 +22,10 @@ def dict_extend(dict_, key, values): def inlines(calls: Calls) -> Calls: # common calls['core_init'] = ['util_init', 'core_log_init', 'out_init'] - calls['core_fini'] = ['out_fini', 'core_log_fini'] + calls['core_fini'] = ['out_fini', 'core_log_fini', 'last_error_msg_fini'] calls['common_init'] = ['core_init', 'util_mmap_init'] calls['common_fini'] = ['util_mmap_fini', 'core_fini'] - calls['Last_errormsg_key_alloc'] = ['_Last_errormsg_key_alloc'] - calls['_Last_errormsg_key_alloc'] = ['os_once', 'os_tls_key_create'] - calls['core_log_va'] = ['core_log_default_function'] + calls['core_log_init'] = ['core_log_default_init', 'core_log_set_function'] # libpmem calls['flush_empty'] = ['flush_empty_nolog'] @@ -41,6 +39,10 @@ def inlines(calls: Calls) -> Calls: return calls +def core_function_pointers(calls: Calls) -> Calls: + calls['core_log_va'] = ['core_log_default_function'] + return calls + def pmem_function_pointers(calls: Calls) -> Calls: calls['pmem_drain'] = ['fence_empty', 'memory_barrier'] @@ -424,6 +426,7 @@ def get_callees(calls): def main(): extra_calls = inlines({}) + extra_calls = core_function_pointers(extra_calls) extra_calls = pmem_function_pointers(extra_calls) extra_calls = pmemobj_function_pointers(extra_calls) with open("extra_calls.json", "w") as outfile: From dd0b61b2b82a76ceb63d0a6588382058ccbe5775 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 27 Mar 2024 13:50:50 +0100 Subject: [PATCH 160/182] common: temporar fix for improper inline functions parsing Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_extra.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index bdc1e9cbe91..c1bc42be3d7 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -424,14 +424,17 @@ def get_callees(calls): callees.extend(v) return list(set(callees)) +# XXX +# The way how inlines() function is used shall be changed according to: +# https://github.com/pmem/pmdk/issues/6070 def main(): - extra_calls = inlines({}) - extra_calls = core_function_pointers(extra_calls) + extra_calls = core_function_pointers({}) extra_calls = pmem_function_pointers(extra_calls) extra_calls = pmemobj_function_pointers(extra_calls) with open("extra_calls.json", "w") as outfile: json.dump(extra_calls, outfile, indent = 4) + extra_calls = inlines(extra_calls) # All functions accessed via function pointers have to be provided # on top of regular API calls for cflow to process their call stacks. extra_entry_points = get_callees(extra_calls) From 88e116d5e25d663c0e2fd619f20f2d3fab6bd550 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 26 Mar 2024 14:14:25 -0400 Subject: [PATCH 161/182] common: introduce benchmakrs/run_and_combine.py Signed-off-by: Jan Michalski --- utils/benchmarks/run_and_combine.py | 176 ++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100755 utils/benchmarks/run_and_combine.py diff --git a/utils/benchmarks/run_and_combine.py b/utils/benchmarks/run_and_combine.py new file mode 100755 index 00000000000..c48fd342832 --- /dev/null +++ b/utils/benchmarks/run_and_combine.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python3 + +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024, Intel Corporation + +import argparse +import json +import pandas as pd +import subprocess + + +PARSER = argparse.ArgumentParser() +PARSER.add_argument('--reference', metavar='LD_LIBRARY_PATH', required=True, + help='LD_LIBRARY_PATH where the first version of PMDK is built') +PARSER.add_argument('--rival', metavar='LD_LIBRARY_PATH', required=True, + help='LD_LIBRARY_PATH where the second version of PMDK is built') +PARSER.add_argument('-c', '--config', required=True, + help='Name of the .cfg file to use') +PARSER.add_argument('-s', '--scenario', required=True, + help='Name of the scenario to run') +PARSER.add_argument('-p', '--pmem_path', required=True, + help='PMEM-mounted directory to use') + + +COLUMNS_COMBINE = [ + 'ops-per-second[1/sec]', + 'total-avg[sec]', + 'total-max[sec]', + 'total-min[sec]', + 'total-median[sec]', + 'total-std-dev[sec]', + 'latency-avg[nsec]', + 'latency-min[nsec]', + 'latency-max[nsec]', + 'latency-std-dev[nsec]', + 'latency-pctl-50.0%[nsec]', + 'latency-pctl-99.0%[nsec]', + 'latency-pctl-99.9%[nsec]', +] + + +COLUMNS_COPY = [ + 'threads', + 'ops-per-thread', + 'data-size', + 'seed', + 'repeats', + 'thread-affinity', + 'main-affinity', + 'min-exe-time', + 'random', + 'min-size', + 'type-number', + 'operation', + 'lib', + 'nestings', + 'type', + 'max-key', + 'external-tx', + 'alloc', +] + + +def get_numa_node(pmem_path: str) -> int: + """Find the NUMA node of the device mounted at the specified path""" + # no slash at the end of the path + if pmem_path[-1] == '/': + pmem_path = pmem_path[0:-1] + # find the line describing the mount point + mount = subprocess.getoutput('mount') + mount_line = None + for line in mount.splitlines(): + if pmem_path in line: + mount_line = line + break + if mount_line is None: + print(mount) + raise Exception(f'Can not find the mounted PMEM device for: {pmem_path}') + # Extract blockdev from the found line e.g. + # /dev/pmem1 on /mnt/pmem1 type ext4 (rw,noatime,seclabel,nodelalloc,dax=always) + # - Linux device is the first part of the line e.g. /dev/pmem1 + # - blockdev is the name of the device file e.g. pmem1 + blockdev = mount_line.split(' ')[0].split('/')[2] + # Find the NDCTL namespace of the blockdev and extract its NUMA node + numa_node = None + namespaces = json.loads(subprocess.getoutput('ndctl list -v')) + for namespace in namespaces: + if namespace['mode'] == 'fsdax' and namespace['blockdev'] == blockdev: + numa_node = namespace['numa_node'] + break + if numa_node is None: + print(namespaces) + raise Exception(f'Can not find the namespace: mode == "fsdax" and blockdev == "{blockdev}"') + return numa_node + + +IDX_TO_NAME = ['ref', 'riv'] + + +def output_name(args: argparse.Namespace, idx: int) -> str: + """Generate a file name for an output ref or riv""" + return f'{args.config}__{args.scenario}_{IDX_TO_NAME[idx]}.csv' + + +def run(numa_node: int, args: argparse.Namespace, idx: int, ld_library_path: str) -> None: + """Run PMEMBENCH according to the provided parameters""" + config = f'src/benchmarks/{args.config}.cfg' + file = f'{args.pmem_path}/testfile.obj' + cmd = f'numactl --cpunodebind {numa_node} --localalloc ./src/benchmarks/pmembench {config} {args.scenario} --file {file}' + env = {'LD_LIBRARY_PATH': ld_library_path} + result = subprocess.run(cmd, env=env, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, encoding='utf-8', shell=True) + # generate the file with the output + if result.returncode == 0: + # drop the first line e.g. obj_rbtree_map_insert: map_insert [1] + out = ''.join(result.stdout.splitlines(keepends=True)[1:]) + else: + out = result.stdout + with open(output_name(args, idx), 'w') as output: + output.write(out) + # validate the run + if result.returncode != 0: + print(result.stdout) + print(result.stderr) + exit(result.returncode) + + +def column_name(column: str, idx: int) -> str: + """Generate a column name with ref or rev infix""" + return f'-{IDX_TO_NAME[idx]}['.join(column.split('[')) + + +def combine(args: argparse.Namespace) -> None: + """" + Combine outputs from the reference and rival runs. + + Output data files: + - combined - contains data from ref and riv together with a normalized + difference between them. + - diff - just a normalized difference between ref and riv + """ + dfs = [pd.read_csv(output_name(args, idx), sep=';') for idx in range(2)] + combined = pd.DataFrame() + diff = pd.DataFrame() + for column in COLUMNS_COMBINE: + # Copy columns to combine from both ref and riv + for idx in range(2): + combined[column_name(column, idx)] = dfs[idx][column] + diff_column = f'{column}-diff' + # Normalized difference between ref and riv: + # diff = (riv - ref) / ref + # Both output data frames contains diff columns. + combined[diff_column] = (dfs[1][column] / dfs[0][column] - 1) + diff[diff_column] = combined[diff_column] + for column in COLUMNS_COPY: + if column in dfs[0].columns: + # These columns are identical in both data frames + # so they can be copied from either data frame ref or riv. + combined[column] = dfs[0][column] + diff[column] = dfs[0][column] + # Write the generated data frames to CSV files. + prefix = f'{args.config}__{args.scenario}' + combined.to_csv(f'{prefix}_combined.csv', index=False, float_format='%.3f') + diff.to_csv(f'{prefix}_diff.csv', index=False, float_format='%.3f') + + +def main(): + args = PARSER.parse_args() + numa_node = get_numa_node(args.pmem_path) + for idx, ld_library_path in enumerate([args.reference, args.rival]): + run(numa_node, args, idx, ld_library_path) + combine(args) + + +if __name__ == '__main__': + main() From fedfc263ab1cff8c1e477386009a9e72d32f8d49 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Tue, 26 Mar 2024 14:15:02 -0400 Subject: [PATCH 162/182] benchmarks: adjust pool size factor to avoid OoM Signed-off-by: Jan Michalski --- src/benchmarks/obj_pmalloc.cpp | 6 +++--- src/benchmarks/pmemobj_tx.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/benchmarks/obj_pmalloc.cpp b/src/benchmarks/obj_pmalloc.cpp index 614bdf074e2..c0efdffd8bf 100644 --- a/src/benchmarks/obj_pmalloc.cpp +++ b/src/benchmarks/obj_pmalloc.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2020, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * obj_pmalloc.cpp -- pmalloc benchmarks definition @@ -27,7 +27,7 @@ * The factor used for PMEM pool size calculation, accounts for metadata, * fragmentation and etc. */ -#define FACTOR 1.2f +#define FACTOR 1.9f /* The minimum allocation size that pmalloc can perform */ #define ALLOC_MIN_SIZE 64 @@ -236,7 +236,7 @@ pmalloc_op(struct benchmark *bench, struct operation_info *info) int ret = pmalloc(ob->pop, &ob->offs[i], ob->sizes[i], 0, 0); if (ret) { - fprintf(stderr, "pmalloc ret: %d\n", ret); + perror("pmalloc"); return ret; } diff --git a/src/benchmarks/pmemobj_tx.cpp b/src/benchmarks/pmemobj_tx.cpp index 9fca99cefbf..3c4ff0fbf33 100644 --- a/src/benchmarks/pmemobj_tx.cpp +++ b/src/benchmarks/pmemobj_tx.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2015-2020, Intel Corporation */ +/* Copyright 2015-2024, Intel Corporation */ /* * pmemobj_tx.cpp -- pmemobj_tx_alloc(), pmemobj_tx_free(), @@ -19,7 +19,7 @@ #include "poolset_util.hpp" #define LAYOUT_NAME "benchmark" -#define FACTOR 1.2f +#define FACTOR 1.3f #define ALLOC_OVERHEAD 64 /* * operations number is limited to prevent stack overflow during From db06716218d92a44696151e7cab71c9b076e4ba8 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 27 Mar 2024 16:56:50 -0400 Subject: [PATCH 163/182] common: install missing benchmarking dependencies - numactl - pandas Signed-off-by: Jan Michalski --- utils/ansible/opensuse-setup.yml | 2 ++ utils/ansible/rockylinux-setup.yml | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/utils/ansible/opensuse-setup.yml b/utils/ansible/opensuse-setup.yml index e6a2bb2dbbd..57406392f3e 100644 --- a/utils/ansible/opensuse-setup.yml +++ b/utils/ansible/opensuse-setup.yml @@ -74,6 +74,8 @@ state: present name: - glib2-devel + - numactl + - python3-pandas - name: Install examples dependencies (optional) package: diff --git a/utils/ansible/rockylinux-setup.yml b/utils/ansible/rockylinux-setup.yml index 50ef95c2b54..dcdee1c870b 100644 --- a/utils/ansible/rockylinux-setup.yml +++ b/utils/ansible/rockylinux-setup.yml @@ -76,6 +76,12 @@ state: present name: - glib2-devel + - numactl + - python3-pip + + - name: Install benchmarks dependencies part 2 (optional) + ansible.builtin.pip: + name: pandas - name: Install examples dependencies (optional) package: From 264bd8cb088fb82746995c031ad0c76255db74ec Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 27 Mar 2024 14:21:49 -0400 Subject: [PATCH 164/182] common: introduce the PMEM Benchmark workflow Signed-off-by: Jan Michalski --- .github/actions/pmem_benchmark_run/action.yml | 45 +++++++ .github/workflows/pmem_benchmark.yml | 115 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 .github/actions/pmem_benchmark_run/action.yml create mode 100644 .github/workflows/pmem_benchmark.yml diff --git a/.github/actions/pmem_benchmark_run/action.yml b/.github/actions/pmem_benchmark_run/action.yml new file mode 100644 index 00000000000..27c989c7ebe --- /dev/null +++ b/.github/actions/pmem_benchmark_run/action.yml @@ -0,0 +1,45 @@ +name: PMEM benchmark procedure +description: PMDK benchmarking procedure for self-hosted runners equipped with PMEM +inputs: + runtime_dir: + description: The root directory of the repository designated as runtime + required: true + reference_LIB_PATH: + description: LD_LIBRARY_PATH where the first version of PMDK is built + required: true + rival_LIB_PATH: + description: LD_LIBRARY_PATH where the second version of PMDK is built + required: true + config: + description: Name of the .cfg file to use + required: true + scenario: + description: Name of the scenario to run + required: true + pmem_path: + description: A PMEM-mounted directory to use + default: /mnt/pmem0 +runs: + using: composite + steps: + - name: Run the benchmark + working-directory: ${{ inputs.runtime_dir }} + shell: bash + run: >- + ./utils/benchmarks/run_and_combine.py + --reference ${{ inputs.reference_LIB_PATH }} --rival ${{ inputs.rival_LIB_PATH }} + --config ${{ inputs.config }} --scenario ${{ inputs.scenario }} + --pmem_path ${{ inputs.pmem_path }} + + - name: Archive logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.config }}__${{ inputs.scenario }} + path: '${{ inputs.runtime_dir }}/*.csv' + + - name: Remove logs + if: always() + working-directory: ${{ inputs.runtime_dir }} + shell: bash + run: rm -f *.csv diff --git a/.github/workflows/pmem_benchmark.yml b/.github/workflows/pmem_benchmark.yml new file mode 100644 index 00000000000..93fcfbb8f1a --- /dev/null +++ b/.github/workflows/pmem_benchmark.yml @@ -0,0 +1,115 @@ +name: PMEM Benchmark + +on: + workflow_dispatch: + inputs: + reference_ref: + type: string + default: stable-2.0 + rival_ref: + type: string + default: master + + +jobs: + prep_runtime: + name: Prepare runtime + runs-on: [self-hosted, benchmark] + permissions: + contents: read + steps: + - name: Clone the git repo + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Build + run: make -j + + + prep_contesters: + name: Prepare ${{ matrix.ROLE }} (${{ matrix.GITHUB_REF }}) + runs-on: [self-hosted, benchmark] + needs: prep_runtime + strategy: + matrix: + include: + - ROLE: reference + GITHUB_REF: ${{ inputs.reference_ref }} + - ROLE: rival + GITHUB_REF: ${{ inputs.rival_ref }} + permissions: + contents: read + env: + MANIFEST: ${{ matrix.ROLE }}/manifest.txt + steps: + - name: Clone the git repo + uses: actions/checkout@v4 + with: + ref: ${{ matrix.GITHUB_REF }} + fetch-depth: 1 + path: ${{ matrix.ROLE }} + + - name: Build + working-directory: ${{ matrix.ROLE }} + run: make -j + + - name: Write the manifest + run: | + echo "${{ matrix.GITHUB_REF }}" >> $MANIFEST + git -C ${{ matrix.ROLE }} rev-parse HEAD >> $MANIFEST + + - name: Archive the manifest + uses: actions/upload-artifact@v4 + with: + name: manifest_${{ matrix.ROLE }} + path: ${{ env.MANIFEST }} + + + run: + name: Run perf.cfg ${{ matrix.SCENARIO }} + runs-on: [self-hosted, benchmark] + needs: prep_contesters + strategy: + matrix: + SCENARIO: + - obj_tx_alloc_small_v_thread + - obj_pmalloc_small_v_threads + - obj_rbtree_map_insert + - obj_hashmap_tx_map_insert + steps: + - name: Benchmark + uses: ./.github/actions/pmem_benchmark_run + with: + runtime_dir: ./ + reference_LIB_PATH: reference/src/nondebug + rival_LIB_PATH: rival/src/nondebug + config: perf + scenario: ${{ matrix.SCENARIO }} + + + repack: + name: Repack + runs-on: ubuntu-latest + needs: run + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: csvs + + - name: Combine the manifests + env: + OUTPUT: csvs/manifest.txt + run: | + for competitor in reference rival; do + echo "$competitor:" >> $OUTPUT + cat csvs/manifest_$competitor/manifest.txt >> $OUTPUT + echo >> $OUTPUT + done + + - name: Upload all as a single artifact + uses: actions/upload-artifact@v4 + with: + name: perf__all__${{ github.run_id }} + path: csvs/**/* From ee83f8a6171789e5bfb6af01163738eaae88b7aa Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Wed, 20 Mar 2024 11:36:51 +0100 Subject: [PATCH 165/182] doc: add pmem_log_* documentations --- doc/Makefile | 2 + doc/libpmem/.gitignore | 3 + doc/libpmem/pmem_log_get_threshold.3.md | 56 ++++++++++++ doc/libpmem/pmem_log_set_function.3.md | 109 ++++++++++++++++++++++++ doc/libpmem/pmem_log_set_threshold.3.md | 104 ++++++++++++++++++++++ 5 files changed, 274 insertions(+) create mode 100644 doc/libpmem/pmem_log_get_threshold.3.md create mode 100644 doc/libpmem/pmem_log_set_function.3.md create mode 100644 doc/libpmem/pmem_log_set_threshold.3.md diff --git a/doc/Makefile b/doc/Makefile index 232e721abf6..7cbc00761fc 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -14,6 +14,7 @@ MANPAGES_7_MD = libpmem/libpmem.7.md libpmemobj/libpmemobj.7.md \ MANPAGES_5_MD = poolset/poolset.5.md pmem_ctl/pmem_ctl.5.md MANPAGES_3_MD = libpmem/pmem_flush.3.md libpmem/pmem_is_pmem.3.md libpmem/pmem_memmove_persist.3.md \ + libpmem/pmem_log_get_threshold.3.md libpmem/pmem_log_set_function.3.md libpmem/pmem_log_set_threshold.3.md \ libpmemobj/oid_is_null.3.md libpmemobj/pmemobj_action.3.md libpmemobj/pmemobj_alloc.3.md libpmemobj/pmemobj_ctl_get.3.md libpmemobj/pmemobj_first.3.md \ libpmemobj/pmemobj_list_insert.3.md libpmemobj/pmemobj_memcpy_persist.3.md libpmemobj/pmemobj_mutex_zero.3.md \ libpmemobj/pmemobj_open.3.md libpmemobj/pmemobj_root.3.md libpmemobj/pmemobj_tx_begin.3.md libpmemobj/pmemobj_tx_add_range.3.md \ @@ -31,6 +32,7 @@ MANPAGES_3_DUMMY = libpmem/pmem_drain.3 libpmem/pmem_has_hw_drain.3 libpmem/pmem libpmem/pmem_memcpy_persist.3 libpmem/pmem_memset_persist.3 libpmem/pmem_memmove_nodrain.3 libpmem/pmem_memcpy_nodrain.3 libpmem/pmem_memset_nodrain.3 \ libpmem/pmem_memcpy.3 libpmem/pmem_memset.3 libpmem/pmem_memmove.3 \ libpmem/pmem_check_version.3 libpmem/pmem_errormsg.3 \ + libpmem/pmem_log_use_default_function.3 \ libpmempool/pmempool_check.3 libpmempool/pmempool_check_end.3 \ libpmempool/pmempool_feature_enable.3 libpmempool/pmempool_feature_disable.3 \ libpmempool/pmempool_transform.3 \ diff --git a/doc/libpmem/.gitignore b/doc/libpmem/.gitignore index 810bf8b91a4..12f98ffb233 100644 --- a/doc/libpmem/.gitignore +++ b/doc/libpmem/.gitignore @@ -1,4 +1,7 @@ libpmem.7 pmem_flush.3 pmem_is_pmem.3 +pmem_log_get_treshold.3 +pmem_log_set_function.3 +pmem_log_set_treshold.3 pmem_memmove_persist.3 diff --git a/doc/libpmem/pmem_log_get_threshold.3.md b/doc/libpmem/pmem_log_get_threshold.3.md new file mode 100644 index 00000000000..ad4ee139804 --- /dev/null +++ b/doc/libpmem/pmem_log_get_threshold.3.md @@ -0,0 +1,56 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmem_log_get_threshold.3.html"] +title: "libpmem | PMDK" +header: "pmem API version 1.1" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmem_log_get_threshold.3 -- get the logging threshold value) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmem_log_get_threshold** - get the logging threshold value + +# SYNOPSIS # + +```c + #include + + int pmem_log_get_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level *value); +``` + +# DESCRIPTION # + +**pmem_log_get_threshold**() gets the current *value* of the *threshold*. +See **pmem_log_set_threshold**(3) for available thresholds and values. + +# RETURN VALUE # + +On success, **pmem_log_get_threshold**() function returns 0 and writes into +*value* the current value of the *threshold*. On failure, it returns +a non-zero value and sets errno. In case of failure, the *value* contents is undefined. + +# ERRORS # + +**pmem_log_get_threshold**() can fail with the following errors: + + - EINVAL - *threshold* is not **PMEM_LOG_THRESHOLD** nor **PMEM_LOG_THRESHOLD_AUX** + - EINVAL - *value* is NULL + +# SEE ALSO # + +**pmem_log_set_function**(3), **pmem_log_set_threshold**(3). diff --git a/doc/libpmem/pmem_log_set_function.3.md b/doc/libpmem/pmem_log_set_function.3.md new file mode 100644 index 00000000000..22f6e3fb203 --- /dev/null +++ b/doc/libpmem/pmem_log_set_function.3.md @@ -0,0 +1,109 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmem_log_set_function.3.html"] +title: "libpmem | PMDK" +header: "pmem API version 1.1" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmem_log_set_function.3 -- set the logging function) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[THE DEFAULT LOGGING FUNCTION](#the-default-logging-function)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[NOTE](#note)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmem_log_set_function**() - set the logging function + +# SYNOPSIS # + +```c + #include + + typedef void pmem_log_function( + enum pmem_log_level level, + const char *file_name, + unsigned line_no, + const char *function_name, + const char *message); + + int pmem_log_set_function(pmem_log_function *log_function); +``` + +# DESCRIPTION # + +**pmem_log_set_function**() allows choosing the function which will get all +the generated logging messages. The *log_function* can be either +**PMEM_LOG_USE_DEFAULT_FUNCTION** which will use the default logging function +(built into the library) or a pointer to a user-defined function. + +The parameters of a user-defined log function are as follows: + + - *level* - the log level of the message (see **pmem_log_set_threshold**(3) + for available log levels) + - *file_name* - name of the source file where the message is coming from. + It could be set to NULL and in such case, neither *line_no* nor *function_name* + are provided. + - *line_no* - the source file line where the message is coming from + - *function_name* - the function name where the message is coming from + - *message* - the message string + +# THE DEFAULT LOGGING FUNCTION # + +The library provides the default logging function which writes messages to +**syslog**(3) and to **stderr**(3). This function is enabled during library +initialization and can be restored using **PMEM_LOG_USE_DEFAULT_FUNCTION** value +as the *log_function* argument. + +The default logging function sinks all the logging messages into **syslog**(3) +unconditionally. Additionally, it sinks a logging message into **stderr**(3) +if its logging level is not less severe than indicated by +the **PMEM_LOG_THRESHOLD_AUX** threshold's value and it is not of level +**PMEM_LOG_LEVEL_HARK**. + +Note that the **PMEM_LOG_THRESHOLD** threshold's value applies to +the default logging function. Please see the notes below. + +# RETURN VALUE # + +**pmem_log_set_function**() function returns 0 on success or returns +a non-zero value and sets errno on failure. On failure, the logging +function remains unchanged. + +# ERRORS # + +**pmem_log_set_function**() can set the following errno values on fail: + + - EAGAIN - multiple threads attempted to change the logging function concurrently. + A retry may fix the problem. This error is not expected when the function is + called from just one thread at a time. + +# NOTE # + +The logging messages of level less severe than indicated by +the **PMEM_LOG_THRESHOLD** threshold's value won't make it to the logging function +no matter whether the logging function is the default logging function or user-provided. + +The user-defined function must be thread-safe. + +The library will call user defined function before returning from **pmem_log_set_function**() +to deliver basic information about the library: + + - "src version: 2.y.z" + - "compiled with support for shutdown state" + - "compiled with libndctl 63+" + +# SEE ALSO # + +**pmem_log_get_threshold**(3), **pmem_log_set_threshold**(3). diff --git a/doc/libpmem/pmem_log_set_threshold.3.md b/doc/libpmem/pmem_log_set_threshold.3.md new file mode 100644 index 00000000000..890c36e1cf1 --- /dev/null +++ b/doc/libpmem/pmem_log_set_threshold.3.md @@ -0,0 +1,104 @@ +--- +draft: false +slider_enable: true +description: "" +disclaimer: "The contents of this web site and the associated GitHub repositories are BSD-licensed open source." +aliases: ["pmem_log_set_threshold.3.html"] +title: "libpmem | PMDK" +header: "pmem API version 1.1" +--- + +[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) +[comment]: <> (Copyright 2024, Intel Corporation) + +[comment]: <> (pmem_log_set_threshold.3 -- set the logging threshold value) + +[NAME](#name)
+[SYNOPSIS](#synopsis)
+[DESCRIPTION](#description)
+[RETURN VALUE](#return-value)
+[ERRORS](#errors)
+[SEE ALSO](#see-also)
+ +# NAME # + +**pmem_log_set_threshold** - set the logging threshold value + +# SYNOPSIS # + +```c + #include + + enum pmem_log_level { + PMEM_LOG_LEVEL_HARK, + PMEM_LOG_LEVEL_FATAL, + PMEM_LOG_LEVEL_ERROR, + PMEM_LOG_LEVEL_WARNING, + PMEM_LOG_LEVEL_NOTICE, + PMEM_LOG_LEVEL_INFO, + PMEM_LOG_LEVEL_DEBUG + }; + + enum pmem_log_threshold { + PMEM_LOG_THRESHOLD, + PMEM_LOG_THRESHOLD_AUX + }; + + int pmem_log_set_threshold(enum pmem_log_threshold threshold, + enum pmem_log_level value); +``` + +# DESCRIPTION # + +**pmem_log_set_threshold**() sets the logging threshold value. + +Available thresholds are: + + - **PMEM_LOG_THRESHOLD** - the main threshold used to filter out undesired + logging messages. Messages less severe than indicated by this threshold's + value are ignored so they won't make it to the logging function + (please see **pmem_log_set_function**(3)). + The default value is **PMEM_LOG_WARNING**. + - **PMEM_LOG_THRESHOLD_AUX** - the auxiliary threshold intended for use inside + the logging function (please see **pmem_log_get_threshold**(3)). A custom + logging function may or may not take this threshold into consideration depending + on the developer's needs. For the default logging function behaviour please see + **pmem_log_set_function**(3). The initial value of this threshold is + **PMEM_LOG_LEVEL_HARK**. + +Available threshold values are defined by enum *pmem_log_level*. +They are listed in descending order of severity: + + - **PMEM_LOG_LEVEL_HARK** - only basic library info. Shall be used to + effectively suppress the logging since it is used just for a few messages + when the program is started and whenever a new logging function is set. + Please see **pmem_log_set_function**(3). + - **PMEM_LOG_LEVEL_FATAL** - an error that causes the program to stop working + immediately. Sorry. + - **PMEM_LOG_LEVEL_ERROR** - an error that causes the current operation to fail + - **PMEM_LOG_LEVEL_WARNING** - an unexpected situation that does NOT + cause the current operation to fail + - **PMEM_LOG_LEVEL_NOTICE** - non-massive info mainly related to public API + function completions + - **PMEM_LOG_LEVEL_INFO** - massive info e.g. every write operation indication + - **PMEM_LOG_LEVEL_DEBUG** - debug info e.g. write operation dump + +# RETURN VALUE # + +**pmem_log_set_threshold**() function returns 0 on success or returns +a non-zero value and sets errno on failure. On failure, the *threshold* value remains unchanged. + +# ERRORS # + +**pmem_log_set_threshold**() can set the following errno values on fail: + + - EINVAL - *threshold* is not **PMEM_LOG_THRESHOLD** nor + **PMEM_LOG_THRESHOLD_AUX** + - EINVAL - *value* is not defined by enum *pmem_log_level* type + - EAGAIN - multiple threads attempted to change the *threshold* value concurrently. + A retry may fix the problem. This error is not expected when the function is + called from just one thread at a time. + +# SEE ALSO # + +**pmem_log_get_threshold**(3), **pmem_log_set_function**(3). From 94ebe88761c6e35761035d62916869ddd9ec12b4 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Thu, 21 Mar 2024 11:39:56 +0100 Subject: [PATCH 166/182] obj: unify description with implementation pmemobj_log* fun --- src/include/libpmemobj/log.h | 14 +++++++++----- src/libpmemobj/obj_log.c | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index 657819f018a..ce426142e4f 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -20,11 +20,14 @@ extern "C" { enum pmemobj_log_level { /* only basic library info */ PMEMOBJ_LOG_LEVEL_HARK, - /* an error that causes the library to stop working immediately */ + /* an error that causes the program to stop working immediately */ PMEMOBJ_LOG_LEVEL_FATAL, - /* an error that causes the library to stop working properly */ + /* an error that causes the current operation or transaction to fail */ PMEMOBJ_LOG_LEVEL_ERROR, - /* an errors that could be handled in the upper level */ + /* + * an unexpected situation that does NOT cause + * the current operation to fail + */ PMEMOBJ_LOG_LEVEL_WARNING, /* non-massive info mainly related to public API function completions */ PMEMOBJ_LOG_LEVEL_NOTICE, @@ -36,8 +39,9 @@ enum pmemobj_log_level { enum pmemobj_log_threshold { /* - * the main threshold level - the logging messages above this level - * won't trigger the logging functions + * the main threshold level - the logging messages less severe than + * indicated by this threshold's value won't trigger the logging + * functions */ PMEMOBJ_LOG_THRESHOLD, /* diff --git a/src/libpmemobj/obj_log.c b/src/libpmemobj/obj_log.c index aad0ad0f11a..ad3791c1844 100644 --- a/src/libpmemobj/obj_log.c +++ b/src/libpmemobj/obj_log.c @@ -10,26 +10,26 @@ #include "util.h" /* - * pmemobj_log_set_threshold -- set the log level threshold + * pmemobj_log_set_threshold -- set the logging threshold value */ int pmemobj_log_set_threshold(enum pmemobj_log_threshold threshold, - enum pmemobj_log_level level) + enum pmemobj_log_level value) { int ret = core_log_set_threshold((enum core_log_threshold)threshold, - (enum core_log_level)level); + (enum core_log_level)value); return core_log_error_translate(ret); } /* - * pmemobj_log_get_threshold -- get the log level threshold + * pmemobj_log_get_threshold -- get the logging value threshold value */ int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, - enum pmemobj_log_level *level) + enum pmemobj_log_level *value) { int ret = core_log_get_threshold((enum core_log_threshold)threshold, - (enum core_log_level *)level); + (enum core_log_level *)value); return core_log_error_translate(ret); } From 8fd5b4e1fa87ab411ae7ec8e9512b78f1d20fe40 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 20 Mar 2024 22:29:46 +0100 Subject: [PATCH 167/182] common: use unsigned for line_no as it is done in DAOS/vos To make PMDK logging system compatible with DAOS/vos logging. Signed-off-by: Tomasz Gromadzki --- doc/libpmemobj/pmemobj_log_set_function.3.md | 2 +- src/core/log.c | 5 +++-- src/core/log_default.c | 4 ++-- src/core/log_default.h | 2 +- src/core/log_internal.h | 6 +++--- src/core/out.c | 10 +++++----- src/core/out.h | 6 +++--- src/include/libpmem.h | 2 +- src/include/libpmemobj/log.h | 2 +- src/test/core_log/core_log_common.c | 6 +++--- src/test/core_log/core_log_common.h | 2 +- .../core_log_default_function.c | 4 ++-- src/test/core_log_function_mt/core_log_function_mt.c | 2 +- src/test/core_log_internal/core_log_internal.c | 4 ++-- src/test/core_log_max/core_log_max.c | 2 +- 15 files changed, 30 insertions(+), 29 deletions(-) diff --git a/doc/libpmemobj/pmemobj_log_set_function.3.md b/doc/libpmemobj/pmemobj_log_set_function.3.md index 642c7231a34..775e436aa1c 100644 --- a/doc/libpmemobj/pmemobj_log_set_function.3.md +++ b/doc/libpmemobj/pmemobj_log_set_function.3.md @@ -34,7 +34,7 @@ header: "pmemobj API version 2.3" typedef void pmemobj_log_function( enum pmemobj_log_level level, const char *file_name, - const int line_no, + unsigned line_no, const char *function_name, const char *message); diff --git a/src/core/log.c b/src/core/log.c index 9f87da38523..529d2a8b043 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -176,7 +176,7 @@ _core_log_get_threshold_internal() static void inline core_log_va(char *buf, size_t buf_len, enum core_log_level level, - int errnum, const char *file_name, int line_no, + int errnum, const char *file_name, unsigned line_no, const char *function_name, const char *message_format, va_list arg) { int msg_len = vsnprintf(buf, buf_len, message_format, arg); @@ -217,7 +217,8 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, void core_log(enum core_log_level level, int errnum, const char *file_name, - int line_no, const char *function_name, const char *message_format, ...) + unsigned line_no, const char *function_name, const char *message_format, + ...) { char message[_CORE_LOG_MSG_MAXPRINT] = ""; char *buf = message; diff --git a/src/core/log_default.c b/src/core/log_default.c index 7f1549efce5..bdb165dd097 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -99,7 +99,7 @@ get_timestamp_prefix(char *buf, size_t buf_size) */ void core_log_default_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, const char *message) + unsigned line_no, const char *function_name, const char *message) { char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; @@ -116,7 +116,7 @@ core_log_default_function(enum core_log_level level, const char *file_name, base_file_name++; if (snprintf(file_info_buffer, sizeof(file_info_buffer), - "%s: %3d: %s: ", base_file_name, line_no, + "%s: %3u: %s: ", base_file_name, line_no, function_name) < 0) { file_info = file_info_error; } diff --git a/src/core/log_default.h b/src/core/log_default.h index 7583dce6905..2a00d388799 100644 --- a/src/core/log_default.h +++ b/src/core/log_default.h @@ -9,7 +9,7 @@ #define CORE_LOG_DEFAULT_H void core_log_default_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, const char *message); + unsigned line_no, const char *function_name, const char *message); void core_log_default_init(void); diff --git a/src/core/log_internal.h b/src/core/log_internal.h index f058d871a0e..dd9d775fdb7 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -73,7 +73,7 @@ typedef void core_log_function( /* name of the source file where the message coming from */ const char *file_name, /* the source file line where the message coming from */ - const int line_no, + unsigned line_no, /* the function name where the message coming from */ const char *function_name, /* message */ @@ -109,8 +109,8 @@ core_log_error_translate(int ret) #define NO_ERRNO (-1) void core_log(enum core_log_level level, int errnum, const char *file_name, - int line_no, const char *function_name, - const char *message_format, ...); + unsigned line_no, const char *function_name, const char *message_format, + ...); #define _CORE_LOG(level, errnum, format, ...) \ do { \ diff --git a/src/core/out.c b/src/core/out.c index f0bd95e4a08..37a17d8855d 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -53,7 +53,7 @@ static const int core_log_level_to_level[CORE_LOG_LEVEL_MAX] = { static void out_legacy(enum core_log_level core_level, const char *file_name, - const int line_no, const char *function_name, const char *message) + unsigned line_no, const char *function_name, const char *message) { int level = core_log_level_to_level[core_level]; out_log(file_name, line_no, function_name, level, "%s", message); @@ -247,7 +247,7 @@ out_snprintf(char *str, size_t size, const char *format, ...) * out_common -- common output code, all output goes through here */ static void -out_common(const char *file, int line, const char *func, int level, +out_common(const char *file, unsigned line, const char *func, int level, const char *suffix, const char *fmt, va_list ap) { int oerrno = errno; @@ -262,7 +262,7 @@ out_common(const char *file, int line, const char *func, int level, if (f) file = f + 1; ret = out_snprintf(&buf[cc], MAXPRINT - cc, - "<%s>: <%d> [%s:%d %s] ", + "<%s>: <%d> [%s:%u %s] ", Log_prefix, level, file, line, func); if (ret < 0) { out_print_func("out_snprintf failed"); @@ -301,7 +301,7 @@ out_common(const char *file, int line, const char *func, int level, * out_log_va/out_log -- output a log line if Log_level >= level */ static void -out_log_va(const char *file, int line, const char *func, int level, +out_log_va(const char *file, unsigned line, const char *func, int level, const char *fmt, va_list ap) { if (Log_level < level) @@ -310,7 +310,7 @@ out_log_va(const char *file, int line, const char *func, int level, } void -out_log(const char *file, int line, const char *func, int level, +out_log(const char *file, unsigned line, const char *func, int level, const char *fmt, ...) { va_list ap; diff --git a/src/core/out.h b/src/core/out.h index d4fc989d38f..5fe86565eaa 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -33,7 +33,7 @@ extern "C" { #else static __attribute__((always_inline)) inline void -out_log_discard(const char *file, int line, const char *func, int level, +out_log_discard(const char *file, unsigned line, const char *func, int level, const char *fmt, ...) { /* suppress unused-parameter errors */ @@ -70,8 +70,8 @@ void out_init(const char *log_prefix, const char *log_level_var, void out_fini(void); #ifdef DEBUG -void out_log(const char *file, int line, const char *func, int level, - const char *fmt, ...) FORMAT_PRINTF(5, 6); +void out_log(const char *file, unsigned line, const char *func, + int level, const char *fmt, ...) FORMAT_PRINTF(5, 6); #endif #ifdef __cplusplus diff --git a/src/include/libpmem.h b/src/include/libpmem.h index 5786cffd0af..5f075c449c8 100644 --- a/src/include/libpmem.h +++ b/src/include/libpmem.h @@ -151,7 +151,7 @@ typedef void pmem_log_function( /* name of the source file where the message coming from */ const char *file_name, /* the source file line where the message coming from */ - const int line_no, + unsigned line_no, /* the function name where the message coming from */ const char *function_name, /* message */ diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index ce426142e4f..96651ccea07 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -72,7 +72,7 @@ typedef void pmemobj_log_function( /* name of the source file where the message coming from */ const char *file_name, /* the source file line where the message coming from */ - const int line_no, + unsigned line_no, /* the function name where the message coming from */ const char *function_name, /* message */ diff --git a/src/test/core_log/core_log_common.c b/src/test/core_log/core_log_common.c index 63c1f7c1651..e5104e60fe3 100644 --- a/src/test/core_log/core_log_common.c +++ b/src/test/core_log/core_log_common.c @@ -64,7 +64,7 @@ FUNC_MOCK_RUN_DEFAULT { FUNC_MOCK_END FUNC_MOCK_NONSTATIC(core_log_default_function, void, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, + const char *file_name, unsigned line_no, const char *function_name, const char *message) FUNC_MOCK_RUN(VALIDATED_CALL) { UT_ASSERTeq(level, Log_function_.exp_level); @@ -85,7 +85,7 @@ FUNC_MOCK_RUN_DEFAULT { FUNC_MOCK_END FUNC_MOCK_NONSTATIC(custom_log_function, void, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, + const char *file_name, unsigned line_no, const char *function_name, const char *message) FUNC_MOCK_RUN(VALIDATED_CALL) { UT_ASSERTeq(level, Log_function_.exp_level); @@ -107,7 +107,7 @@ FUNC_MOCK_END void custom_log_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, const char *message) + unsigned line_no, const char *function_name, const char *message) { SUPPRESS_UNUSED(level, file_name, line_no, function_name, message); } diff --git a/src/test/core_log/core_log_common.h b/src/test/core_log/core_log_common.h index c07c2384ef6..28f0f854c5e 100644 --- a/src/test/core_log/core_log_common.h +++ b/src/test/core_log/core_log_common.h @@ -64,4 +64,4 @@ void test_log_function_call_helper(enum core_log_level level, bool call_log_function); void custom_log_function(enum core_log_level level, const char *file_name, - const int line_no, const char *function_name, const char *message); + unsigned line_no, const char *function_name, const char *message); diff --git a/src/test/core_log_default_function/core_log_default_function.c b/src/test/core_log_default_function/core_log_default_function.c index 66312b07d38..f3d089b39f2 100644 --- a/src/test/core_log_default_function/core_log_default_function.c +++ b/src/test/core_log_default_function/core_log_default_function.c @@ -80,10 +80,10 @@ FUNC_MOCK(snprintf, int, char *__restrict __s, size_t __maxlen, FUNC_MOCK_RUN(0) { va_list arg; va_start(arg, __format); - UT_ASSERTstreq(__format, "%s: %3d: %s: "); + UT_ASSERTstreq(__format, "%s: %3u: %s: "); char *file_name = va_arg(arg, char *); UT_ASSERTstreq(file_name, Snprintf.exp_file_name); - int line_no = va_arg(arg, int); + unsigned line_no = va_arg(arg, unsigned); UT_ASSERTeq(line_no, LINE_NO); char *function_name = va_arg(arg, char *); UT_ASSERTstreq(function_name, FUNCTION_NAME); diff --git a/src/test/core_log_function_mt/core_log_function_mt.c b/src/test/core_log_function_mt/core_log_function_mt.c index afacd31d313..0384907bde5 100644 --- a/src/test/core_log_function_mt/core_log_function_mt.c +++ b/src/test/core_log_function_mt/core_log_function_mt.c @@ -23,7 +23,7 @@ #define LOG_FUNC(FUNC_NAME) \ static void \ -FUNC_NAME(enum core_log_level level, const char *file_name, const int line_no, \ +FUNC_NAME(enum core_log_level level, const char *file_name, unsigned line_no, \ const char *function_name, const char *message) \ { \ SUPPRESS_UNUSED(level, file_name, line_no, function_name, message); \ diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c index 948a4aea915..1016480ad86 100644 --- a/src/test/core_log_internal/core_log_internal.c +++ b/src/test/core_log_internal/core_log_internal.c @@ -40,13 +40,13 @@ static struct { enum core_log_level level; int errnum; const char *file_name; - int line_no; + unsigned line_no; const char *function_name; const char *message_format; } Core_log_context; FUNC_MOCK(core_log, void, enum core_log_level level, int errnum, - const char *file_name, int line_no, const char *function_name, + const char *file_name, unsigned line_no, const char *function_name, const char *message_format, ...) FUNC_MOCK_RUN_DEFAULT { Core_log_no_of_calls++; diff --git a/src/test/core_log_max/core_log_max.c b/src/test/core_log_max/core_log_max.c index c1dcc2875ca..2287affe3de 100644 --- a/src/test/core_log_max/core_log_max.c +++ b/src/test/core_log_max/core_log_max.c @@ -125,7 +125,7 @@ static int Total_message_num = 0; static char The_longest_message[BIG_BUF_SIZE]; FUNC_MOCK(core_log, void, enum core_log_level level, int errnum, - const char *file_name, int line_no, const char *function_name, + const char *file_name, unsigned line_no, const char *function_name, const char *message_format, ...) FUNC_MOCK_RUN_DEFAULT { char buf[BIG_BUF_SIZE] = ""; From 70166e71d8aa278f77ac388a7e55665daee6730e Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Wed, 20 Mar 2024 23:18:56 +0100 Subject: [PATCH 168/182] common: avoid pmem_ prefix for pmem2 functions Signed-off-by: Tomasz Gromadzki --- src/libpmem2/x86_64/init.c | 8 ++++---- utils/call_stacks_analysis/make_extra.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index 33517a0b9ab..e46be1a7610 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -110,7 +110,7 @@ pmem2_memmove_nodrain_eadr(void *dest, const void *src, size_t len, } static void * -pmem_memset_nodrain(void *dest, int c, size_t len, unsigned flags, +pmem2_memset_nodrain(void *dest, int c, size_t len, unsigned flags, flush_func flushf, const struct memset_nodrain *memset_funcs) { /* suppress unused-parameter errors */ @@ -134,7 +134,7 @@ pmem_memset_nodrain(void *dest, int c, size_t len, unsigned flags, } static void * -pmem_memset_nodrain_eadr(void *dest, int c, size_t len, unsigned flags, +pmem2_memset_nodrain_eadr(void *dest, int c, size_t len, unsigned flags, flush_func flushf, const struct memset_nodrain *memset_funcs) { /* suppress unused-parameter errors */ @@ -158,8 +158,8 @@ pmem_set_mem_funcs(struct pmem2_arch_info *info) { info->memmove_nodrain = pmem2_memmove_nodrain; info->memmove_nodrain_eadr = pmem2_memmove_nodrain_eadr; - info->memset_nodrain = pmem_memset_nodrain; - info->memset_nodrain_eadr = pmem_memset_nodrain_eadr; + info->memset_nodrain = pmem2_memset_nodrain; + info->memset_nodrain_eadr = pmem2_memset_nodrain_eadr; } enum memcpy_impl { diff --git a/utils/call_stacks_analysis/make_extra.py b/utils/call_stacks_analysis/make_extra.py index c1bc42be3d7..e1aade25630 100755 --- a/utils/call_stacks_analysis/make_extra.py +++ b/utils/call_stacks_analysis/make_extra.py @@ -59,7 +59,7 @@ def pmem_function_pointers(calls: Calls) -> Calls: calls['pmem_memmove_persist'] = memmove_nodrain_all calls['pmem_memcpy_persist'] = memmove_nodrain_all - memset_nodrain_all = ['memset_nodrain_libc', 'memset_nodrain_generic', 'pmem_memset_nodrain.static', 'pmem_memset_nodrain_eadr.static'] + memset_nodrain_all = ['memset_nodrain_libc', 'memset_nodrain_generic', 'pmem2_memset_nodrain', 'pmem2_memset_nodrain_eadr'] calls['pmem_memset'] = memset_nodrain_all calls['pmem_memset_nodrain'] = memset_nodrain_all calls['pmem_memset_persist'] = memset_nodrain_all @@ -152,12 +152,12 @@ def pmem_function_pointers(calls: Calls) -> Calls: memsetfuncs['nt']['empty'].extend(memsetfuncs_extras['nt']['empty']) memsetfuncs['nt']['flush'].extend(memsetfuncs_extras['nt']['flush']) - calls['pmem_memset_nodrain.static'] = \ + calls['pmem2_memset_nodrain'] = \ memsetfuncs['t']['noflush'] + \ memsetfuncs['nt']['flush'] + \ memsetfuncs['t']['flush'] - calls['pmem_memset_nodrain_eadr.static'] = \ + calls['pmem2_memset_nodrain_eadr'] = \ memsetfuncs['t']['noflush'] + \ memsetfuncs['nt']['empty'] + \ memsetfuncs['t']['empty'] From fe46289b7d97168b5c5f0bbab218fde71f983263 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 22 Mar 2024 12:59:58 +0100 Subject: [PATCH 169/182] common: use bigger function's size in case of conflict Signed-off-by: Tomasz Gromadzki --- utils/call_stacks_analysis/make_call_stacks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/call_stacks_analysis/make_call_stacks.py b/utils/call_stacks_analysis/make_call_stacks.py index 63adf22e7bc..5dacbf8c57b 100755 --- a/utils/call_stacks_analysis/make_call_stacks.py +++ b/utils/call_stacks_analysis/make_call_stacks.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2023, Intel Corporation +# Copyright 2023-2024, Intel Corporation import argparse import json @@ -101,7 +101,15 @@ def parse_stack_usage(stack_usage_file: str) -> StackUsage: # 112 ctl_find_node.isra.5 : src/nondebug/common/ctl.su:ctl.c static found = re.search('([0-9]+) ([a-zA-Z0-9_]+)(.[a-zA-Z0-9.]+)* : ([a-zA-Z0-9.:/_-]+) ([a-z,]+)', line) if found: - funcs[found.group(2)] = {'size': int(found.group(1)), 'type': found.group(5)} + func = found.group(2) + size = int(found.group(1)) + if func in funcs.keys(): + curr_size = funcs[func]['size'] + if size != curr_size: + print(f'Warning: Incompatible function records [{func}].size: {size} != {curr_size}. Continue with the biggest reported size.') + if curr_size > size: + size = curr_size + funcs[func] = {'size': size, 'type': found.group(5)} else: print(f'An unexpected line format: {line}') exit(1) From 025534701967e65c29c486c52ac43fe54e740b7f Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Mon, 27 Nov 2023 13:30:58 +0100 Subject: [PATCH 170/182] common: fix support of OS_DIMM_CFLAG `#if NDCTL_ENABLED` that is used in the source code expects that `NDCTL_ENABLED` is defined all the time with either *0* or *non-0* value. Signed-off-by: Tomasz Gromadzki --- src/common.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common.inc b/src/common.inc index 43c7914d577..1f42b425718 100644 --- a/src/common.inc +++ b/src/common.inc @@ -332,9 +332,7 @@ NDCTL_ENABLE ?= y ifeq ($(NDCTL_ENABLE),y) ifeq ($(LIBNDCTL_LIBS),) HAS_NDCTL := $(call check_package, libndctl --atleast-version $(NDCTL_MIN_VERSION)) - ifeq ($(HAS_NDCTL),y) - OS_DIMM_CFLAG=-DNDCTL_ENABLED=1 - else + ifeq ($(HAS_NDCTL),n) $(error Please install libndctl-dev/libndctl-devel/ndctl-devel >= $(NDCTL_MIN_VERSION)) endif HAS_DAXCTL := $(call check_package, libdaxctl --atleast-version $(NDCTL_MIN_VERSION)) @@ -348,8 +346,10 @@ ifeq ($(NDCTL_ENABLE),y) LIBNDCTL_LIBS := $(shell $(PKG_CONFIG) --libs $(LIBNDCTL_PKG_CONFIG_DEPS)) endif OS_DIMM := ndctl + OS_DIMM_CFLAG=-DNDCTL_ENABLED=1 else OS_DIMM := none + OS_DIMM_CFLAG=-DNDCTL_ENABLED=0 endif export OS_DIMM export LIBNDCTL_PKG_CONFIG_DEPS From 39ca94a459f7ffb4a586eb2087020b4bf8f52862 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Thu, 28 Mar 2024 08:34:29 +0100 Subject: [PATCH 171/182] common: 2.1.0 documentation update Signed-off-by: Tomasz Gromadzki --- ChangeLog | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 808e26f55df..39852a4918f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,17 +2,28 @@ XXX * Version 2.1.0 - This release - - introduces fuses against ill-considered use of NDCTL_ENABLE=n - - PMEMOBJ_IGNORE_DIRTY_SHUTDOWN and PMEMOBJ_IGNORE_BAD_BLOCKS are required to acknowledge the understanding of what production-critical functions are missing for the build without NDCTL - - does not allow opening pmem pool without unsafe shoutdown counter if not explicitly disabled - - remove support for build time define NO_LIBPTHREAD + This release: + - Introduces the new logging subsystem in the release build for all libraries. + - Messages by default are printed to syslog and stderr but might be redirected to a user-defined function, see pmem(obj)_log_set_function() for details. + - Log level thresholds are controlled via new API, see pmem(obj)_log_set_treshold() for details. + - These new APIs are not available for LIBPMEM2 and LIBPMEMPOOL at the moment. + - The new logging subsystem is suppressed in the debug build when any of the legacy debug logging environment variables is set: + - PMEM_LOG_LEVEL/_FILE + - PMEM2_LOG_LEVEL/_FILE + - PMEMOBJ_LOG_LEVEL/_FILE + - PMEMPOOL_LOG_LEVEL/_FILE + - The debug logging subsystem becomes DEPRECATED. + - Introduces fuses against ill-considered use of NDCTL_ENABLE=n. + - PMEMOBJ_IGNORE_DIRTY_SHUTDOWN and PMEMOBJ_IGNORE_BAD_BLOCKS are required to acknowledge the understanding of what production-critical functions are missing for the build without NDCTL. + - Does not allow opening PMEMOBJ pool without unsafe shutdown counter (USC) if not explicitly disabled. (#5968) + - use PMEMOBJ_CONF="sds.at_create=0" to disable USC when working without PMem (emulated PMem, Docker, etc.). + - Drops support for building without libpthread (NO_LIBPTHREAD build-time define). Mon Dec 4 2023 Oksana Sałyk * Version 2.0.1 - This release : + This release: - Significantly reduces the libpmem's stack usage. - Reduces libpmemobj's stack usage below the 11kB threshold. - Fixing minor Coverity issues @@ -22,7 +33,7 @@ Tue Aug 8 2023 Oksana Sałyk * Version 2.0.0 - This release : + This release: - Removes libpmemlog, libpmemblk, btt, and their support in (lib)pmempool - Removes Windows support - Removes FreeBSD support @@ -42,7 +53,7 @@ Wed May 31 2023 Oksana Sałyk * Version 1.13.1 - This release : + This release: - Identifies and temporarily disables tests permanently or sporadically failing in some configurations: - ex_libpmem2 (#5593, #5635, #5638, #5641) From 58038b7f38fcbe39248813463262776b5c514000 Mon Sep 17 00:00:00 2001 From: Jan Michalski Date: Wed, 3 Apr 2024 17:43:57 -0400 Subject: [PATCH 172/182] benchmark: tune perf.cfg for longer execution times Signed-off-by: Jan Michalski --- src/benchmarks/perf.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/benchmarks/perf.cfg b/src/benchmarks/perf.cfg index 7fa71690e09..ede7ac6536b 100644 --- a/src/benchmarks/perf.cfg +++ b/src/benchmarks/perf.cfg @@ -6,8 +6,8 @@ repeats = 3 [obj_tx_alloc_small_v_thread] bench = obj_tx_alloc group = pmemobj -ops-per-thread = 200000 -threads = 1:+1:32 +ops-per-thread = 6000000 +threads = 1:*2:32 type-number = per-thread data-size = 256 @@ -33,8 +33,8 @@ data-size = 64:*2:32768 [obj_pmalloc_small_v_threads] bench = pmalloc group = pmemobj -ops-per-thread = 200000 -threads = 1:+1:32 +ops-per-thread = 2000000 +threads = 1:*2:32 data-size = 100 # pmalloc (size = 128k) vs threads From c45d8c94c77800e3977b30473360f57c3f2c0422 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Mon, 8 Apr 2024 09:20:59 +0200 Subject: [PATCH 173/182] doc: add missing doc file --- doc/libpmem/pmem_log_use_default_function.3 | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/libpmem/pmem_log_use_default_function.3 diff --git a/doc/libpmem/pmem_log_use_default_function.3 b/doc/libpmem/pmem_log_use_default_function.3 new file mode 100644 index 00000000000..145494c6686 --- /dev/null +++ b/doc/libpmem/pmem_log_use_default_function.3 @@ -0,0 +1 @@ +.so pmem_log_set_function.3 From 2185cfdf85e8aeceb8cb184ed72cd2d1b02cfdf0 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 5 Apr 2024 08:35:13 +0200 Subject: [PATCH 174/182] obj: verify the shutdown state in pmemobj pool --- src/common/set.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common/set.c b/src/common/set.c index 57b78bc7723..f82e9fd5141 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -2784,7 +2784,18 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr) LOG(3, "set %p attr %p", set, attr); /* read shutdown state toggle from header */ - set->ignore_sds |= IGNORE_SDS(HDR(REP(set, 0), 0)); + int pool_ignore_sds = IGNORE_SDS(HDR(REP(set, 0), 0)); + if (pool_ignore_sds && (attr->features.incompat & POOL_E_FEAT_SDS)) { + /* + * In case, the user has a pool with the SDS feature turned off + * despite the PMEMOBJ can support it. It is the last call to + * turn on this crucial feature if possible. + */ + CORE_LOG_WARNING( + "Possible silent data corruption. The unsafe shutdown detection (SDS) is not supported in the pool: %s", + set->path); + } + set->ignore_sds |= pool_ignore_sds; for (unsigned r = 0; r < set->nreplicas; r++) { struct pool_replica *rep = set->replica[r]; From a47b7546a53584290afe276b1158664cb705e110 Mon Sep 17 00:00:00 2001 From: "Gromadzki, Tomasz" Date: Tue, 9 Apr 2024 20:03:04 +0200 Subject: [PATCH 175/182] common: add SDS related CORE_LOG_WARNING to core_log_max test Signed-off-by: Gromadzki, Tomasz --- src/test/core_log_max/call_all.c.generated | 2 ++ src/test/core_log_max/core_log_max.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/core_log_max/call_all.c.generated b/src/test/core_log_max/call_all.c.generated index 6c38ba31d31..1ef0385ab22 100644 --- a/src/test/core_log_max/call_all.c.generated +++ b/src/test/core_log_max/call_all.c.generated @@ -452,6 +452,8 @@ call_all_CORE_LOG_WARNING(void) // src/common/set.c CORE_LOG_WARNING("usable space mapping failed - part #%d - retrying", _d); // src/common/set.c + CORE_LOG_WARNING("Possible silent data corruption. The unsafe shutdown detection (SDS) is not supported in the pool: %s", _s); + // src/common/set.c CORE_LOG_WARNING("pool set contains bad blocks, ignoring"); // src/common/set.c CORE_LOG_WARNING("cannot open the part -- \"%s\"", _s); diff --git a/src/test/core_log_max/core_log_max.c b/src/test/core_log_max/core_log_max.c index 2287affe3de..57cb19b6960 100644 --- a/src/test/core_log_max/core_log_max.c +++ b/src/test/core_log_max/core_log_max.c @@ -119,7 +119,7 @@ test_ERR_W_ERRNO(const struct test_case *tc, int argc, char *argv[]) return NO_ARGS_CONSUMED; } -#define TOTAL_MESSAGE_NUM_EXPECTED 212 +#define TOTAL_MESSAGE_NUM_EXPECTED 213 static int Max_message_len = 0; static int Total_message_num = 0; static char The_longest_message[BIG_BUF_SIZE]; From 4637992200361c1b38570acbe7fd1968ee440164 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Mon, 15 Apr 2024 08:03:34 +0200 Subject: [PATCH 176/182] doc: remove unneeded file --- doc/Makefile | 1 - doc/libpmem/pmem_log_use_default_function.3 | 1 - 2 files changed, 2 deletions(-) delete mode 100644 doc/libpmem/pmem_log_use_default_function.3 diff --git a/doc/Makefile b/doc/Makefile index 7cbc00761fc..e7d77f95298 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -32,7 +32,6 @@ MANPAGES_3_DUMMY = libpmem/pmem_drain.3 libpmem/pmem_has_hw_drain.3 libpmem/pmem libpmem/pmem_memcpy_persist.3 libpmem/pmem_memset_persist.3 libpmem/pmem_memmove_nodrain.3 libpmem/pmem_memcpy_nodrain.3 libpmem/pmem_memset_nodrain.3 \ libpmem/pmem_memcpy.3 libpmem/pmem_memset.3 libpmem/pmem_memmove.3 \ libpmem/pmem_check_version.3 libpmem/pmem_errormsg.3 \ - libpmem/pmem_log_use_default_function.3 \ libpmempool/pmempool_check.3 libpmempool/pmempool_check_end.3 \ libpmempool/pmempool_feature_enable.3 libpmempool/pmempool_feature_disable.3 \ libpmempool/pmempool_transform.3 \ diff --git a/doc/libpmem/pmem_log_use_default_function.3 b/doc/libpmem/pmem_log_use_default_function.3 deleted file mode 100644 index 145494c6686..00000000000 --- a/doc/libpmem/pmem_log_use_default_function.3 +++ /dev/null @@ -1 +0,0 @@ -.so pmem_log_set_function.3 From a8b1cc60b4f474cf4b8a92ced375f41ea468fc55 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Mon, 15 Apr 2024 15:27:32 +0200 Subject: [PATCH 177/182] utils: change lower_limit The problem was observed and confirmed only on Ubuntu --- .github/workflows/scan_stack_usage.yml | 6 +++--- utils/call_stacks_analysis/README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scan_stack_usage.yml b/.github/workflows/scan_stack_usage.yml index e133b31ce44..a5b1ecc8984 100644 --- a/.github/workflows/scan_stack_usage.yml +++ b/.github/workflows/scan_stack_usage.yml @@ -52,13 +52,13 @@ jobs: ./make_extra.py ./make_cflow.sh # The lower limit comes up from the DAOS memory requirements. - # 16kB - 4kB - 768B = 11520B + # 16kB - 4kB - 752B = 11536B # 16kB = Stack allocated for a single Argobot's ULT # 4kB = a maximum DAOS' stack usage up to calling a PMDK API calls - # 768B = safety margin + # 752B = safety margin # ~ = Some OSes, e.g. Ubuntu 22.04, generate call stacks of size # a little bit over the exact limit which is not deemed a problem at the moment. - ./make_call_stacks.py --filter-api-file examples/api_filter.txt --filter-lower-limit 11520 + ./make_call_stacks.py --filter-api-file examples/api_filter.txt --filter-lower-limit 11536 - name: List per-function stack usage for all call stacks of interest working-directory: ${{ env.CALL_STACKS_TOOLS_PATH }} diff --git a/utils/call_stacks_analysis/README.md b/utils/call_stacks_analysis/README.md index 4933254effd..40a21cfc15e 100644 --- a/utils/call_stacks_analysis/README.md +++ b/utils/call_stacks_analysis/README.md @@ -15,7 +15,7 @@ ./make_extra.py && \ ./make_cflow.sh && \ ./make_call_stacks.py --filter-api-file examples/api_filter.txt \ - --filter-lower-limit 11520 --dump-all-stacks + --filter-lower-limit 11536 --dump-all-stacks ``` If succesfull, it produces: From 0c3223ee6f22c84cf12fb3c3997001fc455c63d8 Mon Sep 17 00:00:00 2001 From: "Gromadzki, Tomasz" Date: Tue, 7 May 2024 20:43:16 +0200 Subject: [PATCH 178/182] doc: logging information added to manpages (7) Signed-off-by: Tomasz Gromadzki [LIBRARY API VERSIONING](#library-api-versioning-1)
[ENVIRONMENT](#environment)
-[DEBUGGING AND ERROR HANDLING](#debugging-and-error-handling)
+[ERROR HANDLING](#error-handling)
+[DEBUGGING](#debugging)
[EXAMPLE](#example)
[ACKNOWLEDGEMENTS](#acknowledgements)
[SEE ALSO](#see-also) @@ -223,7 +224,7 @@ affects all the PMDK libraries,** disabling mapping address randomization and causing the specified address to be used as a hint about where to place the mapping. -# DEBUGGING AND ERROR HANDLING # +# ERROR HANDLING # If an error is detected during the call to a **libpmem** function, the application may retrieve an error message describing the reason of the failure @@ -238,6 +239,14 @@ call to a **libpmem** function indicated an error. The application must not modify or free the error message string. Subsequent calls to other library functions may modify the previous message. +In parallel to the above mechanism, all logging messages are written to +**syslog**(3) and/or **stderr**(3) or passed to the user-provided logging +function. Please see **pmem_log_set_function**(3) for details. +The influx of the reported messages can be controlled by setting a respective +threshold value. Please see **pmem_log_set_threshold**(3) for details. + +# DEBBUGING # + Two versions of **libpmem** are typically available on a development system. The normal version, accessed when a program is linked using the **-lpmem** option, is optimized for performance. That version skips checks @@ -253,8 +262,8 @@ variables. These variables have no effect on the non-debug version of the librar + **PMEM_LOG_LEVEL** -The value of **PMEM_LOG_LEVEL** enables trace points in the debug version -of the library, as follows: +The value of the **PMEM_LOG_LEVEL** environment variable enables trace points in +the debug version of the library, as follows: + **0** - This is the default level when **PMEM_LOG_LEVEL** is not set. No log messages are emitted at this level. @@ -271,7 +280,8 @@ library. + **4** - Enables voluminous and fairly obscure tracing information that is likely only useful to the **libpmem** developers. -Unless **PMEM_LOG_FILE** is set, debugging output is written to *stderr*. +Unless the **PMEM_LOG_FILE** environment variable is set, the debugging output +is written to *stderr*. + **PMEM_LOG_FILE** @@ -281,6 +291,11 @@ is "-", the *PID* of the current process will be appended to the file name when the log file is created. If **PMEM_LOG_FILE** is not set, output is written to *stderr*. +Whenever either **PMEM_LOG_LEVEL** or **PMEM_LOG_FILE** environment variable is +set the messages are not passed via the routes described in +the [ERROR HANDLING](#error-handling) section except for the **pmem_errormsg**() +which works unconditionally. + # EXAMPLE # The following example uses **libpmem** to flush changes made to raw, diff --git a/doc/libpmemobj/libpmemobj.7.md b/doc/libpmemobj/libpmemobj.7.md index 3c089ae708c..8fdb6b69d6a 100644 --- a/doc/libpmemobj/libpmemobj.7.md +++ b/doc/libpmemobj/libpmemobj.7.md @@ -18,7 +18,8 @@ header: "pmemobj API version 2.3" [DESCRIPTION](#description)
[LIBRARY API VERSIONING](#library-api-versioning-1)
[MANAGING LIBRARY BEHAVIOR](#managing-library-behavior-1)
-[DEBUGGING AND ERROR HANDLING](#debugging-and-error-handling)
+[ERROR HANDLING](#error-handling)
+[DEBUGGING](#debugging)
[EXAMPLE](#example)
[ACKNOWLEDGEMENTS](#acknowledgements)
[SEE ALSO](#see-also)
@@ -162,7 +163,7 @@ transactions/allocations. For debugging purposes it is possible to decrease this value by setting the **PMEMOBJ_NLANES** environment variable to the desired limit. -# DEBUGGING AND ERROR HANDLING # +# ERROR HANDLING # If an error is detected during the call to a **libpmemobj** function, the application may retrieve an error message describing the reason for the failure @@ -177,6 +178,14 @@ call to a **libpmemobj** function indicated an error, or if *errno* was set. The application must not modify or free the error message string, but it may be modified by subsequent calls to other library functions. +In parallel to the above mechanism, all logging messages are written to +**syslog**(3) and/or **stderr**(3) or passed to the user-provided logging +function. Please see **pmemobj_log_set_function**(3) for details. +The influx of the reported messages can be controlled by setting a respective +threshold value. Please see **pmemobj_log_set_threshold**(3) for details. + +# DEBBUGING # + Two versions of **libpmemobj** are typically available on a development system. The normal version, accessed when a program is linked using the **-lpmemobj** option, is optimized for performance. That version skips checks @@ -192,8 +201,8 @@ variables. These variables have no effect on the non-debug version of the librar + **PMEMOBJ_LOG_LEVEL** -The value of **PMEMOBJ_LOG_LEVEL** enables trace points in the debug version -of the library, as follows: +The value of the **PMEMOBJ_LOG_LEVEL** environment variable enables trace points +in the debug version of the library, as follows: + **0** - This is the default level when **PMEMOBJ_LOG_LEVEL** is not set. No log messages are emitted at this level. @@ -210,7 +219,8 @@ tracing in the library. + **4** - Enables voluminous and fairly obscure tracing information that is likely only useful to the **libpmemobj** developers. -Unless **PMEMOBJ_LOG_FILE** is set, debugging output is written to *stderr*. +Unless the **PMEMOBJ_LOG_FILE** environment variable is set, the debugging +output is written to *stderr*. + **PMEMOBJ_LOG_FILE** @@ -219,6 +229,11 @@ If the last character in the name is "-", the *PID* of the current process will be appended to the file name when the log file is created. If **PMEMOBJ_LOG_FILE** is not set, logging output is written to *stderr*. +Whenever either **PMEMOBJ_LOG_LEVEL** or **PMEMOBJ_LOG_FILE** environment +variable is set the messages are not passed via the routes described in +the [ERROR HANDLING](#error-handling) section except for +the **pmemobj_errormsg**() which works unconditionally. + See also **libpmem**(7) to get information about other environment variables affecting **libpmemobj** behavior. From 4f2765173d2b0a91ae002ae7b8afd02861c0055e Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Thu, 9 May 2024 12:42:07 +0200 Subject: [PATCH 179/182] doc: mark old logging as deprecated --- doc/libpmem/libpmem.7.md | 9 +++++++-- doc/libpmemobj/libpmemobj.7.md | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/libpmem/libpmem.7.md b/doc/libpmem/libpmem.7.md index 1334b752af4..8684d7f8482 100644 --- a/doc/libpmem/libpmem.7.md +++ b/doc/libpmem/libpmem.7.md @@ -21,6 +21,7 @@ header: "pmem API version 1.1" [ENVIRONMENT](#environment)
[ERROR HANDLING](#error-handling)
[DEBUGGING](#debugging)
+[LOGGING (DEPRECATED)](#logging-deprecated)
[EXAMPLE](#example)
[ACKNOWLEDGEMENTS](#acknowledgements)
[SEE ALSO](#see-also) @@ -245,7 +246,7 @@ function. Please see **pmem_log_set_function**(3) for details. The influx of the reported messages can be controlled by setting a respective threshold value. Please see **pmem_log_set_threshold**(3) for details. -# DEBBUGING # +# DEBUGGING # Two versions of **libpmem** are typically available on a development system. The normal version, accessed when a program is linked using the @@ -257,7 +258,11 @@ A second version of **libpmem**, accessed when a program uses the libraries under **/usr/lib/pmdk_debug**, contains run-time assertions and trace points. The typical way to access the debug version is to set the environment variable **LD_LIBRARY_PATH** to **/usr/lib/pmdk_debug** or **/usr/lib64/pmdk_debug**, -as appropriate. Debugging output is controlled using the following environment +as appropriate. + +# LOGGING (DEPRECATED) # + +Debugging output is controlled using the following environment variables. These variables have no effect on the non-debug version of the library. + **PMEM_LOG_LEVEL** diff --git a/doc/libpmemobj/libpmemobj.7.md b/doc/libpmemobj/libpmemobj.7.md index 8fdb6b69d6a..8d2135f9bc2 100644 --- a/doc/libpmemobj/libpmemobj.7.md +++ b/doc/libpmemobj/libpmemobj.7.md @@ -20,6 +20,7 @@ header: "pmemobj API version 2.3" [MANAGING LIBRARY BEHAVIOR](#managing-library-behavior-1)
[ERROR HANDLING](#error-handling)
[DEBUGGING](#debugging)
+[LOGGING (DEPRECATED)](#logging-deprecated)
[EXAMPLE](#example)
[ACKNOWLEDGEMENTS](#acknowledgements)
[SEE ALSO](#see-also)
@@ -184,7 +185,7 @@ function. Please see **pmemobj_log_set_function**(3) for details. The influx of the reported messages can be controlled by setting a respective threshold value. Please see **pmemobj_log_set_threshold**(3) for details. -# DEBBUGING # +# DEBUGGING # Two versions of **libpmemobj** are typically available on a development system. The normal version, accessed when a program is linked using the @@ -196,7 +197,11 @@ A second version of **libpmemobj**, accessed when a program uses the libraries under **/usr/lib/pmdk_debug**, contains run-time assertions and trace points. The typical way to access the debug version is to set the environment variable **LD_LIBRARY_PATH** to **/usr/lib/pmdk_debug** or **/usr/lib64/pmdk_debug**, -as appropriate. Debugging output is controlled using the following environment +as appropriate. + +# LOGGING (DEPRECATED) # + +Debugging output is controlled using the following environment variables. These variables have no effect on the non-debug version of the library. + **PMEMOBJ_LOG_LEVEL** From b003aaee71f790dc7534b4d77dfe137549dcbfb0 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 19 Apr 2024 09:07:01 +0200 Subject: [PATCH 180/182] common: update CODECOV workflow file --- .github/workflows/main.yml | 2 ++ .github/workflows/scan_coverage.yml | 13 ++++++- .github/workflows/scans.yml | 2 ++ utils/docker/images/Dockerfile.ubuntu-22.04 | 6 +--- utils/docker/images/download-scripts.sh | 39 --------------------- utils/docker/run-coverage.sh | 20 +---------- 6 files changed, 18 insertions(+), 64 deletions(-) delete mode 100755 utils/docker/images/download-scripts.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e2eef50cc19..49b378103dc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -106,4 +106,6 @@ jobs: coverage_scan: needs: [src_checkers, basic_build] uses: ./.github/workflows/scan_coverage.yml + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} name: Coverage diff --git a/.github/workflows/scan_coverage.yml b/.github/workflows/scan_coverage.yml index 521c0fd8cb1..6fcef3d30a1 100644 --- a/.github/workflows/scan_coverage.yml +++ b/.github/workflows/scan_coverage.yml @@ -3,6 +3,9 @@ name: Coverage on: workflow_call: + secrets: + CODECOV_TOKEN: + required: true env: # Note: All coverage scans, e.g. on pull requests, should be run in the same @@ -32,5 +35,13 @@ jobs: - name: Pull the image run: cd $WORKDIR && ./pull-or-rebuild-image.sh - - name: Measure and upload code coverage + - name: Run the build run: cd $WORKDIR && ./build-CI.sh + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + root_dir: /home/runner/work/pmdk/pmdk/ + directory: /home/runner/work/pmdk/pmdk/ + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/.github/workflows/scans.yml b/.github/workflows/scans.yml index fc7ab815547..7bafd77ad01 100644 --- a/.github/workflows/scans.yml +++ b/.github/workflows/scans.yml @@ -22,6 +22,8 @@ jobs: name: Coverity call-coverage: uses: ./.github/workflows/scan_coverage.yml + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} name: Coverage call-documentation: uses: ./.github/workflows/scan_documentation.yml diff --git a/utils/docker/images/Dockerfile.ubuntu-22.04 b/utils/docker/images/Dockerfile.ubuntu-22.04 index 25ae8a0f62b..41dbb7af646 100644 --- a/utils/docker/images/Dockerfile.ubuntu-22.04 +++ b/utils/docker/images/Dockerfile.ubuntu-22.04 @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2016-2023, Intel Corporation +# Copyright 2016-2024, Intel Corporation # # Dockerfile - a 'recipe' for Docker to build an image of ubuntu-based @@ -83,9 +83,6 @@ ENV PYTHON_DEPS "\ # Copy install valgrind script COPY install-valgrind.sh install-valgrind.sh -# Copy script to download codecov script required in run-coverage.sh -COPY download-scripts.sh download-scripts.sh - # Update the Apt cache and install basic tools RUN apt-get update && apt-get dist-upgrade -y \ && apt-get install -y --no-install-recommends \ @@ -100,7 +97,6 @@ RUN apt-get update && apt-get dist-upgrade -y \ $COVERITY_DEPS \ $MISC_DEPS \ && ./install-valgrind.sh ubuntu \ - && ./download-scripts.sh \ && rm -rf /var/lib/apt/lists/* RUN pip3 install $PYTHON_DEPS diff --git a/utils/docker/images/download-scripts.sh b/utils/docker/images/download-scripts.sh deleted file mode 100755 index 448e38c8f26..00000000000 --- a/utils/docker/images/download-scripts.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: BSD-3-Clause -# Copyright 2020-2023, Intel Corporation - -# -# download-scripts.sh - downloads latest version of -# codecov's uploader to generate and upload reports. -# - -set -e - -if [ "${SKIP_SCRIPTS_DOWNLOAD}" ]; then - echo "Variable 'SKIP_SCRIPTS_DOWNLOAD' is set; skipping scripts' download" - exit -fi - -mkdir -p /opt/scripts - -if ! [ -x "$(command -v curl)" ]; then - echo "Error: curl is not installed." - return 1 -fi - -# Download codecov and check integrity -mkdir -p codecov-tmp -pushd codecov-tmp - -curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import -curl -Os https://uploader.codecov.io/latest/linux/codecov -curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM -curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig -gpgv codecov.SHA256SUM.sig codecov.SHA256SUM -shasum -a 256 -c codecov.SHA256SUM -chmod +x codecov - -mv -v codecov /opt/scripts/codecov - -popd -rm -rf codecov-tmp diff --git a/utils/docker/run-coverage.sh b/utils/docker/run-coverage.sh index 823414c4563..afba8e67fa5 100755 --- a/utils/docker/run-coverage.sh +++ b/utils/docker/run-coverage.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2017-2023, Intel Corporation +# Copyright 2017-2024, Intel Corporation # # run-coverage.sh - is called inside a Docker container; runs tests @@ -31,21 +31,3 @@ make -kj2 pcheck-local-quiet TEST_BUILD=debug || true # do not change -j2 to -j$(nproc) in case of tests (make check/pycheck) make -kj2 pycheck TEST_BUILD=debug || true popd - -# prepare flag for codecov report to differentiate builds -flag=tests -[ -n "${GITHUB_ACTIONS}" ] && flag=GHA - -# validate codecov.yaml file -cat "${WORKDIR}/.codecov.yml" | curl --data-binary @- https://codecov.io/validate - -# run codecov's uploader in current dir (WORKDIR), with gcov executable -# (clean parsed coverage files, set flag and exit 1 if not successful) -/opt/scripts/codecov --rootDir . --gcov --clean --flags ${flag} --nonZero --verbose -echo "Check for any leftover gcov files" -leftover_files=$(find . -name "*.gcov") -if [[ -n "${leftover_files}" ]]; then - # display found files and exit with error (they all should be parsed) - echo "${leftover_files}" - return 1 -fi From 7be415425c8b20829f44b1fc119618246ed11ee4 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 10 May 2024 12:39:10 +0200 Subject: [PATCH 181/182] common: 2.1.0-rc1 release --- ChangeLog | 2 +- GIT_VERSION | 1 - INSTALL.md | 2 +- VERSION | 1 + utils/docker/images/set-images-version.sh | 4 ++-- 5 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 GIT_VERSION create mode 100644 VERSION diff --git a/ChangeLog b/ChangeLog index 39852a4918f..b4e96391a15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -XXX +Fri May 10 2024 Oksana Sałyk * Version 2.1.0 diff --git a/GIT_VERSION b/GIT_VERSION deleted file mode 100644 index 6002f22fa25..00000000000 --- a/GIT_VERSION +++ /dev/null @@ -1 +0,0 @@ -$Format:%h$ \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md index a8876d51c11..4add4622aa8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -39,7 +39,7 @@ cd pmdk For a stable version, checkout a [release tag](https://github.com/pmem/pmdk/releases) as follows. Otherwise skip this step to build the latest development release. ```sh -git checkout tags/2.0.1 +git checkout tags/2.1.0 ``` Once all required [dependencies](#dependencies) are installed, PMDK is built using the diff --git a/VERSION b/VERSION new file mode 100644 index 00000000000..85e0e216a38 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.1.0-rc1 diff --git a/utils/docker/images/set-images-version.sh b/utils/docker/images/set-images-version.sh index d1a937ce672..44b7b08813a 100755 --- a/utils/docker/images/set-images-version.sh +++ b/utils/docker/images/set-images-version.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2020-2023, Intel Corporation +# Copyright 2020-2024, Intel Corporation # # @@ -13,4 +13,4 @@ # has to trigger the rebuild of all Docker images. # -export IMG_VER=2.0 +export IMG_VER=2.1 From 5386e78942841593070e96468a624790484674c0 Mon Sep 17 00:00:00 2001 From: Oksana Salyk Date: Fri, 10 May 2024 12:42:37 +0200 Subject: [PATCH 182/182] common: git versions --- GIT_VERSION | 1 + VERSION | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 GIT_VERSION delete mode 100644 VERSION diff --git a/GIT_VERSION b/GIT_VERSION new file mode 100644 index 00000000000..6002f22fa25 --- /dev/null +++ b/GIT_VERSION @@ -0,0 +1 @@ +$Format:%h$ \ No newline at end of file diff --git a/VERSION b/VERSION deleted file mode 100644 index 85e0e216a38..00000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2.1.0-rc1