From owner-svn-src-head@FreeBSD.ORG Thu Mar 26 17:14:23 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81BE81065753; Thu, 26 Mar 2009 17:14:23 +0000 (UTC) (envelope-from ambrisko@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6B5668FC1B; Thu, 26 Mar 2009 17:14:23 +0000 (UTC) (envelope-from ambrisko@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2QHENSi023740; Thu, 26 Mar 2009 17:14:23 GMT (envelope-from ambrisko@svn.freebsd.org) Received: (from ambrisko@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2QHENQ2023732; Thu, 26 Mar 2009 17:14:23 GMT (envelope-from ambrisko@svn.freebsd.org) Message-Id: <200903261714.n2QHENQ2023732@svn.freebsd.org> From: Doug Ambrisko Date: Thu, 26 Mar 2009 17:14:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190445 - in head/sys: amd64/linux32 compat/linprocfs compat/linux conf dev/ipmi modules/ipmi modules/linprocfs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2009 17:14:26 -0000 Author: ambrisko Date: Thu Mar 26 17:14:22 2009 New Revision: 190445 URL: http://svn.freebsd.org/changeset/base/190445 Log: Add stuff to support upcoming BMC/IPMI flashing of newer Dell machine via the Linux tool. - Add Linux shim to ipmi(4) - Create a partitions file to linprocfs to make Linux fdisk see disks. This file is dynamic so we can see disks come and go. - Convert msdosfs to vfat in mtab since Linux uses that for msdosfs. - In the Linux mount path convert vfat passed in to msdosfs so Linux mount works on FreeBSD. Note that tasting works so that if da0 is a msdos file system /compat/linux/bin/mount /dev/da0 /mnt works. - fix a 64it bug for l_off_t. Grabing sh, mount, fdisk, df from Linux, creating a symlink of mtab to /compat/linux/etc/mtab and then some careful unpacking of the Linux bmc update tool and hacking makes it work on newer Dell boxes. Note, probably if you can't figure out how to do this, then you probably shouldn't be doing it :-) Added: head/sys/dev/ipmi/ipmi_linux.c (contents, props changed) Modified: head/sys/amd64/linux32/linux.h head/sys/compat/linprocfs/linprocfs.c head/sys/compat/linux/linux_file.c head/sys/conf/files.amd64 head/sys/conf/files.i386 head/sys/modules/ipmi/Makefile head/sys/modules/linprocfs/Makefile Modified: head/sys/amd64/linux32/linux.h ============================================================================== --- head/sys/amd64/linux32/linux.h Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/amd64/linux32/linux.h Thu Mar 26 17:14:22 2009 (r190445) @@ -79,7 +79,7 @@ typedef l_ulong l_ino_t; typedef l_int l_key_t; typedef l_longlong l_loff_t; typedef l_ushort l_mode_t; -typedef l_long l_off_t; +typedef l_ulong l_off_t; typedef l_int l_pid_t; typedef l_uint l_size_t; typedef l_long l_suseconds_t; Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/compat/linprocfs/linprocfs.c Thu Mar 26 17:14:22 2009 (r190445) @@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -90,6 +91,9 @@ __FBSDID("$FreeBSD$"); #include +#include +#include + #if defined(__i386__) || defined(__amd64__) #include #include @@ -359,6 +363,9 @@ linprocfs_domtab(PFS_FILL_ARGS) sbuf_printf(sb, "/sys %s sysfs %s", mntto, mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); } else { + /* For Linux msdosfs is called vfat */ + if (strcmp(fstype, "msdosfs") == 0) + fstype = "vfat"; sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype, mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); } @@ -383,6 +390,69 @@ linprocfs_domtab(PFS_FILL_ARGS) } /* + * Filler function for proc/partitions + * + */ +static int +linprocfs_dopartitions(PFS_FILL_ARGS) +{ + struct g_class *cp; + struct g_geom *gp; + struct g_provider *pp; + struct nameidata nd; + const char *lep; + char *dlep, *flep; + size_t lep_len; + int error; + int major, minor; + + /* resolve symlinks etc. in the emulation tree prefix */ + NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, linux_emul_path, td); + flep = NULL; + error = namei(&nd); + lep = linux_emul_path; + if (error == 0) { + if (vn_fullpath(td, nd.ni_vp, &dlep, &flep) == 0) + lep = dlep; + vrele(nd.ni_vp); + VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); + } + lep_len = strlen(lep); + + g_topology_lock(); + error = 0; + sbuf_printf(sb, "major minor #blocks name rio rmerge rsect " + "ruse wio wmerge wsect wuse running use aveq\n"); + + LIST_FOREACH(cp, &g_classes, class) { + if (strcmp(cp->name, "DISK") == 0 || + strcmp(cp->name, "PART") == 0) + LIST_FOREACH(gp, &cp->geom, geom) { + LIST_FOREACH(pp, &gp->provider, provider) { + if (linux_driver_get_major_minor( + pp->name, &major, &minor) != 0) { + major = 0; + minor = 0; + } + sbuf_printf(sb, "%d %d %lld %s " + "%d %d %d %d %d " + "%d %d %d %d %d %d\n", + major, minor, + (long long)pp->mediasize, pp->name, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0); + } + } + } + g_topology_unlock(); + + if (flep != NULL) + free(flep, M_TEMP); + return (error); +} + + +/* * Filler function for proc/stat */ static int @@ -1206,6 +1276,8 @@ linprocfs_init(PFS_INIT_ARGS) NULL, NULL, NULL, PFS_RD); pfs_create_file(root, "mtab", &linprocfs_domtab, NULL, NULL, NULL, PFS_RD); + pfs_create_file(root, "partitions", &linprocfs_dopartitions, + NULL, NULL, NULL, PFS_RD); pfs_create_link(root, "self", &procfs_docurproc, NULL, NULL, NULL, 0); pfs_create_file(root, "stat", &linprocfs_dostat, Modified: head/sys/compat/linux/linux_file.c ============================================================================== --- head/sys/compat/linux/linux_file.c Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/compat/linux/linux_file.c Thu Mar 26 17:14:22 2009 (r190445) @@ -1109,6 +1109,9 @@ linux_mount(struct thread *td, struct li } else if (strcmp(fstypename, "proc") == 0) { strcpy(fstypename, "linprocfs"); fsdata = NULL; + } else if (strcmp(fstypename, "vfat") == 0) { + strcpy(fstypename, "msdosfs"); + fsdata = NULL; } else { return (ENODEV); } @@ -1135,6 +1138,12 @@ linux_mount(struct thread *td, struct li "fstype", fstypename, "fspath", mntonname, NULL); + } else if (strcmp(fstypename, "msdosfs") == 0) { + error = kernel_vmount(fsflags, + "fstype", fstypename, + "fspath", mntonname, + "from", mntfromname, + NULL); } else error = EOPNOTSUPP; return (error); Modified: head/sys/conf/files.amd64 ============================================================================== --- head/sys/conf/files.amd64 Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/conf/files.amd64 Thu Mar 26 17:14:22 2009 (r190445) @@ -183,6 +183,7 @@ dev/ipmi/ipmi_smbus.c optional ipmi smb dev/ipmi/ipmi_smbios.c optional ipmi dev/ipmi/ipmi_ssif.c optional ipmi smbus dev/ipmi/ipmi_pci.c optional ipmi pci +dev/ipmi/ipmi_linux.c optional ipmi linux_compat32 dev/fdc/fdc.c optional fdc dev/fdc/fdc_acpi.c optional fdc dev/fdc/fdc_isa.c optional fdc isa Modified: head/sys/conf/files.i386 ============================================================================== --- head/sys/conf/files.i386 Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/conf/files.i386 Thu Mar 26 17:14:22 2009 (r190445) @@ -196,6 +196,7 @@ dev/ipmi/ipmi_smbus.c optional ipmi smb dev/ipmi/ipmi_smbios.c optional ipmi dev/ipmi/ipmi_ssif.c optional ipmi smbus dev/ipmi/ipmi_pci.c optional ipmi pci +dev/ipmi/ipmi_linux.c optional ipmi linux_compat dev/kbd/kbd.c optional atkbd | sc | ukbd | usb2_input_kbd dev/le/if_le_isa.c optional le isa dev/mem/memutil.c optional mem Added: head/sys/dev/ipmi/ipmi_linux.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/ipmi/ipmi_linux.c Thu Mar 26 17:14:22 2009 (r190445) @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2009 IronPort Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Linux ioctl handler for the ipmi device driver + */ + +#include +#include +#include +#include +#include +#include +#include +#ifdef __amd64__ +#include +#include +#else +#include +#include +#endif +#include +#include +#include + +/* There are multiple ioctl number ranges that need to be handled */ +#define IPMI_LINUX_IOCTL_MIN 0x690b +#define IPMI_LINUX_IOCTL_MAX 0x6915 + +/* Linux versions of ioctl's */ +#define L_IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, struct ipmi_recv) +#define L_IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, struct ipmi_recv) +#define L_IPMICTL_SEND_COMMAND _IOW(IPMI_IOC_MAGIC, 13, struct ipmi_req) +#define L_IPMICTL_REGISTER_FOR_CMD _IOW(IPMI_IOC_MAGIC, 14, struct ipmi_cmdspec) +#define L_IPMICTL_UNREGISTER_FOR_CMD _IOW(IPMI_IOC_MAGIC, 15, struct ipmi_cmdspec) +#define L_IPMICTL_SET_GETS_EVENTS_CMD _IOW(IPMI_IOC_MAGIC, 16, int) +#define L_IPMICTL_SET_MY_ADDRESS_CMD _IOW(IPMI_IOC_MAGIC, 17, unsigned int) +#define L_IPMICTL_GET_MY_ADDRESS_CMD _IOW(IPMI_IOC_MAGIC, 18, unsigned int) +#define L_IPMICTL_SET_MY_LUN_CMD _IOW(IPMI_IOC_MAGIC, 19, unsigned int) +#define L_IPMICTL_GET_MY_LUN_CMD _IOW(IPMI_IOC_MAGIC, 20, unsigned int) + +static linux_ioctl_function_t ipmi_linux_ioctl; +static struct linux_ioctl_handler ipmi_linux_handler = {ipmi_linux_ioctl, + IPMI_LINUX_IOCTL_MIN, + IPMI_LINUX_IOCTL_MAX}; + +SYSINIT (ipmi_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE, + linux_ioctl_register_handler, &ipmi_linux_handler); +SYSUNINIT(ipmi_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE, + linux_ioctl_unregister_handler, &ipmi_linux_handler); + +static int +ipmi_linux_modevent(module_t mod, int type, void *data) +{ + /* Do we care about any specific load/unload actions? */ + return (0); +} + +DEV_MODULE(ipmi_linux, ipmi_linux_modevent, NULL); +MODULE_DEPEND(ipmi_linux, linux, 1, 1, 1); + +static int +ipmi_linux_ioctl(struct thread *td, struct linux_ioctl_args *args) +{ + struct file *fp; + u_long cmd; + int error; + + if ((error = fget(td, args->fd, &fp)) != 0) + return (error); + cmd = args->cmd; + + switch(cmd) { + case L_IPMICTL_GET_MY_ADDRESS_CMD: + cmd = IPMICTL_GET_MY_ADDRESS_CMD; + break; + case L_IPMICTL_GET_MY_LUN_CMD: + cmd = IPMICTL_GET_MY_LUN_CMD; + break; + } + /* + * Pass the ioctl off to our standard handler. + */ + error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td)); + fdrop(fp, td); + return (error); +} Modified: head/sys/modules/ipmi/Makefile ============================================================================== --- head/sys/modules/ipmi/Makefile Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/modules/ipmi/Makefile Thu Mar 26 17:14:22 2009 (r190445) @@ -1,5 +1,7 @@ # $FreeBSD$ +SUBDIR+= ipmi_linux + .PATH: ${.CURDIR}/../../dev/ipmi # XXX - ipmi_smbus and ipmi_ssif depend on smbus Modified: head/sys/modules/linprocfs/Makefile ============================================================================== --- head/sys/modules/linprocfs/Makefile Thu Mar 26 17:04:08 2009 (r190444) +++ head/sys/modules/linprocfs/Makefile Thu Mar 26 17:14:22 2009 (r190445) @@ -4,6 +4,7 @@ KMOD= linprocfs SRCS= vnode_if.h \ + device_if.h bus_if.h \ linprocfs.c \ opt_compat.h \ opt_route.h