public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ANNIE LI <annie.li@oracle.com>
To: Paul Durrant <Paul.Durrant@citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>,
	"jeremy@goop.org" <jeremy@goop.org>,
	Ian Campbell <Ian.Campbell@citrix.com>,
	"kurt.hackel@oracle.com" <kurt.hackel@oracle.com>
Subject: Re: [PATCH V2 1/2] xen/granttable: Support sub-page grants
Date: Thu, 08 Dec 2011 18:01:49 +0800	[thread overview]
Message-ID: <4EE08B0D.80504@oracle.com> (raw)
In-Reply-To: <291EDFCB1E9E224A99088639C4762022B5988E5528@LONPMAILBOX01.citrite.net>


>> +
>> +int gnttab_grant_foreign_access_subpage(domid_t domid, unsigned
>> long frame,
>> +					int flags, unsigned page_off,
>> +					unsigned length)
>> +{
>> +	int ref;
>> +
>> +	if (flags&  (GTF_accept_transfer | GTF_reading |
>> +		     GTF_writing | GTF_transitive))
>> +		return -EPERM;
>> +
>> +	if (gnttab_interface->update_subpage_entry == NULL)
>> +		return -ENOSYS;
>> +
>> +	ref = get_free_entries(1);
>> +	if (unlikely(ref<  0))
>> +		return -ENOSPC;
>> +
>> +	gnttab_interface->update_subpage_entry(ref, domid, frame,
>> flags,
>> +					       page_off, length);
>> +
>> +	return ref;
>> +}
>> +EXPORT_SYMBOL_GPL(gnttab_grant_foreign_access_subpage);
> There's quite a lot of duplicated code here. What about something along the lines of:
>
> #define get_free_entry()	get_free_entries(1)
>
> int gnttab_grant_foreign_access_subpage(domid_t domid, unsigned long frame,
> 					int flags, unsigned page_off,
> 					unsigned length)
> {
> 	int ref;
>
> 	ref = get_free_entry();
> 	if (unlikely(ref<  0))
> 		return -ENOSPC;
>
> 	rc = gnttab_grant_foreign_access_subpage_ref(ref, domid, frame, flags, page_off, length);
> 	if (rc<  0)
> 		put_free_entry(ref);
>
> 	return (rc<  0) rc : ref;
> }
> EXPORT_SYMBOL_GPL(gnttab_grant_foreign_access_subpage);
>
> I think this is more akin to the format for existing non-ref variants.
>
I hesitated between those two implement ways before sending them out. 
Those two ways all have shortcoming, one has duplicated code, but is 
simple when condition does not meet. The other way you pointed out added 
more put_free_entry process when _ref function fails.

Thanks
Annie

  reply	other threads:[~2011-12-08 10:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-08  9:35 [PATCH V2 0/2] xen: patches for supporting sub-page and transitive grants annie.li
2011-12-08  9:37 ` [PATCH V2 1/2] xen/granttable: Support sub-page grants annie.li
2011-12-08  9:49   ` Paul Durrant
2011-12-08 10:01     ` ANNIE LI [this message]
2011-12-08 10:04       ` Paul Durrant
2011-12-08 13:46         ` annie li
2011-12-09  5:19         ` annie li
2011-12-09  7:45           ` annie li
2011-12-09  8:37             ` Ian Campbell
2011-12-09  8:48               ` Paul Durrant
2011-12-09 11:27                 ` annie li
2011-12-08  9:37 ` [PATCH V2 2/2] xen/granttable: Support transitive grants annie.li
2011-12-08  9:51   ` Paul Durrant

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=4EE08B0D.80504@oracle.com \
    --to=annie.li@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Paul.Durrant@citrix.com \
    --cc=jeremy@goop.org \
    --cc=konrad.wilk@oracle.com \
    --cc=kurt.hackel@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xensource.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