Commit 020f7784 authored by Ezekiel Dohmen's avatar Ezekiel Dohmen
Browse files

Merge branch 'debian/bullseye-librts' into 'debian/bullseye'

Removing auto start of dolphin proxy km, adding catch because librts will use...

See merge request !431
parents 21c6dad8 7027b0f6
......@@ -99,6 +99,11 @@ ifdef RCG_BUILD_USP
@echo Done
endif
ifdef RCG_BUILD_LIBRTS
#ifneq ($(and $(RCG_BUILD_USP),$(RCG_BUILD_LIBRTS)),)
@env LIBRTS_OUT_OF_TREE_BUILD=1 env RCG_BUILDD=$(bld_dir) make --no-print-directory -f $(srcdir)/src/librts/Makefile $@
endif
@#Save build config and source files for traceability
@/bin/mkdir -p $(bld_info_dir)
@echo $(srcdir) > $(bld_info_dir)/rcg_location.txt
......
......@@ -17,4 +17,4 @@ src/util usr/share/advligorts/src/src
src/python/sequence/main.py usr/share/advligorts/src/src/python/sequence
support/symvers/ usr/share/advligorts/src/support/
src/dolphin_daemon/include/ usr/share/advligorts/src/src/dolphin_daemon/
src/librts/ usr/share/advligorts/src/src/
advligorts (5.0.0~dev12+deb11-1) unstable; urgency=medium
* Adding librts to advligorts
* Removing dolphin proxy km auto start, as fe_generator manages it now
-- Ezekiel Dohmen <ezekiel.dohmen@ligo.org> Tue, 16 Aug 2022 17:00:47 -0700
advligorts (5.0.0~dev11+deb11-1) unstable; urgency=medium
* Merge with master for dev 11
......
......@@ -166,6 +166,7 @@ Depends:
tcsh,
git,
cmake,
catch,
${misc:Depends},
${perl:Depends},
Recommends:
......
......@@ -66,7 +66,6 @@ install-advligorts-dolphin-proxy-km:
install --mode=644 -t debian/advligorts-dolphin-proxy-km-dkms/usr/src/dolphin-proxy-km-$(SVERSION) src/dolphin_daemon/include/daemon_messages.h
install --mode=644 -t debian/advligorts-dolphin-proxy-km-dkms/usr/src/dolphin-proxy-km-$(SVERSION)/util/ src/include/util/fixed_width_types.h
install --mode=644 -t debian/advligorts-dolphin-proxy-km-dkms/usr/src/dolphin-proxy-km-$(SVERSION) support/bin/dkms_install_files
echo dolphin-proxy-km > debian/advligorts-dolphin-proxy-km-dkms/usr/lib/modules-load.d/dolphin-proxy-km.conf
install-version:
......
......@@ -24,17 +24,27 @@
#define MAX_ADAPTERS 4
#define MODULE_ID 0
//Dolphin globals
volatile void * g_read_addrs [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ] = {0};
volatile void * g_write_addrs [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ] = {0};
//
// Dolphin globals
//
static volatile void * g_read_addrs [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ] = {0};
static volatile void * g_write_addrs [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ] = {0};
static sci_l_segment_handle_t g_segments [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static sci_map_handle_t g_client_map_handles [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static sci_r_segment_handle_t g_remote_segment_handles [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
//static sci_device_info_t g_sci_dev_info [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
// State tracking for cleanup
static int g_local_segment_created [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static int g_local_segment_exported [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static int g_remote_segment_mapped [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static int g_remote_segment_connected [ MAX_ADAPTERS ][ MAX_MCAST_GROUPS ];
static int g_callback_registered [ MAX_ADAPTERS ]; //One callback per adapter
// Netlink Globals
struct sock *nl_sock = NULL;
static DEFINE_MUTEX(g_msg_mutex);
void send_netlink_response(void * msg, unsigned sz_bytes, unsigned pid)
{
......@@ -93,19 +103,8 @@ session_callback( session_cb_arg_t IN arg,
uint32_t IN local_adapter_number )
{
/// @brief This function contains the required Dolphin callback routine. \n
printk(KERN_INFO MODULE_NAME ": Session callback reason=%d status=%d target_node=%d\n", reason,
printk(KERN_INFO MODULE_NAME ": Session callback reason=%d status=0x%x target_node=%d\n", reason,
status, target_node);
//if (reason == SR_OK) iop_rfm_valid = 1;
/*
if ( reason == SR_OK || status == SS_NONE ) //TODO: This does not seem like a good check, we could pass if reason has an error and status is SR_NONE
iop_rfm_valid = 1;
else
iop_rfm_valid = 0;
*/
// This is being called when the one of the other nodes is prepared for
// shutdown :TODO: may need to check target_node == <our local node>
// if (reason == SR_DISABLED || reason == SR_LOST) iop_rfm_valid = 0;
return 0;
}
......@@ -116,15 +115,7 @@ connect_callback( void IN* arg,
uint32_t IN reason,
uint32_t IN status )
{
printk(KERN_INFO MODULE_NAME ": Connect callback reason=%d status=%d\n", reason, status);
/*
if ( reason == 1 )
iop_rfm_valid = 1;
if ( reason == 3 )
iop_rfm_valid = 0;
if ( reason == 5 )
iop_rfm_valid = 1;
*/
printk(KERN_INFO MODULE_NAME ": Connect callback reason=%d status=0x%x\n", reason, status);
return 0;
}
......@@ -139,6 +130,52 @@ create_segment_callback( void IN* arg,
return 0;
}
void free_dolphin_segment( unsigned segment_id, unsigned adapter_num )
{
//MAX_ADAPTERS ][ MAX_MCAST_GROUPS
if(segment_id > MAX_ADAPTERS || adapter_num > MAX_MCAST_GROUPS)
{
printk(KERN_ERR MODULE_NAME ":free_dolphin_segment() called but segment_id: %u or adapter_num: %u invalid. \n", segment_id, adapter_num);
return;
}
if( g_remote_segment_mapped[ adapter_num ][segment_id ] == 1)
{
sci_unmap_segment( &g_client_map_handles[ adapter_num ][ segment_id ], 0 );
g_remote_segment_mapped[ adapter_num ][segment_id ] = 0;
}
if( g_remote_segment_connected[ adapter_num ][ segment_id ] == 1)
{
sci_disconnect_segment( &g_remote_segment_handles[ adapter_num ][ segment_id ], NO_FLAGS );
g_remote_segment_connected[ adapter_num ][ segment_id ] = 0;
}
if( g_callback_registered[ adapter_num ] == 1)
{
sci_cancel_session_cb( adapter_num, NO_FLAGS );
g_callback_registered[ adapter_num ] = 0;
}
if( g_local_segment_exported[ adapter_num ][ segment_id ] == 1 )
{
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS );
g_local_segment_exported[ adapter_num ][ segment_id ] = 0;
}
if( g_local_segment_created[ adapter_num ][ segment_id ] == 1)
{
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
g_local_segment_created[ adapter_num ][ segment_id ] = 0;
}
g_read_addrs[ adapter_num ][segment_id] = NULL;
g_write_addrs[ adapter_num ][segment_id] = NULL;
}
DOLPHIN_ERROR_CODES allocate_segment(unsigned segment_id, unsigned adapter_num, unsigned size)
{
scierror_t err;
......@@ -153,30 +190,35 @@ DOLPHIN_ERROR_CODES allocate_segment(unsigned segment_id, unsigned adapter_num,
&g_segments[ adapter_num ][ segment_id ] );
printk(KERN_INFO MODULE_NAME ": DIS segment alloc status %d\n", err);
if ( err )
{
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
g_local_segment_created[ adapter_num ][ segment_id ] = 1;
err = sci_set_local_segment_available( g_segments[ adapter_num ][ segment_id ], adapter_num );
printk(KERN_INFO MODULE_NAME ": DIS segment making available status %d\n", err);
if ( err )
{
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS);
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
err = sci_export_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, DIS_BROADCAST );
printk(KERN_INFO MODULE_NAME ": DIS segment export status 0x%x\n", err);
if ( err )
{
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
g_local_segment_exported[ adapter_num ][ segment_id ] = 1;
g_read_addrs[ adapter_num ][segment_id] = sci_local_kernel_virtual_address( g_segments[ adapter_num ][ segment_id ] );
if ( g_read_addrs[ adapter_num ][segment_id] == 0 )
{
printk(KERN_ERR MODULE_NAME ": DIS sci_local_kernel_virtual_address returned 0\n");
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS);
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
else
......@@ -195,13 +237,13 @@ DOLPHIN_ERROR_CODES allocate_segment(unsigned segment_id, unsigned adapter_num,
connect_callback,
0,
&g_remote_segment_handles[ adapter_num ][ segment_id ] );
printk(KERN_INFO MODULE_NAME ": DIS connect segment status %d\n", err);
printk(KERN_INFO MODULE_NAME ": DIS connect segment status %d\n", err);
if ( err )
{
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS);
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
g_remote_segment_connected[ adapter_num ][ segment_id ] = 1;
mdelay( 40 );
err = sci_map_segment( g_remote_segment_handles[ adapter_num ][ segment_id ],
......@@ -209,23 +251,18 @@ DOLPHIN_ERROR_CODES allocate_segment(unsigned segment_id, unsigned adapter_num,
adapter_num,
size,
&g_client_map_handles[ adapter_num ][ segment_id ] );
printk(KERN_INFO MODULE_NAME ": DIS segment mapping status 0x%x\n", err);
printk(KERN_INFO MODULE_NAME ": DIS segment mapping status 0x%x\n", err);
if ( err )
{
sci_disconnect_segment( &g_remote_segment_handles[ adapter_num ][ segment_id ], NO_FLAGS );
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS);
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
g_remote_segment_mapped[ adapter_num ][segment_id ] = 1;
g_write_addrs[ adapter_num ][ segment_id ] = sci_kernel_virtual_address_of_mapping( g_client_map_handles[ adapter_num ][segment_id ] );
if ( g_write_addrs[ adapter_num ][ segment_id ] == 0 )
{
// RTSLOG_INFO ("Got zero pointer from
// sci_kernel_virtual_address_of_mapping\n");
sci_disconnect_segment( &g_remote_segment_handles[ adapter_num ][ segment_id ], NO_FLAGS );
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS);
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
free_dolphin_segment(adapter_num, segment_id);
return DOLPHIN_ERROR_SEGMENT_SETUP_ERROR;
}
else
......@@ -234,27 +271,11 @@ DOLPHIN_ERROR_CODES allocate_segment(unsigned segment_id, unsigned adapter_num,
}
sci_register_session_cb( adapter_num, NO_FLAGS, session_callback, NULL );
g_callback_registered[ adapter_num ] = 1;
return DOLPHIN_ERROR_OK;
}
void free_dolphin_segment( unsigned segment_id, unsigned adapter_num )
{
if( g_read_addrs[adapter_num][segment_id] != NULL )
{
sci_unmap_segment( &g_client_map_handles[ adapter_num ][ segment_id ], 0 );
sci_disconnect_segment( &g_remote_segment_handles[ adapter_num ][ segment_id ], NO_FLAGS );
sci_unexport_segment( g_segments[ adapter_num ][ segment_id ], adapter_num, NO_FLAGS );
sci_remove_segment( &g_segments[ adapter_num ][ segment_id ], NO_FLAGS );
sci_cancel_session_cb( adapter_num, NO_FLAGS );
g_read_addrs[ adapter_num ][segment_id] = NULL;
g_write_addrs[ adapter_num ][segment_id] = NULL;
}
else
{
printk(KERN_INFO MODULE_NAME ": Free requested for segment_id %u, adapter_num: %d, but not allocated\n", segment_id, adapter_num);
}
}
void handle_alloc_req( dolphin_mc_alloc_req * req_ptr , unsigned pid)
......@@ -348,6 +369,10 @@ static void netlink_recv_unicast_msg(struct sk_buff *skb)
all_dolphin_daemon_msgs_union any_msg;
int pid;
// We are only going to process one message at a time
mutex_lock(&g_msg_mutex);
nlh = (struct nlmsghdr *)skb->data;
pid = nlh->nlmsg_pid; // pid of sending process
......@@ -359,12 +384,16 @@ static void netlink_recv_unicast_msg(struct sk_buff *skb)
if ( !check_mc_header_valid(any_msg.as_hdr, nlmsg_len(nlh)) )
{
mutex_unlock(&g_msg_mutex);
printk(KERN_ERR MODULE_NAME ": Malformed message, too short or bad preamble\n");
return;
}
if(any_msg.as_hdr->interface_id != DOLPHIN_KM_INTERFACE_ID)
{
mutex_unlock(&g_msg_mutex);
return; //Msg not ment for us
}
//Switch on message ID and handle accordingly
......@@ -388,6 +417,7 @@ static void netlink_recv_unicast_msg(struct sk_buff *skb)
break;
}
mutex_unlock(&g_msg_mutex);
}
......
......@@ -119,7 +119,6 @@ class NetlinkSocket
if( ret > 0)
{
memcpy(data, NLMSG_DATA(nlh), ret - NLMSG_HDRLEN);
spdlog::info("Sender PID was {}", _dest_addr.nl_groups);
return ret - NLMSG_HDRLEN; //Return size of data
}
......
......@@ -57,7 +57,7 @@ void DolphinKernelProxy::thread_body()
unsigned payload_sz = ret; //Header is removed by NetlinkSocket
spdlog::info("Received {} byte request, payload_sz : {}", ret, payload_sz);
spdlog::debug("Received {} byte request, payload_sz : {}", ret, payload_sz);
all_dolphin_daemon_msgs_union any_msg;
any_msg.as_hdr = (dolphin_mc_header*)buffer;//(dolphin_mc_header *) NLMSG_DATA((struct nlmsghdr *) &buffer);
......@@ -88,7 +88,7 @@ void DolphinKernelProxy::thread_body()
}
spdlog::info("DolphinKernelProxy - Done handling kernel multicast request message.");
spdlog::debug("DolphinKernelProxy - Done handling kernel multicast request message.");
}
......
......@@ -93,7 +93,8 @@ static unsigned int usage_cnt[MAX_AREAS];
// Memory area sizes
static unsigned int kmalloc_area_size[MAX_AREAS];
static DEFINE_SPINLOCK(lock);
//This global mutex protects critical sections of this module
struct mutex g_mutex;
/// @brief Stores the error message mapping for each MBUF_KERNEL_CODE.
......@@ -161,7 +162,10 @@ enum MBUF_KERNEL_CODE mbuf_release_area(const char* name)
verbose = (int)atomic_read(&mbuf_verbosity);
spin_lock(&lock);
//name is cleared out by mtag[i][0] = 0; below
if(verbose) printk(KERN_INFO "mbuf_release_area - releasing buffer with name %s\n", name);
mutex_lock(&g_mutex);
// See if allocated
for (i = 0; i < MAX_AREAS; i++) {
if (0 == strcmp (mtag[i], name)) {
......@@ -174,15 +178,14 @@ enum MBUF_KERNEL_CODE mbuf_release_area(const char* name)
kmalloc_area[i] = 0;
kmalloc_area_size[i] = 0;
}
spin_unlock(&lock);
if(verbose) printk(KERN_INFO " mbuf_release_area - released buffer %s\n", name);
mutex_unlock(&g_mutex);
return MBUF_KERNEL_CODE_OK;
}
}
//We only get here if we don't find the buffer
spin_unlock(&lock);
if(verbose) printk(KERN_INFO " mbuf_release_area - %s could not be found\n", name);
mutex_unlock(&g_mutex);
if(verbose) printk(KERN_INFO "mbuf_release_area - %s could not be found\n", name);
return MBUF_KERNEL_CODE_NAME_NOT_FOUND;
}
EXPORT_SYMBOL(mbuf_release_area);
......@@ -199,12 +202,12 @@ int mbuf_allocate_area_file(const char* name, unsigned int size, struct file *fi
if(ret != MBUF_KERNEL_CODE_OK) return -1;
//Get the index of the buffer we just created
spin_lock(&lock);
mutex_lock(&g_mutex);
buffer_index = find_mbuf_index(name);
spin_unlock(&lock);
mutex_unlock(&g_mutex);
if( buffer_index < 0) return -1;
if (file) file -> private_data = mtag [buffer_index];
if (file) file->private_data = mtag [buffer_index];
return buffer_index;
}
......@@ -218,7 +221,7 @@ enum MBUF_KERNEL_CODE mbuf_allocate_area(const char *name, unsigned int size, vo
verbose = (int)atomic_read(&mbuf_verbosity);
spin_lock(&lock);
mutex_lock(&g_mutex);
//Round up the requested size to the closest page size
mod = size % PAGE_SIZE;
......@@ -233,14 +236,14 @@ enum MBUF_KERNEL_CODE mbuf_allocate_area(const char *name, unsigned int size, vo
{
if (kmalloc_area_size[i] != size) {
*buffer_ptr = NULL;
spin_unlock(&lock);
mutex_unlock(&g_mutex);
return MBUF_KERNEL_CODE_SZ_ERROR;
}
++usage_cnt[i];
*buffer_ptr = kmalloc_area[i];
spin_unlock(&lock);
if(verbose) printk(KERN_INFO " mbuf_allocate_area - increased usage count of %s\n", name);
mutex_unlock(&g_mutex);
if(verbose) printk(KERN_INFO "mbuf_allocate_area - increased usage count of %s\n", name);
return MBUF_KERNEL_CODE_OK;
}
......@@ -253,9 +256,9 @@ enum MBUF_KERNEL_CODE mbuf_allocate_area(const char *name, unsigned int size, vo
// Out of slots
if (i >= MAX_AREAS) {
*buffer_ptr = NULL;
spin_unlock(&lock);
mutex_unlock(&g_mutex);
if(verbose){
printk(KERN_INFO " mbuf_allocate_area - Could not create "
printk(KERN_INFO "mbuf_allocate_area - Could not create "
"buffer : %s, out of free slots\n", name);
}
return MBUF_KERNEL_CODE_NO_BUFFERS;
......@@ -266,7 +269,7 @@ enum MBUF_KERNEL_CODE mbuf_allocate_area(const char *name, unsigned int size, vo
if (kmalloc_area[i] == 0) {
*buffer_ptr = NULL;
spin_unlock(&lock);
mutex_unlock(&g_mutex);
printk("malloc() failed\n");
return MBUF_KERNEL_CODE_ALLOC_FAILED;
}
......@@ -279,8 +282,8 @@ enum MBUF_KERNEL_CODE mbuf_allocate_area(const char *name, unsigned int size, vo
mtag[i][MBUF_NAME_LEN] = 0;
usage_cnt[i] = 1;
*buffer_ptr = kmalloc_area[i];
spin_unlock(&lock);
if(verbose) printk(KERN_INFO " mbuf_allocate_area - Created new buffer %s, sz: %u\n", name, size);
mutex_unlock(&g_mutex);
if(verbose) printk(KERN_INFO "mbuf_allocate_area - Created new buffer %s, sz: %u\n", name, size);
return MBUF_KERNEL_CODE_OK;
}
......@@ -306,33 +309,47 @@ static int mbuf_release(struct inode *inode, struct file *filp)
int mmap_kmem(unsigned int i, struct vm_area_struct *vma)
{
long length = vma->vm_end - vma->vm_start;
int ret = -EINVAL;
if (kmalloc_area_size[i] < length) {
//printk("mbuf mmap() request to map 0x%lx bytes; allocated 0x%lx\n", length, kmalloc_area_size[i]);
printk("mbuf_mmap() request to map %lu bytes; but only allocated %u\n",
length, kmalloc_area_size[i]);
return -EINVAL;
}
//printk("mbuf mmap() length is 0x%lx\n", length);
return rvmmap(kmalloc_area[i], length, vma);
mutex_lock(&g_mutex);
ret = rvmmap(kmalloc_area[i], length, vma);
mutex_unlock(&g_mutex);
return ret;
}
/* character device mmap method */
static int mbuf_mmap(struct file *file, struct vm_area_struct *vma)
{
int i;
int buffer_index;
char *name;
if (file -> private_data == 0) return -EINVAL;
name = (char *) file -> private_data;
// Find our memory area
for (i = 0; i < MAX_AREAS; i++) {
if (0 == strcmp (mtag[i], name)) {
return mmap_kmem (i, vma);
}
if (file->private_data == 0)
{
printk(KERN_ERR "buf_mmap - No private_data, allocation error.\n");
return -EINVAL;
}
name = (char *) file->private_data;
// Find our memory area index by name
mutex_lock(&g_mutex);
buffer_index = find_mbuf_index(name);
mutex_unlock(&g_mutex);
if( buffer_index < 0)
{
printk(KERN_ERR "mbuf_mmap - Did not find the buffer by the name %s, for mmap.\n", name);
return -EINVAL;
}
return -EINVAL;
}
return mmap_kmem (buffer_index, vma);
}
static long mbuf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
......@@ -344,20 +361,28 @@ static long mbuf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
verbose = (int)atomic_read(&mbuf_verbosity);
if (verbose > 0) {
printk(KERN_INFO
"mbuf_ioctl: command=%d\n", cmd);
}
switch(cmd){
case IOCTL_MBUF_ALLOCATE:
{
if (copy_from_user (&req, (void *) argp, sizeof (req))) {
return -EFAULT;
}
if( strnlen(req.name, MBUF_NAME_LEN + 1) > MBUF_NAME_LEN )
{
printk(KERN_ERR "mbuf_ioctl() - Buffer name in request is too long or malformed.\n");
return -EINVAL; //Catch no null termination
}
if (verbose > 0) {
printk(KERN_INFO
"mbuf_ioctl: name:%.32s, size:%d, cmd:%d, file:%p\n", req.name, (int) req.size, cmd, file);
}
if( file->private_data != 0 )
{
printk(KERN_ERR "mbuf_ioctl() - Got request to allocatei buffer: %s, but fd already used for buffer.\n", req.name);
return -EBUSY;
}
res = mbuf_allocate_area_file(req.name, req.size, file);
if (res < 0) return -EINVAL; //If there was an issue
return kmalloc_area_size[res];
......@@ -368,7 +393,8 @@ static long mbuf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (copy_from_user (&req, (void *) argp, sizeof (req))) {
return -EFAULT;
}
//printk("mbuf_ioctl: name:%.32s, size:%d, cmd:%d, file:%p\n", req.name, req.size, cmd, file);
if (verbose > 0) printk(KERN_INFO "mbuf_ioctl() - Got ioctl to deallocate, name: %s\n", req.name);
res = mbuf_release_area_file(req.name, file);
if (res == MBUF_KERNEL_CODE_OK) {
return 0;
......@@ -378,17 +404,6 @@ static long mbuf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
}
break;
case IOCTL_MBUF_INFO:
#if 0
for (i = 0; i < MAX_AREAS; i++) {
if (kmalloc_area[i]) {
printk("mbuf %d: name:%.32s, size:%d, usage:%d\n",
i, mtag[i], kmalloc_area_size[i], usage_cnt[i]);
}
}
#endif
return 1;
break;
default:
return -EINVAL;
}
......@@ -402,7 +417,7 @@ static ssize_t mbuf_sysfs_status(struct kobject *kobj, struct kobj_attribute *at
char *cur = buf;
int i = 0;
spin_lock(&lock);
mutex_lock(&g_mutex);
for (i = 0; i < MAX_AREAS; i++) {
if (kmalloc_area[i] == 0) continue;
......@@ -414,7 +429,7 @@ static ssize_t mbuf_sysfs_status(struct kobject *kobj, struct kobj_attribute *at
count += tmp;
}
spin_unlock(&lock);
mutex_unlock(&g_mutex);
return count;
}
......@@ -470,6 +485,8 @@ static int __init mbuf_init(void)
int i;
int ret = -EINVAL;
mutex_init(&g_mutex);
/* get the major number of the character device */
if ((ret = alloc_chrdev_region(&mbuf_dev, 0, 1, "mbuf")) < 0) {
printk(KERN_ERR "could not allocate major number for mbuf\n");
......
......@@ -3,10 +3,15 @@ set(this_target mbuf_userspace_utest)
add_executable(${this_target}
test.cc)