public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] syscalls/keyctl02: wait for last key to be garbage collected
Date: Wed, 17 Oct 2018 15:25:28 +0200	[thread overview]
Message-ID: <20181017132528.GB31018@rei> (raw)
In-Reply-To: <79fc54a1540ed236a5539d9f848cc18045aa6c4d.1539781539.git.jstancek@redhat.com>

Hi!
>  static void do_test(void)
>  {
> -	int i;
> -	key_serial_t key;
> +	int i, ret;
> +	key_serial_t key, key_inv;
>  	pthread_t pth[4];
>  
>  	for (i = 0; i < LOOPS; i++) {
> @@ -94,13 +95,45 @@ static void do_test(void)
>  		SAFE_PTHREAD_JOIN(pth[3], NULL);
>  	}
>  
> +	/*
> +	 * Kernel should start garbage collect when last reference to key
> +	 * is removed (see key_put()). Since we are adding keys with identical
> +	 * description and type, each replacement should schedule a gc run,
> +	 * see comment at __key_link().
> +	 *
> +	 * We create extra key here, to remove reference to last revoked key.
> +	 */
> +	key_inv = add_key("user", "ltptestkey", "foo", 3,
> +		KEY_SPEC_PROCESS_KEYRING);
> +	if (key_inv == -1)
> +		tst_brk(TBROK | TERRNO, "Failed to add key");
> +
> +	/*
> +	 * If we have invalidate, we can drop extra key immediately as well,
> +	 * which also schedules gc.
> +	 */
> +	if (keyctl(KEYCTL_INVALIDATE, key_inv) == -1 && errno != EOPNOTSUPP)
> +		tst_brk(TBROK | TERRNO, "Failed to invalidate key");
> +
> +	/*
> +	 * At this point we are quite confident that gc has been scheduled,
> +	 * so we wait and periodically check for last test key to be removed.
> +	 */
> +	for (i = 0; i < MAX_WAIT_FOR_GC_MS; i += 100) {
> +		ret = keyctl(KEYCTL_REVOKE, key);
> +		if (ret == -1 && errno == ENOKEY)
> +			break;
> +		usleep(100*1000);
> +	}
> +
> +	tst_res(TINFO, "waiting for key gc took: %d ms", i);

Minor enhancement may be:

	if (i)
		tst_res(TINFO, "waiting for key gc took: %d ms", i);


Anyways, the patch looks good, acked.

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2018-10-17 13:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-17 13:10 [LTP] [PATCH v2] syscalls/keyctl02: wait for last key to be garbage collected Jan Stancek
2018-10-17 13:25 ` Cyril Hrubis [this message]
2018-10-17 13:32   ` Jan Stancek

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=20181017132528.GB31018@rei \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox