]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
*** empty log message ***
authorsage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 24 Jan 2005 21:54:50 +0000 (21:54 +0000)
committersage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 24 Jan 2005 21:54:50 +0000 (21:54 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@124 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/include/filepath.h
ceph/mds/MDS.cc
ceph/messages/MClientRequest.h

index 0679d8f5d79094861e6224ef10c83b7d55161523..d1b51556a1fe4efc2a0567613139eb0383bea5ba 100644 (file)
@@ -48,6 +48,10 @@ class filepath {
   string& get_path() {
        return path;
   }
+  int length() {
+       return path.length();
+  }
+
   const char *c_str() {
        return path.c_str();
   }
index a646fe59b7899e2c27f73f5c9d99905e2792fd64..415d2fa1041d15de3e33a38e2c9b17fa9dda3b3e 100644 (file)
@@ -417,11 +417,12 @@ int MDS::handle_client_request(MClientRequest *req)
   case MDS_OP_RMDIR:
        handle_client_rmdir(req, cur);
        break;
+       */
 
   case MDS_OP_RENAME:
        handle_client_rename(req, cur);
        break;
-       */
+       
 
   default:
        dout(1) << " unknown mop " << req->get_op() << endl;
@@ -994,6 +995,137 @@ void MDS::handle_client_mkdir(MClientRequest *req)
 }
 
 
+/*
+
+
+
+ */
+
+void MDS::handle_client_rename(MClientRequest *req,
+                                                          CInode *cur)
+{
+  // make sure i'm auth on source
+  if (!cur->is_auth()) {
+       // forward
+       dout(10) << "handle_client_rename " << *cur << "  not auth, forwarding" << endl;
+       int auth = cur->authority();
+       assert(auth != mdcluster->get_nodeid());
+       messenger->send_message(req,
+                                                       MSG_ADDR_MDS(auth), MDS_PORT_SERVER,
+                                                       MDS_PORT_SERVER);
+       return;
+  }
+
+  dout(10) << "handle_client_rename " << *cur << " to " << cur->get_arg() << endl;
+
+  // find the destination.
+  // discover, etc. on the way.. get just it on the local node.
+  filepath dirpath = cur->get_arg(); 
+  // ** FIXME ** relative destination path???
+  vector<CInode*> trace;
+  int r = mdcache->path_traverse(dirpath, trace, req, MDS_TRAVERSE_DISCOVER);
+
+  string name;
+  CDir *destdir = 0;
+
+  // what is the dest?  (dir or file or complete filename)
+  if (trace.size() == dirpath.depth()) {
+       CInode *d = trace[trace.size()-1];
+       if (d->is_dir()) {
+         // mv some/thing /to/some/dir 
+         destdir = d->get_or_open_dir(this);  // /to/some/dir
+         name = cur->get_file_path().last();  // thing
+       } else {
+         // mv some/thing /to/some/existing_filename
+         destdir = trace[trace.size()-2]->get_or_open_dir();  // /to/some
+         name = dirpath.last();                               // existing_filename
+       }
+  }
+  else if (trace.size() == dirpath.depth() - 1) {
+       CInode *d = trace[trace.size()-1];
+       if (d->is_dir()) {
+         // mv some/thing /to/some/place_that_dne
+         destdir = d->get_or_open_dir(this);   // /to/some
+         name = cur->get_file_path().last();   // place_that_dne
+       }
+  }
+  else {
+       assert(trace.size() < dirpath.depth()-1);
+       // check traverse return value
+       if (r > 0) return;  // discover, readdir, etc.
+       assert(r < 0);  // musta been an error
+
+       // error out
+       dout(7) << "rename " << *cur << " dest " << dirpath << " dne" << end;
+       MClientReply *reply = new MClientReply(req, -ENODEST);
+       messenger->send_message(reply,
+                                                       MSG_ADDR_CLIENT(req->get_client()), 0,
+                                                       MDS_PORT_SERVER);
+       delete req;
+       return;
+  }
+
+  // local or remote?
+  assert(cur->is_auth());
+  int dauth = destdir->dentry_authority(name);
+  if (dauth != mdcluster->get_nodeid()) {
+       dout(7) << "rename has remote dest " << dauth << endl;
+
+       // implement me
+       assert(0);
+       return 0;
+  }
+
+  // file or dir?
+  if (cur->is_dir()) {
+       handle_client_rename_dir(req,cur);
+  } else {
+       handle_client_rename_file(req,cur);
+  }
+}
+
+void MDS::handle_client_rename_file(MClientRequest *req,
+                                                                       CInode *from,
+                                                                       CDir *destdir,
+                                                                       string name)
+{
+  // does destination exist?  (is this an overwrite?)
+  CDentry *dn = destdir->lookup(name);
+  CInode *oldin = 0;
+  if (dn) {
+       oldin = dn->get_inode();
+       // make sure it's also a file!
+       if (oldin->is_dir()) {
+         // fail!
+         dout(7) << "dest exists and is dir" << endl;
+         MClientReply *reply = new MClientReply(req, -EISDIR);
+         messenger->send_message(reply,
+                                                         MSG_ADDR_CLIENT(req->get_client()), 0,
+                                                         MDS_PORT_SERVER);
+         delete req;
+         return;
+       }
+
+       // make sure we can lock dest
+       
+  }
+
+  // make sure we can lock source
+
+
+
+  
+  
+}
+
+void MDS::handle_client_rename_dir(MClientRequest *req,
+                                                                       CInode *from,
+                                                                       CDir *destdir,
+                                                                       string name)
+{
+}
+
+
 
 // WRITE ME
 
index 0990988deacd51855fcad2e5b696b2e56d87b537..6e604201bf3c244381b2a9c81c3e23ae2aa71b09 100644 (file)
@@ -16,6 +16,7 @@ typedef struct {
 class MClientRequest : public Message {
   MClientRequest_st st;
   filepath path;
+  string arg;
 
  public:
   MClientRequest() {}
@@ -41,6 +42,8 @@ class MClientRequest : public Message {
   virtual int decode_payload(crope s) {
        s.copy(0, sizeof(st), (char*)&st);
        path.set_path( s.c_str() + sizeof(st) );
+       int off = sizeof(st) + path.length() + 0;
+       arg = s.c_str() + off;  
        return 0;
   }
 
@@ -49,6 +52,8 @@ class MClientRequest : public Message {
        r.append((char*)&st, sizeof(st));
        r.append(path.c_str());
        r.append((char)0);
+       r.append(arg.c_str());
+       r.append((char)0);
        return r;
   }
 };