| diff -ru --exclude-from freebsd-src-diff-exclude-names --new-file /var/archive3/public/freebsd-releng-10.4-src/sys/compat/linprocfs/linprocfs.c freebsd-10.4/sys/compat/linprocfs/linprocfs.c |
| --- /var/archive3/public/freebsd-releng-10.4-src/sys/compat/linprocfs/linprocfs.c 2017-09-29 08:19:56.000000000 +0800 |
| +++ freebsd-10.4/sys/compat/linprocfs/linprocfs.c 2025-01-09 14:08:08.398734000 +0800 |
| @@ -39,6 +39,13 @@ |
| * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 |
| */ |
| |
| +#include "linprocfs_version.h" |
| +#ifndef LINPROCFS_VERSION |
| +#define LINPROCFS_VERSION LINRPOCFS_VERSION_BUILD_VERSION " " LINPROCFS_VERSION_BUILD_TIME |
| +#endif |
| + |
| +#define _NO_CONVERT_IFNAME 1 |
| + |
| #include <sys/cdefs.h> |
| __FBSDID("$FreeBSD: releng/10.4/sys/compat/linprocfs/linprocfs.c 299221 2016-05-07 19:05:39Z dchagin $"); |
| |
| @@ -119,6 +126,13 @@ |
| #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ |
| #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000) |
| |
| +static SYSCTL_NODE(_vfs, OID_AUTO, linprocfs, CTLFLAG_RW, 0, "Linux procfs"); |
| + |
| +int compatible_unit_prefix = 1; |
| +SYSCTL_INT(_vfs_linprocfs, OID_AUTO, compatible_unit_prefix, CTLFLAG_RW, |
| + &compatible_unit_prefix, 0, |
| + "use Linux-compatible (but incorrect) unit prefix names for byte values"); |
| + |
| /** |
| * @brief Mapping of ki_stat in struct kinfo_proc to the linux state |
| * |
| @@ -133,7 +147,7 @@ |
| * This character array is used with ki_stati-1 as an index and tries to |
| * map our states to suitable linux states. |
| */ |
| -static char linux_state[] = "RRSTZDD"; |
| +static char linux_state[] = "RRSTZID"; |
| |
| /* |
| * Filler function for proc/meminfo |
| @@ -141,68 +155,69 @@ |
| static int |
| linprocfs_domeminfo(PFS_FILL_ARGS) |
| { |
| + size_t len; |
| unsigned long memtotal; /* total memory in bytes */ |
| unsigned long memused; /* used memory in bytes */ |
| unsigned long memfree; /* free memory in bytes */ |
| unsigned long memshared; /* shared memory ??? */ |
| - unsigned long buffers, cached; /* buffer / cache memory ??? */ |
| + unsigned long cached; /* file system cache */ |
| unsigned long long swaptotal; /* total swap space in bytes */ |
| unsigned long long swapused; /* used swap space in bytes */ |
| unsigned long long swapfree; /* free swap space in bytes */ |
| vm_object_t object; |
| int i, j; |
| + int e; |
| + const char *kibibyte_name = compatible_unit_prefix ? "kB" : "KiB"; |
| |
| memtotal = physmem * PAGE_SIZE; |
| - /* |
| - * The correct thing here would be: |
| - * |
| +#if 1 |
| memfree = cnt.v_free_count * PAGE_SIZE; |
| memused = memtotal - memfree; |
| - * |
| - * but it might mislead linux binaries into thinking there |
| - * is very little memory left, so we cheat and tell them that |
| - * all memory that isn't wired down is free. |
| - */ |
| - memused = cnt.v_wire_count * PAGE_SIZE; |
| +#else |
| + memused = (cnt.v_active_count + cnt.v_wire_count + cnt.v_inactive_count + cnt.v_cache_count) * PAGE_SIZE; |
| memfree = memtotal - memused; |
| +#endif |
| swap_pager_status(&i, &j); |
| swaptotal = (unsigned long long)i * PAGE_SIZE; |
| swapused = (unsigned long long)j * PAGE_SIZE; |
| swapfree = swaptotal - swapused; |
| memshared = 0; |
| mtx_lock(&vm_object_list_mtx); |
| - TAILQ_FOREACH(object, &vm_object_list, object_list) |
| - if (object->shadow_count > 1) |
| + TAILQ_FOREACH(object, &vm_object_list, object_list) { |
| + if (object->shadow_count > 1) { |
| memshared += object->resident_page_count; |
| + } |
| + } |
| mtx_unlock(&vm_object_list_mtx); |
| memshared *= PAGE_SIZE; |
| - /* |
| - * We'd love to be able to write: |
| - * |
| - buffers = bufspace; |
| - * |
| - * but bufspace is internal to vfs_bio.c and we don't feel |
| - * like unstaticizing it just for linprocfs's sake. |
| - */ |
| - buffers = 0; |
| - cached = cnt.v_cache_count * PAGE_SIZE; |
| + |
| + len = sizeof cached; |
| + e = kernel_sysctlbyname(td, "vfs.bufspace", &cached, &len, NULL, 0, NULL, 0); |
| + if(e) cached = 0; |
| + cached += cnt.v_cache_count * PAGE_SIZE; |
| |
| sbuf_printf(sb, |
| - " total: used: free: shared: buffers: cached:\n" |
| - "Mem: %lu %lu %lu %lu %lu %lu\n" |
| - "Swap: %llu %llu %llu\n" |
| - "MemTotal: %9lu kB\n" |
| - "MemFree: %9lu kB\n" |
| - "MemShared:%9lu kB\n" |
| - "Buffers: %9lu kB\n" |
| - "Cached: %9lu kB\n" |
| - "SwapTotal:%9llu kB\n" |
| - "SwapFree: %9llu kB\n", |
| - memtotal, memused, memfree, memshared, buffers, cached, |
| + " total: used: free: shared: buffers: cached:\n" |
| + "Mem: %8lu %8lu %8lu %8lu %8lu %8lu\n" |
| + "Swap: %8llu %8llu %8llu\n" |
| + "MemTotal: %9lu %s\n" |
| + "MemFree: %9lu %s\n" |
| + "MemShared:%9lu %s\n" |
| + "Cached: %9lu %s\n" |
| + "Active: %9lu %s\n" |
| + "Inactive: %9lu %s\n" |
| + "SwapTotal:%9llu %s\n" |
| + "SwapFree: %9llu %s\n", |
| + memtotal, memused, memfree, memshared, 0, cached, |
| swaptotal, swapused, swapfree, |
| - B2K(memtotal), B2K(memfree), |
| - B2K(memshared), B2K(buffers), B2K(cached), |
| - B2K(swaptotal), B2K(swapfree)); |
| + B2K(memtotal), kibibyte_name, |
| + B2K(memfree), kibibyte_name, |
| + B2K(memshared), kibibyte_name, |
| + B2K(cached), kibibyte_name, |
| + P2K((unsigned long int)cnt.v_active_count), kibibyte_name, |
| + P2K((unsigned long int)cnt.v_inactive_count), kibibyte_name, |
| + B2K(swaptotal), kibibyte_name, |
| + B2K(swapfree), kibibyte_name); |
| |
| return (0); |
| } |
| @@ -350,26 +365,24 @@ |
| /* determine mount point */ |
| mntto = mp->mnt_stat.f_mntonname; |
| if (strncmp(mntto, lep, lep_len) == 0 && |
| - mntto[lep_len] == '/') |
| + mntto[lep_len] == '/') { |
| mntto += lep_len; |
| + } |
| |
| /* determine fs type */ |
| fstype = mp->mnt_stat.f_fstypename; |
| - if (strcmp(fstype, pn->pn_info->pi_name) == 0) |
| - mntfrom = fstype = "proc"; |
| - else if (strcmp(fstype, "procfs") == 0) |
| + if (strcmp(fstype, pn->pn_info->pi_name) == 0) { |
| + fstype = "proc"; |
| + } else if (strcmp(fstype, "procfs") == 0) { |
| continue; |
| - |
| - if (strcmp(fstype, "linsysfs") == 0) { |
| - sbuf_printf(sb, "/sys %s sysfs %s", mntto, |
| - mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); |
| - } else { |
| + } else if(strcmp(fstype, "linsysfs") == 0) { |
| + fstype = "sysfs"; |
| + } else if (strcmp(fstype, "msdosfs") == 0) { |
| /* 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"); |
| + fstype = "vfat"; |
| } |
| + sbuf_printf(sb, "%s %s %s %s", mntfrom, mntto, fstype, |
| + mp->mnt_stat.f_flags & MNT_RDONLY ? "ro" : "rw"); |
| #define ADD_OPTION(opt, name) \ |
| if (mp->mnt_stat.f_flags & (opt)) sbuf_printf(sb, "," name); |
| ADD_OPTION(MNT_SYNCHRONOUS, "sync"); |
| @@ -429,6 +442,37 @@ |
| return (0); |
| } |
| |
| +/* |
| + * Filler function for proc/diskstats |
| + */ |
| +static int |
| +linprocfs_dodiskstats(PFS_FILL_ARGS) |
| +{ |
| + struct g_class *cp; |
| + struct g_geom *gp; |
| + struct g_provider *pp; |
| + int major, minor; |
| + |
| + g_topology_lock(); |
| + LIST_FOREACH(cp, &g_classes, class) { |
| + if(strcmp(cp->name, "DISK") == 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, "%4d %7d %s \n", |
| + major, minor, pp->name); |
| + } |
| + } |
| + } |
| + } |
| + g_topology_unlock(); |
| + |
| + return 0; |
| +} |
| |
| /* |
| * Filler function for proc/stat |
| @@ -541,7 +585,8 @@ |
| sbuf_printf(sb, "%s%s", cp1, cp2 + 1); |
| else |
| #endif |
| - sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); |
| + // sbuf_cat(sb, "#4 Sun Dec 18 04:30:00 CET 1977"); |
| + sbuf_cat(sb, LINPROCFS_VERSION); |
| } |
| |
| /* |
| @@ -566,7 +611,8 @@ |
| sbuf_cat(sb, builder); |
| else |
| #endif |
| - sbuf_cat(sb, "des@freebsd.org"); |
| + // sbuf_cat(sb, "des@freebsd.org"); |
| + sbuf_cat(sb, LINPROCFS_VERSION_BUILD_BY); |
| } |
| |
| /* |
| @@ -642,8 +688,10 @@ |
| kp.ki_stat, sizeof(linux_state)); |
| ++ratelimit; |
| } |
| - } else |
| - state = linux_state[kp.ki_stat - 1]; |
| + } else { |
| + state = kp.ki_stat == SRUN ? |
| + ((kp.ki_tdflags & TDF_SINTR) ? 'S' : 'D') : linux_state[kp.ki_stat - 1]; |
| + } |
| PS_ADD("state", "%c", state); |
| PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); |
| PS_ADD("pgrp", "%d", p->p_pgid); |
| @@ -1096,6 +1144,7 @@ |
| return (error); |
| } |
| |
| +#ifndef _NO_CONVERT_IFNAME |
| /* |
| * Criteria for interface name translation |
| */ |
| @@ -1124,6 +1173,7 @@ |
| |
| return (0); |
| } |
| +#endif |
| |
| /* |
| * Filler function for proc/net/dev |
| @@ -1131,7 +1181,9 @@ |
| static int |
| linprocfs_donetdev(PFS_FILL_ARGS) |
| { |
| +#ifndef _NO_CONVERT_IFNAME |
| char ifname[16]; /* XXX LINUX_IFNAMSIZ */ |
| +#endif |
| struct ifnet *ifp; |
| |
| sbuf_printf(sb, "%6s|%58s|%s\n" |
| @@ -1144,8 +1196,12 @@ |
| CURVNET_SET(TD_TO_VNET(curthread)); |
| IFNET_RLOCK(); |
| TAILQ_FOREACH(ifp, &V_ifnet, if_link) { |
| +#ifdef _NO_CONVERT_IFNAME |
| + sbuf_printf(sb, "%6.6s: ", ifp->if_xname); |
| +#else |
| linux_ifname(ifp, ifname, sizeof ifname); |
| sbuf_printf(sb, "%6.6s: ", ifname); |
| +#endif |
| sbuf_printf(sb, "%7lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu ", |
| ifp->if_ibytes, /* rx_bytes */ |
| ifp->if_ipackets, /* rx_packets */ |
| @@ -1522,6 +1578,8 @@ |
| NULL, NULL, NULL, PFS_RD); |
| pfs_create_file(root, "devices", &linprocfs_dodevices, |
| NULL, NULL, NULL, PFS_RD); |
| + pfs_create_file(root, "diskstats", &linprocfs_dodiskstats, |
| + NULL, NULL, NULL, PFS_RD); |
| pfs_create_file(root, "filesystems", &linprocfs_dofilesystems, |
| NULL, NULL, NULL, PFS_RD); |
| pfs_create_file(root, "loadavg", &linprocfs_doloadavg, |
| diff -ru --exclude-from freebsd-src-diff-exclude-names /var/archive3/public/freebsd-releng-10.4-src/sys/modules/linprocfs/Makefile freebsd-10.4/sys/modules/linprocfs/Makefile |
| --- /var/archive3/public/freebsd-releng-10.4-src/sys/modules/linprocfs/Makefile 2017-09-29 08:19:59.000000000 +0800 |
| +++ freebsd-10.4/sys/modules/linprocfs/Makefile 2019-08-17 22:23:56.243622065 +0800 |
| @@ -5,6 +5,12 @@ |
| KMOD= linprocfs |
| SRCS= vnode_if.h \ |
| device_if.h bus_if.h \ |
| - linprocfs.c |
| + linprocfs.c \ |
| + linprocfs_version.h |
| + |
| +CLEANFILES += linprocfs_version.h .linprocfs_build_version |
| + |
| +linprocfs_version.h: generate-linprocfs-version.sh linprocfs.c |
| + sh ${.CURDIR}/generate-linprocfs-version.sh > $@ |
| |
| .include <bsd.kmod.mk> |
| --- /dev/null 2019-08-17 22:27:18.000000000 +0800 |
| +++ freebsd-10.4/sys/modules/linprocfs/generate-linprocfs-version.sh 2019-08-17 22:24:15.370617775 +0800 |
| @@ -0,0 +1,13 @@ |
| +#!/bin/sh |
| + |
| +export LANG=C |
| +if [ -f .linprocfs_build_version ]; then |
| + build_version="`cat .linprocfs_build_version`" |
| +else |
| + build_version=1 |
| +fi |
| +printf '#define LINRPOCFS_VERSION_BUILD_VERSION "#%s"\n' "$build_version" |
| +printf '#define LINPROCFS_VERSION_BUILD_TIME "%s"\n' "`date`" |
| +printf '#define LINPROCFS_VERSION LINRPOCFS_VERSION_BUILD_VERSION " " LINPROCFS_VERSION_BUILD_TIME\n' |
| +printf '#define LINPROCFS_VERSION_BUILD_BY "%s@%s"\n' "`whoami`" "`hostname`" |
| +echo $((build_version+1)) > .linprocfs_build_version |