[BACK]Return to puffs_priv.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libpuffs

Annotation of src/lib/libpuffs/puffs_priv.h, Revision 1.44

1.44    ! mrg         1: /*     $NetBSD: puffs_priv.h,v 1.43 2010/12/06 14:50:34 pooka Exp $    */
1.1       pooka       2:
                      3: /*
1.38      pooka       4:  * Copyright (c) 2006, 2007, 2008 Antti Kantee.  All Rights Reserved.
1.1       pooka       5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     16:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     18:  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     19:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     20:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     21:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     23:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     24:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     25:  * SUCH DAMAGE.
                     26:  */
                     27:
                     28: #ifndef _PUFFS_PRIVATE_H_
                     29: #define _PUFFS_PRIVATE_H_
                     30:
                     31: #include <sys/types.h>
                     32: #include <fs/puffs/puffs_msgif.h>
                     33:
1.43      pooka      34: #include <pthread.h>
1.1       pooka      35: #include <puffs.h>
1.2       pooka      36: #include <ucontext.h>
                     37:
1.30      pooka      38: extern pthread_mutex_t pu_lock;
1.31      pooka      39: #define PU_LOCK() pthread_mutex_lock(&pu_lock)
                     40: #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
1.30      pooka      41:
1.37      pooka      42: #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
1.4       pooka      43:
1.9       pooka      44: struct puffs_framectrl {
1.10      pooka      45:        puffs_framev_readframe_fn rfb;
                     46:        puffs_framev_writeframe_fn wfb;
1.11      pooka      47:        puffs_framev_cmpframe_fn cmpfb;
1.21      pooka      48:        puffs_framev_gotframe_fn gotfb;
1.10      pooka      49:        puffs_framev_fdnotify_fn fdnotfn;
1.9       pooka      50: };
                     51:
                     52: struct puffs_fctrl_io {
1.33      pooka      53:        struct puffs_framectrl *fctrl;
                     54:
1.9       pooka      55:        int io_fd;
1.10      pooka      56:        int stat;
1.9       pooka      57:
1.19      pooka      58:        int rwait;
                     59:        int wwait;
                     60:
1.9       pooka      61:        struct puffs_framebuf *cur_in;
                     62:
                     63:        TAILQ_HEAD(, puffs_framebuf) snd_qing;  /* queueing to be sent */
                     64:        TAILQ_HEAD(, puffs_framebuf) res_qing;  /* q'ing for rescue */
1.19      pooka      65:        LIST_HEAD(, puffs_fbevent) ev_qing;     /* q'ing for events */
1.9       pooka      66:
                     67:        LIST_ENTRY(puffs_fctrl_io) fio_entries;
                     68: };
1.10      pooka      69: #define FIO_WR         0x01
                     70: #define FIO_WRGONE     0x02
                     71: #define FIO_RDGONE     0x04
                     72: #define FIO_DEAD       0x08
1.17      pooka      73: #define FIO_ENABLE_R   0x10
                     74: #define FIO_ENABLE_W   0x20
1.10      pooka      75:
1.19      pooka      76: #define FIO_EN_WRITE(fio)                              \
                     77:     (!(fio->stat & FIO_WR)                             \
                     78:       && ((!TAILQ_EMPTY(&fio->snd_qing)                        \
                     79:             && (fio->stat & FIO_ENABLE_W))             \
                     80:          || fio->wwait))
1.17      pooka      81:
                     82: #define FIO_RM_WRITE(fio)                      \
                     83:     ((fio->stat & FIO_WR)                      \
1.19      pooka      84:       && (((TAILQ_EMPTY(&fio->snd_qing)                \
                     85:         || (fio->stat & FIO_ENABLE_W) == 0))   \
                     86:        && (fio->wwait == 0)))
1.7       pooka      87:
1.28      pooka      88:
1.5       pooka      89: /*
                     90:  * usermount: describes one file system instance
                     91:  */
                     92: struct puffs_usermount {
                     93:        struct puffs_ops        pu_ops;
1.18      pooka      94:
                     95:        int                     pu_fd;
                     96:        size_t                  pu_maxreqlen;
1.5       pooka      97:
                     98:        uint32_t                pu_flags;
1.27      pooka      99:        int                     pu_cc_stackshift;
1.5       pooka     100:
1.40      pooka     101:        ucontext_t              pu_mainctx;
1.38      pooka     102: #define PUFFS_CCMAXSTORE 32
                    103:        int                     pu_cc_nstored;
                    104:
1.9       pooka     105:        int                     pu_kq;
1.5       pooka     106:        int                     pu_state;
1.40      pooka     107: #define PU_STATEMASK   0x00ff
                    108: #define PU_INLOOP      0x0100
                    109: #define PU_ASYNCFD     0x0200
                    110: #define PU_HASKQ       0x0400
                    111: #define PU_PUFFSDAEMON 0x0800
                    112: #define PU_MAINRESTORE 0x1000
1.42      pooka     113: #define PU_DONEXIT     0x2000
1.9       pooka     114: #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
1.40      pooka     115: #define PU_SETSFLAG(pu, s) (pu->pu_state |= (s))
                    116: #define PU_CLRSFLAG(pu, s) \
1.44    ! mrg       117:     (pu->pu_state = ((pu->pu_state & ~(s)) | (pu->pu_state & PU_STATEMASK)))
1.32      pooka     118:        int                     pu_dpipe[2];
1.5       pooka     119:
                    120:        struct puffs_node       *pu_pn_root;
                    121:
                    122:        LIST_HEAD(, puffs_node) pu_pnodelst;
1.38      pooka     123:
                    124:        LIST_HEAD(, puffs_cc)   pu_ccmagazin;
1.39      pooka     125:        TAILQ_HEAD(, puffs_cc)  pu_lazyctx;
1.25      pooka     126:        TAILQ_HEAD(, puffs_cc)  pu_sched;
1.5       pooka     127:
1.37      pooka     128:        pu_cmap_fn              pu_cmap;
1.5       pooka     129:
                    130:        pu_pathbuild_fn         pu_pathbuild;
                    131:        pu_pathtransform_fn     pu_pathtransform;
                    132:        pu_pathcmp_fn           pu_pathcmp;
                    133:        pu_pathfree_fn          pu_pathfree;
                    134:        pu_namemod_fn           pu_namemod;
                    135:
1.22      pooka     136:        pu_errnotify_fn         pu_errnotify;
                    137:
1.29      pooka     138:        pu_prepost_fn           pu_oppre;
                    139:        pu_prepost_fn           pu_oppost;
                    140:
1.33      pooka     141:        struct puffs_framectrl  pu_framectrl[2];
                    142: #define PU_FRAMECTRL_FS   0
                    143: #define PU_FRAMECTRL_USER 1
                    144:        LIST_HEAD(, puffs_fctrl_io) pu_ios;
                    145:        LIST_HEAD(, puffs_fctrl_io) pu_ios_rmlist;
                    146:        struct kevent           *pu_evs;
1.42      pooka     147:        size_t                  pu_nevs;
1.7       pooka     148:
1.10      pooka     149:        puffs_ml_loop_fn        pu_ml_lfn;
                    150:        struct timespec         pu_ml_timeout;
                    151:        struct timespec         *pu_ml_timep;
                    152:
1.18      pooka     153:        struct puffs_kargs      *pu_kargp;
                    154:
1.34      pooka     155:        uint64_t                pu_nextreq;
1.10      pooka     156:        void                    *pu_privdata;
1.5       pooka     157: };
                    158:
1.2       pooka     159: /* call context */
                    160:
1.39      pooka     161: struct puffs_cc;
                    162: typedef void (*puffs_ccfunc)(struct puffs_cc *);
                    163:
1.2       pooka     164: struct puffs_cc {
                    165:        struct puffs_usermount  *pcc_pu;
1.33      pooka     166:        struct puffs_framebuf   *pcc_pb;
1.2       pooka     167:
1.39      pooka     168:        /* real cc */
                    169:        union {
                    170:                struct {
                    171:                        ucontext_t      uc;             /* "continue"   */
                    172:                        ucontext_t      uc_ret;         /* "yield"      */
                    173:                } real;
                    174:                struct {
                    175:                        puffs_ccfunc    func;
                    176:                        void            *farg;
                    177:                } fake;
                    178:        } pcc_u;
1.2       pooka     179:
1.24      pooka     180:        pid_t                   pcc_pid;
                    181:        lwpid_t                 pcc_lid;
                    182:
1.2       pooka     183:        int                     pcc_flags;
                    184:
1.38      pooka     185:        TAILQ_ENTRY(puffs_cc)   pcc_schedent;
                    186:        LIST_ENTRY(puffs_cc)    pcc_rope;
1.2       pooka     187: };
1.39      pooka     188: #define pcc_uc         pcc_u.real.uc
                    189: #define pcc_uc_ret     pcc_u.real.uc_ret
                    190: #define pcc_func       pcc_u.fake.func
                    191: #define pcc_farg       pcc_u.fake.farg
                    192: #define PCC_DONE       0x01
                    193: #define PCC_BORROWED   0x02
                    194: #define PCC_HASCALLER  0x04
                    195: #define PCC_MLCONT     0x08
1.2       pooka     196:
1.16      pooka     197: struct puffs_newinfo {
                    198:        void            **pni_cookie;
                    199:        enum vtype      *pni_vtype;
                    200:        voff_t          *pni_size;
                    201:        dev_t           *pni_rdev;
                    202: };
                    203:
1.13      pooka     204: #define PUFFS_MAKEKCRED(to, from)                                      \
                    205:        /*LINTED: tnilxnaht, the cast is ok */                          \
1.15      pooka     206:        const struct puffs_kcred *to = (const void *)from
1.13      pooka     207: #define PUFFS_MAKECRED(to, from)                                       \
                    208:        /*LINTED: tnilxnaht, the cast is ok */                          \
1.15      pooka     209:        const struct puffs_cred *to = (const void *)from
1.13      pooka     210: #define PUFFS_KCREDTOCRED(to, from)                                    \
                    211:        /*LINTED: tnilxnaht, the cast is ok */                          \
1.15      pooka     212:        to = (void *)from
1.9       pooka     213:
1.2       pooka     214: __BEGIN_DECLS
                    215:
1.39      pooka     216: void   puffs__framev_input(struct puffs_usermount *, struct puffs_framectrl *,
1.33      pooka     217:                           struct puffs_fctrl_io *);
1.39      pooka     218: int    puffs__framev_output(struct puffs_usermount *, struct puffs_framectrl*,
1.33      pooka     219:                            struct puffs_fctrl_io *);
1.39      pooka     220: void   puffs__framev_exit(struct puffs_usermount *);
                    221: void   puffs__framev_readclose(struct puffs_usermount *,
1.10      pooka     222:                               struct puffs_fctrl_io *, int);
1.39      pooka     223: void   puffs__framev_writeclose(struct puffs_usermount *,
1.10      pooka     224:                                struct puffs_fctrl_io *, int);
1.39      pooka     225: void   puffs__framev_notify(struct puffs_fctrl_io *, int);
1.33      pooka     226: void   *puffs__framebuf_getdataptr(struct puffs_framebuf *);
                    227: int    puffs__framev_addfd_ctrl(struct puffs_usermount *, int, int,
                    228:                                 struct puffs_framectrl *);
                    229: void   puffs__framebuf_moveinfo(struct puffs_framebuf *,
                    230:                                 struct puffs_framebuf *);
1.10      pooka     231:
1.39      pooka     232: void   puffs__theloop(struct puffs_cc *);
                    233: void   puffs__ml_dispatch(struct puffs_usermount *, struct puffs_framebuf *);
                    234:
                    235: int    puffs__cc_create(struct puffs_usermount *, puffs_ccfunc,
                    236:                         struct puffs_cc **);
                    237: void   puffs__cc_cont(struct puffs_cc *);
                    238: void   puffs__cc_destroy(struct puffs_cc *, int);
                    239: void   puffs__cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
                    240: void   puffs__goto(struct puffs_cc *);
1.40      pooka     241: int    puffs__cc_savemain(struct puffs_usermount *);
                    242: int    puffs__cc_restoremain(struct puffs_usermount *);
1.41      pooka     243: void   puffs__cc_exit(struct puffs_usermount *);
1.39      pooka     244:
                    245: int    puffs__fsframe_read(struct puffs_usermount *, struct puffs_framebuf *,
                    246:                            int, int *);
                    247: int    puffs__fsframe_write(struct puffs_usermount *, struct puffs_framebuf *,
                    248:                            int, int *);
                    249: int    puffs__fsframe_cmp(struct puffs_usermount *, struct puffs_framebuf *,
                    250:                           struct puffs_framebuf *, int *);
                    251: void   puffs__fsframe_gotframe(struct puffs_usermount *,
                    252:                                struct puffs_framebuf *);
1.33      pooka     253:
1.34      pooka     254: uint64_t       puffs__nextreq(struct puffs_usermount *pu);
                    255:
1.2       pooka     256: __END_DECLS
                    257:
1.1       pooka     258: #endif /* _PUFFS_PRIVATE_H_ */

CVSweb <webmaster@jp.NetBSD.org>