[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Fedora-packaging] yum kmdl plugin (was: atrpms kernel modules)



On Tue, Jul 25, 2006 at 11:31:29PM +0200, Axel Thimm wrote:
> On Sun, Jul 23, 2006 at 05:13:40PM -0400, seth vidal wrote:
> > On Sun, 2006-07-23 at 23:03 +0200, Axel Thimm wrote:
> > > On Sun, Jul 23, 2006 at 04:38:59PM -0400, seth vidal wrote:
> > > > On Sun, 2006-07-23 at 22:19 +0200, Axel Thimm wrote:
> > > > > On Sun, Jul 23, 2006 at 10:32:06PM +0300, Ville Skyttä wrote:
> > > > > > > rpm -U/-i will nuke or overwrite kernel modules of the running
> > > > > > > kernel in a uname-r-less scheme.
> > > 
> > > > But I thought it was already stated that we don't care about
> > > > rpm used on the cli to handle these sorts of things. That
> > > > we've assumed we're operating at a level above rpm for
> > > > constructing the transaction set.
> > > 
> > > A scheme were two independent EVRs are merged together into one
> > > is broken and banning the tool that exhibits it and pasting it
> > > away from others isn't the solution. kmod-foo-1-a just has
> > > nothing to do with kmod-foo-<anything>-b (in the simplified
> > > notation).
> > 
> > okay. I can take that.
> > 
> > Here's my only complaint and it is a complaint for all sides
> > equally:
> > 
> > I would like one and final standard decided on BEFORE FC6 is
> > released.  We need to get the code for yum complete so we can stop
> > messing around with this stuff.
> > 
> > At this point I'm in favor of whatever gets it done.
> 
> Would you be interested in adding support for the kmdl scheme to yum
> (or a plugin) *before* a decision is made?
> 
> I'm suggesting this because kernel module handling is for many in this
> list too abstract to discuss on paper and a live demonstration using
> yum and kmdls would certainly help moving on on this subject here. A
> bash shell script doing it is 9 lines, so I hope for you it would be
> almost trivial to pluginize.
> 
> Even if the decision can't be made in time for FC6 (which effectively
> would mean to keep the current scheme) it would not be a waste of time
> as it is already in use at ATrpms, and many users want to see yum
> auto-coinstalling them upon new kernels.

On Wed, Jul 26, 2006 at 10:33:05AM -0400, Jack Neely wrote:
> If you'd like to contribute a Yum plugin or patches to one of the
> existing 2 they are in the yum-utils project.  They're not hard to
> write and there are a handful of good examples now.  My time is
> going toward the current proposal.
> 
> Panu does have a plugin in yum-utils to support a uname-r in name
> scheme for kernel modules.  Looks like it needs to be updated a bit,
> but perhaps that could be a starting point for your work.

Thanks, I looked it up and indeed writing a yum plugin for kmdls is
trivial. I really like the design of the plugin/hook mechanism.

So I managed to get a fully featured kmdl plugin under 100 python
lines (actually 99 ;). It even has two modes of operation:

yum update:  Will update/coinstall kmdl of all old and new kernels

yum install: Will only do something with kmdls if a kernel is asked to
	     be installed (and only for that kernel)

I differ between the two, because I don't want the user to be
surprised with kernel module installations when he yum-installs
openoffice :)

It also supports asynced kernel/kernel-module repo arrival. When a
kernel update appears it will be installed even when the kmdls aren't
yet available/built. If on the next yum update the previously missing
kmdls appear, they will get installed at that time.

I'm attaching the file (kmdl.py) to this mail. Seth & Jack you have a
look and if approved add it to yum/yum-util sources (whatever is more
appropriate)? If you don't like it let me know what needs improvement.

To atrpms-devel: Please test the kmdl.py by copying it to
/usr/lib/yum-plugins/kmdl.py

To fedora-packaging: Now we have full support on rpm and yum level for
kmdls [*], and it's rather comprehendable and maintainable code. If we
can get over the ugliness or uname-r-in-name we should really adopt
that scheme.

[*] apt has kmdl support from lua, but during apt's time-off I think
    it regressed, but it can be easily resurrected, it will also be a
    couple of lua lines. smart support for any kernel module scheme
    seems to be the toughest because it's plugin scheme is not well
    documented and it looks like it misses some important hooks.
-- 
Axel.Thimm at ATrpms.net
#! /usr/bin/python
# -*- coding: utf-8 mode: python -*-
# kmdl.py - plugin for handling kmdls
# Copyright (C) 2006 A. Thimm
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# $Id$

import re
import rpm

from yum.plugins import TYPE_CORE
from rpmUtils.miscutils import compareEVR

requires_api_version = '2.2'
plugin_type = (TYPE_CORE,)

KERNELS=["kernel", "kernel-smp", "kernel-bigmem", "kernel-hugemem", "kernel-largesmp", "kernel-xen0", "kernel-xenU", "kernel-kdump", "kernel-xen"]

def uname_r(name, version, release):
    if name == 'kernel':
        return "%s-%s" % (version, release)
    else:
        (dummy, flavour) = name.split('-')
        return "%s-%s%s" % (version, release, flavour)

def kmdls(conduit):
    kmdls=[]
    for hdr in conduit.getRpmDB().getHdrList():
        m=re.match('(.*)-kmdl-.*', hdr[rpm.RPMTAG_NAME])
        if m:
            kmdls.append(m.group(1))
    tsInfo=conduit.getTsInfo()
    for txmbr in tsInfo.getMembers():
        m=re.match('(.*)-kmdl-.*', txmbr.name)
        if m and txmbr.ts_state in ('i', 'u'):
            kmdls.append(m.group(1))
    return kmdls

def old_kernels(conduit):
    kernels=[]
    for hdr in conduit.getRpmDB().getHdrList():
        if hdr[rpm.RPMTAG_NAME] in KERNELS:
            kernels.append([uname_r(hdr[rpm.RPMTAG_NAME],
                                    hdr[rpm.RPMTAG_VERSION],
                                    hdr[rpm.RPMTAG_RELEASE]),
                             hdr[rpm.RPMTAG_ARCH]])
    return kernels

def new_kernels(conduit):
    kernels=[]
    tsInfo=conduit.getTsInfo()
    for txmbr in tsInfo.getMembers():
        if txmbr.name in KERNELS and txmbr.ts_state in ('i', 'u'):
            kernels.append([uname_r(txmbr.name, txmbr.version, txmbr.release),
                             txmbr.arch])
    return kernels

def kmdl_install(conduit, kernels, kmdls):
    tsInfo = conduit.getTsInfo()
    for kernel in kernels:
        for kmdl in kmdls:
            pkgname="%s-kmdl-%s" % (kmdl, kernel[0])
            pkgfound=None
            for pkg in conduit.getPackages():
                if pkg.name == pkgname and pkg.arch == kernel[1]:
                    if not pkgfound or compareEVR(pkg.returnEVR(), pkgfound.returnEVR()) == 1:
                        pkgfound=pkg
            if pkgfound:
                print "Installing " + pkgfound.name
                (n, a, e, v, r) = pkgfound.pkgtup
                conduit.info(2, '---> Package %s.%s %s:%s-%s set to be %s' % (n, a, e, v, r,
                                                                              'installed'))
                tsInfo.addInstall(pkgfound)

def postresolve_hook(conduit):
    opts, commands = conduit.getCmdLine()
    if commands[0] == 'update':
        kernels = old_kernels(conduit) + new_kernels(conduit)
    elif commands[0] == 'install':
        kernels = new_kernels(conduit)
    else:
        return

    kmdl_install(conduit, kernels, kmdls(conduit))

Attachment: pgpn4K5rxHxTq.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]