Re: [LAD] [PATCH] kfusd against 2.6.29 kernel

From: James Warden <warjamy@email-addr-hidden>
Date: Tue May 19 2009 - 17:26:40 EEST

I completely forgot to post the kfusd patch. I understand cuse will supersede all this but some ppl out there may want to use kfusd in the mean time against kernel 2.6.29.x

I warn you, there may be cleaner way to do this but it works. Some changes might be due to some spacing or tabbing. Sorry about that. Note that I have no clue when the kernel API changed after 2.6.24. So I you try it against say 2.6.27 or 2.6.28, it may not work at all. Here it is:

Here it is:

------- PATCH start ----------------------------------
diff -Naur fusd-kor/include/kfusd.h fusd-kor-new/include/kfusd.h
--- fusd-kor/include/kfusd.h 2007-06-26 02:01:36.000000000 +0200
+++ fusd-kor-new/include/kfusd.h 2009-05-19 07:40:27.549694054 +0200
@@ -44,6 +44,7 @@
#define __KFUSD_H__

#include "fusd_msg.h"
+#include <linux/version.h>

/* magic numbers for structure checking; unique w.r.t
  * /usr/src/linux/Documentation/magic-number.txt */
@@ -125,7 +126,11 @@
        char *dev_name;
        struct CLASS *clazz;
        int owns_class;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
        struct class_device *class_device;
+#else
+ struct device *class_device;
+#endif

   void *private_data; /* User's private data */
        struct cdev* handle;
diff -Naur fusd-kor/kfusd/kfusd.c fusd-kor-new/kfusd/kfusd.c
--- fusd-kor/kfusd/kfusd.c 2008-01-31 22:38:53.000000000 +0100
+++ fusd-kor-new/kfusd/kfusd.c 2009-05-19 07:40:36.412703934 +0200
@@ -85,7 +85,7 @@
#define STATIC

/* Define this if you want to emit debug messages (adds ~8K) */
-#define CONFIG_FUSD_DEBUG
+/* #define CONFIG_FUSD_DEBUG */

/* Default debug level for FUSD messages. Has no effect unless
  * CONFIG_FUSD_DEBUG is defined. */
@@ -126,8 +126,17 @@

#else

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
+
#define CLASS_DEVICE_CREATE(a, b, c, d, e) class_device_create(a, b, c, d, e)

+#else
+
+#define CLASS_DEVICE_CREATE(a, b, c, d, e) device_create(a, b, c, d, e)
+#define class_device_destroy(a, b) device_destroy(a, b)
+
+#endif
+
#endif

#endif
@@ -150,8 +159,13 @@

static struct CLASS *fusd_class;

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
static struct class_device *fusd_control_class_device;
static struct class_device *fusd_status_class_device;
+#else
+static struct device *fusd_control_class_device;
+static struct device *fusd_status_class_device;
+#endif

extern struct CLASS *sound_class;

@@ -725,8 +739,10 @@

  /* fill the rest of the structure */
  fusd_msg->parm.fops_msg.pid = current->pid;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
  fusd_msg->parm.fops_msg.uid = current->uid;
  fusd_msg->parm.fops_msg.gid = current->gid;
+#endif
  fusd_msg->parm.fops_msg.flags = fusd_file->file->f_flags;
  fusd_msg->parm.fops_msg.offset = fusd_file->file->f_pos;
  fusd_msg->parm.fops_msg.device_info = fusd_dev->private_data;
@@ -1533,6 +1549,7 @@
}
static void fusd_client_mm_open(struct vm_area_struct * vma);
static void fusd_client_mm_close(struct vm_area_struct * vma);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
static struct page* fusd_client_nopage(struct vm_area_struct* vma, unsigned long address, int* type);
static struct vm_operations_struct fusd_remap_vm_ops =
{
@@ -1540,6 +1557,16 @@
  close: fusd_client_mm_close,
  nopage: fusd_client_nopage,
};
+#else
+static int fusd_client_fault(struct vm_area_struct* vma, struct vm_fault *vmf, int* type);
+static struct vm_operations_struct fusd_remap_vm_ops =
+{
+ .fault = fusd_client_fault,
+ .open = fusd_client_mm_open,
+ .close = fusd_client_mm_close,
+};
+#endif
+

struct fusd_mmap_instance
{
@@ -1631,13 +1658,14 @@
  return -EPIPE;
}

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
static struct page* fusd_client_nopage(struct vm_area_struct* vma, unsigned long address,
  int* type)
{
  struct fusd_mmap_instance* mmap_instance = (struct fusd_mmap_instance*) vma->vm_private_data;
  unsigned long offset;
- struct page *page = NOPAGE_SIGBUS;
  int result;
+ struct page *page = NOPAGE_SIGBUS;
  offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
  // todo: worry about size
  if(offset > mmap_instance->size)
@@ -1662,9 +1690,46 @@
  }
out:
  return page;
+}

+#else

+static int fusd_client_fault(struct vm_area_struct* vma, struct vm_fault *vmf,
+ int* type)
+{
+ struct fusd_mmap_instance* mmap_instance = (struct fusd_mmap_instance*) vma->vm_private_data;
+ unsigned long offset;
+ int result;
+ struct page *page = NULL;
+ offset = ((unsigned long)vmf->virtual_address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+ // todo: worry about size
+ if(offset > mmap_instance->size)
+ goto out;
+
+ down_read(&mmap_instance->fusd_dev->task->mm->mmap_sem);
+ result = get_user_pages(mmap_instance->fusd_dev->task, mmap_instance->fusd_dev->task->mm, mmap_instance->addr + offset, 1, 1, 0, &page, NULL);
+ up_read(&mmap_instance->fusd_dev->task->mm->mmap_sem);
+
+
+ if(PageAnon(page))
+ {
+ RDEBUG(2, "Cannot mmap anonymous pages. Be sure to allocate your shared buffer with MAP_SHARED | MAP_ANONYMOUS");
+ return VM_FAULT_SIGBUS;
+ }
+
+ if(result > 0)
+ {
+ get_page(page);
+ vmf->page = page;
+ if (type)
+ *type = VM_FAULT_MINOR;
+ }
+out:
+ return 0;
}
+#endif
+
+

/*
----- PATCH end ----------------------------------

Cheers!
J.

> --- On Fri, 5/15/09, Lennart Poettering <mzynq@email-addr-hidden>
> wrote:
>
> > From: Lennart Poettering <mzynq@email-addr-hidden>
> > Subject: Re: [LAD] [PATCH] kfusd against 2.6.29
> kernel
> > To: linux-audio-dev@email-addr-hidden
> > Date: Friday, May 15, 2009, 8:29 AM
> > On Fri, 15.05.09 05:21, James Warden
> > (warjamy@email-addr-hidden)
> > wrote:
> >
> > > Hi,
> > >
> > > I created a patch for kfusd (fusd-kor kernel
> module)
> > because I
> > > needed oss2jack to work again against kernel
> 2.6.29.x
> > >
> > > I need to clean up the patch as it bulldozes the
> old
> > kernel API. If
> > > anyone is interested, I can post it here when I
> clean
> > it up (some
> > > time tonight or tomorrow). I already contacted
> the
> > author of fusd
> > > but I've got no reply so far.
> > >
> > > Note that I am no kernel guru, I got inspired by
> the
> > update to
> > > module source drm_mm.c and tested oss2jack in a
> > 2.6.29.2-rt10
> > > environment against jack1_svn (latest). I need to
> fix
> > something to
> > > make it work with jack2 (some problem linked to
> > libsamplerate -
> > > which is used in oss2jack - specifically in
> > src_process, the
> > > src_ratio field of the passed data is out of
> range).
> >
> > Please note that cuse (which does mostly the same as
> fusd)
> > is on its
> > way into the kernel:
> >
> > http://lwn.net/Articles/296388/
> >
> > Lennart
> >
> > --
> > Lennart Poettering           
> >             Red Hat, Inc.
> > lennart [at] poettering [dot] net
> > http://0pointer.net/lennart/       
> >    GnuPG 0x1A015CC4
> > _______________________________________________
> > Linux-audio-dev mailing list
> > Linux-audio-dev@email-addr-hidden
> > http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
> >
>
>
>
>

      
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Tue May 19 20:15:05 2009

This archive was generated by hypermail 2.1.8 : Tue May 19 2009 - 20:15:05 EEST