]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uclient/libceph: setattr and _setattr now use a stat_precise struct
authorGreg Farnum <gregf@hq.newdream.net>
Fri, 14 Aug 2009 23:55:27 +0000 (16:55 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Mon, 17 Aug 2009 19:21:14 +0000 (12:21 -0700)
that handles both seconds and microseconds.
stat_precise has a stat_precise(struct stat) constructor.
ll_setattr still uses struct stat.

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

index 9752e549ef5ba208c0acd395d1f1a7bd16e7398f..37d6bfeb9163d05e77e4c6e04394cd7307eeaf18 100644 (file)
@@ -3150,7 +3150,7 @@ int Client::_getattr(Inode *in, int mask, int uid, int gid)
   return res;
 }
 
-int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid)
+int Client::_setattr(Inode *in, struct stat_precise *attr, int mask, int uid, int gid)
 {
   int issued = in->caps_issued();
 
@@ -3177,9 +3177,9 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid)
   if (in->caps_issued_mask(CEPH_CAP_FILE_EXCL)) {
     if (mask & (CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME)) {
       if (mask & CEPH_SETATTR_MTIME)
-       in->mtime = utime_t(attr->st_mtime, 0);
+       in->mtime = utime_t(attr->st_mtime_sec, attr->st_mtime_micro);
       if (mask & CEPH_SETATTR_ATIME)
-       in->atime = utime_t(attr->st_atime, 0);
+       in->atime = utime_t(attr->st_atime_sec, attr->st_atime_micro);
       in->time_warp_seq++;
       mark_caps_dirty(in, CEPH_CAP_FILE_EXCL);
       mask &= ~(CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME);
@@ -3201,9 +3201,11 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid)
   if (mask & CEPH_SETATTR_GID)
     req->head.args.setattr.gid = attr->st_gid;
   if (mask & CEPH_SETATTR_MTIME)
-    req->head.args.setattr.mtime = utime_t(attr->st_mtime, 0);
+    req->head.args.setattr.mtime =
+      utime_t(attr->st_mtime_sec, attr->st_mtime_micro);
   if (mask & CEPH_SETATTR_ATIME)
-    req->head.args.setattr.atime = utime_t(attr->st_atime, 0);
+    req->head.args.setattr.atime =
+      utime_t(attr->st_atime_sec, attr->st_atime_micro);
   if (mask & CEPH_SETATTR_SIZE)
     req->head.args.setattr.size = attr->st_size;
   req->head.args.setattr.mask = mask;
@@ -3213,7 +3215,7 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid)
   return res;
 }
 
-int Client::setattr(const char *relpath, struct stat *attr, int mask)
+int Client::setattr(const char *relpath, struct stat_precise *attr, int mask)
 {
   Mutex::Locker lock(client_lock);
   tout << "setattr" << std::endl;
@@ -3290,7 +3292,7 @@ int Client::chmod(const char *relpath, mode_t mode)
   int r = path_walk(path, &in);
   if (r < 0)
     return r;
-  struct stat attr;
+  stat_precise attr;
   attr.st_mode = mode;
   return _setattr(in, &attr, CEPH_SETATTR_MODE);
 }
@@ -3307,7 +3309,7 @@ int Client::chown(const char *relpath, uid_t uid, gid_t gid)
   int r = path_walk(path, &in);
   if (r < 0)
     return r;
-  struct stat attr;
+  stat_precise attr;
   attr.st_uid = uid;
   attr.st_gid = gid;
   return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID);
@@ -3325,9 +3327,9 @@ int Client::utime(const char *relpath, struct utimbuf *buf)
   int r = path_walk(path, &in);
   if (r < 0)
     return r;
-  struct stat attr;
-  attr.st_mtime = buf->modtime;
-  attr.st_atime = buf->actime;
+  stat_precise attr;
+  attr.st_mtime_sec = buf->modtime;
+  attr.st_atime_sec = buf->actime;
   return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME);
 }
 
@@ -4222,7 +4224,7 @@ int Client::_flush(Fh *f)
 
 int Client::truncate(const char *relpath, loff_t length) 
 {
-  struct stat attr;
+  stat_precise attr;
   attr.st_size = length;
   return setattr(relpath, &attr, CEPH_SETATTR_SIZE);
 }
@@ -4236,7 +4238,7 @@ int Client::ftruncate(int fd, loff_t length)
 
   assert(fd_map.count(fd));
   Fh *f = fd_map[fd];
-  struct stat attr;
+  stat_precise attr;
   attr.st_size = length;
   return _setattr(f->inode, &attr, CEPH_SETATTR_SIZE);
 }
@@ -4656,8 +4658,8 @@ int Client::ll_setattr(vinodeno_t vino, struct stat *attr, int mask, int uid, in
   tout << mask << std::endl;
 
   Inode *in = _ll_get_inode(vino);
-
-  int res = _setattr(in, attr, mask, uid, gid);
+  stat_precise precise_attr(*attr);
+  int res = _setattr(in, &precise_attr, mask, uid, gid);
   if (res == 0)
     fill_stat(in, attr);
   dout(3) << "ll_setattr " << vino << " = " << res << dendl;
index 02a0e364ef9d701a2a3a0c426abce4229e389843..42bbbf86feb00498e047b9b8f30424585c0f2ee3 100644 (file)
@@ -702,6 +702,36 @@ class Client : public Dispatcher {
     bool at_end() { return (offset == END); }
   };
 
+  struct stat_precise {
+    ino_t st_ino;
+    dev_t st_dev;
+    mode_t st_mode;
+    nlink_t st_nlink;
+    uid_t st_uid;
+    gid_t st_gid;
+    off_t st_size;
+    blksize_t st_blksize;
+    blkcnt_t st_blocks;
+    time_t st_atime_sec;
+    time_t st_atime_micro;
+    time_t st_mtime_sec;
+    time_t st_mtime_micro;
+    time_t st_ctime_sec;
+    time_t st_ctime_micro;
+    stat_precise() {}
+    stat_precise(struct stat attr): st_ino(attr.st_ino), st_dev(attr.st_dev),
+                              st_mode(attr.st_mode), st_nlink(attr.st_nlink),
+                              st_uid(attr.st_uid), st_gid(attr.st_gid),
+                              st_size(attr.st_size),
+                              st_blksize(attr.st_blksize),
+                              st_blocks(attr.st_blocks),
+                              st_atime_sec(attr.st_atime/1000),
+                              st_atime_micro((attr.st_atime%1000)*1000),
+                              st_mtime_sec(attr.st_mtime/1000),
+                              st_mtime_micro((attr.st_mtime%1000)*1000),
+                              st_ctime_sec(attr.st_ctime/1000),
+                              st_ctime_micro((attr.st_ctime%1000)*1000) {}
+  };
 
   // cluster descriptors
   MDSMap *mdsmap; 
@@ -1045,7 +1075,7 @@ private:
   int _rmdir(Inode *dir, const char *name, int uid=-1, int gid=-1);
   int _symlink(Inode *dir, const char *name, const char *target, int uid=-1, int gid=-1);
   int _mknod(Inode *dir, const char *name, mode_t mode, dev_t rdev, int uid=-1, int gid=-1);
-  int _setattr(Inode *in, struct stat *attr, int mask, int uid=-1, int gid=-1);
+  int _setattr(Inode *in, stat_precise *attr, int mask, int uid=-1, int gid=-1);
   int _getattr(Inode *in, int mask, int uid=-1, int gid=-1);
   int _getxattr(Inode *in, const char *name, void *value, size_t len, int uid=-1, int gid=-1);
   int _listxattr(Inode *in, char *names, size_t len, int uid=-1, int gid=-1);
@@ -1106,7 +1136,7 @@ public:
   int lstat(const char *path, struct stat *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, struct stat *attr, int mask);
+  int setattr(const char *relpath, stat_precise *attr, int mask);
   int chmod(const char *path, mode_t mode);
   int chown(const char *path, uid_t uid, gid_t gid);
   int utime(const char *path, struct utimbuf *buf);
index 7f39bd6a1a6730b43bc4193a33302956434a81b6..f516acef8d7ede49ac2dbe917520ed72ac72a7ab 100644 (file)
@@ -7,7 +7,6 @@
 #include "common/Mutex.h"
 #include "messages/MMonMap.h"
 #include "common/common_init.h"
-#include "Client.h"
 #include "msg/SimpleMessenger.h"
 
 /* ************* ************* ************* *************
@@ -181,7 +180,7 @@ extern "C" int ceph_lstat(const char *path, struct stat *stbuf, struct frag_info
   return client->lstat(path, stbuf, dirstat);
 }
 
-extern "C" int ceph_setattr(const char *relpath, struct stat *attr, int mask)
+extern "C" int ceph_setattr(const char *relpath, Client::stat_precise *attr, int mask)
 {
   return client->setattr(relpath, attr, mask);
 }
index 2d8343c487b404b057b4bec5d1722aaaffeba7c4..bd656271fa21b105bff62f8c0bfafa0b50aba651 100644 (file)
@@ -12,6 +12,7 @@
 #ifdef __cplusplus
 #include <list>
 #include <string>
+#include "Client.h"
 extern "C" {
 #endif
 
@@ -50,7 +51,7 @@ int ceph_symlink(const char *existing, const char *newname);
 // inode stuff
 int ceph_lstat(const char *path, struct stat *stbuf, frag_info_t *dirstat=0);
 
-int ceph_setattr(const char *relpath, struct stat *attr, int mask);
+int ceph_setattr(const char *relpath, Client::stat_precise *attr, int mask);
 int ceph_chmod(const char *path, mode_t mode);
 int ceph_chown(const char *path, uid_t uid, gid_t gid);
 int ceph_utime(const char *path, struct utimbuf *buf);