From ef4a4f1a401e2216d13acfd3454ae7586765c853 Mon Sep 17 00:00:00 2001 From: sageweil Date: Fri, 16 Nov 2007 05:29:15 +0000 Subject: [PATCH] some client request/reply struct redefinition; no more file_data_version, for now; utime_t now uses ceph_timeval git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2071 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/common/Clock.h | 9 ++- trunk/ceph/include/ceph_fs.h | 114 +++++++++++++++++++++++++-- trunk/ceph/include/utime.h | 42 ++++++---- trunk/ceph/mds/Server.cc | 4 +- trunk/ceph/messages/MClientReply.h | 13 +-- trunk/ceph/messages/MClientRequest.h | 76 ++++-------------- 6 files changed, 161 insertions(+), 97 deletions(-) diff --git a/trunk/ceph/common/Clock.h b/trunk/ceph/common/Clock.h index 1ea7227adebd4..ba106ade229d0 100644 --- a/trunk/ceph/common/Clock.h +++ b/trunk/ceph/common/Clock.h @@ -55,15 +55,18 @@ class Clock { // relative time (from startup) void tare() { - gettimeofday(&zero.timeval(), NULL); + struct timeval tv; + gettimeofday(&tv, NULL); + zero.set_from_timeval(&tv); } void tare(utime_t z) { zero = z; } utime_t now() { //lock.Lock(); - utime_t n; - gettimeofday(&n.timeval(), NULL); + struct timeval tv; + gettimeofday(&tv, NULL); + utime_t n(&tv); n -= zero; if (n < last) { //std::cerr << "WARNING: clock jumped backwards from " << last << " to " << n << std::endl; diff --git a/trunk/ceph/include/ceph_fs.h b/trunk/ceph/include/ceph_fs.h index dce1e66c3210e..db8aaa1cbdb56 100644 --- a/trunk/ceph/include/ceph_fs.h +++ b/trunk/ceph/include/ceph_fs.h @@ -50,6 +50,9 @@ struct ceph_object { typedef struct ceph_object ceph_object_t; +/* misc */ +typedef __u32 ceph_frag_t; + struct ceph_timeval { __u32 tv_sec; __u32 tv_usec; @@ -143,6 +146,10 @@ struct ceph_object_extent { +struct ceph_frag_tree { + +}; + /********************************************* @@ -199,13 +206,23 @@ struct ceph_entity_inst { /* * message header */ -struct ceph_message_header { +struct ceph_message_header { /* old one, just for now */ __u32 seq; /* message seq# for this session */ __u32 type; /* message type */ struct ceph_entity_inst src, dst; __u32 nchunks; }; +/* new way */ +struct ceph_msg_header { + __u32 seq; /* message seq# for this session */ + __u32 type; /* message type */ + struct ceph_entity_inst src, dst; + __u16 front_len; + __u16 data_off; /* sender: include full offset; receiver: mask against PAGE_MASK */ + __u32 data_len; /* bytes of data payload */ +}; + /* * message types @@ -244,10 +261,97 @@ struct ceph_message_header { /* client_session message op values */ enum { - CEPH_SESSION_REQUEST_OPEN, - CEPH_SESSION_OPEN, - CEPH_SESSION_REQUEST_CLOSE, - CEPH_SESSION_CLOSE + CEPH_SESSION_REQUEST_OPEN, + CEPH_SESSION_OPEN, + CEPH_SESSION_REQUEST_CLOSE, + CEPH_SESSION_CLOSE +}; + +/* client_request */ + +struct ceph_client_request_head { + struct ceph_entity_inst client_inst; + __u64 tid, oldest_client_tid; + __u32 num_fwd; + __u32 retry_attempt; + ceph_ino_t mds_wants_replica_in_dirino; + __u32 op; + __u32 caller_uid, caller_gid; + ceph_ino_t cwd_ino; +}; + +union ceph_client_request_args { + struct { + __u32 mask; + } stat; + struct { + ceph_ino_t ino; + __u32 mask; + } fstat; + struct { + ceph_frag_t frag; + } readdir; + struct { + struct ceph_timeval mtime; + struct ceph_timeval atime; + } utime; + struct { + __u32 mode; + } chmod; + struct { + uid_t uid; + gid_t gid; + } chown; + struct { + __u32 mode; + __u32 rdev; + } mknod; + struct { + __u32 mode; + } mkdir; + struct { + __u32 flags; + __u32 mode; + } open; + struct { + ceph_ino_t ino; // optional + __s64 length; + } truncate; + struct { + ceph_ino_t ino; + } fsync; +}; + +/* client reply */ + +struct ceph_client_reply_head { + __u64 tid; + __u32 op; + __s32 result; + __u32 file_caps; + __u64 file_caps_seq; +}; + +struct ceph_client_reply_inode { + ceph_ino_t ino; + struct ceph_file_layout layout; + struct ceph_timeval ctime, mtime, atime; + __u32 mode, uid, gid; + __u32 nlink; + __u64 size; + __u32 rdev; + __u32 mask; + char *symlink; + struct ceph_frag_tree dirfragdir; +}; +/* followed by symlink string, then dirfragtree */ + +struct ceph_client_reply_dirfrag { + __u32 frag; + __s32 auth; + unsigned char is_rep; + int ndist; + __u32 dist[]; }; diff --git a/trunk/ceph/include/utime.h b/trunk/ceph/include/utime.h index 7fef5a7f930d2..683c148423627 100644 --- a/trunk/ceph/include/utime.h +++ b/trunk/ceph/include/utime.h @@ -18,19 +18,17 @@ #include #include #include +#include "ceph_fs.h" // -------- // utime_t -typedef struct timeval _utime_t; +typedef struct ceph_timeval _utime_t; class utime_t { - private: - struct timeval tv; + _utime_t tv; - struct timeval& timeval() { return tv; } friend class Clock; - public: void normalize() { @@ -45,12 +43,17 @@ class utime_t { //utime_t(time_t s) { tv.tv_sec = s; tv.tv_usec = 0; } utime_t(time_t s, int u) { tv.tv_sec = s; tv.tv_usec = u; normalize(); } utime_t(const _utime_t &v) : tv(v) {} - /* - utime_t(double d) { - tv.tv_sec = (time_t)trunc(d); - tv.tv_usec = (__suseconds_t)((d - tv.tv_sec) / (double)1000000.0); + utime_t(const struct timeval &v) { + set_from_timeval(&v); + } + utime_t(const struct timeval *v) { + set_from_timeval(v); + } + + void set_from_double(double d) { + tv.tv_sec = (__u32)trunc(d); + tv.tv_usec = (__u32)((d - tv.tv_sec) / (double)1000000.0); } - */ // accessors time_t sec() const { return tv.tv_sec; } @@ -58,12 +61,21 @@ class utime_t { int nsec() const { return tv.tv_usec*1000; } // ref accessors/modifiers - time_t& sec_ref() { return tv.tv_sec; } - // FIXME: tv.tv_usec is a __darwin_suseconds_t on Darwin. - // is just casting it to long& OK? - long& usec_ref() { return (long&) tv.tv_usec; } + __u32& sec_ref() { return tv.tv_sec; } + __u32& usec_ref() { return tv.tv_usec; } + + void copy_to_timeval(struct timeval *v) const { + v->tv_sec = tv.tv_sec; + v->tv_usec = tv.tv_usec; + } + void set_from_timeval(const struct timeval *v) { + tv.tv_sec = v->tv_sec; + tv.tv_usec = v->tv_usec; + } + //struct timeval& timeval() { return tv; } + //struct timeval& tv_ref() { return tv; } - struct timeval& tv_ref() { return tv; } + struct ceph_timeval& tv_ref() { return tv; } // cast to double operator double() { diff --git a/trunk/ceph/mds/Server.cc b/trunk/ceph/mds/Server.cc index f633e1856a6ee..5a2429d117f2e 100644 --- a/trunk/ceph/mds/Server.cc +++ b/trunk/ceph/mds/Server.cc @@ -3709,7 +3709,7 @@ void Server::_do_open(MDRequest *mdr, CInode *cur) int cmode = req->get_open_file_mode(); // can we issue the caps they want? - version_t fdv = mds->locker->issue_file_data_version(cur); + //version_t fdv = mds->locker->issue_file_data_version(cur); Capability *cap = mds->locker->issue_new_caps(cur, cmode, req); if (!cap) return; // can't issue (yet), so wait! @@ -3730,7 +3730,7 @@ void Server::_do_open(MDRequest *mdr, CInode *cur) MClientReply *reply = new MClientReply(req, 0); reply->set_file_caps(cap->pending()); reply->set_file_caps_seq(cap->get_last_seq()); - reply->set_file_data_version(fdv); + //reply->set_file_data_version(fdv); reply_request(mdr, reply, cur); // journal? diff --git a/trunk/ceph/messages/MClientReply.h b/trunk/ceph/messages/MClientReply.h index ecdf88a520104..3717d21e7d8ce 100644 --- a/trunk/ceph/messages/MClientReply.h +++ b/trunk/ceph/messages/MClientReply.h @@ -125,14 +125,7 @@ struct InodeStat { class MClientReply : public Message { // reply data - struct st_ { - long tid; - int op; - int result; // error code - unsigned char file_caps; // for open - long file_caps_seq; - uint64_t file_data_version; // for client buffercache consistency - } st; + struct ceph_client_reply_head st; string path; @@ -158,12 +151,12 @@ class MClientReply : public Message { unsigned char get_file_caps() { return st.file_caps; } long get_file_caps_seq() { return st.file_caps_seq; } - uint64_t get_file_data_version() { return st.file_data_version; } + //uint64_t get_file_data_version() { return st.file_data_version; } void set_result(int r) { st.result = r; } void set_file_caps(unsigned char c) { st.file_caps = c; } void set_file_caps_seq(long s) { st.file_caps_seq = s; } - void set_file_data_version(uint64_t v) { st.file_data_version = v; } + //void set_file_data_version(uint64_t v) { st.file_data_version = v; } MClientReply() : dir_dir(0) {} MClientReply(MClientRequest *req, int result = 0) : diff --git a/trunk/ceph/messages/MClientRequest.h b/trunk/ceph/messages/MClientRequest.h index fece04f779df1..d8784c981df2f 100644 --- a/trunk/ceph/messages/MClientRequest.h +++ b/trunk/ceph/messages/MClientRequest.h @@ -73,19 +73,7 @@ class MClientRequest : public Message { - struct { - tid_t tid; - tid_t oldest_client_tid; - int num_fwd; - int retry_attempt; - inodeno_t mds_wants_replica_in_dirino; - - entity_inst_t client_inst; - - int op; - int caller_uid, caller_gid; - inodeno_t cwd_ino; - } st; + struct ceph_client_request_head st; // path arguments filepath path; @@ -93,49 +81,7 @@ class MClientRequest : public Message { public: // fixed size arguments. in a union. - // note: nothing with a constructor can go here; use underlying base - // types for _inodeno_t, _frag_t. - union { - struct { - int mask; - } stat; - struct { - _inodeno_t ino; - int mask; - } fstat; - struct { - _frag_t frag; - } readdir; - struct { - _utime_t mtime; - _utime_t atime; - } utime; - struct { - mode_t mode; - } chmod; - struct { - uid_t uid; - gid_t gid; - } chown; - struct { - mode_t mode; - dev_t rdev; - } mknod; - struct { - mode_t mode; - } mkdir; - struct { - int flags; - mode_t mode; - } open; - struct { - _inodeno_t ino; // optional - off_t length; - } truncate; - struct { - _inodeno_t ino; - } fsync; - } args; + union ceph_client_request_args args; // cons MClientRequest() : Message(CEPH_MSG_CLIENT_REQUEST) {} @@ -143,12 +89,13 @@ class MClientRequest : public Message { memset(&st, 0, sizeof(st)); memset(&args, 0, sizeof(args)); this->st.op = op; - this->st.client_inst = ci; + this->st.client_inst.name = ci.name.v; + this->st.client_inst.addr = ci.addr.v; } metareqid_t get_reqid() { // FIXME: for now, assume clients always have 1 incarnation - return metareqid_t(st.client_inst.name.num(), st.tid); + return metareqid_t(st.client_inst.name.num, st.tid); } int get_open_file_mode() { @@ -222,10 +169,15 @@ class MClientRequest : public Message { void set_mds_wants_replica_in_dirino(inodeno_t dirino) { st.mds_wants_replica_in_dirino = dirino; } - void set_client_inst(const entity_inst_t& i) { st.client_inst = i; } - const entity_inst_t& get_client_inst() { return st.client_inst; } + void set_client_inst(const entity_inst_t& i) { + st.client_inst.name = i.name.v; + st.client_inst.addr = i.addr.v; + } + entity_inst_t get_client_inst() { + return entity_inst_t(st.client_inst); + } - int get_client() { return st.client_inst.name.num(); } + int get_client() { return st.client_inst.name.num; } tid_t get_tid() { return st.tid; } tid_t get_oldest_client_tid() { return st.oldest_client_tid; } int get_num_fwd() { return st.num_fwd; } @@ -240,7 +192,7 @@ class MClientRequest : public Message { inodeno_t get_mds_wants_replica_in_dirino() { return st.mds_wants_replica_in_dirino; } - inodeno_t get_cwd_ino() { return st.cwd_ino ? st.cwd_ino:inodeno_t(MDS_INO_ROOT); } + inodeno_t get_cwd_ino() { return st.cwd_ino ? st.cwd_ino:MDS_INO_ROOT; } void decode_payload() { int off = 0; -- 2.39.5