Giter Club home page Giter Club logo

Comments (8)

ming1 avatar ming1 commented on August 24, 2024

Environment: I' m running a Debian 11 Virtual Machine, and I have installed the latest 6.0 Linux kernel.

Thanks for the report, I didn't test ublksrv on Debian before.

Problem: I' m following the official instructions from README, (btw I think we need to add explicit instructions prior to autoreconf -i and ./configure, because they need some packages to be installed. I can do it in a subsequent PR if you agree) and I'm bumping into the following problem:

Sure, please send PR for the steps.

$ make
make  all-recursive
make[1]: Entering directory '/home/dim/ubdsrv'
Making all in include
make[2]: Entering directory '/home/dim/ubdsrv/include'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/dim/ubdsrv/include'
Making all in lib
make[2]: Entering directory '/home/dim/ubdsrv/lib'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/dim/ubdsrv/lib'
Making all in tests
make[2]: Entering directory '/home/dim/ubdsrv/tests'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/dim/ubdsrv/tests'
make[2]: Entering directory '/home/dim/ubdsrv'
/bin/bash ./libtool  --tag=CXX   --mode=link g++ -fcoroutines -std=c++20 -g -O2 -pthread   -o ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o ublk-tgt_qcow2.o ublk-qcow2.o ublk-qcow2_meta.o ublk-utils.o lib/libublksrv.la -luring  
libtool: link: g++ -fcoroutines -std=c++20 -g -O2 -pthread -o .libs/ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o ublk-tgt_qcow2.o ublk-qcow2.o ublk-qcow2_meta.o ublk-utils.o  lib/.libs/libublksrv.so -luring -pthread
/usr/bin/ld: ublk-qcow2_meta.o: in function `Qcow2ClusterMapping::__find_slice(unsigned long, bool)':
/home/dim/ubdsrv/qcow2/qcow2.h:1181: undefined reference to `slice_cache<Qcow2L2Table>::__find_slice(unsigned long, bool)'
/usr/bin/ld: ublk-qcow2_meta.o: in function `Qcow2ClusterAllocator::__find_slice(unsigned long)':
/home/dim/ubdsrv/qcow2/qcow2.h:1292: undefined reference to `slice_cache<Qcow2RefcountBlock>::__find_slice(unsigned long, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:600: ublk] Error 1
make[2]: Leaving directory '/home/dim/ubdsrv'
make[1]: *** [Makefile:829: all-recursive] Error 1
make[1]: Leaving directory '/home/dim/ubdsrv'
make: *** [Makefile:477: all] Error 2

Note: If I copy the body of __find_slice() (as defined in qcow2/qcow2.cpp), under the declaration of __find_slice() in qcow2/qcow2.h, the error is gone.

OK, I think the following patch should fix it:

diff --git a/qcow2/qcow2.cpp b/qcow2/qcow2.cpp
index 9f2645c..569dc6d 100644
--- a/qcow2/qcow2.cpp
+++ b/qcow2/qcow2.cpp
@@ -395,6 +395,11 @@ Qcow2ClusterAllocator::Qcow2ClusterAllocator(Qcow2State &qs): state(qs),
 	max_alloc_states = 0;
 };
 
+Qcow2RefcountBlock* Qcow2ClusterAllocator::__find_slice(u64 key)
+{
+	return cache.__find_slice(key, true);
+}
+
 int Qcow2ClusterAllocator::figure_group_from_refcount_table()
 {
 	int ret = cache.figure_group_for_flush(state);
@@ -642,6 +647,11 @@ Qcow2ClusterMapping::Qcow2ClusterMapping(Qcow2State &qs): state(qs),
 {
 }
 
+Qcow2L2Table* Qcow2ClusterMapping::__find_slice(u64 key, bool use_dirty)
+{
+	return cache.__find_slice(key, use_dirty);
+}
+
 int Qcow2ClusterMapping::figure_group_from_l1_table()
 {
 	int ret = cache.figure_group_for_flush(state);
diff --git a/qcow2/qcow2.h b/qcow2/qcow2.h
index affadb7..1ae259a 100644
--- a/qcow2/qcow2.h
+++ b/qcow2/qcow2.h
@@ -1177,9 +1177,7 @@ public:
 	u64 map_cluster(const qcow2_io_ctx_t &ioc, u64 offset, bool create_l2);
 	int figure_group_from_l1_table();
 
-	Qcow2L2Table* __find_slice(u64 key, bool use_dirty=true) {
-		return cache.__find_slice(key, use_dirty);
-	}
+	Qcow2L2Table* __find_slice(u64 key, bool use_dirty=true);
 
 	u64 l1_idx(u64 offset) {
 		return offset >> (cluster_bits + l2_entries_order);
@@ -1288,9 +1286,7 @@ public:
 	void dump_meta();
 	int figure_group_from_refcount_table();
 
-	Qcow2RefcountBlock* __find_slice(u64 key) {
-		return cache.__find_slice(key, true);
-	}
+	Qcow2RefcountBlock* __find_slice(u64 key);
 
 	bool has_evicted_dirty_slices()
 	{

Having said that, I just want to inform you that prior to this, I faced during make the 2 following errors:

1. Same as issue [[build error]gettimeofday is undefined #20](https://github.com/ming1/ubdsrv/issues/20).
   I solved it, by including the `<sys/time.h>` in `qcow2/qcow2.h`.

It is fixed yesterday.

2. Undefined reference to various pthread specific functions (`ptread_create(), pthread_join()` etc). I solved it, by appending the  `-pthread`  flag to CXXFLAGS in Makefile.

autoconf-archive package is required, or maybe we can simply add
-pthread in your way, care to send one PR?

Thanks,

from ublksrv.

DimitrisCharisis avatar DimitrisCharisis commented on August 24, 2024

OK, I think the following patch should fix it

Thank you for this. Yes, I applied it and it works. But it is really something that puzzles me.
I understand something must be different in the library versions that Debian ships, could you help me understand more about the fix, and how your original code may have been working on Fedora and not on Debian?
Also, let me note that I'm using g++ and gcc version 10(10.2.1-6)

autoconf-archive package is required

I have installed autoconf-archive during the initial process, before running autoreconf -i.
Because I encountered the following error:
configure.ac:31: error: The m4 macro AX_PTHREAD has not been defined. Please install the autoconf-archive package.

Thanks for your reply and the awesome work you have put into this project!

from ublksrv.

ming1 avatar ming1 commented on August 24, 2024

OK, I think the following patch should fix it

Thank you for this. Yes, I applied it and it works. But it is really something that puzzles me. I understand something must be different in the library versions that Debian ships, could you help me understand more about the fix, and how your original code may have been working on Fedora and not on Debian? Also, let me note that I'm using g++ and gcc version 10(10.2.1-6)

Sorry, I am not a gcc expert, but the preferred way is to not inline
the two functions, otherwise it is easier to trigger such kind of warning.

autoconf-archive package is required

I have installed autoconf-archive during the initial process, before running autoreconf -i. Because I encountered the following error: configure.ac:31: error: The m4 macro AX_PTHREAD has not been defined. Please install the autoconf-archive package.

OK, once autoconf-archive is installed, you need to re-run the whole
build steps again, please let me know if the build can succeed after
installing autoconf-archive and re-build.

Thanks,
Ming

from ublksrv.

DimitrisCharisis avatar DimitrisCharisis commented on August 24, 2024

OK, once autoconf-archive is installed, you need to re-run the whole build steps again, please let me know if the build can succeed after installing autoconf-archive and re-build.

If you're running a Debian-based distribution, like Debian 11 or Ubuntu focal, you need to install all necessary packages using APT:
sudo apt install autoconf autoconf-archive libtool pkg-config

These 4 packages required for autoreconf -i and ./configure.

Now, the only reason that breaks the building process is the absence of -pthread flag in CXXFLAGS.
The error:

libtool: link: g++ -fcoroutines -std=c++20 -g -O2 -o .libs/ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o ublk-tgt_qcow2.o ublk-qcow2.o ublk-qcow2_meta.o ublk-utils.o  lib/.libs/libublksrv.so -luring
/usr/bin/ld: ublk-ublksrv_tgt.o: in function `ublksrv_io_handler(void*)':
/home/dim/ubdsrv/ublksrv_tgt.cpp:236: undefined reference to `pthread_sigmask'
/usr/bin/ld: /home/dim/ubdsrv/ublksrv_tgt.cpp:287: undefined reference to `pthread_create'
/usr/bin/ld: /home/dim/ubdsrv/ublksrv_tgt.cpp:251: undefined reference to `pthread_join'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_init'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_unlock'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_lock'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_setaffinity_np'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:600: ublk] Error 1
make[2]: Leaving directory '/home/dim/ubdsrv'
make[1]: *** [Makefile:829: all-recursive] Error 1
make[1]: Leaving directory '/home/dim/ubdsrv'
make: *** [Makefile:477: all] Error 2

By appendig -pthread to CXXFLAGS in Makefile the building process succeeds!

from ublksrv.

ming1 avatar ming1 commented on August 24, 2024

OK, once autoconf-archive is installed, you need to re-run the whole build steps again, please let me know if the build can succeed after installing autoconf-archive and re-build.

If you're running a Debian-based distribution, like Debian 11 or Ubuntu focal, you need to install all necessary packages using APT: sudo apt install autoconf autoconf-archive libtool pkg-config

These 4 packages required for autoreconf -i and ./configure.

Now, the only reason that breaks the building process is the absence of -pthread flag in CXXFLAGS. The error:

libtool: link: g++ -fcoroutines -std=c++20 -g -O2 -o .libs/ublk ublk-ublksrv_tgt.o ublk-tgt_null.o ublk-tgt_loop.o ublk-tgt_qcow2.o ublk-qcow2.o ublk-qcow2_meta.o ublk-utils.o  lib/.libs/libublksrv.so -luring
/usr/bin/ld: ublk-ublksrv_tgt.o: in function `ublksrv_io_handler(void*)':
/home/dim/ubdsrv/ublksrv_tgt.cpp:236: undefined reference to `pthread_sigmask'
/usr/bin/ld: /home/dim/ubdsrv/ublksrv_tgt.cpp:287: undefined reference to `pthread_create'
/usr/bin/ld: /home/dim/ubdsrv/ublksrv_tgt.cpp:251: undefined reference to `pthread_join'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_init'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_unlock'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_spin_lock'
/usr/bin/ld: lib/.libs/libublksrv.so: undefined reference to `pthread_setaffinity_np'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:600: ublk] Error 1
make[2]: Leaving directory '/home/dim/ubdsrv'
make[1]: *** [Makefile:829: all-recursive] Error 1
make[1]: Leaving directory '/home/dim/ubdsrv'
make: *** [Makefile:477: all] Error 2

By appendig -pthread to CXXFLAGS in Makefile the building process succeeds!

But 'The m4 macro AX_PTHREAD' is supposed to be included in
autoconf-archive pacage.

I just tried ubuntu 22.04 VM built from cloud image, once the depended packages are installed, ublk can be built successfully.

Thanks,

from ublksrv.

ming1 avatar ming1 commented on August 24, 2024

Looks it is one ubuntu 20.04 specific issue, and it can be workaround
by:

./configure LDFLAGS="-lpthread"

Thanks,

from ublksrv.

ming1 avatar ming1 commented on August 24, 2024

Looks it is one ubuntu 20.04 specific issue, and it can be workaround by:

./configure LDFLAGS="-lpthread"

Thanks,

It looks like one bug on ubuntu 20.04, given ax_pthread m4 is really included by autoconf-archive:

root@ktest-20:~/git/ubdsrv# dpkg-query -L autoconf-archive | grep pthread
/usr/share/aclocal/ax_pthread.m4

from ublksrv.

ming1 avatar ming1 commented on August 24, 2024

Fixed by d6dd72f qcow2: don't inline __find_slice for both Qcow2ClusterAllocator and Qcow2ClusterMapping

from ublksrv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.