mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>, kvm@vger.kernel.org
Cc: borntraeger@de.ibm.com, pbonzini@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/1] KVM: trigger uevents when creating or destroying a VM
Date: Mon, 17 Jul 2017 17:53:51 +0200	[thread overview]
Message-ID: <ccdb4556-f396-60c3-e095-fbc292223931@redhat.com> (raw)
In-Reply-To: <1499875004-17113-2-git-send-email-imbrenda@linux.vnet.ibm.com>


> +	add_uevent_var(env, "CREATED=%llu", created);
> +	add_uevent_var(env, "COUNT=%llu", active);

I like that much better.

> +
> +	if (type == KVM_EVENT_CREATE_VM)
> +		add_uevent_var(env, "EVENT=create");
> +	else if (type == KVM_EVENT_DESTROY_VM)
> +		add_uevent_var(env, "EVENT=destroy");
> +
> +	if (kvm->debugfs_dentry) {
> +		char p[ITOA_MAX_LEN];

I'd move this also to the top of the function. Or move tmp and pathbuf
in here, so you could also move them to this place.

> +
> +		snprintf(p, sizeof(p), "%s", kvm->debugfs_dentry->d_name.name);

Probably just me, but I prefer ARRAY_SIZE() instead of sizeof() for any
kind of array sizes.

> +		tmp = strchrnul(p + 1, '-');> +		*tmp = '\0';
> +		add_uevent_var(env, "PID=%s", p);
> +		pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
> +		if (pathbuf) {
> +			/* sizeof counts the final '\0' */
> +			int len = sizeof("STATS_PATH=") - 1;
> +			const char *pvar = "STATS_PATH=";

Can't you avoid that? See next paragraph.


> +
> +			tmp = dentry_path_raw(kvm->debugfs_dentry,
> +					      pathbuf + len,
> +					      PATH_MAX - len);
> +			if (!IS_ERR(tmp)) {

Why not

tmp = dentry_path_raw(kvm->debugfs_dentry, pathbuf, PATH_MAX);
if (!IS_ERR(tmp)) {
	add_uevent_var(env, "STATS_PATH=s", tmp);
}

and avoid len / pvar / memcpy? And keep internal env size checking
consistent.

(are my tired eyes missing something? :) )


> +				memcpy(tmp - len, pvar, len);
> +				env->envp[env->envp_idx++] = tmp - len;
> +			}
> +		}
> +	}
> +	/* no need for checks, since we are adding at most only 5 keys */
> +	env->envp[env->envp_idx++] = NULL;
> +	kobject_uevent_env(&kvm_dev.this_device->kobj, KOBJ_CHANGE, env->envp);
> +	kfree(env);
> +	kfree(pathbuf);
> +}
> +
>  static int kvm_init_debug(void)
>  {
>  	int r = -EEXIST;
> 


-- 

Thanks,

David

  reply	other threads:[~2017-07-17 15:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 15:56 [PATCH v5 0/1] " Claudio Imbrenda
2017-07-12 15:56 ` [PATCH v5 1/1] " Claudio Imbrenda
2017-07-17 15:53   ` David Hildenbrand [this message]
2017-07-17 16:27     ` Claudio Imbrenda
2017-07-19 16:21       ` Radim Krčmář

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=ccdb4556-f396-60c3-e095-fbc292223931@redhat.com \
    --to=david@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=imbrenda@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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

all inboxes | Powered by JetHome®