Skip to content

Commit 557ad66

Browse files
committed
mpd: add libnfs 6+ build patch
upstream commit ref, MusicPlayerDaemon/MPD@31e583e Signed-off-by: Rui Chen <[email protected]>
1 parent 6f215cf commit 557ad66

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed

mpd/0.23.16-libnfs-6.patch

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx
2+
index fd73338..bfd675d 100644
3+
--- a/src/lib/nfs/Connection.cxx
4+
+++ b/src/lib/nfs/Connection.cxx
5+
@@ -103,14 +103,28 @@ NfsConnection::CancellableCallback::Stat(nfs_context *ctx,
6+
7+
inline void
8+
NfsConnection::CancellableCallback::Read(nfs_context *ctx, struct nfsfh *fh,
9+
- uint64_t offset, size_t size)
10+
+ uint64_t offset,
11+
+#ifdef LIBNFS_API_2
12+
+ std::span<std::byte> dest
13+
+#else
14+
+ std::size_t size
15+
+#endif
16+
+ )
17+
{
18+
- assert(connection.GetEventLoop().IsInside());
19+
+ assert(connection.GetEventLoop().IsInside());
20+
21+
- int result = nfs_pread_async(ctx, fh, offset, size, Callback, this);
22+
- if (result < 0)
23+
- throw FormatRuntimeError("nfs_pread_async() failed: %s",
24+
- nfs_get_error(ctx));
25+
+ int result = nfs_pread_async(ctx, fh,
26+
+#ifdef LIBNFS_API_2
27+
+ dest.data(), dest.size(),
28+
+#endif
29+
+ offset,
30+
+#ifndef LIBNFS_API_2
31+
+ size,
32+
+#endif
33+
+ Callback, this);
34+
+
35+
+ if (result < 0)
36+
+ throw NfsClientError(ctx, "nfs_pread_async() failed");
37+
}
38+
39+
inline void
40+
@@ -329,7 +343,12 @@ NfsConnection::Stat(struct nfsfh *fh, NfsCallback &callback)
41+
}
42+
43+
void
44+
-NfsConnection::Read(struct nfsfh *fh, uint64_t offset, size_t size,
45+
+NfsConnection::Read(struct nfsfh *fh, uint64_t offset,
46+
+#ifdef LIBNFS_API_2
47+
+ std::span<std::byte> dest,
48+
+#else
49+
+ std::size_t size,
50+
+#endif
51+
NfsCallback &callback)
52+
{
53+
assert(GetEventLoop().IsInside());
54+
@@ -337,7 +356,13 @@ NfsConnection::Read(struct nfsfh *fh, uint64_t offset, size_t size,
55+
56+
auto &c = callbacks.Add(callback, *this, false);
57+
try {
58+
- c.Read(context, fh, offset, size);
59+
+ c.Read(context, fh, offset,
60+
+#ifdef LIBNFS_API_2
61+
+ dest
62+
+#else
63+
+ size
64+
+#endif
65+
+ );
66+
} catch (...) {
67+
callbacks.Remove(c);
68+
throw;
69+
diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx
70+
index 49987e2..a5d7fa0 100644
71+
--- a/src/lib/nfs/Connection.hxx
72+
+++ b/src/lib/nfs/Connection.hxx
73+
@@ -29,6 +29,7 @@
74+
#include <list>
75+
#include <forward_list>
76+
#include <exception>
77+
+#include <span>
78+
79+
struct nfs_context;
80+
struct nfsdir;
81+
@@ -71,7 +72,13 @@ class NfsConnection {
82+
void Open(nfs_context *context, const char *path, int flags);
83+
void Stat(nfs_context *context, struct nfsfh *fh);
84+
void Read(nfs_context *context, struct nfsfh *fh,
85+
- uint64_t offset, size_t size);
86+
+ uint64_t offset,
87+
+#ifdef LIBNFS_API_2
88+
+ std::span<std::byte> dest
89+
+#else
90+
+ std::size_t size
91+
+#endif
92+
+ );
93+
94+
/**
95+
* Cancel the operation and schedule a call to
96+
@@ -193,7 +200,12 @@ public:
97+
/**
98+
* Throws std::runtime_error on error.
99+
*/
100+
- void Read(struct nfsfh *fh, uint64_t offset, size_t size,
101+
+ void Read(struct nfsfh *fh, uint64_t offset,
102+
+#ifdef LIBNFS_API_2
103+
+ std::span<std::byte> dest,
104+
+#else
105+
+ std::size_t size,
106+
+#endif
107+
NfsCallback &callback);
108+
109+
void Cancel(NfsCallback &callback) noexcept;
110+
diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx
111+
index 6e9457d..8de9801 100644
112+
--- a/src/lib/nfs/FileReader.cxx
113+
+++ b/src/lib/nfs/FileReader.cxx
114+
@@ -129,7 +129,15 @@ NfsFileReader::Read(uint64_t offset, size_t size)
115+
{
116+
assert(state == State::IDLE);
117+
118+
+#ifdef LIBNFS_API_2
119+
+ assert(!read_buffer);
120+
+ // TOOD read into caller-provided buffer
121+
+ read_buffer = std::make_unique<std::byte[]>(size);
122+
+ connection->Read(fh, offset, {read_buffer.get(), size}, *this);
123+
+#else
124+
connection->Read(fh, offset, size, *this);
125+
+#endif
126+
+
127+
state = State::READ;
128+
}
129+
130+
diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx
131+
index 8d257ef..939d53d 100644
132+
--- a/src/lib/nfs/FileReader.hxx
133+
+++ b/src/lib/nfs/FileReader.hxx
134+
@@ -30,6 +30,10 @@
135+
#include <exception>
136+
#include <string>
137+
138+
+#ifdef LIBNFS_API_2
139+
+#include <memory>
140+
+#endif
141+
+
142+
#include <sys/stat.h>
143+
144+
struct nfsfh;
145+
@@ -68,6 +72,10 @@ class NfsFileReader : NfsLease, NfsCallback {
146+
*/
147+
InjectEvent defer_open;
148+
149+
+#ifdef LIBNFS_API_2
150+
+ std::unique_ptr<std::byte[]> read_buffer;
151+
+#endif
152+
+
153+
public:
154+
NfsFileReader() noexcept;
155+
~NfsFileReader() noexcept;
156+
diff --git a/src/lib/nfs/meson.build b/src/lib/nfs/meson.build
157+
index 467da59..74d82cd 100644
158+
--- a/src/lib/nfs/meson.build
159+
+++ b/src/lib/nfs/meson.build
160+
@@ -4,6 +4,13 @@ if not nfs_dep.found()
161+
subdir_done()
162+
endif
163+
164+
+if nfs_dep.version().version_compare('>=6')
165+
+ # libnfs has no version macro therefore we must detect the API
166+
+ # version 2 at configure time
167+
+ nfs_dep = declare_dependency(compile_args: '-DLIBNFS_API_2',
168+
+ dependencies: nfs_dep)
169+
+endif
170+
+
171+
nfs = static_library(
172+
'nfs',
173+
'Connection.cxx',

0 commit comments

Comments
 (0)