Anonymous inodes and file structures

Previously, when we discussed QEMU, we said the Linux kernel allocates file structures and sets its f_ops and anonymous inodes. Let's look into the kvm-main.c file:

static struct file_operations kvm_chardev_ops = {
      .unlocked_ioctl = kvm_dev_ioctl,
      .compat_ioctl   = kvm_dev_ioctl,
      .llseek         = noop_llseek,
 kvm_dev_ioctl () 
    switch (ioctl) {
          case KVM_GET_API_VERSION:
              if (arg)
                    	goto out;
              r = KVM_API_VERSION;
          case KVM_CREATE_VM:
              r = kvm_dev_ioctl_create_vm(arg);
          case KVM_CHECK_EXTENSION:
              r = kvm_vm_ioctl_check_extension_generic(NULL, arg);
          case KVM_GET_VCPU_MMAP_SIZE:
  .    …..

As such as kvm_chardev_fops, there exist kvm_vm_fops and kvm_vcpu_fops:

static struct file_operations kvm_vm_fops = { .release ...

Get Mastering KVM Virtualization now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.