ublk-org / ublksrv

ublk: userspace block device driver
MIT License
138 stars 47 forks source link

Can we let ublk support lower gcc version #36

Closed old-memories closed 1 year ago

old-memories commented 1 year ago

Hi, Ming

Our users cannot compile ublksrv by simply typing "make" in the top directory since they only have gcc 8.5.0 which does not support c++ coroutine. Actually they just want to run demo_*.c which do not require any c++ coroutine.

It is hard to update GCC on some machine. So I think we should let user choose whether build with c++ coroutine files(maybe ublksrv_tgt c++ files) or not. If they have lower GCC version, they can build without ublksrv c++ files such as ublksrv_tgt.c, loop_tgt.c.

old-memories commented 1 year ago

The log:

make[2]: Entering directory '/root/workspace/ubdsrv'
gcc -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT demo_null-demo_null.o -MD -MP -MF .deps/demo_null-demo_null.Tpo -c -o demo_null-demo_null.o `test -f 'demo_null.c' || echo './'`demo_null.c
gcc -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT demo_event-demo_event.o -MD -MP -MF .deps/demo_event-demo_event.Tpo -c -o demo_event-demo_event.o `test -f 'demo_event.c' || echo './'`demo_event.c
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT ublk-ublksrv_tgt.o -MD -MP -MF .deps/ublk-ublksrv_tgt.Tpo -c -o ublk-ublksrv_tgt.o `test -f 'ublksrv_tgt.cpp' || echo './'`ublksrv_tgt.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT ublk-tgt_null.o -MD -MP -MF .deps/ublk-tgt_null.Tpo -c -o ublk-tgt_null.o `test -f 'tgt_null.cpp' || echo './'`tgt_null.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT ublk-tgt_loop.o -MD -MP -MF .deps/ublk-tgt_loop.Tpo -c -o ublk-tgt_loop.o `test -f 'tgt_loop.cpp' || echo './'`tgt_loop.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT qcow2/ublk-tgt_qcow2.o -MD -MP -MF qcow2/.deps/ublk-tgt_qcow2.Tpo -c -o qcow2/ublk-tgt_qcow2.o `test -f 'qcow2/tgt_qcow2.cpp' || echo './'`qcow2/tgt_qcow2.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT qcow2/ublk-qcow2.o -MD -MP -MF qcow2/.deps/ublk-qcow2.Tpo -c -o qcow2/ublk-qcow2.o `test -f 'qcow2/qcow2.cpp' || echo './'`qcow2/qcow2.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT qcow2/ublk-qcow2_meta.o -MD -MP -MF qcow2/.deps/ublk-qcow2_meta.Tpo -c -o qcow2/ublk-qcow2_meta.o `test -f 'qcow2/qcow2_meta.cpp' || echo './'`qcow2/qcow2_meta.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT qcow2/ublk-utils.o -MD -MP -MF qcow2/.deps/ublk-utils.Tpo -c -o qcow2/ublk-utils.o `test -f 'qcow2/utils.cpp' || echo './'`qcow2/utils.cpp
g++ -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -fcoroutines -std=c++20 -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT qcow2/ublk-qcow2_flush_meta.o -MD -MP -MF qcow2/.deps/ublk-qcow2_flush_meta.Tpo -c -o qcow2/ublk-qcow2_flush_meta.o `test -f 'qcow2/qcow2_flush_meta.cpp' || echo './'`qcow2/qcow2_flush_meta.cpp
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
make[2]: *** [Makefile:724: ublk-ublksrv_tgt.o] Error 1
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [Makefile:738: ublk-tgt_null.o] Error 1
make[2]: *** [Makefile:752: ublk-tgt_loop.o] Error 1
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
g++: error: unrecognized command line option ‘-fcoroutines’; did you mean ‘-fc-prototypes’?
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
make[2]: *** [Makefile:780: qcow2/ublk-qcow2.o] Error 1
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
make[2]: *** [Makefile:766: qcow2/ublk-tgt_qcow2.o] Error 1
make[2]: *** [Makefile:794: qcow2/ublk-qcow2_meta.o] Error 1
make[2]: *** [Makefile:808: qcow2/ublk-utils.o] Error 1
g++: error: unrecognized command line option ‘-std=c++20’; did you mean ‘-std=c++2a’?
ming1 commented 1 year ago

You can just build libublksrv with the two demos only by:

make -C lib/
make demo_null demo_event
old-memories commented 1 year ago
[root@love ubdsrv]# make  demo_null demo_event
gcc -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT demo_null-demo_null.o -MD -MP -MF .deps/demo_null-demo_null.Tpo -c -o demo_null-demo_null.o `test -f 'demo_null.c' || echo './'`demo_null.c
demo_null.c: In function ‘demo_null_io_handler_fn’:
demo_null.c:52:21: error: implicit declaration of function ‘getpid’; did you mean ‘getpt’? [-Werror=implicit-function-declaration]
  sched_setscheduler(getpid(), SCHED_RR, NULL);
                     ^~~~~~
                     getpt
demo_null.c:56:10: error: implicit declaration of function ‘gettid’; did you mean ‘getopt’? [-Werror=implicit-function-declaration]
    q_id, gettid());
          ^~~~~~
          getopt
cc1: all warnings being treated as errors
make: *** [Makefile:686: demo_null-demo_null.o] Error 1

Looks like unistd.h is not included? And gettid() is not defined here. My glibc version is 2.28.

ming1 commented 1 year ago

Please test the following patch and see if the build issue can be fixed:

diff --git a/demo_event.c b/demo_event.c index e6153e1..85c401e 100644 --- a/demo_event.c +++ b/demo_event.c @@ -14,6 +14,8 @@

include

include

include <sys/ioctl.h>

+#include +#include <sys/types.h>

include "ublksrv.h"

include "ublksrv_aio.h"

diff --git a/demo_null.c b/demo_null.c index 07795c9..210a0f5 100644 --- a/demo_null.c +++ b/demo_null.c @@ -10,6 +10,8 @@

include

include

include

+#include +#include <sys/types.h>

include "ublksrv.h"

old-memories commented 1 year ago
# make  demo_null demo_event
gcc -DHAVE_CONFIG_H -I.  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I./include  -Wall -Werror -Wuninitialized -Wmaybe-uninitialized -Wno-sign-compare -Wno-parentheses -Wvla -Wframe-larger-than=5000 -Wstack-usage=10000  -pthread -I/root/workspace/liburing-liburing-2.2/src/include -g -O0 -MT demo_null-demo_null.o -MD -MP -MF .deps/demo_null-demo_null.Tpo -c -o demo_null-demo_null.o `test -f 'demo_null.c' || echo './'`demo_null.c
demo_null.c: In function ‘demo_null_io_handler_fn’:
demo_null.c:58:10: error: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Werror=implicit-function-declaration]
    q_id, gettid());
          ^~~~~~
          getgid
cc1: all warnings being treated as errors
make: *** [Makefile:686: demo_null-demo_null.o] Error 1

OK, they can find getpid() now but gettid() does exist. Looks like lib/ublksrv.c, ublksrv_tgt.cpp, demo_event.c and demo_null.c all use gettid().

BTW, can we add

#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif

in include/ublksrv.h to solve this problem? This works for me.

ming1 commented 1 year ago

Hi Ziyang,

Please verify if the following commit fixes your issue:

https://github.com/ming1/ubdsrv/commit/681cf304a0ab37839b5591efd9edd7c7b9c76373

thanks,

old-memories commented 1 year ago

Thanks. https://github.com/ming1/ubdsrv/commit/681cf304a0ab37839b5591efd9edd7c7b9c76373 fixes the second problem. Could you please fix the missing "#include #include <sys/types.h>" in demo_event demo_null too?

ming1 commented 1 year ago

Yeah, it is done, just missed getpid().

https://github.com/ming1/ubdsrv/commit/267928480bf4bc00d62b232c01c573dad3be140d