aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/fdso.h
blob: caf2a1e6918cfed088afc733fc417ab071389524 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* fdso.h - file descriptor attached shared objects
 *
 * (c) 2007 B. Brandenburg, LITMUS^RT project
 */

#ifndef _LINUX_FDSO_H_
#define _LINUX_FDSO_H_

#include <linux/list.h>
#include <asm/atomic.h>

#include <linux/fs.h>
#include <linux/slab.h>

#define MAX_OBJECT_DESCRIPTORS 32

typedef enum  {
	MIN_OBJ_TYPE 	= 0,

	FMLP_SEM	= 0,
	SRP_SEM		= 1,

	MAX_OBJ_TYPE	= 1
} obj_type_t;

struct inode_obj_id {
	struct list_head	list;
	atomic_t		count;
	struct inode*		inode;

	obj_type_t 		type;
	void*			obj;
	unsigned int		id;
};

struct fdso_ops;

struct od_table_entry {
	unsigned int		used;

	struct inode_obj_id*	obj;
	const struct fdso_ops*	class;
};

struct fdso_ops {
	int   (*create)(void** obj_ref, obj_type_t type, void* __user);
	void  (*destroy)(obj_type_t type, void*);
	int   (*open)	(struct od_table_entry*, void* __user);
	int   (*close)	(struct od_table_entry*);
};

/* translate a userspace supplied od into the raw table entry
 * returns NULL if od is invalid
 */
struct od_table_entry* get_entry_for_od(int od);

/* translate a userspace supplied od into the associated object
 * returns NULL if od is invalid
 */
static inline void* od_lookup(int od, obj_type_t type)
{
	struct od_table_entry* e = get_entry_for_od(od);
	return e && e->obj->type == type ? e->obj->obj : NULL;
}

#define lookup_fmlp_sem(od)((struct pi_semaphore*)  od_lookup(od, FMLP_SEM))
#define lookup_srp_sem(od) ((struct srp_semaphore*) od_lookup(od, SRP_SEM))
#define lookup_ics(od)     ((struct ics*)           od_lookup(od, ICS_ID))


#endif