client: use platform-specific stat time members

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2013-11-07 15:38:58 -08:00
parent 35eaa66da0
commit 01f7b463d1
4 changed files with 181 additions and 23 deletions

View File

@ -539,6 +539,17 @@ AC_CHECK_FUNC([fallocate],
[AC_DEFINE([CEPH_HAVE_FALLOCATE], [], [fallocate(2) is supported])],
[])
#
# Test for time-related `struct stat` members.
#
AC_CHECK_MEMBER([struct stat.st_mtim.tv_nsec],
[AC_DEFINE(HAVE_STAT_ST_MTIM_TV_NSEC, 1,
[Define if you have struct stat.st_mtim.tv_nsec])])
AC_CHECK_MEMBER([struct stat.st_mtimespec.tv_nsec],
[AC_DEFINE(HAVE_STAT_ST_MTIMESPEC_TV_NSEC, 1,
[Define if you have struct stat.st_mtimespec.tv_nsec])])
AC_CHECK_HEADERS([arpa/nameser_compat.h])
AC_CHECK_HEADERS([sys/prctl.h])

View File

@ -84,6 +84,7 @@ using namespace std;
#include "ObjecterWriteback.h"
#include "include/assert.h"
#include "include/stat.h"
#undef dout_prefix
#define dout_prefix *_dout << "client." << whoami << " "
@ -4503,9 +4504,9 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid, I
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_mtim.tv_sec, attr->st_mtim.tv_nsec);
in->mtime = utime_t(stat_get_mtime_sec(attr), stat_get_mtime_nsec(attr));
if (mask & CEPH_SETATTR_ATIME)
in->atime = utime_t(attr->st_atim.tv_sec, attr->st_atim.tv_nsec);
in->atime = utime_t(stat_get_atime_sec(attr), stat_get_atime_nsec(attr));
in->ctime = ceph_clock_now(cct);
in->time_warp_seq++;
mark_caps_dirty(in, CEPH_CAP_FILE_EXCL);
@ -4535,14 +4536,14 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid, I
req->inode_drop |= CEPH_CAP_AUTH_SHARED;
}
if (mask & CEPH_SETATTR_MTIME) {
req->head.args.setattr.mtime =
utime_t(attr->st_mtim.tv_sec, attr->st_mtim.tv_nsec);
utime_t mtime = utime_t(stat_get_mtime_sec(attr), stat_get_mtime_nsec(attr));
req->head.args.setattr.mtime = mtime;
req->inode_drop |= CEPH_CAP_AUTH_SHARED | CEPH_CAP_FILE_RD |
CEPH_CAP_FILE_WR;
}
if (mask & CEPH_SETATTR_ATIME) {
req->head.args.setattr.atime =
utime_t(attr->st_atim.tv_sec, attr->st_atim.tv_nsec);
utime_t atime = utime_t(stat_get_atime_sec(attr), stat_get_atime_nsec(attr));
req->head.args.setattr.atime = atime;
req->inode_drop |= CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_RD |
CEPH_CAP_FILE_WR;
}
@ -4652,16 +4653,16 @@ int Client::fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat, nest_inf
st->st_uid = in->uid;
st->st_gid = in->gid;
if (in->ctime.sec() > in->mtime.sec()) {
st->st_ctim.tv_sec = in->ctime.sec();
st->st_ctim.tv_nsec = in->ctime.nsec();
stat_set_ctime_sec(st, in->ctime.sec());
stat_set_ctime_nsec(st, in->ctime.nsec());
} else {
st->st_ctim.tv_sec = in->mtime.sec();
st->st_ctim.tv_nsec = in->mtime.nsec();
stat_set_ctime_sec(st, in->mtime.sec());
stat_set_ctime_nsec(st, in->mtime.nsec());
}
st->st_atim.tv_sec = in->atime.sec();
st->st_atim.tv_nsec = in->atime.nsec();
st->st_mtim.tv_sec = in->mtime.sec();
st->st_mtim.tv_nsec = in->mtime.nsec();
stat_set_atime_sec(st, in->atime.sec());
stat_set_atime_nsec(st, in->atime.nsec());
stat_set_mtime_sec(st, in->mtime.sec());
stat_set_mtime_nsec(st, in->mtime.nsec());
if (in->is_dir()) {
//st->st_size = in->dirstat.size();
st->st_size = in->rstat.rbytes;
@ -4807,10 +4808,10 @@ int Client::utime(const char *relpath, struct utimbuf *buf)
if (r < 0)
return r;
struct stat attr;
attr.st_mtim.tv_sec = buf->modtime;
attr.st_mtim.tv_nsec = 0;
attr.st_atim.tv_sec = buf->actime;
attr.st_atim.tv_nsec = 0;
stat_set_mtime_sec(&attr, buf->modtime);
stat_set_mtime_nsec(&attr, 0);
stat_set_atime_sec(&attr, buf->actime);
stat_set_atime_nsec(&attr, 0);
return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME);
}
@ -4828,10 +4829,10 @@ int Client::lutime(const char *relpath, struct utimbuf *buf)
if (r < 0)
return r;
struct stat attr;
attr.st_mtim.tv_sec = buf->modtime;
attr.st_mtim.tv_nsec = 0;
attr.st_atim.tv_sec = buf->actime;
attr.st_atim.tv_nsec = 0;
stat_set_mtime_sec(&attr, buf->modtime);
stat_set_mtime_nsec(&attr, 0);
stat_set_atime_sec(&attr, buf->actime);
stat_set_atime_nsec(&attr, 0);
return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME);
}

View File

@ -78,4 +78,5 @@ noinst_HEADERS += \
include/rbd/features.h \
include/rbd/librbd.h \
include/rbd/librbd.hpp\
include/util.h
include/util.h\
include/stat.h

145
src/include/stat.h Normal file
View File

@ -0,0 +1,145 @@
#ifndef CEPH_STAT_H
#define CEPH_STAT_H
#include <acconfig.h>
#include <sys/stat.h>
/*
* Access time-related `struct stat` members.
*
* Note that for each of the stat member get/set functions below, setting a
* high-res value (stat_set_*_nsec) on a platform without high-res support is
* a no-op.
*/
#ifdef HAVE_STAT_ST_MTIM_TV_NSEC
static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
return st->st_mtim.tv_nsec;
}
static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
st->st_mtim.tv_nsec = nsec;
}
static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
return st->st_atim.tv_nsec;
}
static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
st->st_atim.tv_nsec = nsec;
}
static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
return st->st_ctim.tv_nsec;
}
static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
st->st_ctim.tv_nsec = nsec;
}
#elif defined(HAVE_STAT_ST_MTIMESPEC_TV_NSEC)
static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
return st->st_mtimespec.tv_nsec;
}
static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
st->st_mtimespec.tv_nsec = nsec;
}
static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
return st->st_atimespec.tv_nsec;
}
static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
st->st_atimespec.tv_nsec = nsec;
}
static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
return st->st_ctimespec.tv_nsec;
}
static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
st->st_ctimespec.tv_nsec = nsec;
}
#else
static inline uint32_t stat_get_mtime_nsec(struct stat *st)
{
return 0;
}
static inline void stat_set_mtime_nsec(struct stat *st, uint32_t nsec)
{
}
static inline uint32_t stat_get_atime_nsec(struct stat *st)
{
return 0;
}
static inline void stat_set_atime_nsec(struct stat *st, uint32_t nsec)
{
}
static inline uint32_t stat_get_ctime_nsec(struct stat *st)
{
return 0;
}
static inline void stat_set_ctime_nsec(struct stat *st, uint32_t nsec)
{
}
#endif
/*
* Access second-resolution `struct stat` members.
*/
static inline uint32_t stat_get_mtime_sec(struct stat *st)
{
return st->st_mtime;
}
static inline void stat_set_mtime_sec(struct stat *st, uint32_t sec)
{
st->st_mtime = sec;
}
static inline uint32_t stat_get_atime_sec(struct stat *st)
{
return st->st_atime;
}
static inline void stat_set_atime_sec(struct stat *st, uint32_t sec)
{
st->st_atime = sec;
}
static inline uint32_t stat_get_ctime_sec(struct stat *st)
{
return st->st_ctime;
}
static inline void stat_set_ctime_sec(struct stat *st, uint32_t sec)
{
st->st_ctime = sec;
}
#endif