]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
uclient/hadoop: Implement lstat_precise.
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 18 Aug 2009 20:31:25 +0000 (13:31 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 18 Aug 2009 20:31:25 +0000 (13:31 -0700)
libceph: Some functions were getting C bindings where it
didn't make sense (having string parameters. Fixed now.

src/client/Client.cc
src/client/Client.h
src/client/hadoop/CephFSInterface.cc
src/client/libceph.cc
src/client/libceph.h

index d11cdeb27a76069579cccecb0287b79b55bf3a81..21d576292b8828b686643ee6857723b7060e1c64 100644 (file)
@@ -3280,6 +3280,64 @@ int Client::lstat(const char *relpath, struct stat *stbuf, frag_info_t *dirstat,
   fill_stat(in, stbuf, dirstat);
   return r;
 }
+int Client::fill_stat_precise(Inode *in, struct stat_precise *st, frag_info_t *dirstat, nest_info_t *rstat) 
+{
+  dout(10) << "fill_stat_precise on " << in->ino << " snap/dev" << in->snapid 
+          << " mode 0" << oct << in->mode << dec
+          << " mtime " << in->mtime << " ctime " << in->ctime << dendl;
+  memset(st, 0, sizeof(struct stat_precise));
+  st->st_ino = in->ino;
+  st->st_dev = in->snapid;
+  st->st_mode = in->mode;
+  st->st_rdev = in->rdev;
+  st->st_nlink = in->nlink;
+  st->st_uid = in->uid;
+  st->st_gid = in->gid;
+  if (in->ctime.sec() > in->mtime.sec()) {
+    st->st_ctime_sec = in->ctime.sec();
+    st->st_ctime_micro = in->ctime.usec();
+  } else {
+    st->st_ctime_sec = in->mtime.sec();
+    st->st_ctime_micro = in->ctime.usec();
+  }
+  st->st_atime_sec = in->atime.sec();
+  st->st_atime_micro = in->atime.usec();
+  st->st_mtime_sec = in->mtime.sec();
+  st->st_mtime_micro = in->mtime.usec();
+  if (in->is_dir()) {
+    //st->st_size = in->dirstat.size();
+    st->st_size = in->rstat.rbytes;
+    st->st_blocks = 1;
+  } else {
+    st->st_size = in->size;
+    st->st_blocks = (in->size + 511) >> 9;
+  }
+  st->st_blksize = MAX(ceph_file_layout_su(in->layout), 4096);
+
+  if (dirstat)
+    *dirstat = in->dirstat;
+  if (rstat)
+    *rstat = in->rstat;
+
+  return in->caps_issued();
+}
+
+int Client::lstat_precise(const char *relpath, struct stat_precise *stbuf,
+                         frag_info_t *dirstat, int mask) {
+  Mutex::Locker lock(client_lock);
+  tout << "lstat_precise" << std::endl;
+  tout << relpath << std::endl;
+  filepath path(relpath);
+  Inode *in;
+  int r = path_walk(path, &in);
+  if (r < 0)
+    return r;
+  r = _getattr(in, mask);
+  if (r < 0)
+    return r;
+  fill_stat_precise(in, stbuf, dirstat);
+  return r;
+}
 
 int Client::chmod(const char *relpath, mode_t mode)
 {
index 6dfbdcea79c03bf17472fe4263edb0e693dcb388..c724e0ec0edfe0c7bcf2b24e0ae911419bab5baf 100644 (file)
@@ -709,6 +709,7 @@ class Client : public Dispatcher {
     nlink_t st_nlink;
     uid_t st_uid;
     gid_t st_gid;
+    dev_t st_rdev;
     off_t st_size;
     blksize_t st_blksize;
     blkcnt_t st_blocks;
@@ -950,6 +951,7 @@ protected:
   Inode *cwd;
   int path_walk(const filepath& fp, Inode **end, bool followsym=true);
   int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0);
+  int fill_stat_precise(Inode *in, struct stat_precise *st, frag_info_t *dirstat=0, nest_info_t *rstat=0);
   void touch_dn(Dentry *dn) { lru.lru_touch(dn); }  
 
   // trim cache.
@@ -1134,6 +1136,7 @@ public:
 
   // inode stuff
   int lstat(const char *path, struct stat *stbuf, frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL);
+  int lstat_precise(const char *relpath, struct stat_precise *stbuf, frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL);
   int lstatlite(const char *path, struct statlite *buf);
 
   int setattr(const char *relpath, stat_precise *attr, int mask);
index bfc6e9aa4876bfe9eafaaa94c2653008ea436f93..47c73033815f06cab8fa9914c47a9e7c221d2472 100644 (file)
@@ -488,7 +488,7 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1k
 JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1stat
 (JNIEnv * env, jobject obj, jstring j_path, jobject j_stat) {
   //setup variables
-  struct stat st;
+  struct Client::stat_precise st;
   const char* c_path = env->GetStringUTFChars(j_path, 0);
   if (c_path == NULL) return false;
 
@@ -516,8 +516,10 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1s
   env->SetLongField(j_stat, c_size_id, (long)st.st_size);
   env->SetBooleanField(j_stat, c_dir_id, (0 != S_ISDIR(st.st_mode)));
   env->SetLongField(j_stat, c_block_id, (long)st.st_blksize);
-  env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime);
-  env->SetLongField(j_stat, c_access_id, (long long)st.st_atime);
+  env->SetLongField(j_stat, c_mod_id, (long long)st.st_mtime_sec*1000
+                   +st.st_mtime_micro/1000);
+  env->SetLongField(j_stat, c_access_id, (long long)st.st_atime_sec*1000
+                   +st.st_atime_micro/1000);
   env->SetIntField(j_stat, c_mode_id, (int)st.st_mode);
 
   //return happy
index f516acef8d7ede49ac2dbe917520ed72ac72a7ab..3205fdf45f5ba61e91a094c19c91828da6004a82 100644 (file)
@@ -180,6 +180,11 @@ extern "C" int ceph_lstat(const char *path, struct stat *stbuf, struct frag_info
   return client->lstat(path, stbuf, dirstat);
 }
 
+int ceph_lstat(const char *path, Client::stat_precise *stbuf, frag_info_t *dirstat)
+{
+  return client->lstat_precise(path, stbuf, dirstat);
+}
+
 extern "C" int ceph_setattr(const char *relpath, Client::stat_precise *attr, int mask)
 {
   return client->setattr(relpath, attr, mask);
index bd656271fa21b105bff62f8c0bfafa0b50aba651..3b055862fa975e050ac71f4d487f0a3f3e9f2a80 100644 (file)
@@ -72,11 +72,13 @@ int ceph_sync_fs();
 int ceph_get_file_stripe_unit(int fh);
 int ceph_get_file_replication(const char *path);
 #ifdef __cplusplus
+}
 //not for C, sorry!
 int ceph_getdir(const char *relpath, std::list<std::string>& names);
 void ceph_getcwd(std::string& cwd);
 int ceph_get_file_stripe_address(int fd, loff_t offset, std::string& address);
-}
+int ceph_lstat(const char *path, Client::stat_precise *stbuf, frag_info_t *dirstat=0);
+
 #endif
 
 #endif