Ejemplo n.º 1
0
/*
 ***************************************************************************
 * Allocate and init structures, according to system state.
 ***************************************************************************
 */
void io_sys_init(void)
{
	/* Allocate and init stat common counters */
	init_stats();

	/* How many processors on this machine? */
	cpu_nr = get_cpu_nr(~0, FALSE);

	/* Get number of block devices and partitions in /proc/diskstats */
	if ((iodev_nr = get_diskstats_dev_nr(CNT_PART, CNT_ALL_DEV)) > 0) {
		flags |= I_F_HAS_DISKSTATS;
		iodev_nr += NR_DEV_PREALLOC;
	}

	if (!HAS_DISKSTATS(flags) ||
	    (DISPLAY_PARTITIONS(flags) && !DISPLAY_PART_ALL(flags))) {
		/*
		 * If /proc/diskstats exists but we also want stats for the partitions
		 * of a particular device, stats will have to be found in /sys. So we
		 * need to know if /sys is mounted or not, and set flags accordingly.
		 */

		/* Get number of block devices (and partitions) in sysfs */
		if ((iodev_nr = get_sysfs_dev_nr(DISPLAY_PARTITIONS(flags))) > 0) {
			flags |= I_F_HAS_SYSFS;
			iodev_nr += NR_DEV_PREALLOC;
		}
		else {
			fprintf(stderr, _("Cannot find disk data\n"));
			exit(2);
		}
	}

	/* Also allocate stat structures for "group" devices */
	iodev_nr += group_nr;

	/*
	 * Allocate structures for number of disks found, but also
	 * for groups of devices if option -g has been entered on the command line.
	 * iodev_nr must be <> 0.
	 */
	salloc_device(iodev_nr);
}
Ejemplo n.º 2
0
/*
 ***************************************************************************
 * Allocate and init structures, according to system state
 ***************************************************************************
 */
void io_sys_init(int *flags)
{
   int i;

   /* Init stat common counters */
   init_stats();

   /* How many processors on this machine ? */
   cpu_nr = get_cpu_nr(~0);

   /* Get number of block devices and partitions in /proc/diskstats */
   if ((iodev_nr = get_diskstats_dev_nr(CNT_PART, CNT_ALL_DEV)) > 0) {
      *flags |= I_F_HAS_DISKSTATS;
      iodev_nr += NR_DEV_PREALLOC;
   }

   if (!HAS_DISKSTATS(*flags) ||
       (DISPLAY_PARTITIONS(*flags) && !DISPLAY_PART_ALL(*flags))) {
      /*
       * If /proc/diskstats exists but we also want stats for the partitions
       * of a particular device, stats will have to be found in /sys. So we
       * need to know if /sys is mounted or not, and set *flags accordingly.
       */

      /* Get number of block devices (and partitions) in sysfs */
      if ((iodev_nr = get_sysfs_dev_nr(DISPLAY_PARTITIONS(*flags))) > 0) {
	 *flags |= I_F_HAS_SYSFS;
	 iodev_nr += NR_DEV_PREALLOC;
      }
      /*
       * Get number of block devices and partitions in /proc/partitions,
       * those with statistics...
       */
      else if ((iodev_nr = get_ppartitions_dev_nr(CNT_PART)) > 0) {
	 *flags |= I_F_HAS_PPARTITIONS;
	 iodev_nr += NR_DEV_PREALLOC;
      }
      /* Get number of "disk_io:" entries in /proc/stat */
      else if ((iodev_nr = get_disk_io_nr()) > 0) {
	 *flags |= I_F_PLAIN_KERNEL24;
	 iodev_nr += NR_DISK_PREALLOC;
      }
      else {
	 /* Assume we have an old kernel: stats for 4 disks are in /proc/stat */
	 iodev_nr = 4;
	 *flags |= I_F_OLD_KERNEL;
      }
   }
   /*
    * Allocate structures for number of disks found.
    * iodev_nr must be <> 0.
    */
   salloc_device(iodev_nr);

   if (HAS_OLD_KERNEL(*flags)) {
      struct io_hdr_stats *shi = st_hdr_iodev;
      /*
       * If we have an old kernel with the stats for the first four disks
       * in /proc/stat, then set the devices names to hdisk[0..3].
       */
      for (i = 0; i < 4; i++, shi++) {
	 shi->used = TRUE;
	 sprintf(shi->name, "%s%d", K_HDISK, i);
      }
   }
}