Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH 4/5] session: introduce session_owner
Date: Tue, 20 Mar 2018 21:29:20 +0300	[thread overview]
Message-ID: <20180320182920.2pzb2axxxnojd6gc@esperanza> (raw)
In-Reply-To: <3009c98123cc3be6c5d0b0a0db064757b71faf16.1521466428.git.v.shpilevoy@tarantool.org>

On Mon, Mar 19, 2018 at 04:34:51PM +0300, Vladislav Shpilevoy wrote:
> Session owner stores a session type specific data. For example,
> IProto session has authentication salt, console session has
> file descriptor.
> 
> For #2677 session owner of IProto and console will have push()
> virtual function to do box.session.push, which implementation
> depends on a session type.
> 
> Needed for #2677

> diff --git a/src/box/session.h b/src/box/session.h
> @@ -60,6 +58,49 @@ enum session_type {
>  
>  extern const char *session_type_strs[];
>  
> +struct session_owner_vtab;
> +
> +/**
> + * Object to store session type specific data. For example, IProto
> + * stores iproto_connection, console stores file descriptor.
> + */
> +struct session_owner {

I don't really like the name. Please come up with some alternatives
(session_context, creator, data? dunno) so that we can pick the best
one.

> +	/** Session type. */
> +	enum session_type type;
> +	/** Virtual session owner methods. */
> +	const struct session_owner_vtab *vtab;
> +};
> +
> +struct session_owner_vtab {
> +	/** Allocate a duplicate of an owner. */
> +	struct session_owner *(*dup)(struct session_owner *);
> +	/** Destroy an owner, and free its memory. */
> +	void (*free)(struct session_owner *);
> +	/** Get the descriptor of an owner, if has. Else -1. */
> +	int (*fd)(const struct session_owner *);
> +};
> +
> +static inline struct session_owner *
> +session_owner_dup(struct session_owner *owner)
> +{
> +	return owner->vtab->dup(owner);
> +}
> +
> +static inline void
> +session_owner_delete(struct session_owner *owner)
> +{
> +	owner->vtab->free(owner);
> +}

> diff --git a/src/box/session.cc b/src/box/session.cc
> @@ -112,13 +155,25 @@ session_create(int fd, enum session_type type)
>  	return session;
>  }
>  
> +int
> +session_set_owner(struct session *session, struct session_owner *new_owner)
> +{
> +	struct session_owner *dup = session_owner_dup(new_owner);
> +	if (dup == NULL)
> +		return -1;
> +	if (session->owner != NULL)
> +		session_owner_delete(session->owner);
> +	session->owner = dup;
> +	return 0;
> +}

> diff --git a/src/box/applier.cc b/src/box/applier.cc
> @@ -533,7 +533,9 @@ applier_f(va_list ap)
>  	 * Set correct session type for use in on_replace()
>  	 * triggers.
>  	 */
> -	current_session()->type = SESSION_TYPE_APPLIER;
> +	struct session_owner applier_owner;
> +	session_owner_create(&applier_owner, SESSION_TYPE_APPLIER);
> +	session_set_owner(current_session(), &applier_owner);

I don't like the way you set the owner: first you initialize it on
stack, then duplicate it on heap. This doesn't look good.

Let's try to embed the session_owner structure (or whatever it will be
called) in struct session with some padding so that we don't need to
allocate anything, i.e.:

struct session_owner {
	int type;
	struct session_owner_vtab vtab;
	char pad[128];
};

struct session {
	struct session_owner owner;

We can use static assertions to make sure all deriving structures fit in
(see struct port for example).

Then we would add

iproto_init_session(session, ...)
console_init_session(session, ...)
session_clear_owner(session)

(elaborate the names pls)

that would initialize session->owner appropriately.

  reply	other threads:[~2018-03-20 18:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19 13:34 [PATCH 0/5] session: introduce box.session.push Vladislav Shpilevoy
2018-03-19 13:34 ` [PATCH 1/5] session: forbid creation from Lua binary and applier sessions Vladislav Shpilevoy
2018-03-20 13:20   ` Vladimir Davydov
2018-03-20 13:46     ` v.shpilevoy
2018-03-19 13:34 ` [PATCH 2/5] lua: port console yaml formatting to C Vladislav Shpilevoy
2018-03-20 17:51   ` Vladimir Davydov
2018-03-20 18:04     ` v.shpilevoy
2018-03-21  9:14       ` Vladimir Davydov
2018-03-21  9:30         ` v.shpilevoy
2018-03-19 13:34 ` [PATCH 3/5] Remove empty function declaration Vladislav Shpilevoy
2018-03-20 17:55   ` Vladimir Davydov
2018-03-20 17:57     ` [tarantool-patches] " v.shpilevoy
2018-03-21  9:16       ` Vladimir Davydov
2018-03-19 13:34 ` [PATCH 4/5] session: introduce session_owner Vladislav Shpilevoy
2018-03-20 18:29   ` Vladimir Davydov [this message]
2018-03-19 13:34 ` [PATCH 5/5] session: introduce box.session.push Vladislav Shpilevoy
2018-03-21  9:10   ` Vladimir Davydov
2018-03-21  9:30     ` [tarantool-patches] " v.shpilevoy
2018-03-21 12:25       ` Vladimir Davydov
2018-03-19 13:41 ` [tarantool-patches] [PATCH 0/5] " v.shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180320182920.2pzb2axxxnojd6gc@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [PATCH 4/5] session: introduce session_owner' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox