Revision ea2bcb82 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
80 80
  ])
81 81

  
82 82

  
83
def _ProbeTapVnetHdr(fd):
83
def _GetTunFeatures(fd, _ioctl=fcntl.ioctl):
84
  """Retrieves supported TUN features from file descriptor.
85

  
86
  @see: L{_ProbeTapVnetHdr}
87

  
88
  """
89
  req = struct.pack("I", 0)
90
  try:
91
    buf = _ioctl(fd, TUNGETFEATURES, req)
92
  except EnvironmentError, err:
93
    logging.warning("ioctl(TUNGETFEATURES) failed: %s" % err)
94
    return None
95
  else:
96
    (flags, ) = struct.unpack("I", buf)
97
    return flags
98

  
99

  
100
def _ProbeTapVnetHdr(fd, _features_fn=_GetTunFeatures):
84 101
  """Check whether to enable the IFF_VNET_HDR flag.
85 102

  
86 103
  To do this, _all_ of the following conditions must be met:
......
97 114
   @param fd: the file descriptor of /dev/net/tun
98 115

  
99 116
  """
100
  req = struct.pack("I", 0)
101
  try:
102
    res = fcntl.ioctl(fd, TUNGETFEATURES, req)
103
  except EnvironmentError:
104
    logging.warning("TUNGETFEATURES ioctl() not implemented")
105
    return False
117
  flags = _features_fn(fd)
106 118

  
107
  tunflags = struct.unpack("I", res)[0]
108
  if tunflags & IFF_VNET_HDR:
109
    return True
110
  else:
111
    logging.warning("Host does not support IFF_VNET_HDR, not enabling")
119
  if flags is None:
120
    # Not supported
112 121
    return False
113 122

  
123
  result = bool(flags & IFF_VNET_HDR)
124

  
125
  if not result:
126
    logging.warning("Kernel does not support IFF_VNET_HDR, not enabling")
127

  
128
  return result
129

  
114 130

  
115 131
def _OpenTap(vnet_hdr=True):
116 132
  """Open a new tap device and return its file descriptor.

Also available in: Unified diff