Thread Synch AOSV 2020  1.2
LKM for exchanging messages between threads
Macros | Functions | Variables
group_manager.h File Reference

Handles all procedures releated to file operation issued on a group device. More...

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/semaphore.h>
#include <linux/ioctl.h>
#include <linux/string.h>
#include <linux/idr.h>
#include <linux/errno.h>
#include <linux/cred.h>
#include "message.h"
Include dependency graph for group_manager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INVALID_IOCTL_COMMAND   -1
 
#define ALLOC_ERR   -2
 
#define MEM_ACCESS_ERR   -5
 
#define CLASS_EXISTS   -10
 
#define CLASS_ERR   -11
 
#define DEV_CREATION_ERR   -12
 
#define CDEV_ALLOC_ERR   -13
 
#define EMPTY_LIST   -20
 
#define NODE_NOT_FOUND   -21
 
#define CHDEV_ALLOC_ERR   -22
 
#define GROUP_MAX_MINORS   255
 
#define DEVICE_NAME_SIZE   64
 
#define DEFAULT_MSG_SIZE   256
 
#define DEFAULT_STORAGE_SIZE   1024
 
#define IOCTL_GET_GROUP_DESC   _IOR('Q', 1, group_t*)
 
#define IOCTL_SET_STRICT_MODE   _IOW('Q', 101, bool)
 
#define IOCTL_CHANGE_OWNER   _IOW('Q', 102, uid_t)
 
#define IOCTL_SET_SEND_DELAY   _IOW('Y', 0, long)
 
#define IOCTL_REVOKE_DELAYED_MESSAGES   _IO('Y', 1)
 
#define IOCTL_CANCEL_DELAY   _IO('Y', 2)
 
#define IOCTL_SLEEP_ON_BARRIER   _IO('Z', 0)
 
#define IOCTL_AWAKE_BARRIER   _IO('Z', 1)
 
#define GROUP_CLASS_NAME   "group_synch"
 

Functions

void initParticipants (group_data *grp_data)
 Initialize group_data participants' structures. More...
 
int installGroupClass (void)
 Install the global 'group_device_class'. More...
 
int registerGroupDevice (group_data *grp_data, struct device *parent)
 register a group device More...
 
void unregisterGroupDevice (group_data *grp_data, bool flag)
 unregister a group device More...
 
int copy_group_t_from_user (__user group_t *user_group, group_t *kern_group)
 Copy a 'group_t' structure to kernel space. More...
 

Variables

struct class * group_device_class
 

Detailed Description

Handles all procedures releated to file operation issued on a group device.

Function Documentation

◆ copy_group_t_from_user()

int copy_group_t_from_user ( __user group_t user_group,
group_t kern_group 
)

Copy a 'group_t' structure to kernel space.

Parameters
[in]user_groupPointer to a userspace 'group_t' structure
[out]kern_groupDestination that will contain the 'group_t' structure
Return values
0on success
MEM_ACCESS_ERRif the user memory is not valid for the kernel
USER_COPY_ERRif there was error while copying user data to kernel
ALLOC_ERRif there was some meory allocation error

◆ initParticipants()

void initParticipants ( group_data grp_data)
inline

Initialize group_data participants' structures.

Parameters
[in]grp_dataPointer to the device's group_data structure
Returns
nothing

◆ installGroupClass()

int installGroupClass ( )

Install the global 'group_device_class'.

Return values
0if the class already exists
CLASS_ERRIf the class cannot be installed
CLASS_EXISTSIf the class already exists

◆ registerGroupDevice()

int registerGroupDevice ( group_data grp_data,
struct device *  parent 
)

register a group device

Parameters
[in]grp_dataThe group data descriptor
[in]parentdevice parent (usually 'main_device')
Return values
0on success
CHDEV_ALLOC_ERRIf the char device allocation fails
ALLOC_ERRIf some memory allocation fails
DEV_CREATION_ERRIf the char device creation fails
Note
Charter device creation This should be perfomed after all the all the necessary data structures are allocated since, immediately after 'cdev_add', the device becomes live and starts to respond to requests

◆ unregisterGroupDevice()

void unregisterGroupDevice ( group_data grp_data,
bool  flag 
)

unregister a group device

Parameters
[in]grp_dataThe group data descriptor
Returns
nothing
Note
This guarantees that cdev device will no longer be able to be opened, however any cdevs already open will remain and their fops will still be callable even after cdev_del returns. For this reason the 'initialized' flag of a group will be set to zero
Todo:
: Check if this causes starvation