nfs-ganesha 1.4

9p.h

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2011)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 3 of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  * ---------------------------------------
00023  */
00024 
00025 /* 
00026  * Copied from 2.6.38-rc2 kernel, taken from diod sources (code.google.com/p/diod/) then adapted to ganesha
00027  */
00028 
00029 #ifndef _9P_H
00030 #define _9P_H
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <unistd.h>
00034 #include <sys/select.h>
00035 #include "fsal.h"
00036 #include "cache_inode.h"
00037 
00038 typedef uint8_t   u8;
00039 typedef uint16_t u16;
00040 typedef uint32_t u32;
00041 typedef uint64_t u64;
00042 
00043 #define NB_PREALLOC_HASH_9P 100
00044 #define NB_PREALLOC_FID_9P  100
00045 #define PRIME_9P 17 
00046 
00047 #define _9P_PORT 564
00048 #define _9P_SEND_BUFFER_SIZE 131072
00049 #define _9P_RECV_BUFFER_SIZE 131072
00050 #define _9p_READ_BUFFER_SIZE _9P_SEND_BUFFER_SIZE
00051 #define _9P_MAXDIRCOUNT 2000 /* Must be bigger than _9P_SEND_BUFFER_SIZE / 40 */
00052 #define _9P_LOCK_CLIENT_LEN 64
00053 #define CONF_LABEL_9P "_9P"
00054 
00055 #define _9P_MSG_SIZE 70000 
00056 #define _9P_HDR_SIZE  4
00057 #define _9P_TYPE_SIZE 1
00058 #define _9P_TAG_SIZE  2
00059 #define _9p_BLK_SIZE 4096
00060 
00115 enum _9p_msg_t {
00116         _9P_TLERROR = 6,
00117         _9P_RLERROR,
00118         _9P_TSTATFS = 8,
00119         _9P_RSTATFS,
00120         _9P_TLOPEN = 12,
00121         _9P_RLOPEN,
00122         _9P_TLCREATE = 14,
00123         _9P_RLCREATE,
00124         _9P_TSYMLINK = 16,
00125         _9P_RSYMLINK,
00126         _9P_TMKNOD = 18,
00127         _9P_RMKNOD,
00128         _9P_TRENAME = 20,
00129         _9P_RRENAME,
00130         _9P_TREADLINK = 22,
00131         _9P_RREADLINK,
00132         _9P_TGETATTR = 24,
00133         _9P_RGETATTR,
00134         _9P_TSETATTR = 26,
00135         _9P_RSETATTR,
00136         _9P_TXATTRWALK = 30,
00137         _9P_RXATTRWALK,
00138         _9P_TXATTRCREATE = 32,
00139         _9P_RXATTRCREATE,
00140         _9P_TREADDIR = 40,
00141         _9P_RREADDIR,
00142         _9P_TFSYNC = 50,
00143         _9P_RFSYNC,
00144         _9P_TLOCK = 52,
00145         _9P_RLOCK,
00146         _9P_TGETLOCK = 54,
00147         _9P_RGETLOCK,
00148         _9P_TLINK = 70,
00149         _9P_RLINK,
00150         _9P_TMKDIR = 72,
00151         _9P_RMKDIR,
00152         _9P_TRENAMEAT = 74,
00153         _9P_RRENAMEAT,
00154         _9P_TUNLINKAT = 76,
00155         _9P_RUNLINKAT,
00156         _9P_TVERSION = 100,
00157         _9P_RVERSION,
00158         _9P_TAUTH = 102,
00159         _9P_RAUTH,
00160         _9P_TATTACH = 104,
00161         _9P_RATTACH,
00162         _9P_TERROR = 106,
00163         _9P_RERROR,
00164         _9P_TFLUSH = 108,
00165         _9P_RFLUSH,
00166         _9P_TWALK = 110,
00167         _9P_RWALK,
00168         _9P_TOPEN = 112,
00169         _9P_ROPEN,
00170         _9P_TCREATE = 114,
00171         _9P_RCREATE,
00172         _9P_TREAD = 116,
00173         _9P_RREAD,
00174         _9P_TWRITE = 118,
00175         _9P_RWRITE,
00176         _9P_TCLUNK = 120,
00177         _9P_RCLUNK,
00178         _9P_TREMOVE = 122,
00179         _9P_RREMOVE,
00180         _9P_TSTAT = 124,
00181         _9P_RSTAT,
00182         _9P_TWSTAT = 126,
00183         _9P_RWSTAT,
00184 };
00185 
00205 enum _9p_qid_t {
00206         _9P_QTDIR = 0x80,
00207         _9P_QTAPPEND = 0x40,
00208         _9P_QTEXCL = 0x20,
00209         _9P_QTMOUNT = 0x10,
00210         _9P_QTAUTH = 0x08,
00211         _9P_QTTMP = 0x04,
00212         _9P_QTSYMLINK = 0x02,
00213         _9P_QTLINK = 0x01,
00214         _9P_QTFILE = 0x00,
00215 };
00216 
00217 /* 9P Magic Numbers */
00218 #define _9P_NOTAG       (u16)(~0)
00219 #define _9P_NOFID       (u32)(~0)
00220 #define _9P_NONUNAME    (u32)(~0)
00221 #define _9P_MAXWELEM    16
00222 
00223 /* ample room for _9P_TWRITE/_9P_RREAD header */
00224 #define _9P_IOHDRSZ     24
00225 
00226 /* Room for readdir header */
00227 #define _9P_READDIRHDRSZ        24
00228 #define _9P_FID_PER_CONN        32
00229 
00240 struct _9p_str {
00241         u16  len   ;
00242         char *str ;
00243 };
00244 
00265 typedef struct _9p_qid {
00266         u8 type;
00267         u32 version;
00268         u64 path;
00269 } _9p_qid_t;
00270 
00271 typedef struct _9p_param__
00272 {
00273   unsigned short _9p_port ;
00274 } _9p_parameter_t ;
00275 
00276 typedef struct _9p_fid__
00277 {
00278   u32                  fid ;
00279   fsal_op_context_t    fsal_op_context ;
00280   exportlist_t       * pexport ;
00281   cache_entry_t      * pentry ;
00282   _9p_qid_t            qid ;
00283   union 
00284     { 
00285        u32      iounit ;
00286        struct _9p_xattr_desc 
00287         {  
00288           unsigned int xattr_id ;
00289           caddr_t      xattr_content ;
00290         } xattr ;
00291     } specdata ;
00292 } _9p_fid_t ;
00293 
00294 
00295 typedef struct _9p_conn__
00296 {
00297   long int        sockfd ;
00298   struct timeval  birth;  /* This is useful if same sockfd is reused on socket's close/open  */
00299   _9p_fid_t       fids[_9P_FID_PER_CONN] ;
00300 } _9p_conn_t ;
00301 
00302 typedef struct _9p_request_data__
00303 {
00304   char         _9pmsg[_9P_MSG_SIZE] ;
00305   _9p_conn_t  *  pconn ; 
00306 } _9p_request_data_t ;
00307 
00308 typedef int (*_9p_function_t) (_9p_request_data_t * preq9p, 
00309                                void * pworker_data,
00310                                u32 * plenout, char * preply) ;
00311 
00312 typedef struct _9p_function_desc__
00313 {
00314   _9p_function_t service_function;
00315   char *funcname;
00316 } _9p_function_desc_t;
00317 
00318 
00319 #define _9p_getptr( __cursor, __pvar, __type ) \
00320 do                                             \
00321 {                                              \
00322   __pvar=(__type *)__cursor ;                  \
00323   __cursor += sizeof( __type ) ;               \
00324 } while( 0 ) 
00325 
00326 #define _9p_getstr( __cursor, __len, __str ) \
00327 do                                           \
00328 {                                            \
00329   __len = (u16 *)__cursor ;                  \
00330   __cursor += sizeof( u16 ) ;                \
00331   __str = __cursor ;                         \
00332   __cursor += *__len ;                       \
00333 } while( 0 )                           
00334 
00335 #define _9p_setptr( __cursor, __pvar, __type ) \
00336 do                                             \
00337 {                                              \
00338   *((__type *)__cursor) = *__pvar ;              \
00339   __cursor += sizeof( __type ) ;               \
00340 } while( 0 ) 
00341 
00342 #define _9p_setvalue( __cursor, __var, __type ) \
00343 do                                             \
00344 {                                              \
00345   *((__type *)__cursor) = __var ;              \
00346   __cursor += sizeof( __type ) ;               \
00347 } while( 0 ) 
00348 
00349 #define _9p_savepos( __cursor, __savedpos, __type ) \
00350 do                                                  \
00351 {                                                   \
00352   __savedpos = __cursor ;                           \
00353   __cursor += sizeof( __type ) ;                    \
00354 } while ( 0 ) 
00355 
00356 /* Insert a qid */
00357 #define _9p_setqid( __cursor, __qid )  \
00358 do                                     \
00359 {                                      \
00360   *((u8 *)__cursor) = __qid.type ;     \
00361   __cursor += sizeof( u8 ) ;           \
00362   *((u32 *)__cursor) = __qid.version ; \
00363   __cursor += sizeof( u32 ) ;          \
00364   *((u64 *)__cursor) = __qid.path ;    \
00365   __cursor += sizeof( u64 ) ;          \
00366 } while( 0 ) 
00367 
00368 /* Insert a non-null terminated string */
00369 #define _9p_setstr( __cursor, __len, __str ) \
00370 do                                           \
00371 {                                            \
00372   *((u16 *)__cursor) = __len ;               \
00373   __cursor += sizeof( u16 ) ;                \
00374   memcpy( __cursor, __str, __len ) ;         \
00375   __cursor += __len ;                        \
00376 } while( 0 )
00377 
00378 #define _9p_setbuffer( __cursor, __len, __buffer ) \
00379 do                                           \
00380 {                                            \
00381   *((u32 *)__cursor) = __len ;               \
00382   __cursor += sizeof( u32 ) ;                \
00383   memcpy( __cursor, __buffer, __len ) ;         \
00384   __cursor += __len ;                        \
00385 } while( 0 )
00386 
00387 #define _9p_setinitptr( __cursor, __start, __reqtype ) \
00388 do                                                     \
00389 {                                                      \
00390   __cursor = __start + _9P_HDR_SIZE;                   \
00391   *((u8 *)__cursor) = __reqtype ;                      \
00392   __cursor += sizeof( u8 ) ;                           \
00393 } while( 0 ) 
00394 
00395 #define _9p_setendptr( __cursor, __start )         \
00396 do                                                 \
00397 {                                                  \
00398   *((u32 *)__start) =  (u32)(__cursor - __start) ; \
00399 } while( 0 ) 
00400 
00401 #define _9p_checkbound( __cursor, __start, __maxlen ) \
00402 do                                                    \
00403 {                                                     \
00404 if( (u32)( __cursor - __start ) > *__maxlen )         \
00405   return -1 ;                                         \
00406 else                                                  \
00407    *__maxlen = (u32)( __cursor - __start )  ;         \
00408 } while( 0 ) 
00409 
00410 /* Bit values for getattr valid field.
00411  */
00412 #define _9P_GETATTR_MODE        0x00000001ULL
00413 #define _9P_GETATTR_NLINK       0x00000002ULL
00414 #define _9P_GETATTR_UID         0x00000004ULL
00415 #define _9P_GETATTR_GID         0x00000008ULL
00416 #define _9P_GETATTR_RDEV        0x00000010ULL
00417 #define _9P_GETATTR_ATIME       0x00000020ULL
00418 #define _9P_GETATTR_MTIME       0x00000040ULL
00419 #define _9P_GETATTR_CTIME       0x00000080ULL
00420 #define _9P_GETATTR_INO         0x00000100ULL
00421 #define _9P_GETATTR_SIZE        0x00000200ULL
00422 #define _9P_GETATTR_BLOCKS      0x00000400ULL
00423 
00424 #define _9P_GETATTR_BTIME       0x00000800ULL
00425 #define _9P_GETATTR_GEN         0x00001000ULL
00426 #define _9P_GETATTR_DATA_VERSION        0x00002000ULL
00427 
00428 #define _9P_GETATTR_BASIC       0x000007ffULL /* Mask for fields up to BLOCKS */
00429 #define _9P_GETATTR_ALL         0x00003fffULL /* Mask for All fields above */
00430 
00431 /* Bit values for setattr valid field from <linux/fs.h>.
00432  */
00433 #define _9P_SETATTR_MODE        0x00000001UL
00434 #define _9P_SETATTR_UID         0x00000002UL
00435 #define _9P_SETATTR_GID         0x00000004UL
00436 #define _9P_SETATTR_SIZE        0x00000008UL
00437 #define _9P_SETATTR_ATIME       0x00000010UL
00438 #define _9P_SETATTR_MTIME       0x00000020UL
00439 #define _9P_SETATTR_CTIME       0x00000040UL
00440 #define _9P_SETATTR_ATIME_SET   0x00000080UL
00441 #define _9P_SETATTR_MTIME_SET   0x00000100UL
00442 
00443 /* Bit values for lock type.
00444  */
00445 #define _9P_LOCK_TYPE_RDLCK 0
00446 #define _9P_LOCK_TYPE_WRLCK 1
00447 #define _9P_LOCK_TYPE_UNLCK 2
00448 
00449 /* Bit values for lock status.
00450  */
00451 #define _9P_LOCK_SUCCESS 0
00452 #define _9P_LOCK_BLOCKED 1
00453 #define _9P_LOCK_ERROR 2
00454 #define _9P_LOCK_GRACE 3
00455 
00456 /* Bit values for lock flags.
00457  */
00458 #define _9P_LOCK_FLAGS_BLOCK 1
00459 #define _9P_LOCK_FLAGS_RECLAIM 2
00460 
00461 /* service functions */
00462 int _9p_read_conf( config_file_t   in_config,
00463                    _9p_parameter_t *pparam ) ;
00464 int _9p_init( _9p_parameter_t * pparam ) ;
00465 
00466 /* Tools functions */
00467 int _9p_tools_get_fsal_op_context_by_uid( u32 uid, _9p_fid_t * pfid ) ;
00468 int _9p_tools_get_fsal_op_context_by_name( int uname_len, char * uname_str, _9p_fid_t * pfid ) ;
00469 int _9p_tools_errno( cache_inode_status_t cache_status ) ;
00470 void _9p_tools_fsal_attr2stat( fsal_attrib_list_t * pfsalattr, struct stat * pstat ) ;
00471 void _9p_tools_acess2fsal( u32 * paccessin, fsal_accessflags_t * pfsalaccess ) ;
00472 void _9p_openflags2FSAL( u32 * inflags, fsal_openflags_t * outflags ) ;
00473 void _9p_chomp_attr_value(char *str, size_t size) ;
00474 
00475 /* Protocol functions */
00476 int _9p_not_2000L( _9p_request_data_t * preq9p, 
00477                    void * pworker_data,
00478                    u32 * plenout, 
00479                    char * preply) ;
00480 
00481 int _9p_clunk( _9p_request_data_t * preq9p, 
00482                void * pworker_data,
00483                u32 * plenout,
00484                char * preply) ;
00485 
00486 int _9p_attach( _9p_request_data_t * preq9p, 
00487                 void * pworker_data,
00488                 u32 * plenout, 
00489                 char * preply) ;
00490 
00491 int _9p_auth( _9p_request_data_t * preq9p, 
00492               void * pworker_data,
00493               u32 * plenout, 
00494               char * preply) ;
00495 
00496 int _9p_lcreate( _9p_request_data_t * preq9p, 
00497                  void * pworker_data,
00498                  u32 * plenout, 
00499                  char * preply) ;
00500 
00501 int _9p_flush( _9p_request_data_t * preq9p, 
00502                void * pworker_data,
00503                u32 * plenout, 
00504                char * preply) ;
00505 
00506 int _9p_getattr( _9p_request_data_t * preq9p, 
00507                  void * pworker_data,
00508                  u32 * plenout, 
00509                  char * preply) ;
00510 
00511 int _9p_getlock( _9p_request_data_t * preq9p, 
00512                  void * pworker_data,
00513                  u32 * plenout, 
00514                  char * preply) ;
00515 
00516 int _9p_link( _9p_request_data_t * preq9p, 
00517               void * pworker_data,
00518               u32 * plenout, 
00519               char * preply) ;
00520 
00521 int _9p_lock( _9p_request_data_t * preq9p, 
00522               void * pworker_data,
00523               u32 * plenout, 
00524               char * preply) ;
00525 
00526 int _9p_lopen( _9p_request_data_t * preq9p, 
00527                void * pworker_data,
00528                u32 * plenout, 
00529                char * preply) ;
00530 
00531 int _9p_mkdir( _9p_request_data_t * preq9p, 
00532                void * pworker_data,
00533                u32 * plenout, 
00534                char * preply) ;
00535 
00536 int _9p_mknod( _9p_request_data_t * preq9p, 
00537                void * pworker_data,
00538                u32 * plenout, 
00539                char * preply) ;
00540 
00541 int _9p_read( _9p_request_data_t * preq9p, 
00542               void * pworker_data,
00543               u32 * plenout, 
00544               char * preply) ;
00545 
00546 int _9p_readdir( _9p_request_data_t * preq9p, 
00547                  void * pworker_data,
00548                  u32 * plenout, 
00549                  char * preply) ;
00550 
00551 int _9p_readlink( _9p_request_data_t * preq9p, 
00552                   void * pworker_data,
00553                   u32 * plenout, 
00554                   char * preply) ;
00555 
00556 int _9p_setattr( _9p_request_data_t * preq9p, 
00557                  void * pworker_data,
00558                  u32 * plenout, 
00559                  char * preply) ;
00560 
00561 int _9p_symlink( _9p_request_data_t * preq9p, 
00562                  void * pworker_data,
00563                  u32 * plenout, 
00564                  char * preply) ;
00565 
00566 int _9p_remove( _9p_request_data_t * preq9p, 
00567                 void * pworker_data,
00568                 u32 * plenout, 
00569                 char * preply) ;
00570 
00571 int _9p_rename( _9p_request_data_t * preq9p, 
00572                 void * pworker_data,
00573                 u32 * plenout, 
00574                 char * preply) ;
00575 
00576 int _9p_renameat( _9p_request_data_t * preq9p, 
00577                   void * pworker_data,
00578                   u32 * plenout, 
00579                   char * preply) ;
00580 
00581 int _9p_statfs( _9p_request_data_t * preq9p, 
00582                 void * pworker_data,
00583                 u32 * plenout, 
00584                 char * preply) ;
00585 
00586 int _9p_fsync( _9p_request_data_t * preq9p, 
00587                void  * pworker_data,
00588                u32 * plenout, 
00589                char * preply) ;
00590 
00591 int _9p_unlinkat( _9p_request_data_t * preq9p, 
00592                   void * pworker_data,
00593                   u32 * plenout, 
00594                   char * preply) ;
00595 
00596 int _9p_version( _9p_request_data_t * preq9p, 
00597                  void * pworker_data,
00598                  u32 * plenout,
00599                  char * preply) ;
00600 
00601 int _9p_walk( _9p_request_data_t * preq9p, 
00602               void * pworker_data,
00603               u32 * plenout,
00604               char * preply) ;
00605 
00606 int _9p_write( _9p_request_data_t * preq9p, 
00607                void * pworker_data,
00608                u32 * plenout,
00609                char * preply) ;
00610 
00611 int _9p_xattrcreate( _9p_request_data_t * preq9p, 
00612                      void * pworker_data,
00613                      u32 * plenout,
00614                      char * preply) ;
00615 
00616 int _9p_xattrwalk( _9p_request_data_t * preq9p, 
00617                    void * pworker_data,
00618                    u32 * plenout,
00619                    char * preply) ;
00620 
00621 int _9p_rerror( _9p_request_data_t * preq9p,
00622                 u16 * msgtag,
00623                 u32   err, 
00624                 u32 * plenout, 
00625                 char * preply) ;
00626 
00627 #endif /* _9P_H */