From fba9e0818e96a31d376d1a0cb558b1ab276803da Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 17 Jun 2007 21:31:07 +0000 Subject: [PATCH] More syslink messaging work. Now basically done except for the I/O 'DMA' component. --- sys/kern/kern_syslink.c | 82 +++++++++++++++++++++++++++++++++---------------- sys/sys/syslink.h | 7 +++-- sys/sys/syslink_msg.h | 20 +++++++++--- sys/sys/syslink_msg2.h | 20 +++++++----- 4 files changed, 87 insertions(+), 42 deletions(-) diff --git a/sys/kern/kern_syslink.c b/sys/kern/kern_syslink.c index 89fcd614cb..100f8dda01 100644 --- a/sys/kern/kern_syslink.c +++ b/sys/kern/kern_syslink.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_syslink.c,v 1.11 2007/05/27 20:35:38 dillon Exp $ + * $DragonFly: src/sys/kern/kern_syslink.c,v 1.12 2007/06/17 21:31:05 dillon Exp $ */ /* * This module implements the core syslink() system call and provides @@ -128,9 +128,9 @@ static void backend_dispose_kern(struct sldesc *sl, struct slmsg *slmsg); * more complex ctor/dtor API in order to provide ready-to-go slmsg's. */ -struct objcache *sl_objcache_big; -struct objcache *sl_objcache_small; -struct objcache *sl_objcache_none; +static struct objcache *sl_objcache_big; +static struct objcache *sl_objcache_small; +static struct objcache *sl_objcache_none; MALLOC_DEFINE(M_SYSLINK, "syslink", "syslink manager"); @@ -429,10 +429,17 @@ shutdownsldesc(struct sldesc *sl, int how) * Call shutdown on the peer with the opposite flags */ rhow = 0; - if (how & SHUT_RD) - rhow |= SHUT_WR; - if (how & SHUT_WR) - rhow |= SHUT_RD; + switch(how) { + case SHUT_RD: + rhow = SHUT_WR; + break; + case SHUT_WR: + rhow = SHUT_WR; + break; + case SHUT_RDWR: + rhow = SHUT_RDWR; + break; + } shutdownsldesc2(sl->peer, rhow); } @@ -441,10 +448,17 @@ void shutdownsldesc2(struct sldesc *sl, int how) { spin_lock_wr(&sl->spin); - if (how & SHUT_RD) + switch(how) { + case SHUT_RD: sl->flags |= SLF_RSHUTDOWN; - if (how & SHUT_WR) + break; + case SHUT_WR: sl->flags |= SLF_WSHUTDOWN; + break; + case SHUT_RDWR: + sl->flags |= SLF_RSHUTDOWN | SLF_WSHUTDOWN; + break; + } spin_unlock_wr(&sl->spin); /* @@ -755,7 +769,7 @@ slfileop_close(struct file *fp) * Shutdown both directions. The other side will not issue API * calls to us after we've shutdown both directions. */ - shutdownsldesc(sl, SHUT_RD|SHUT_WR); + shutdownsldesc(sl, SHUT_RDWR); /* * Cleanup @@ -1123,10 +1137,9 @@ syslink_ukbackend(int *fdp, struct sldesc **kslp) * and wait for a reply. */ int -syslink_kdomsg(struct sldesc *ksl, struct syslink_msg *msg, - struct bio *bio, int flags) +syslink_kdomsg(struct sldesc *ksl, struct slmsg *slmsg) { - struct slmsg slmsg; + struct syslink_msg *msg; int error; /* @@ -1134,11 +1147,9 @@ syslink_kdomsg(struct sldesc *ksl, struct syslink_msg *msg, * reply matching. If the message id is already in use we return * EEXIST, giving the originator the chance to roll a new msgid. */ - bzero(&slmsg, sizeof(slmsg)); - slmsg.msg = msg; - slmsg.msgsize = msg->sm_bytes; - slmsg.bio = bio; - if ((error = syslink_validate_msg(slmsg.msg, slmsg.msgsize)) != 0) + msg = slmsg->msg; + slmsg->msgsize = msg->sm_bytes; + if ((error = syslink_validate_msg(msg, msg->sm_bytes)) != 0) return (error); msg->sm_msgid = allocsysid(); @@ -1146,25 +1157,42 @@ syslink_kdomsg(struct sldesc *ksl, struct syslink_msg *msg, * Issue the request and wait for a matching reply or failure, * then remove the message from the matching tree and return. */ - error = ksl->peer->backend_write(ksl->peer, &slmsg); + error = ksl->peer->backend_write(ksl->peer, slmsg); spin_lock_wr(&ksl->spin); if (error == 0) { - while (slmsg.rep == NULL) { - error = msleep(&slmsg, &ksl->spin, flags, "kwtmsg", 0); + while (slmsg->rep == NULL) { + error = msleep(slmsg, &ksl->spin, 0, "kwtmsg", 0); /* XXX ignore error for now */ } - if (slmsg.rep == (struct slmsg *)-1) { + if (slmsg->rep == (struct slmsg *)-1) { error = EIO; + slmsg->rep = NULL; } else { - error = slmsg.rep->msg->sm_head.se_aux; - kprintf("reply with error %d\n", error); - ksl->peer->backend_dispose(ksl->peer, slmsg.rep); + error = slmsg->rep->msg->sm_head.se_aux; } } spin_unlock_wr(&ksl->spin); return(error); } +struct slmsg * +syslink_kallocmsg(void) +{ + return(objcache_get(sl_objcache_small, M_WAITOK)); +} + +void +syslink_kfreemsg(struct sldesc *ksl, struct slmsg *slmsg) +{ + struct slmsg *rep; + + if ((rep = slmsg->rep) != NULL) { + slmsg->rep = NULL; + ksl->peer->backend_dispose(ksl->peer, rep); + } + objcache_put(slmsg->oc, slmsg); +} + void syslink_kshutdown(struct sldesc *ksl, int how) { @@ -1174,7 +1202,7 @@ syslink_kshutdown(struct sldesc *ksl, int how) void syslink_kclose(struct sldesc *ksl) { - shutdownsldesc(ksl, SHUT_RD|SHUT_WR); + shutdownsldesc(ksl, SHUT_RDWR); sldrop(ksl); } diff --git a/sys/sys/syslink.h b/sys/sys/syslink.h index 9a3e3cab87..e9b5541491 100644 --- a/sys/sys/syslink.h +++ b/sys/sys/syslink.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/syslink.h,v 1.9 2007/05/27 20:35:43 dillon Exp $ + * $DragonFly: src/sys/sys/syslink.h,v 1.10 2007/06/17 21:31:06 dillon Exp $ */ /* @@ -157,8 +157,9 @@ struct slmsg { struct sldesc; int syslink_ukbackend(int *fdp, struct sldesc **kslp); -int syslink_kdomsg(struct sldesc *ksl, struct syslink_msg *msg, - struct bio *bio, int flags); +struct slmsg *syslink_kallocmsg(void); +int syslink_kdomsg(struct sldesc *ksl, struct slmsg *msg); +void syslink_kfreemsg(struct sldesc *ksl, struct slmsg *msg); void syslink_kshutdown(struct sldesc *ksl, int how); void syslink_kclose(struct sldesc *ksl); diff --git a/sys/sys/syslink_msg.h b/sys/sys/syslink_msg.h index 5a8b8394d7..12b01b0102 100644 --- a/sys/sys/syslink_msg.h +++ b/sys/sys/syslink_msg.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/syslink_msg.h,v 1.8 2007/05/27 20:35:43 dillon Exp $ + * $DragonFly: src/sys/sys/syslink_msg.h,v 1.9 2007/06/17 21:31:07 dillon Exp $ */ /* * The syslink infrastructure implements an optimized RPC mechanism across a @@ -84,16 +84,21 @@ typedef u_int16_t sl_reclen_t; /* item length */ * structured syslink_elm's, otherwise the payload is considered to * be opaque. * - * SE_CMDF_GLOBAL indicates that the command is globally defined by the + * SE_CMDF_GLOBAL - indicates that the command is globally defined by the * syslink standard and is not protocol-specific. Note that PADs * are not global commands. * - * SE_CMDF_UNTRANSLATED indicates that the syslink_elm structure had + * SE_CMDF_UNTRANSLATED - indicates that the syslink_elm structure had * to be translated into host endian format but any directly or * indirectly represented opaque data has not been. This bit is used * by the protocol layer to properly endian-translate protocol-specific * opaque data. * + * SE_CMDF_ASIZE* - These 2 bits can encode the size for simple elments. + * The size is verified prior to delivery so command switches on simple + * elements need not check se_bytes. This also makes it easier for + * the protocol code to do endian conversions. + * * SE_AUX field - auxillary data field (signed 32 bit integer) * * This field contains protocol and command/element specific data. @@ -111,7 +116,14 @@ struct syslink_elm { #define SE_CMDF_STRUCTURED 0x4000 /* payload is structured */ #define SE_CMDF_GLOBAL 0x2000 /* non-proto-specific global cmd */ #define SE_CMDF_UNTRANSLATED 0x1000 /* needs endian translation */ -#define SE_CMD_MASK 0x0FFF + +#define SE_CMDF_ASIZEMASK 0x0C00 /* auto-size mask */ +#define SE_CMDF_ASIZEX 0x0000 /* N bytes of extended data */ +#define SE_CMDF_ASIZE0 0x0400 /* 0 bytes of extended data */ +#define SE_CMDF_ASIZE4 0x0800 /* 4 bytes of extended data */ +#define SE_CMDF_ASIZE8 0x0C00 /* 8 bytes of extended data */ + +#define SE_CMD_MASK 0x03FF #define SE_CMD_PAD 0x0000 /* always reserved to mean PAD */ diff --git a/sys/sys/syslink_msg2.h b/sys/sys/syslink_msg2.h index 7160efe4ca..ee623daf3a 100644 --- a/sys/sys/syslink_msg2.h +++ b/sys/sys/syslink_msg2.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/syslink_msg2.h,v 1.2 2007/05/27 20:35:43 dillon Exp $ + * $DragonFly: src/sys/sys/syslink_msg2.h,v 1.3 2007/06/17 21:31:07 dillon Exp $ */ /* * Helper inlines and macros for syslink message generation @@ -49,7 +49,7 @@ static __inline struct syslink_elm * -syslink_msg_init_cmd(struct syslink_msg *msg, sl_proto_t proto, sl_cmd_t cmd) +sl_msg_init_cmd(struct syslink_msg *msg, sl_proto_t proto, sl_cmd_t cmd) { msg->sm_proto = proto; msg->sm_bytes = 0; @@ -63,8 +63,8 @@ syslink_msg_init_cmd(struct syslink_msg *msg, sl_proto_t proto, sl_cmd_t cmd) static __inline struct syslink_elm * -syslink_msg_init_reply(struct syslink_msg *msg, struct syslink_msg *rep, - int32_t error) +sl_msg_init_reply(struct syslink_msg *msg, struct syslink_msg *rep, + int32_t error) { rep->sm_proto = msg->sm_proto | SM_PROTO_REPLY; rep->sm_bytes = 0; @@ -78,7 +78,7 @@ syslink_msg_init_reply(struct syslink_msg *msg, struct syslink_msg *rep, static __inline void -syslink_msg_done(struct syslink_msg *msg) +sl_msg_fini(struct syslink_msg *msg) { msg->sm_bytes = offsetof(struct syslink_msg, sm_head) + SL_MSG_ALIGN(msg->sm_head.se_bytes); @@ -86,7 +86,7 @@ syslink_msg_done(struct syslink_msg *msg) static __inline struct syslink_elm * -syslink_elm_make(struct syslink_elm *par, sl_cmd_t cmd, int bytes) +sl_elm_make(struct syslink_elm *par, sl_cmd_t cmd, int bytes) { struct syslink_elm *elm = (void *)((char *)par + par->se_bytes); @@ -105,7 +105,7 @@ syslink_elm_make(struct syslink_elm *par, sl_cmd_t cmd, int bytes) */ static __inline struct syslink_elm * -syslink_elm_push(struct syslink_elm *par, sl_cmd_t cmd) +sl_elm_push(struct syslink_elm *par, sl_cmd_t cmd) { struct syslink_elm *elm = (void *)((char *)par + par->se_bytes); @@ -123,10 +123,14 @@ syslink_elm_push(struct syslink_elm *par, sl_cmd_t cmd) */ static __inline void -syslink_elm_pop(struct syslink_elm *par, struct syslink_elm *elm) +sl_elm_pop(struct syslink_elm *par, struct syslink_elm *elm) { par->se_bytes = (char *)elm - (char *)par + elm->se_bytes; } +#define SL_FOREACH_ELEMENT(par, elm) \ + for (elm = par + 1; (char *)elm < (char *)par + par->se_bytes; \ + elm = (void *)((char *)elm + SL_MSG_ALIGN(elm->se_bytes))) + #endif -- 2.11.4.GIT