From 4cd9f97f851355c90a84c56bd3abbe2c9ab03a39 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 6 Oct 2010 19:12:24 +0000 Subject: Commit more work to date --- netfs/Jamfile.jam | 1 + netfs/daemon.cpp | 8 ++++---- netfs/daemon.h | 4 ++-- netfs/daemonConfig.h | 24 +++++++++++++----------- netfs/daemonDirs.cpp | 7 +++++-- netfs/daemonDirs.h | 10 +++++++++- netfs/daemonFiles.cpp | 35 +++++++++++++++++++++++++++++++++-- netfs/daemonFiles.h | 10 +++++++++- netfs/daemonMisc.cpp | 32 +++++--------------------------- netfs/daemonMisc.h | 6 ++++-- netfs/daemonModule.cpp | 6 ++++++ netfs/daemonModule.h | 12 ++++++++++++ netfs/daemonSystem.cpp | 5 +++++ netfs/daemonSystem.h | 5 ++++- netfs/fuseFiles.cpp | 25 +++++++++++++++++++++++++ netfs/fuseMisc.cpp | 25 ------------------------- netfs/netfsComms.ice | 2 +- 17 files changed, 138 insertions(+), 79 deletions(-) create mode 100644 netfs/daemonModule.cpp create mode 100644 netfs/daemonModule.h diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 2e688cc..33f1ecd 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -100,5 +100,6 @@ exe netfsd : common common boost_regex + boost_filesystem Ice ; diff --git a/netfs/daemon.cpp b/netfs/daemon.cpp index 314479a..65388e5 100644 --- a/netfs/daemon.cpp +++ b/netfs/daemon.cpp @@ -15,10 +15,10 @@ int main(int argc, char* argv[]) try { ic = Ice::initialize(argc, argv); Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("NetFSDaemonAdapter", "default -p 10000"); - adapter->add(new FileServer(), ic->stringToIdentity("Files")); - adapter->add(new DirsServer(), ic->stringToIdentity("Dirs")); - adapter->add(new MiscServer(), ic->stringToIdentity("Misc")); - adapter->add(new SystemServer(), ic->stringToIdentity("System")); + adapter->add(new FileServer(dgs), ic->stringToIdentity("Files")); + adapter->add(new DirsServer(dgs), ic->stringToIdentity("Dirs")); + adapter->add(new MiscServer(dgs), ic->stringToIdentity("Misc")); + adapter->add(new SystemServer(dgs), ic->stringToIdentity("System")); adapter->activate(); ic->waitForShutdown(); } diff --git a/netfs/daemon.h b/netfs/daemon.h index a34c586..7dd6d63 100644 --- a/netfs/daemon.h +++ b/netfs/daemon.h @@ -3,7 +3,7 @@ #include "daemonConfig.h" -class DaemonGlobalState : public IsRefCounted { +class DaemonGlobalState : public IntrusivePtrBase { public: DaemonGlobalState(DaemonConfigPtr c) : config(c) @@ -12,7 +12,7 @@ class DaemonGlobalState : public IsRefCounted { const DaemonConfigPtr config; }; -typedef SmartPointer DaemonGlobalStatePtr; +typedef boost::intrusive_ptr DaemonGlobalStatePtr; #endif diff --git a/netfs/daemonConfig.h b/netfs/daemonConfig.h index 223436c..a27f686 100644 --- a/netfs/daemonConfig.h +++ b/netfs/daemonConfig.h @@ -4,12 +4,14 @@ #include #include #include -#include "smartpointer.h" +#include +#include +#include #include "xml.h" -class DaemonConfig : public virtual IsRefCounted { +class DaemonConfig : public virtual IntrusivePtrBase { public: - class Host : public virtual IsRefCounted { + class Host : public virtual IntrusivePtrBase { public: Host(xmlNodePtr); @@ -17,30 +19,30 @@ class DaemonConfig : public virtual IsRefCounted { std::string name; bool self; }; - typedef SmartPointer HostPtr; + typedef boost::intrusive_ptr HostPtr; typedef std::map HostMap; typedef std::set HostSet; - class Export : public virtual IsRefCounted { + class Export : public virtual IntrusivePtrBase { public: Export(xmlNodePtr, const HostMap &); - std::string root; - std::string name; - HostSet replicate; + boost::filesystem::path root; + std::string name; + HostSet replicate; }; - typedef SmartPointer ExportPtr; + typedef boost::intrusive_ptr ExportPtr; typedef std::map ExportMap; DaemonConfig(xmlNodePtr); - static SmartPointer Load(const char * path); + static boost::intrusive_ptr Load(const char * path); ExportMap exports; HostMap hosts; HostPtr self; }; -typedef SmartPointer DaemonConfigPtr; +typedef boost::intrusive_ptr DaemonConfigPtr; #endif diff --git a/netfs/daemonDirs.cpp b/netfs/daemonDirs.cpp index 75ce7c9..3833e8c 100644 --- a/netfs/daemonDirs.cpp +++ b/netfs/daemonDirs.cpp @@ -5,8 +5,11 @@ #include #include "daemonDirs.h" -int dirNo = 0; -std::map dirs; +DirsServer::DirsServer(DaemonGlobalStatePtr dgs) : + DaemonModule(dgs), + dirNo(0) +{ +} Ice::Int DirsServer::opendir(const std::string & path, const Ice::Current&) diff --git a/netfs/daemonDirs.h b/netfs/daemonDirs.h index 8073583..dfd04fb 100644 --- a/netfs/daemonDirs.h +++ b/netfs/daemonDirs.h @@ -2,15 +2,23 @@ #define DAEMONDIRS_H #include "netfsComms.h" +#include "daemonModule.h" +#include -class DirsServer : public NetFSComms::Dirs { +class DirsServer : public DaemonModule, public NetFSComms::Dirs { public: + DirsServer(DaemonGlobalStatePtr dgs); + virtual Ice::Int opendir(const std::string & path, const Ice::Current&); virtual void closedir(Ice::Int id, const Ice::Current&); virtual NetFSComms::NameList readdir(Ice::Int id, const Ice::Current&); virtual void mkdir(const std::string & path, Ice::Int id, const Ice::Current&); virtual void rmdir(const std::string & path, const Ice::Current&); + + private: + int dirNo; + std::map dirs; }; #endif diff --git a/netfs/daemonFiles.cpp b/netfs/daemonFiles.cpp index 31a48cf..f447a20 100644 --- a/netfs/daemonFiles.cpp +++ b/netfs/daemonFiles.cpp @@ -1,10 +1,14 @@ #include #include #include +#include #include "daemonFiles.h" -int fileNo = 0; -std::map files; +FileServer::FileServer(DaemonGlobalStatePtr dgs) : + DaemonModule(dgs), + fileNo(0) +{ +} void FileServer::truncate(const std::string & path, Ice::Long size, const Ice::Current&) @@ -29,6 +33,33 @@ FileServer::ftruncate(Ice::Int id, Ice::Long size, const Ice::Current&) // s.replicatedRequest = true; } +NetFSComms::Attr +FileServer::fgetattr(Ice::Int id, const Ice::Current &) +{ + if (files.find(id) == files.end()) { + throw NetFSComms::SystemError(EBADF); + } + struct stat s; + if (::fstat(files[id], &s) != 0) { + throw NetFSComms::SystemError(errno); + } + NetFSComms::Attr a; + a.dev = s.st_dev; + a.inode = s.st_ino; + a.mode = s.st_mode; + a.links = s.st_nlink; + a.uid = s.st_uid; + a.gid = s.st_gid; + a.rdev = s.st_rdev; + a.size = s.st_size; + a.blockSize = s.st_blksize; + a.blocks = s.st_blocks; + a.atime = s.st_atime; + a.mtime = s.st_mtime; + a.ctime = s.st_ctime; + return a; +} + void FileServer::unlink(const std::string & path, const Ice::Current&) { diff --git a/netfs/daemonFiles.h b/netfs/daemonFiles.h index be24586..1ba844c 100644 --- a/netfs/daemonFiles.h +++ b/netfs/daemonFiles.h @@ -2,11 +2,15 @@ #define DAEMONFILES_H #include "netfsComms.h" +#include "daemonModule.h" -class FileServer : public NetFSComms::Files { +class FileServer : public DaemonModule, public NetFSComms::Files { public: + FileServer(DaemonGlobalStatePtr dgs); + virtual void truncate(const std::string & path, Ice::Long size, const Ice::Current&); virtual void ftruncate(Ice::Int id, Ice::Long size, const Ice::Current&); + virtual NetFSComms::Attr fgetattr(Ice::Int id, const Ice::Current&); virtual void unlink(const std::string & path, const Ice::Current&); @@ -15,6 +19,10 @@ class FileServer : public NetFSComms::Files { virtual void close(Ice::Int id, const Ice::Current&); virtual NetFSComms::Buffer read(Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Current&); virtual void write(Ice::Int id, Ice::Long offset, Ice::Long size, const NetFSComms::Buffer & data, const Ice::Current&); + + private: + int fileNo; + std::map files; }; #endif diff --git a/netfs/daemonMisc.cpp b/netfs/daemonMisc.cpp index 5a30e31..9327fad 100644 --- a/netfs/daemonMisc.cpp +++ b/netfs/daemonMisc.cpp @@ -7,6 +7,11 @@ extern std::map files; +MiscServer::MiscServer(DaemonGlobalStatePtr dgs) : + DaemonModule(dgs) +{ +} + Ice::Int MiscServer::access(const std::string & path, Ice::Int mode, const Ice::Current &) { @@ -37,33 +42,6 @@ MiscServer::getattr(const std::string & path, const Ice::Current &) return a; } -NetFSComms::Attr -MiscServer::fgetattr(Ice::Int id, const Ice::Current &) -{ - if (files.find(id) == files.end()) { - throw NetFSComms::SystemError(EBADF); - } - struct stat s; - if (::fstat(files[id], &s) != 0) { - throw NetFSComms::SystemError(errno); - } - NetFSComms::Attr a; - a.dev = s.st_dev; - a.inode = s.st_ino; - a.mode = s.st_mode; - a.links = s.st_nlink; - a.uid = s.st_uid; - a.gid = s.st_gid; - a.rdev = s.st_rdev; - a.size = s.st_size; - a.blockSize = s.st_blksize; - a.blocks = s.st_blocks; - a.atime = s.st_atime; - a.mtime = s.st_mtime; - a.ctime = s.st_ctime; - return a; -} - void MiscServer::symlink(const std::string & path1, const std::string & path2, const Ice::Current &) { diff --git a/netfs/daemonMisc.h b/netfs/daemonMisc.h index af36392..69223f5 100644 --- a/netfs/daemonMisc.h +++ b/netfs/daemonMisc.h @@ -2,12 +2,14 @@ #define DAEMONMISC_H #include "netfsComms.h" +#include "daemonModule.h" -class MiscServer : public NetFSComms::Misc { +class MiscServer : public DaemonModule, public NetFSComms::Misc { public: + MiscServer(DaemonGlobalStatePtr dgs); + virtual Ice::Int access(const std::string & path, Ice::Int mode, const Ice::Current&); virtual NetFSComms::Attr getattr(const std::string & path, const Ice::Current&); - virtual NetFSComms::Attr fgetattr(Ice::Int id, const Ice::Current&); virtual void symlink(const std::string & path1, const std::string & path2, const Ice::Current&); virtual void link(const std::string & path1, const std::string & path2, const Ice::Current&); virtual void rename(const std::string & path1, const std::string & path2, const Ice::Current&); diff --git a/netfs/daemonModule.cpp b/netfs/daemonModule.cpp new file mode 100644 index 0000000..e0f59bd --- /dev/null +++ b/netfs/daemonModule.cpp @@ -0,0 +1,6 @@ +#include "daemonModule.h" + +DaemonModule::DaemonModule(DaemonGlobalStatePtr dgs) +{ +} + diff --git a/netfs/daemonModule.h b/netfs/daemonModule.h new file mode 100644 index 0000000..5d2123c --- /dev/null +++ b/netfs/daemonModule.h @@ -0,0 +1,12 @@ +#ifndef DAEMONMODULE_H +#define DAEMONMODULE_H + +#include "daemon.h" + +class DaemonModule { + protected: + DaemonModule(DaemonGlobalStatePtr dgs); +}; + +#endif + diff --git a/netfs/daemonSystem.cpp b/netfs/daemonSystem.cpp index 74c9a57..9690fc4 100644 --- a/netfs/daemonSystem.cpp +++ b/netfs/daemonSystem.cpp @@ -3,6 +3,11 @@ #include #include "daemonSystem.h" +SystemServer::SystemServer(DaemonGlobalStatePtr dgs) : + DaemonModule(dgs) +{ +} + NetFSComms::VFS SystemServer::statfs(const std::string & path, const Ice::Current&) { diff --git a/netfs/daemonSystem.h b/netfs/daemonSystem.h index 0e2bedb..3d5f2be 100644 --- a/netfs/daemonSystem.h +++ b/netfs/daemonSystem.h @@ -2,9 +2,12 @@ #define DAEMONSYSTEM_H #include "netfsComms.h" +#include "daemonModule.h" -class SystemServer : public NetFSComms::System { +class SystemServer : public DaemonModule, public NetFSComms::System { public: + SystemServer(DaemonGlobalStatePtr dgs); + virtual NetFSComms::VFS statfs(const std::string & path, const Ice::Current&); }; diff --git a/netfs/fuseFiles.cpp b/netfs/fuseFiles.cpp index 8cb96b3..430b411 100644 --- a/netfs/fuseFiles.cpp +++ b/netfs/fuseFiles.cpp @@ -89,6 +89,31 @@ NetFS::ftruncate(const char *, off_t o, fuse_file_info * fi) } } +int +NetFS::fgetattr(const char *, struct stat * s, fuse_file_info * fi) +{ + try { + NetFSComms::Attr a = files->fgetattr(fi->fh); + s->st_dev = a.dev; + s->st_ino = a.inode; + s->st_mode = a.mode; + s->st_nlink = a.links; + s->st_uid = a.uid; + s->st_gid = a.gid; + s->st_rdev = a.rdev; + s->st_size = a.size; + s->st_blksize = a.blockSize; + s->st_blocks = a.blocks; + s->st_atime = a.atime; + s->st_mtime = a.mtime; + s->st_ctime = a.ctime; + return 0; + } + catch (NetFSComms::SystemError & e) { + return -e.syserrno; + } +} + int NetFS::unlink(const char * p) { diff --git a/netfs/fuseMisc.cpp b/netfs/fuseMisc.cpp index 074da48..4b3a4bf 100644 --- a/netfs/fuseMisc.cpp +++ b/netfs/fuseMisc.cpp @@ -31,31 +31,6 @@ NetFS::getattr(const char * p, struct stat * s) } } -int -NetFS::fgetattr(const char *, struct stat * s, fuse_file_info * fi) -{ - try { - NetFSComms::Attr a = misc->fgetattr(fi->fh); - s->st_dev = a.dev; - s->st_ino = a.inode; - s->st_mode = a.mode; - s->st_nlink = a.links; - s->st_uid = a.uid; - s->st_gid = a.gid; - s->st_rdev = a.rdev; - s->st_size = a.size; - s->st_blksize = a.blockSize; - s->st_blocks = a.blocks; - s->st_atime = a.atime; - s->st_mtime = a.mtime; - s->st_ctime = a.ctime; - return 0; - } - catch (NetFSComms::SystemError & e) { - return -e.syserrno; - } -} - int NetFS::chmod(const char * p, mode_t m) { diff --git a/netfs/netfsComms.ice b/netfs/netfsComms.ice index 32c96bc..1fcfaf1 100644 --- a/netfs/netfsComms.ice +++ b/netfs/netfsComms.ice @@ -38,6 +38,7 @@ module NetFSComms { interface Files { void truncate(string path, long size); void ftruncate(int id, long size); + Attr fgetattr(int id); void unlink(string path); @@ -62,7 +63,6 @@ module NetFSComms { interface Misc { int access(string path, int mode); Attr getattr(string path); - Attr fgetattr(int id); void symlink(string path1, string path2); void link(string path1, string path2); void rename(string from, string to); -- cgit v1.2.3