Closed smajl87 closed 2 years ago
sysfs_emit was added to the kernel starting at version 5.10.
On Mar 10, 2022, at 3:17 AM, smajl87 @.***> wrote:
On newly installed Ubuntu LTS server
@.***:/tmp# date Thu 10 Mar 2022 11:55:42 AM CET
@.***:/tmp# cat /etc/os-release NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.4 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
@.***:/tmp# uname -a Linux sp01 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
@.***:/tmp# git clone https://github.com/markh794/mhvtl.git Cloning into 'mhvtl'... remote: Enumerating objects: 8006, done. remote: Counting objects: 100% (590/590), done. remote: Compressing objects: 100% (387/387), done. remote: Total 8006 (delta 381), reused 348 (delta 200), pack-reused 7416 Receiving objects: 100% (8006/8006), 3.18 MiB | 1.61 MiB/s, done. Resolving deltas: 100% (5761/5761), done.
@.***:/tmp# cd mhvtl/kernel/
@.:/tmp/mhvtl/kernel# make make -C /lib/modules/5.4.0-100-generic/build M=/tmp/mhvtl/kernel modules make[1]: Entering directory '/usr/src/linux-headers-5.4.0-100-generic' CC [M] /tmp/mhvtl/kernel/mhvtl.o In file included from /tmp/mhvtl/kernel/mhvtl.c:95: /tmp/mhvtl/kernel/backport.h:63:12: error: static declaration of ‘sysfs_emit’ follows non-static declaration 63 | static int sysfs_emit(char buf, const char fmt, ...) | ^
~~~~~ In file included from ./include/linux/kobject.h:20, from ./include/linux/module.h:17, from /tmp/mhvtl/kernel/mhvtl.c:45: ./include/linux/sysfs.h:325:5: note: previous declaration of ‘sysfs_emit’ was here 325 | int sysfs_emit(char buf, const char fmt, ...); | ^~~~~~ make[2]: [scripts/Makefile.build:270: /tmp/mhvtl/kernel/mhvtl.o] Error 1 make[1]: [Makefile:1762: /tmp/mhvtl/kernel] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-100-generic' make: [Makefile:26: default] Error 2@.***:/tmp/mhvtl/kernel# Same situation on Rocky Linux 8
@. kernel]# make make -C /lib/modules/4.18.0-348.el8.0.2.x86_64/build M=/tmp/mhvtl/kernel modules make[1]: Entering directory '/usr/src/kernels/4.18.0-348.12.2.el8_5.x86_64' CC [M] /tmp/mhvtl/kernel/mhvtl.o In file included from /tmp/mhvtl/kernel/mhvtl.c:95: /tmp/mhvtl/kernel/backport.h:63:12: error: static declaration of ‘sysfs_emit’ follows non-static declaration static int sysfs_emit(char buf, const char fmt, ...) ^
~~~~~ In file included from ./include/linux/kobject.h:20, from ./include/linux/module.h:17, from /tmp/mhvtl/kernel/mhvtl.c:45: ./include/linux/sysfs.h:336:5: note: previous declaration of ‘sysfs_emit’ was here int sysfs_emit(char buf, const char fmt, ...); ^~~~~~ make[2]: [scripts/Makefile.build:322: /tmp/mhvtl/kernel/mhvtl.o] Error 1 make[1]: [Makefile:1571: module/tmp/mhvtl/kernel] Error 2 make[1]: Leaving directory '/usr/src/kernels/4.18.0-348.12.2.el8_5.x86_64' make: [Makefile:26: default] Error 2 @.*** kernel]# — Reply to this email directly, view it on GitHub https://github.com/markh794/mhvtl/issues/95, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOJGHFQ2BV7QFHFKK2BSDLU7HK43ANCNFSM5QMKBXPQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.
In the age of backports, this mean nothing, unfortunately.
Hi:
On Mar 10, 2022, at 12:51 PM, melak @.***> wrote:
In the age of backports, this mean nothing, unfortunately.
So your distro has sysfs_emit() backported, and the code in mhvtl.c is assuming that for 5.4 kernel it needs to define it’s own. So you get a duplicate definition.
Side note: this wouldn’t be an issue if mhvtl.c was merged in the kernel. :) [I had to say that.]
You will have to make your own branch, and change the code in backport.h. I don’t know any generic cleaner way to address it, but perhaps somebody else does.
— Lee Duncan
It would be nice if distros that back port functions would add a #define so it could be tested at compile time.
Lets see what we can come up with. As Lee states, the sysfs_emit function will need to be commented out of mhvtl kernel/backport.h
Re: mhvtl.c was merged. I hear you :) Or I use an available module - perhaps virtio_scsi, or lio. It's all just a matter of spare time.
On Mar 10, 2022, at 2:10 PM, Mark Harvey @.***> wrote:
It would be nice if distros that back port functions would add a #define so it could be tested at compile time.
Lets see what we can come up with. As Lee states, the sysfs_emit function will need to be commented out of mhvtl kernel/backport.h
Re: mhvtl.c was merged. I hear you :) Or I use an available module - perhaps virtio_scsi, or lio. It's all just a matter of spare time.
Time! :O LOL. Ya, who has enough of that?
I planned, once, to try using tcmu-runner for mhvtl, but like you I never found the time. And, honestly, it’d be purely a labor of love, since I don’t need that for my daily job. Maybe when I retire … :P
— Lee Duncan
Two things I can think of off the top of my head. Both are ugly and will need some continued TLC as new items arise (which I'm sure they will).
ubuntu2004:/tmp/mhvtl/kernel$ git diff
diff --git a/kernel/Makefile b/kernel/Makefile
index 5a81dcc..8437b09 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -20,6 +20,10 @@ KDIR := /usr/src/linux-headers-$(V)
endif
endif
+ifeq ($(shell grep -q sysfs_emit $(KDIR)/include/linux/sysfs.h && echo yes),yes)
+EXTRA_CFLAGS += -DHAVE_SYSFS_EMIT
+endif
+
PWD := $(shell pwd)
default:
diff --git a/kernel/backport.h b/kernel/backport.h
index ef70aef..eecbcd7 100644
--- a/kernel/backport.h
+++ b/kernel/backport.h
@@ -49,7 +49,7 @@ static inline struct inode *file_inode(struct file *f)
#define HAVE_UNLOCKED_IOCTL 1
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && !defined(HAVE_SYSFS_EMIT)
/* https://patches.linaro.org/project/stable/patch/20210305120853.392925382@linuxfoundation.org/ */
/**
* sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer.
ubuntu2004:/tmp/mhvtl/kernel$ make clean
rm -f mhvtl.ko
rm -f TAGS
ubuntu2004:/tmp/mhvtl/kernel$ make
make -C /lib/modules/5.4.0-104-generic/build M=/tmp/mhvtl/kernel modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-104-generic'
Building modules, stage 2.
MODPOST 1 modules
LD [M] /tmp/mhvtl/kernel/mhvtl.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-104-generic'
ubuntu2004:/tmp/mhvtl/kernel$ ls -l mhvtl.ko
-rw-r--r-- 1 ice 1000 54488 Mar 10 23:28 mhvtl.ko
ubuntu2004:/tmp/mhvtl/kernel$ lsb_release -ir
Distributor ID: Ubuntu
Release: 20.04
ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl
ubuntu2004:/tmp/mhvtl/kernel$ sudo insmod ./mhvtl.ko
ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl
mhvtl 40960 0
ubuntu2004:/tmp/mhvtl/kernel$
Another option might be to look for the symbol in /boot/System.map-$(uname -r)
, but that requires root (the symbol map is only readable by root usually), and, if memory serves, some distros (in some circumstances only maybe? memory serves not) put it elsewhere.
I don't know of a "clean" solution.
Actually, $(KDIR)/Module.symvers
looks better a source of truth.
Two things I can think of off the top of my head. Both are ugly and will need some continued TLC as new items arise (which I'm sure they will).
ubuntu2004:/tmp/mhvtl/kernel$ git diff diff --git a/kernel/Makefile b/kernel/Makefile index 5a81dcc..8437b09 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -20,6 +20,10 @@ KDIR := /usr/src/linux-headers-$(V) endif endif +ifeq ($(shell grep -q sysfs_emit $(KDIR)/include/linux/sysfs.h && echo yes),yes) +EXTRA_CFLAGS += -DHAVE_SYSFS_EMIT +endif + PWD := $(shell pwd) default: diff --git a/kernel/backport.h b/kernel/backport.h index ef70aef..eecbcd7 100644 --- a/kernel/backport.h +++ b/kernel/backport.h @@ -49,7 +49,7 @@ static inline struct inode *file_inode(struct file *f) #define HAVE_UNLOCKED_IOCTL 1 #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && !defined(HAVE_SYSFS_EMIT) /* https://patches.linaro.org/project/stable/patch/20210305120853.392925382@linuxfoundation.org/ */ /** * sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer. ubuntu2004:/tmp/mhvtl/kernel$ make clean rm -f mhvtl.ko rm -f TAGS ubuntu2004:/tmp/mhvtl/kernel$ make make -C /lib/modules/5.4.0-104-generic/build M=/tmp/mhvtl/kernel modules make[1]: Entering directory '/usr/src/linux-headers-5.4.0-104-generic' Building modules, stage 2. MODPOST 1 modules LD [M] /tmp/mhvtl/kernel/mhvtl.ko make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-104-generic' ubuntu2004:/tmp/mhvtl/kernel$ ls -l mhvtl.ko -rw-r--r-- 1 ice 1000 54488 Mar 10 23:28 mhvtl.ko ubuntu2004:/tmp/mhvtl/kernel$ lsb_release -ir Distributor ID: Ubuntu Release: 20.04 ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl ubuntu2004:/tmp/mhvtl/kernel$ sudo insmod ./mhvtl.ko ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl mhvtl 40960 0 ubuntu2004:/tmp/mhvtl/kernel$
Another option might be to look for the symbol in
/boot/System.map-$(uname -r)
, but that requires root (the symbol map is only readable by root usually), and, if memory serves, some distros (in some circumstances only maybe? memory serves not) put it elsewhere.I don't know of a "clean" solution.
If we're defining/checking for sysfs_emit function in sysfs.h/Module.symvers - there is no real reason to include the kernel version test in the backport.h i.e. Simplify +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && !defined(HAVE_SYSFS_EMIT) to +#if !defined(HAVE_SYSFS_EMIT)
If we're defining/checking for sysfs_emit function in sysfs.h/Module.symvers - there is no real reason to include the kernel version test in the backport.h
Makes sense. I'm trying to cobble something reusable together, but we are fast approaching the limits of my make-fu.
How about a Make option, like HAVE_SYSFS_EMIT=yes? Also not pretty and not very generic.
-- Lee-Man Duncan Sent from my iPhone, dude
On Mar 10, 2022, at 2:41 PM, melak @.***> wrote:
Two things I can think of off the top of my head. Both are ugly and will need some continued TLC as new items arise (which I'm sure they will).
ubuntu2004:/tmp/mhvtl/kernel$ git diff diff --git a/kernel/Makefile b/kernel/Makefile index 5a81dcc..8437b09 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -20,6 +20,10 @@ KDIR := /usr/src/linux-headers-$(V) endif endif
+ifeq ($(shell grep -q sysfs_emit $(KDIR)/include/linux/sysfs.h && echo yes),yes) +EXTRA_CFLAGS += -DHAVE_SYSFS_EMIT +endif + PWD := $(shell pwd)
default: diff --git a/kernel/backport.h b/kernel/backport.h index ef70aef..eecbcd7 100644 --- a/kernel/backport.h +++ b/kernel/backport.h @@ -49,7 +49,7 @@ static inline struct inode file_inode(struct file f)
define HAVE_UNLOCKED_IOCTL 1
endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && !defined(HAVE_SYSFS_EMIT) /* @./ / /
- sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer. ubuntu2004:/tmp/mhvtl/kernel$ make clean rm -f mhvtl.ko rm -f TAGS ubuntu2004:/tmp/mhvtl/kernel$ make make -C /lib/modules/5.4.0-104-generic/build M=/tmp/mhvtl/kernel modules make[1]: Entering directory '/usr/src/linux-headers-5.4.0-104-generic' Building modules, stage 2.
MODPOST 1 modules LD [M] /tmp/mhvtl/kernel/mhvtl.ko make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-104-generic' ubuntu2004:/tmp/mhvtl/kernel$ ls -l mhvtl.ko -rw-r--r-- 1 ice 1000 54488 Mar 10 23:28 mhvtl.ko ubuntu2004:/tmp/mhvtl/kernel$ lsb_release -ir Distributor ID: Ubuntu Release: 20.04 ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl ubuntu2004:/tmp/mhvtl/kernel$ sudo insmod ./mhvtl.ko ubuntu2004:/tmp/mhvtl/kernel$ lsmod | grep mhvtl mhvtl 40960 0 ubuntu2004:/tmp/mhvtl/kernel$ Another option might be to look for the symbol in /boot/System.map-$(uname -r), but that requires root (the symbol map is only readable to root usually), and, if memory serves, some distros (in some circumstances only maybe? memory serves not) put it elsewhere.I don't know of a "clean" solution.
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.
On newly installed Ubuntu LTS server
Same situation on Rocky Linux 8