summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-04-19 00:34:07 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-04-19 00:34:07 +0100
commit9c434e791e3982386d601c5cf4c9407ec6841f79 (patch)
tree2a5f5731a633b2716756df101b0d241b2b5c1cf6
parentMove construct ReqEnv from mapper values (diff)
downloadnetfs-9c434e791e3982386d601c5cf4c9407ec6841f79.tar.bz2
netfs-9c434e791e3982386d601c5cf4c9407ec6841f79.tar.xz
netfs-9c434e791e3982386d601c5cf4c9407ec6841f79.zip
Use cpp:array on write data, prevents copying
-rw-r--r--netfs/daemon/daemonFile.cpp8
-rw-r--r--netfs/daemon/daemonFile.h3
-rw-r--r--netfs/fuse/fuseFiles.cpp7
-rw-r--r--netfs/ice/file.ice2
4 files changed, 12 insertions, 8 deletions
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp
index 7b2dd8e..d9f5105 100644
--- a/netfs/daemon/daemonFile.cpp
+++ b/netfs/daemon/daemonFile.cpp
@@ -59,10 +59,11 @@ FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current &)
}
void
-FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current &)
+FileServer::write(Ice::Long offset, Ice::Long size, const ::std::pair<const ::Ice::Byte *, const ::Ice::Byte *> data,
+ const Ice::Current &)
{
errno = 0;
- if (pwrite(fd, &data.front(), safe {size}, offset) != size) {
+ if (pwrite(fd, data.first, safe {size}, offset) != size) {
throw NetFS::SystemError(errno);
}
}
@@ -80,7 +81,8 @@ FileServer::copyrange(NetFS::FilePrxPtr to, Ice::Long offsrc, Ice::Long offdst,
throw NetFS::SystemError(errno);
}
else {
- to->write(offdst, size, read(offsrc, size, ice));
+ const auto bytes = read(offsrc, size, ice);
+ to->write(offdst, size, {bytes.data(), bytes.data() + size});
return size;
}
}
diff --git a/netfs/daemon/daemonFile.h b/netfs/daemon/daemonFile.h
index 2da4c6f..e1c6c06 100644
--- a/netfs/daemon/daemonFile.h
+++ b/netfs/daemon/daemonFile.h
@@ -12,7 +12,8 @@ public:
NetFS::Attr fgetattr(const NetFS::ReqEnv, const Ice::Current &) override;
NetFS::Buffer read(Ice::Long offset, Ice::Long size, const Ice::Current &) override;
- void write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current &) override;
+ void write(Ice::Long offset, Ice::Long size, const ::std::pair<const ::Ice::Byte *, const ::Ice::Byte *> data,
+ const Ice::Current &) override;
Ice::Long copyrange(NetFS::FilePrxPtr, Ice::Long, Ice::Long, Ice::Long, Ice::Int, const Ice::Current &) override;
private:
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index 9f7bf5e..6b1ad1a 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -171,11 +171,12 @@ namespace NetFS {
try {
auto of = getProxy<OpenFilePtr>(fi->fh);
auto remote = of->remote;
+ auto bytes = reinterpret_cast<const ::Ice::Byte *>(buf);
if (fcr->Async) {
- waitOnWriteRangeAndThen<void>(s, o, of, [o, s, buf, &of, remote](const auto & key) {
+ waitOnWriteRangeAndThen<void>(s, o, of, [o, s, bytes, &of, remote](const auto & key) {
auto p = std::make_shared<OpenFile::WriteState>();
remote->writeAsync(
- o, safe {s}, Buffer(buf, buf + s),
+ o, safe {s}, std::make_pair(bytes, bytes + s),
[p, of, key]() {
p->promise.set_value();
ScopeLock(of->mutex) {
@@ -192,7 +193,7 @@ namespace NetFS {
});
}
else {
- remote->write(o, safe {s}, Buffer(buf, buf + s));
+ remote->write(o, safe {s}, std::make_pair(bytes, bytes + s));
}
return safe {s};
}
diff --git a/netfs/ice/file.ice b/netfs/ice/file.ice
index fba14df..45241f9 100644
--- a/netfs/ice/file.ice
+++ b/netfs/ice/file.ice
@@ -10,7 +10,7 @@ module NetFS {
idempotent Attr fgetattr(ReqEnv env) throws AuthError, SystemError;
idempotent Buffer read(long offset, long size) throws AuthError, SystemError;
idempotent void ftruncate(ReqEnv env, long size) throws AuthError, SystemError;
- idempotent void write(long offset, long size, Buffer data) throws AuthError, SystemError;
+ idempotent void write(long offset, long size, ["cpp:array"] Buffer data) throws AuthError, SystemError;
idempotent long copyrange(File * to, long offsetsrc, long offsetdest, long size, int flags) throws AuthError, SystemError;
};
};