From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: george.dunlap@eu.citrix.com
Subject: [PATCH 1 of 4] libxl: Make a helper function write a BDF to a sysfs path
Date: Wed, 9 May 2012 11:28:41 +0100 [thread overview]
Message-ID: <0772f1d07d1c0b91fc37.1336559321@kodo2> (raw)
In-Reply-To: <patchbomb.1336559320@kodo2>
This functionality will be used several times in subsequent patches.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
diff -r d5268710a5ca -r 0772f1d07d1c tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c Fri May 04 10:46:23 2012 +0100
+++ b/tools/libxl/libxl_pci.c Tue May 08 17:18:31 2012 +0100
@@ -327,6 +327,36 @@ static int is_pcidev_in_array(libxl_devi
return 0;
}
+/* Write the standard BDF into the sysfs path given by sysfs_path. */
+static int sysfs_write_bdf(libxl__gc *gc, const char * sysfs_path,
+ libxl_device_pci *pcidev)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+ int rc, fd;
+ char *buf;
+
+ fd = open(sysfs_path, O_WRONLY);
+ if (fd < 0) {
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s",
+ sysfs_path);
+ return ERROR_FAIL;
+ }
+
+ buf = libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus,
+ pcidev->dev, pcidev->func);
+ rc = write(fd, buf, strlen(buf));
+ /* Annoying to have two if's, but we need the errno */
+ if (rc < 0)
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
+ "write to %s returned %d", sysfs_path, rc);
+ close(fd);
+
+ if (rc < 0)
+ return ERROR_FAIL;
+
+ return 0;
+}
+
libxl_device_pci *libxl_device_pci_list_assignable(libxl_ctx *ctx, int *num)
{
GC_INIT(ctx);
@@ -571,27 +601,12 @@ static int do_pci_add(libxl__gc *gc, uin
/* Don't restrict writes to the PCI config space from this VM */
if (pcidev->permissive) {
- int fd;
- char *buf;
-
- sysfs_path = libxl__sprintf(gc, SYSFS_PCIBACK_DRIVER"/permissive");
- fd = open(sysfs_path, O_WRONLY);
- if (fd < 0) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s",
- sysfs_path);
+ if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive",
+ pcidev) < 0 ) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "Setting permissive for device");
return ERROR_FAIL;
}
-
- buf = libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus,
- pcidev->dev, pcidev->func);
- rc = write(fd, buf, strlen(buf));
- /* Annoying to have two if's, but we need the errno */
- if (rc < 0)
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
- "write to %s returned %d", sysfs_path, rc);
- close(fd);
- if (rc < 0)
- return ERROR_FAIL;
}
break;
}
next prev parent reply other threads:[~2012-05-09 10:28 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 10:28 [PATCH 0 of 4] Add commands to automatically prep devices for pass-through George Dunlap
2012-05-09 10:28 ` George Dunlap [this message]
2012-05-10 10:40 ` [PATCH 1 of 4] libxl: Make a helper function write a BDF to a sysfs path Ian Campbell
2012-05-09 10:28 ` [PATCH 2 of 4] libxl: Rename pci_list_assignable to pci_assignable_list George Dunlap
2012-05-10 10:43 ` Ian Campbell
2012-05-10 10:54 ` George Dunlap
2012-05-09 10:28 ` [PATCH 3 of 4] libxl: Introduce pci_assignable_add and pci_assignable_remove George Dunlap
2012-05-10 11:19 ` Ian Campbell
2012-05-10 14:55 ` George Dunlap
2012-05-10 15:04 ` Ian Campbell
2012-05-10 16:29 ` George Dunlap
2012-05-10 16:45 ` Ian Campbell
2012-05-09 10:28 ` [PATCH 4 of 4] xl: Add pci_assignable_add and remove commands George Dunlap
2012-05-10 11:31 ` Ian Campbell
2012-05-11 11:13 ` George Dunlap
2012-05-11 11:19 ` Ian Campbell
2012-05-11 12:50 ` George Dunlap
2012-05-11 12:58 ` Ian Campbell
2012-05-09 10:49 ` [PATCH 0 of 4] Add commands to automatically prep devices for pass-through Ian Campbell
2012-05-09 11:03 ` George Dunlap
2012-05-09 11:59 ` Ian Campbell
2012-05-09 13:45 ` George Dunlap
2012-05-10 10:17 ` George Dunlap
2012-05-10 10:38 ` Ian Campbell
2012-05-10 14:12 ` Sander Eikelenboom
2012-05-10 14:16 ` Ian Campbell
2012-05-10 16:15 ` Konrad Rzeszutek Wilk
2012-05-09 10:56 ` David Vrabel
2012-05-09 11:11 ` George Dunlap
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=0772f1d07d1c0b91fc37.1336559321@kodo2 \
--to=george.dunlap@eu.citrix.com \
--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;
as well as URLs for NNTP newsgroup(s).