LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2017, 01:35 AM   #1
AccumPlus
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Rep: Reputation: Disabled
Writing device-mapper target module for 2.4 kernel


Hello forum users!

I need to write my own kernel module to use it as a target for device-mapper module. I used this article as a start point. The code there is written for >=2.6 kernel version, but I need to have the same for 2.4 kernel.

I tried to change functions as the are declared in kernel headers. Now I have something like this:

Code:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/fs.h>
#include <linux/device-mapper.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/mm.h>
 
struct Sddm_target
{
    struct dm_dev *dev;
    sector_t start;
};
 
static int sddm_target_map(struct dm_target *ti, struct buffer_head *bh, int rw, union map_info *map_context)
{
    struct Sddm_target *mdt;
 
    mdt = (struct Sddm_target *) ti->private;
 
    bh->b_dev = mdt->dev->dev;
 
    submit_bh(rw, bh);
 
    return 0;
}
 
static int sddm_target_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
    struct Sddm_target *mdt;
    unsigned long start;
    unsigned long len;
    int err;
 
    if (argc != 2)
    {
        ti->error = "Invalid argument count";
        return -EINVAL;
    }
 
    mdt = (struct Sddm_target*)kmalloc(sizeof(struct Sddm_target), GFP_KERNEL);
 
    if (mdt == NULL)
    {
        ti->error = "dm-basic_target: Cannot allocate linear context";
        return -ENOMEM;
    }       
 
    if (sscanf(argv[1], "%lu", &start) != 1)
    {
        ti->error = "dm-basic_target: Invalid deviceee sector";
        kfree(mdt);
        return -EINVAL;
    }
 
    mdt->start = (sector_t)start;
 
    err = dm_get_device(ti, argv[0], ti->begin, ti->len, dm_table_get_mode(ti->table), &mdt->dev);

    if (err)
    {
        ti->error = "dm-basic_target: Device lookup failed";
        kfree(mdt);
        return -EINVAL;
    }
 
    ti->private = mdt;
 
    return 0;
}
 
static void sddm_target_dtr(struct dm_target *ti)
{
    struct Sddm_target *mdt = (struct Sddm_target *) ti->private;
 
    dm_put_device(ti, mdt->dev);
    kfree(mdt);
}
 
static struct target_type sddm_target = {
        .name = "sddm_target",
        .version = {1,0,0},
        .module = THIS_MODULE,
        .ctr = sddm_target_ctr,
        .dtr = sddm_target_dtr,
        .map = sddm_target_map,
};
 
static int __init init_sddm_target(void)
{
    int result;
 
    result = dm_register_target(&sddm_target);
 
    return 0;
}
 
static void __exit cleanup_sddm_target(void)
{
    dm_unregister_target(&sddm_target);
}
 
module_init(init_sddm_target);
 
module_exit(cleanup_sddm_target);
 
MODULE_LICENSE("GPL");
And it almost works. Virlual device created, but when I try to mount it, I get several calls of sddm_target_map function and then the process hangs with the message:

kjoutnald starting. Commit interval 5 seconds

I know that it is a kind of filesystem checking, but I can't understand why does it hang. So, I need your help! Any kind of message can be helpful!


If it can be useful... dm_dev structure in device-mapper.h kernel header was not implemented on that system (only prototype). So I completed it:

Code:
struct dm_dev
{
    struct list_head list;

    atomic_t count;
    int mode;
    kdev_t dev;
    struct block_device *bdev;
}
My module didn't compile withoun it.
 
Old 02-18-2017, 11:04 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
the 2.4 kernel is long dead ( long unsupported) and the 2.6 is also

use the current 3.x or 4.x kernel

but if you REALLY NEED the ancent 2.4 kernel
use the also ancent and UNSUPPORTED RH7.1 ( from 2001 ) or the equally UNSUPPORTED RH9 from 2003 to 2004 ( rh9 went EOL in 2004 )

Last edited by John VV; 02-18-2017 at 11:10 AM.
 
Old 02-20-2017, 12:03 AM   #3
AccumPlus
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you for the reply!

Quote:
Originally Posted by John VV View Post
the 2.4 kernel is long dead ( long unsupported) and the 2.6 is also

use the current 3.x or 4.x kernel
If only it were possible. It works great on my system with actual kernel version. But of course the code differs.

Quote:
Originally Posted by John VV View Post
use the also ancent and UNSUPPORTED RH7.1 ( from 2001 ) or the equally UNSUPPORTED RH9 from 2003 to 2004 ( rh9 went EOL in 2004 )
I should make this working under the system based on RedHat. There is no big difference, I suppose.
 
Old 02-20-2017, 12:42 AM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
if you need a 13 year old and unsupported kernel then what 13 year old and out of date operating system are you using

using a OS that is missing 13 years of SECURITY updates is not good

for the ancient 2.4 kernel you can not use tools for the old 2.6 kernel

nor code that is NOT in the 2.4 kernel
 
Old 02-20-2017, 12:52 AM   #5
AccumPlus
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by John VV View Post
if you need a 13 year old and unsupported kernel then what 13 year old and out of date operating system are you using
It is my task, not my desire. The system sounds like MSVS, but it is Russian one and can be revealed as Armed Forses Mobile System.

Quote:
Originally Posted by John VV View Post
using a OS that is missing 13 years of SECURITY updates is not good
I totally agree with you.

Quote:
Originally Posted by John VV View Post
for the ancient 2.4 kernel you can not use tools for the old 2.6 kernel

nor code that is NOT in the 2.4 kernel
I know this. I put the code, that is sutable for 2.4 kernel. The only problem was dm_dev structure. But even device-mapper developers offer a patch for 2.4 kernel, where I got an implementation of this structure.

Last edited by AccumPlus; 02-20-2017 at 12:54 AM.
 
Old 02-20-2017, 02:32 PM   #6
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
MSVS

as in Microsoft Visual Studio IDE
"msvs 6" and "msvs 7.net" date from then

or a for a rather old military Truck ( like the Navistar 7000)that is called a "Medium Support Vehicle System "

if a Canadian military truck , ask the manufacturer for the "classified" documentation

the 2.4 kernel mostly predates me and building kernel modals

look up the old 2.4 kernel documentation , and use a version of gcc that dates from back then
the gcc4 (and newer) series REALLY clamped down on BAD codding
use gcc-3.3 or 3.4

Keep in mind that the 2.4 kernel has NO!!!! support for anything newer than 2002 / 2003
so no hardware support for things that are LESS that 15 years old ( 3 full computer generations old)

as in things like usb2

Last edited by John VV; 02-20-2017 at 02:36 PM.
 
Old 02-21-2017, 01:17 AM   #7
AccumPlus
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by John VV View Post
MSVS

as in Microsoft Visual Studio IDE
"msvs 6" and "msvs 7.net" date from then

or a for a rather old military Truck ( like the Navistar 7000)that is called a "Medium Support Vehicle System "

if a Canadian military truck , ask the manufacturer for the "classified" documentation
Nice jokes It only sounds like MSVS. And spelling like "МСВС", but in Russian letters.

Quote:
Originally Posted by John VV View Post
look up the old 2.4 kernel documentation , and use a version of gcc that dates from back then
the gcc4 (and newer) series REALLY clamped down on BAD codding
use gcc-3.3 or 3.4

Keep in mind that the 2.4 kernel has NO!!!! support for anything newer than 2002 / 2003
so no hardware support for things that are LESS that 15 years old ( 3 full computer generations old)

as in things like usb2
Thank you for advice. I'll try to find something helpful.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom kernel - lilo complains device-mapper missing donni Linux - Software 3 07-26-2010 12:47 PM
Device-mapper missing from kernel jazpaisley Linux - Kernel 1 07-26-2010 12:09 PM
unable to find device-mapper major/minor? help!!!!! can't boot up! kernel panic! newtovanilla Linux - Newbie 5 11-23-2008 02:39 PM
trying to install/boot 2.6.15 kernel - device mapper error jmike1 Linux - Software 2 03-15-2006 09:49 PM
Help please to mount windows partitions - device-mapper: error adding target to table Indian_bee Linux - General 3 07-06-2004 07:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration