aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-06 11:29:43 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-10-06 11:29:43 -0400
commit51905871ddafdeb1f06236b8bef37f04c5acca8f (patch)
tree118254d31e5e43a38b8727b22583135009c23571
parentaeb7a10b15401c80fc1c5ecf93b1e22240f046e6 (diff)
ftdev: provide a callback to test whether a device can be opened
This is useful to deny opening per-cpu buffers if a CPU is not online.
-rw-r--r--include/litmus/ftdev.h5
-rw-r--r--litmus/ftdev.c8
2 files changed, 11 insertions, 2 deletions
diff --git a/include/litmus/ftdev.h b/include/litmus/ftdev.h
index 8df916d1fc..7697b46166 100644
--- a/include/litmus/ftdev.h
+++ b/include/litmus/ftdev.h
@@ -13,9 +13,13 @@
13 13
14struct ftdev; 14struct ftdev;
15 15
16/* return 0 if buffer can be opened, otherwise -$REASON */
17typedef int (*ftdev_can_open_t)(struct ftdev* dev, unsigned int buf_no);
18/* return 0 on success, otherwise -$REASON */
16typedef int (*ftdev_alloc_t)(struct ftdev* dev, unsigned int buf_no); 19typedef int (*ftdev_alloc_t)(struct ftdev* dev, unsigned int buf_no);
17typedef void (*ftdev_free_t)(struct ftdev* dev, unsigned int buf_no); 20typedef void (*ftdev_free_t)(struct ftdev* dev, unsigned int buf_no);
18 21
22
19struct ftdev_event; 23struct ftdev_event;
20 24
21struct ftdev_minor { 25struct ftdev_minor {
@@ -33,6 +37,7 @@ struct ftdev {
33 unsigned int minor_cnt; 37 unsigned int minor_cnt;
34 ftdev_alloc_t alloc; 38 ftdev_alloc_t alloc;
35 ftdev_free_t free; 39 ftdev_free_t free;
40 ftdev_can_open_t can_open;
36}; 41};
37 42
38struct ft_buffer* alloc_ft_buffer(unsigned int count, size_t size); 43struct ft_buffer* alloc_ft_buffer(unsigned int count, size_t size);
diff --git a/litmus/ftdev.c b/litmus/ftdev.c
index fe3005db6d..20402c476f 100644
--- a/litmus/ftdev.c
+++ b/litmus/ftdev.c
@@ -106,6 +106,9 @@ static int ftdev_open(struct inode *in, struct file *filp)
106 err = -ENODEV; 106 err = -ENODEV;
107 goto out; 107 goto out;
108 } 108 }
109 if (ftdev->can_open && (err = ftdev->can_open(ftdev, buf_idx)))
110 goto out;
111
109 ftdm = ftdev->minor + buf_idx; 112 ftdm = ftdev->minor + buf_idx;
110 filp->private_data = ftdm; 113 filp->private_data = ftdm;
111 114
@@ -313,8 +316,9 @@ void ftdev_init(struct ftdev* ftdev, struct module* owner)
313 ftdev->minor[i].buf = NULL; 316 ftdev->minor[i].buf = NULL;
314 ftdev->minor[i].events = NULL; 317 ftdev->minor[i].events = NULL;
315 } 318 }
316 ftdev->alloc = NULL; 319 ftdev->alloc = NULL;
317 ftdev->free = NULL; 320 ftdev->free = NULL;
321 ftdev->can_open = NULL;
318} 322}
319 323
320int register_ftdev(struct ftdev* ftdev, const char* name, int major) 324int register_ftdev(struct ftdev* ftdev, const char* name, int major)