]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
synclient: mksnapfile to generate a simple multi-snapshot object
authorSage Weil <sage@newdream.net>
Tue, 28 Oct 2008 23:48:21 +0000 (16:48 -0700)
committerSage Weil <sage@newdream.net>
Tue, 28 Oct 2008 23:48:21 +0000 (16:48 -0700)
writes 0~4M, takes snapshot, then overwrites 1~2M.

src/client/SyntheticClient.cc
src/client/SyntheticClient.h

index 08ef4023c4383a363b8f791bc2ba351b434b135a..3d7266cd19533ef449ace8234310276cd788d079 100644 (file)
@@ -66,6 +66,9 @@ void parse_syn_options(vector<const char*>& args)
        syn_modes.push_back(SYNCLIENT_MODE_RMSNAP);
        syn_sargs.push_back(args[++i]); // path
        syn_sargs.push_back(args[++i]); // name
+      } else if (strcmp(args[i], "mksnapfile") == 0) {
+       syn_modes.push_back(SYNCLIENT_MODE_MKSNAPFILE);
+       syn_sargs.push_back(args[++i]); // path
       } else if (strcmp(args[i],"rmfile") == 0) {
         syn_modes.push_back( SYNCLIENT_MODE_RMFILE );
       } else if (strcmp(args[i],"writefile") == 0) {
@@ -856,6 +859,14 @@ int SyntheticClient::run()
        did_run_me();
       }
       break;
+    case SYNCLIENT_MODE_MKSNAPFILE:
+      {
+       string base = get_sarg(0);
+       if (run_me())
+         mksnapfile(base.c_str());
+       did_run_me();
+      }
+      break;
 
     default:
       assert(0);
@@ -3333,3 +3344,26 @@ void SyntheticClient::rmsnap(const char *base, const char *name)
 {
   client->rmsnap(base, name);
 }
+
+void SyntheticClient::mksnapfile(const char *dir)
+{
+  client->mkdir(dir, 0755);
+
+  string f = dir;
+  f += "/foo";
+  int fd = client->open(f.c_str(), O_WRONLY|O_CREAT|O_TRUNC);
+
+  char buf[1048576*4];
+  client->write(fd, buf, sizeof(buf), 0);
+  client->fsync(fd, true);
+  client->close(fd);
+  
+  string s = dir;
+  s += "/.snap/1";
+  client->mkdir(s.c_str(), 0755);
+
+  fd = client->open(f.c_str(), O_WRONLY);
+  client->write(fd, buf, 1048576*2, 1048576);
+  client->fsync(fd, true);
+  client->close(fd);
+}
index ec2719d0dd605f161700ba04f0ba2c3930adaa5d..e0b48864f47dddf1cce42360e71bdd9db0f74302 100644 (file)
@@ -84,6 +84,8 @@
 #define SYNCLIENT_MODE_MKSNAP 1000
 #define SYNCLIENT_MODE_RMSNAP 1001
 
+#define SYNCLIENT_MODE_MKSNAPFILE 1002
+
 
 void parse_syn_options(vector<const char*>& args);
 
@@ -260,6 +262,7 @@ class SyntheticClient {
 
   void mksnap(const char *base, const char *name);
   void rmsnap(const char *base, const char *name);
+  void mksnapfile(const char *dir);
 };
 
 #endif