Commit bb37616b authored by Kirill Smelkov's avatar Kirill Smelkov

Merge branch 'master' into t

* master:
  wcfs: client: Adjust to be forward-compatible with upcoming pygolang changes
  wcfs: client: Adjust naming for os::File to match upcoming pygolang
parents 89bee96e 11e023cf
// Copyright (C) 2019-2021 Nexedi SA and Contributors.
// Copyright (C) 2019-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -27,6 +27,8 @@
#include "bigfile/_file_zodb.h"
#include <ccan/container_of/container_of.h>
using namespace xgolang;
static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
_ZBigFile* _zfile = container_of(file, _ZBigFile, __pyx_base.file);
......@@ -39,7 +41,7 @@ static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blkl
tie(mmap, err) = fileh->mmap(blk, blklen, vma);
if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1;
}
......@@ -56,7 +58,7 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
error err;
err = mmap->remmap_blk(blk);
if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1;
}
......@@ -74,7 +76,7 @@ static int zfile_munmap(VMA *vma, BigFile *file) {
error err;
err = mmap->unmap();
if (err != nil) {
log::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
xlog::Errorf("%s", v(err)); // XXX no way to return error details to virtmem
return -1;
}
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -229,7 +229,7 @@ using std::min;
using std::max;
using std::vector;
namespace ioutil = io::ioutil;
namespace ioutil = xgolang::io::ioutil;
#define TRACE 0
......@@ -755,7 +755,7 @@ error _Conn::resync(zodb::Tid at) {
// update f._headfsize and remmap to head/f zero regions that are now covered by head/f
struct stat st;
err = f->_headf->stat(&st);
err = f->_headf->Stat(&st);
if (err != nil)
return E(err);
......@@ -956,18 +956,18 @@ error _FileH::_open() {
bool retok = false;
defer([&]() {
if (!retok)
f._headf->close();
f._headf->Close();
});
struct stat st;
err = f._headf->stat(&st);
err = f._headf->Stat(&st);
if (err != nil)
return err;
f.blksize = st.st_blksize;
f._headfsize = st.st_size;
if (!(f._headfsize % f.blksize == 0))
return fmt::errorf("wcfs bug: %s size (%d) %% blksize (%d) != 0",
v(f._headf->name()), f._headfsize, f.blksize);
v(f._headf->Name()), f._headfsize, f.blksize);
// start watching f
// NOTE we are _not_ holding wconn.filehMu nor f.mmapMu - only wconn.atMu to rely on wconn.at being stable.
......@@ -1066,7 +1066,7 @@ error _FileH::_closeLocked(bool force) {
panic("BUG: fileh.close: wconn.filehTab[fileh.foid] != fileh");
wconn->_filehTab.erase(fileh.foid);
reterr1(fileh._headf->close());
reterr1(fileh._headf->Close());
// change all fileh.mmaps to cause EFAULT on any access after fileh.close
fileh._mmapMu.lock();
......@@ -1110,7 +1110,7 @@ void _FileH::_afterFork() {
panic("BUG: fileh.closeAfterFork: wconn.filehTab[fileh.foid] != fileh");
wconn->_filehTab.erase(fileh.foid);
fileh._headf->close(); // ignore err
fileh._headf->Close(); // ignore err
// change all fileh.mmaps to cause EFAULT on access
for (auto mmap : fileh._mmaps) {
......@@ -1343,11 +1343,11 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
}
defer([&]() {
if (fclose)
fsfile->close();
fsfile->Close();
});
struct stat st;
err = fsfile->stat(&st);
err = fsfile->Stat(&st);
if (err != nil)
return E(err);
if ((size_t)st.st_blksize != f->blksize)
......@@ -1426,7 +1426,7 @@ string WCFS::_path(const string &obj) {
tuple<os::File, error> WCFS::_open(const string &path, int flags) {
WCFS& wc = *this;
string path_ = wc._path(path);
return os::open(path_, flags);
return os::Open(path_, flags);
}
......@@ -1441,11 +1441,11 @@ static error mmap_zero_into(void *addr, size_t size, int prot) {
// this way the mapping will be able to be read, but no memory will be allocated to keep it.
os::File z;
error err;
tie(z, err) = os::open("/dev/zero");
tie(z, err) = os::Open("/dev/zero");
if (err != nil)
return E(err);
defer([&]() {
z->close();
z->Close();
});
err = mm::map_into(addr, size, prot, MAP_SHARED | MAP_NORESERVE, z, 0);
if (err != nil)
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -118,6 +118,10 @@ struct VMA;
namespace wcfs {
using namespace golang;
namespace os = xgolang::xos;
namespace mm = xgolang::xmm;
namespace xstrconv = xgolang::xstrconv;
namespace log = xgolang::xlog;
using cxx::dict;
using cxx::set;
using std::tuple;
......
// Copyright (C) 2019-2021 Nexedi SA and Contributors.
// Copyright (C) 2019-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -36,11 +36,13 @@ using namespace golang;
#include <algorithm>
#include <memory>
// golang::
namespace golang {
// xgolang::
namespace xgolang {
// os::
namespace os {
// xos::
namespace xos {
namespace io = golang::io;
global<error> ErrClosed = errors::New("file already closed");
......@@ -49,8 +51,8 @@ global<error> ErrClosed = errors::New("file already closed");
static error _pathError(const char *op, const string &path, int syserr);
static string _sysErrString(int syserr);
int _File::fd() const { return _fd; }
string _File::name() const { return _path; }
int _File::_sysfd() const { return _fd; }
string _File::Name() const { return _path; }
_File::_File() {}
_File::~_File() {}
......@@ -60,7 +62,7 @@ void _File::decref() {
}
tuple<File, error> open(const string &path, int flags, mode_t mode) {
tuple<File, error> Open(const string &path, int flags, mode_t mode) {
int fd = ::open(path.c_str(), flags, mode);
if (fd == -1)
return make_tuple(nil, _pathError("open", path, errno));
......@@ -71,7 +73,7 @@ tuple<File, error> open(const string &path, int flags, mode_t mode) {
return make_tuple(f, nil);
}
error _File::close() {
error _File::Close() {
_File& f = *this;
int err = ::close(f._fd);
......@@ -81,7 +83,7 @@ error _File::close() {
return nil;
}
tuple<int, error> _File::read(void *buf, size_t count) {
tuple<int, error> _File::Read(void *buf, size_t count) {
_File& f = *this;
int n;
......@@ -94,7 +96,7 @@ tuple<int, error> _File::read(void *buf, size_t count) {
return make_tuple(n, nil);
}
tuple <int, error> _File::write(const void *buf, size_t count) {
tuple <int, error> _File::Write(const void *buf, size_t count) {
_File& f = *this;
int n, wrote=0;
......@@ -112,7 +114,7 @@ tuple <int, error> _File::write(const void *buf, size_t count) {
return make_tuple(wrote, nil);
}
error _File::stat(struct stat *st) {
error _File::Stat(struct stat *st) {
_File& f = *this;
int err = fstat(f._fd, st);
......@@ -196,24 +198,24 @@ static string _sysErrString(int syserr) {
return string(estr);
}
} // os::
} // xos::
// mm::
namespace mm {
// xmm::
namespace xmm {
// map memory-maps f.fd[offset +size) somewhere into memory.
// prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED must not be used.
tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t size) {
tuple<uint8_t*, error> map(int prot, int flags, xos::File f, off_t offset, size_t size) {
void *addr;
if (flags & MAP_FIXED)
panic("MAP_FIXED not allowed for map - use map_into");
addr = ::mmap(nil, size, prot, flags, f->fd(), offset);
addr = ::mmap(nil, size, prot, flags, f->_sysfd(), offset);
if (addr == MAP_FAILED)
return make_tuple(nil, os::_pathError("mmap", f->name(), errno));
return make_tuple(nil, xos::_pathError("mmap", f->Name(), errno));
return make_tuple((uint8_t*)addr, nil);
}
......@@ -221,12 +223,12 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t
// map_into memory-maps f.fd[offset +size) into [addr +size).
// prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED is added automatically.
error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t offset) {
error map_into(void *addr, size_t size, int prot, int flags, xos::File f, off_t offset) {
void *addr2;
addr2 = ::mmap(addr, size, prot, MAP_FIXED | flags, f->fd(), offset);
addr2 = ::mmap(addr, size, prot, MAP_FIXED | flags, f->_sysfd(), offset);
if (addr2 == MAP_FAILED)
return os::_pathError("mmap", f->name(), errno);
return xos::_pathError("mmap", f->Name(), errno);
if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr");
return nil;
......@@ -236,11 +238,11 @@ error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t o
error unmap(void *addr, size_t size) {
int err = ::munmap(addr, size);
if (err != 0)
return os::_pathError("munmap", "<memory>", errno);
return xos::_pathError("munmap", "<memory>", errno);
return nil;
}
} // mm::
} // xmm::
// io::ioutil::
......@@ -249,10 +251,10 @@ namespace ioutil {
tuple<string, error> ReadFile(const string& path) {
// errctx is ok as returned by all calls.
os::File f;
error err;
xos::File f;
error err;
tie(f, err) = os::open(path);
tie(f, err) = xos::Open(path);
if (err != nil)
return make_tuple("", err);
......@@ -261,16 +263,16 @@ tuple<string, error> ReadFile(const string& path) {
while (1) {
int n;
tie(n, err) = f->read(&buf[0], buf.size());
tie(n, err) = f->Read(&buf[0], buf.size());
data.append(&buf[0], n);
if (err != nil) {
if (err == io::EOF_)
if (err == golang::io::EOF_)
err = nil;
break;
}
}
error err2 = f->close();
error err2 = f->Close();
if (err == nil)
err = err2;
if (err != nil)
......@@ -318,7 +320,7 @@ tuple<uint64_t, error> parseUint(const string& s) {
} // xstrconv::
} // golang::
} // xgolang::
// xerr::
......@@ -354,9 +356,9 @@ error Contextf::operator() (error err) const {
#include <sys/types.h>
#include <sys/syscall.h>
// golang::log::
namespace golang {
namespace log {
// xgolang::xlog::
namespace xgolang {
namespace xlog {
void __Logf(const char *file, int line, char level, const char *format, ...) {
double t = time::now();
......@@ -385,7 +387,7 @@ void __Logf(const char *file, int line, char level, const char *format, ...) {
funlockfile(stderr);
}
}} // golang::log::
}} // xgolang::xlog::
// wcfs::
......
// Copyright (C) 2019-2021 Nexedi SA and Contributors.
// Copyright (C) 2019-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -55,11 +55,11 @@ using std::vector;
#include <sys/stat.h>
#include <fcntl.h>
// golang::
namespace golang {
// xgolang::
namespace xgolang {
// os::
namespace os {
// xos::
namespace xos {
extern global<error> ErrClosed;
......@@ -75,34 +75,34 @@ class _File : public object {
private:
_File();
~_File();
friend tuple<File, error> open(const string &path, int flags, mode_t mode);
friend tuple<File, error> Open(const string &path, int flags, mode_t mode);
public:
void decref();
public:
int fd() const;
string name() const;
error close();
int _sysfd() const;
string Name() const;
error Close();
// read implements io.Reader from Go: it reads into buf up-to count bytes.
// XXX buf -> slice<byte> ?
tuple<int, error> read(void *buf, size_t count);
tuple<int, error> Read(void *buf, size_t count);
// write implements io.Writer from Go: it writes all data from buf.
//
// NOTE write behaves like io.Writer in Go - it tries to write as much
// bytes as requested, and if it could write only less - it returns error.
// XXX buf -> slice<byte> ?
tuple<int, error> write(const void *buf, size_t count);
tuple<int, error> Write(const void *buf, size_t count);
error stat(struct stat *st);
error Stat(struct stat *st);
private:
error _errno(const char *op);
};
// open opens file @path.
tuple<File, error> open(const string &path, int flags = O_RDONLY,
// Open opens file @path.
tuple<File, error> Open(const string &path, int flags = O_RDONLY,
mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH);
......@@ -126,15 +126,15 @@ void RegisterAfterFork(IAfterFork obj);
// It is noop if obj was not registered.
void UnregisterAfterFork(IAfterFork obj);
} // os::
} // xos::
// mm::
namespace mm {
tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t size);
error map_into(void *addr, size_t size, int prot, int flags, os::File f, off_t offset);
// xmm::
namespace xmm {
tuple<uint8_t*, error> map(int prot, int flags, xos::File f, off_t offset, size_t size);
error map_into(void *addr, size_t size, int prot, int flags, xos::File f, off_t offset);
error unmap(void *addr, size_t size);
} // mm::
} // xmm::
// io::ioutil::
......@@ -157,8 +157,8 @@ tuple<uint64_t, error> parseUint(const string& s);
} // xstrconv::
// log::
namespace log {
// xlog::
namespace xlog {
#define Debugf(format, ...) __Logf(__FILE__, __LINE__, 'D', format, ##__VA_ARGS__)
#define Infof(format, ...) __Logf(__FILE__, __LINE__, 'I', format, ##__VA_ARGS__)
......@@ -167,9 +167,9 @@ namespace log {
#define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__)
void __Logf(const char *file, int line, char level, const char *format, ...);
} // log::
} // xlog::
} // golang::
} // xgolang::
// zodb::
......
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Copyright (C) 2018-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -94,7 +94,7 @@ error _WatchLink::close() {
errors::Is(err2, ErrLinkDown)) // link shutdown due to logic error; details logged
err2 = nil;
error err3 = wlink._f->close();
error err3 = wlink._f->Close();
if (err == nil)
err = err2;
if (err == nil)
......@@ -115,7 +115,7 @@ void _WatchLink::afterFork() {
// _serveRX is not running. Just release the file handle, that fork
// duplicated, to make sure that child cannot send anything to wcfs and
// interfere into parent-wcfs exchange.
wlink._f->close(); // ignore err
wlink._f->Close(); // ignore err
}
// closeWrite closes send half of the link.
......@@ -386,7 +386,7 @@ error _WatchLink::_write(const string &pkt) {
int n;
error err;
tie(n, err) = wlink._f->write(pkt.c_str(), pkt.size());
tie(n, err) = wlink._f->Write(pkt.c_str(), pkt.size());
return err;
}
......@@ -454,7 +454,7 @@ tuple<string, error> _WatchLink::_readline() {
int n;
error err;
tie(n, err) = wlink._f->read(buf, sizeof(buf));
tie(n, err) = wlink._f->Read(buf, sizeof(buf));
if (n > 0) {
wlink._rxbuf += string(buf, n);
continue;
......@@ -515,12 +515,12 @@ void _WatchLink::decref() {
string _WatchLink::String() const {
const _WatchLink& wlink = *this;
// XXX don't include wcfs as prefix here? (see Conn.String for details)
return fmt::sprintf("%s: wlink%d", v(wlink._wc), wlink._f->fd());
return fmt::sprintf("%s: wlink%d", v(wlink._wc), wlink._f->_sysfd());
}
int _WatchLink::fd() const {
const _WatchLink& wlink = *this;
return wlink._f->fd();
return wlink._f->_sysfd();
}
// _nextReqID returns stream ID for next client-originating request to be made.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment