diff options
author | randomdan <randomdan@localhost> | 2010-10-30 21:10:06 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-10-30 21:10:06 +0000 |
commit | adaab3c3caaddd8e6a829be9342679016e1d1b59 (patch) | |
tree | 03211c5e4c67fe977e239c8079040a4a44403f97 | |
parent | Merge all FS operations into one interface (diff) | |
download | netfs-adaab3c3caaddd8e6a829be9342679016e1d1b59.tar.bz2 netfs-adaab3c3caaddd8e6a829be9342679016e1d1b59.tar.xz netfs-adaab3c3caaddd8e6a829be9342679016e1d1b59.zip |
Reopen files and directories on reauthentication
-rw-r--r-- | netfs/fuse.cpp | 22 | ||||
-rw-r--r-- | netfs/fuse.h | 34 | ||||
-rw-r--r-- | netfs/fuseDirs.cpp | 22 | ||||
-rw-r--r-- | netfs/fuseFiles.cpp | 33 | ||||
-rw-r--r-- | netfs/fuseapp.cpp | 2 | ||||
-rw-r--r-- | netfs/fuseapp.h | 2 |
6 files changed, 97 insertions, 18 deletions
diff --git a/netfs/fuse.cpp b/netfs/fuse.cpp index 14ce0ba..4b3f3bd 100644 --- a/netfs/fuse.cpp +++ b/netfs/fuse.cpp @@ -1,4 +1,5 @@ #include <string.h> +#include <boost/foreach.hpp> #include "fuse.h" NetFS::ReqEnv::ReqEnv(const NetFS * netfs) @@ -12,7 +13,8 @@ NetFS::ReqEnv::ReqEnv(const NetFS * netfs) NetFS::NetFS(int & argc, char ** argv) : _argc(argc), _argv(argv), - authtok(0) + authtok(0), + openFileID(0) { } @@ -56,12 +58,24 @@ NetFS::opt_parse(void *, const char * arg, int key, struct fuse_args *) return 1; } +void +NetFS::connect() +{ + authtok = service->connect(exportName, "bar"); + BOOST_FOREACH(const OpenFiles::value_type & of, openFiles) { + of.second->remoteID = filesystem->open(reqEnv(), of.second->path, of.second->flags); + } + BOOST_FOREACH(const OpenDirs::value_type & of, openDirs) { + of.second->remoteID = filesystem->opendir(reqEnv(), of.second->path); + } +} + int -NetFS::onError(const std::exception & e) const throw() +NetFS::onError(const std::exception & e) throw() { if (dynamic_cast<const NetFSComms::AuthError *>(&e)) { // I've become unauthenticated... reauthenticate - authtok = service->connect(exportName, "bar"); + connect(); return 0; } return FuseAppBase::onError(e); @@ -85,7 +99,7 @@ NetFS::reqEnv() } } if (authtok == 0) { - authtok = service->connect(exportName, "bar"); + connect(); } return ReqEnv(this); } diff --git a/netfs/fuse.h b/netfs/fuse.h index b890838..b16a67c 100644 --- a/netfs/fuse.h +++ b/netfs/fuse.h @@ -6,20 +6,44 @@ #include "fuseapp.h" #include "fuseConfig.h" #include "entCache.h" +#include "intrusivePtrBase.h" class NetFS : public FuseAppBase { - public: + private: class ReqEnv : public NetFSComms::ReqEnv { public: ReqEnv(const NetFS *); }; + class OpenDir : public IntrusivePtrBase { + public: + OpenDir(Ice::Int remoteID, const std::string & path); + + Ice::Int remoteID; + const std::string path; + }; + typedef boost::intrusive_ptr<OpenDir> OpenDirPtr; + typedef std::map<int, OpenDirPtr> OpenDirs; + + class OpenFile : public IntrusivePtrBase { + public: + OpenFile(Ice::Int remoteID, const std::string & path, int flags); + + Ice::Int remoteID; + const std::string path; + const int flags; + }; + typedef boost::intrusive_ptr<OpenFile> OpenFilePtr; + typedef std::map<int, OpenFilePtr> OpenFiles; + + public: NetFS(int & argc, char ** argv); ~NetFS(); private: void * init (struct fuse_conn_info * info); int opt_parse(void *, const char * arg, int key, struct fuse_args *); + void connect(); // misc int access(const char * p, int a); int getattr(const char * p, struct stat * s); @@ -49,7 +73,9 @@ class NetFS : public FuseAppBase // fs int statfs(const char *, struct statvfs *); // stuff - int onError(const std::exception & err) const throw(); + int onError(const std::exception & err) throw(); + int getNextFileID(); + int getNextDirID(); ReqEnv reqEnv(); @@ -68,6 +94,10 @@ class NetFS : public FuseAppBase std::string configPath; EntCache entries; + OpenDirs openDirs; + int openDirID; + OpenFiles openFiles; + int openFileID; }; #endif diff --git a/netfs/fuseDirs.cpp b/netfs/fuseDirs.cpp index 36440a9..41f3013 100644 --- a/netfs/fuseDirs.cpp +++ b/netfs/fuseDirs.cpp @@ -1,11 +1,26 @@ #include "fuse.h" #include "misc.h" +NetFS::OpenDir::OpenDir(Ice::Int rid, const std::string & p) : + remoteID(rid), + path(p) +{ +} + +int +NetFS::getNextDirID() +{ + while (openDirs.find(++openDirID) != openDirs.end()) ; + return openDirID; +} + int NetFS::opendir(const char * p, struct fuse_file_info * fi) { try { - fi->fh = filesystem->opendir(reqEnv(), p); + Ice::Int remoteID = filesystem->opendir(reqEnv(), p); + fi->fh = getNextDirID(); + openDirs[fi->fh] = new OpenDir(remoteID, p); return 0; } catch (NetFSComms::SystemError & e) { @@ -17,7 +32,8 @@ int NetFS::releasedir(const char *, struct fuse_file_info * fi) { try { - filesystem->closedir(authtok, fi->fh); + filesystem->closedir(authtok, openDirs[fi->fh]->remoteID); + openDirs.erase(fi->fh); return 0; } catch (NetFSComms::SystemError & e) { @@ -29,7 +45,7 @@ int NetFS::readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi) { try { - NetFSComms::NameList ds = filesystem->readdir(authtok, fi->fh); + NetFSComms::NameList ds = filesystem->readdir(authtok, openDirs[fi->fh]->remoteID); for (NetFSComms::NameList::const_iterator e = ds.begin(); e != ds.end(); e++) { filler(buf, e->c_str(), NULL, 0); } diff --git a/netfs/fuseFiles.cpp b/netfs/fuseFiles.cpp index 24e1934..2bf18b7 100644 --- a/netfs/fuseFiles.cpp +++ b/netfs/fuseFiles.cpp @@ -1,11 +1,27 @@ #include <string.h> #include "fuse.h" +NetFS::OpenFile::OpenFile(Ice::Int rid, const std::string & p, int f) : + remoteID(rid), + path(p), + flags(f) +{ +} + +int +NetFS::getNextFileID() +{ + while (openFiles.find(++openFileID) != openFiles.end()) ; + return openFileID; +} + int NetFS::open(const char * p, struct fuse_file_info * fi) { try { - fi->fh = filesystem->open(reqEnv(), p, fi->flags); + Ice::Int remoteID = filesystem->open(reqEnv(), p, fi->flags); + fi->fh = getNextFileID(); + openFiles[fi->fh] = new OpenFile(remoteID, p, fi->flags); return 0; } catch (NetFSComms::SystemError & e) { @@ -17,7 +33,9 @@ int NetFS::create(const char * p, mode_t m, struct fuse_file_info * fi) { try { - fi->fh = filesystem->create(reqEnv(), p, fi->flags, m); + Ice::Int remoteID = filesystem->create(reqEnv(), p, fi->flags, m); + fi->fh = getNextFileID(); + openFiles[fi->fh] = new OpenFile(remoteID, p, fi->flags); return 0; } catch (NetFSComms::SystemError & e) { @@ -29,7 +47,8 @@ int NetFS::release(const char *, struct fuse_file_info * fi) { try { - filesystem->close(authtok, fi->fh); + filesystem->close(authtok, openFiles[fi->fh]->remoteID); + openFiles.erase(fi->fh); return 0; } catch (NetFSComms::SystemError & e) { @@ -41,7 +60,7 @@ int NetFS::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi) { try { - NetFSComms::Buffer data = filesystem->read(authtok, fi->fh, o, s); + NetFSComms::Buffer data = filesystem->read(authtok, openFiles[fi->fh]->remoteID, o, s); for (NetFSComms::Buffer::const_iterator i = data.begin(); i != data.end(); i++, buf++) { *buf = *i; } @@ -57,7 +76,7 @@ NetFS::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file { try { NetFSComms::Buffer data(buf, buf + s); - filesystem->write(authtok, fi->fh, o, s, data); + filesystem->write(authtok, openFiles[fi->fh]->remoteID, o, s, data); return s; } catch (NetFSComms::SystemError & e) { @@ -81,7 +100,7 @@ int NetFS::ftruncate(const char *, off_t o, fuse_file_info * fi) { try { - filesystem->ftruncate(reqEnv(), fi->fh, o); + filesystem->ftruncate(reqEnv(), openFiles[fi->fh]->remoteID, o); return 0; } catch (NetFSComms::SystemError & e) { @@ -93,7 +112,7 @@ int NetFS::fgetattr(const char *, struct stat * s, fuse_file_info * fi) { try { - NetFSComms::Attr a = filesystem->fgetattr(reqEnv(), fi->fh); + NetFSComms::Attr a = filesystem->fgetattr(reqEnv(), openFiles[fi->fh]->remoteID); s->st_dev = a.dev; s->st_ino = a.inode; s->st_mode = a.mode; diff --git a/netfs/fuseapp.cpp b/netfs/fuseapp.cpp index e293156..13d8bdf 100644 --- a/netfs/fuseapp.cpp +++ b/netfs/fuseapp.cpp @@ -158,7 +158,7 @@ int FuseAppBase::bmap(const char *, size_t, uint64_t *) { return -ENOSYS; } -int FuseAppBase::onError(const std::exception & e) const throw() +int FuseAppBase::onError(const std::exception & e) throw() { fprintf(stderr, "Unknown exception calling (what: %s)\n", e.what()); return -ENOSYS; diff --git a/netfs/fuseapp.h b/netfs/fuseapp.h index b75d6f8..c823721 100644 --- a/netfs/fuseapp.h +++ b/netfs/fuseapp.h @@ -45,7 +45,7 @@ class FuseAppBase { virtual int lock(const char *, struct fuse_file_info *, int cmd, struct flock *); virtual int utimens(const char *, const struct timespec tv[2]); virtual int bmap(const char *, size_t blocksize, uint64_t *idx); - virtual int onError(const std::exception & err) const throw(); + virtual int onError(const std::exception & err) throw(); static int run(int &, char ** &, FuseAppBase *); }; |