Commit 493ac6ce authored by Kirill Smelkov's avatar Kirill Smelkov

wcfs: client: Adjust naming for os::File to match upcoming pygolang

See pygolang!17
parent 38dde766
// 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
......@@ -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) 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
......@@ -49,8 +49,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 +60,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 +71,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 +81,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 +94,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 +112,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);
......@@ -211,9 +211,9 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t
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, os::_pathError("mmap", f->Name(), errno));
return make_tuple((uint8_t*)addr, nil);
}
......@@ -224,9 +224,9 @@ tuple<uint8_t*, error> map(int prot, int flags, os::File f, off_t offset, size_t
error map_into(void *addr, size_t size, int prot, int flags, os::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 os::_pathError("mmap", f->Name(), errno);
if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr");
return nil;
......@@ -252,7 +252,7 @@ tuple<string, error> ReadFile(const string& path) {
os::File f;
error err;
tie(f, err) = os::open(path);
tie(f, err) = os::Open(path);
if (err != nil)
return make_tuple("", err);
......@@ -261,7 +261,7 @@ 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_)
......@@ -270,7 +270,7 @@ tuple<string, error> ReadFile(const string& path) {
}
}
error err2 = f->close();
error err2 = f->Close();
if (err == nil)
err = err2;
if (err != nil)
......
// 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
......@@ -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);
......
// 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