From patchwork Fri Jul 29 15:48:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 73045 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1460389qga; Fri, 29 Jul 2016 08:53:15 -0700 (PDT) X-Received: by 10.194.11.72 with SMTP id o8mr42494726wjb.10.1469807595375; Fri, 29 Jul 2016 08:53:15 -0700 (PDT) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id j83si4032398wmi.83.2016.07.29.08.53.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 29 Jul 2016 08:53:15 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u6TFmW3K009181; Fri, 29 Jul 2016 11:48:33 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u6TFmV5b008326 for ; Fri, 29 Jul 2016 11:48:31 -0400 Received: from [10.3.116.46] (ovpn-116-46.phx2.redhat.com [10.3.116.46]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6TFmVtS001742; Fri, 29 Jul 2016 11:48:31 -0400 To: Jovanka Gulicoska , libvir-list@redhat.com References: <1469707377-18488-1-git-send-email-jovanka.gulicoska@gmail.com> <1469707377-18488-7-git-send-email-jovanka.gulicoska@gmail.com> From: Cole Robinson Message-ID: <3ddd0b71-2572-5a3c-b803-a1604d29c351@redhat.com> Date: Fri, 29 Jul 2016 11:48:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1469707377-18488-7-git-send-email-jovanka.gulicoska@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH v2 6/8] node_device: Implement event queue in udev X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com On 07/28/2016 08:02 AM, Jovanka Gulicoska wrote: > --- > src/node_device/node_device_udev.c | 46 ++++++++++++++++++++++++++++++-------- > 1 file changed, 37 insertions(+), 9 deletions(-) > > diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c > index 76c60ea..e7a407f 100644 > --- a/src/node_device/node_device_udev.c > +++ b/src/node_device/node_device_udev.c > @@ -28,6 +28,7 @@ > > #include "dirname.h" > #include "node_device_conf.h" > +#include "node_device_event.h" > #include "node_device_driver.h" > #include "node_device_linux_sysfs.h" > #include "node_device_udev.h" > @@ -1024,22 +1025,31 @@ static int udevGetDeviceDetails(struct udev_device *device, > static int udevRemoveOneDevice(struct udev_device *device) > { > virNodeDeviceObjPtr dev = NULL; > + virObjectEventPtr event = NULL; > const char *name = NULL; > - int ret = 0; > + int ret = -1; > > name = udev_device_get_syspath(device); > dev = virNodeDeviceFindBySysfsPath(&driver->devs, name); > > - if (dev != NULL) { > - VIR_DEBUG("Removing device '%s' with sysfs path '%s'", > - dev->def->name, name); > - virNodeDeviceObjRemove(&driver->devs, dev); > - } else { > + if (!dev) { > VIR_DEBUG("Failed to find device to remove that has udev name '%s'", > name); > - ret = -1; > + goto cleanup; > } > > + event = virNodeDeviceEventLifecycleNew(dev->def->name, > + VIR_NODE_DEVICE_EVENT_DELETED, > + 0); > + > + VIR_DEBUG("Removing device '%s' with sysfs path '%s'", > + dev->def->name, name); > + virNodeDeviceObjRemove(&driver->devs, dev); > + > + ret = 0; > + cleanup: > + if (event) > + virObjectEventStateQueue(driver->nodeDeviceEventState, event); > return ret; > } > > @@ -1096,6 +1106,8 @@ static int udevAddOneDevice(struct udev_device *device) > { > virNodeDeviceDefPtr def = NULL; > virNodeDeviceObjPtr dev = NULL; > + virObjectEventPtr event = NULL; > + bool new_device; > int ret = -1; > > if (VIR_ALLOC(def) != 0) > @@ -1119,17 +1131,28 @@ static int udevAddOneDevice(struct udev_device *device) > if (udevSetParent(device, def) != 0) > goto cleanup; > > + dev = virNodeDeviceFindByName(&driver->devs, def->name); > + new_device = !!dev; I know I recommended this little tidbit offline, but the logic is actually wrong :) new_device should be !dev > + if (new_device) > + nodeDeviceUnlock(); > + Wrong unlock call, we need to unlock 'dev', not the whole driver. > /* If this is a device change, the old definition will be freed > * and the current definition will take its place. */ > dev = virNodeDeviceAssignDef(&driver->devs, def); > - if (dev == NULL) > - goto cleanup; > + We shouldn't drop this NULL check either. These were the only issues in the patch series, so applied locally with this stuff fixed: I'll push after the 2.1.0 release is out! Thanks, Cole -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index e7a407f..4182d5b 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1107,7 +1107,7 @@ static int udevAddOneDevice(struct udev_device *device) virNodeDeviceDefPtr def = NULL; virNodeDeviceObjPtr dev = NULL; virObjectEventPtr event = NULL; - bool new_device; + bool new_device = true; int ret = -1; if (VIR_ALLOC(def) != 0) @@ -1132,13 +1132,16 @@ static int udevAddOneDevice(struct udev_device *device) goto cleanup; dev = virNodeDeviceFindByName(&driver->devs, def->name); - new_device = !!dev; - if (new_device) - nodeDeviceUnlock(); + if (dev) { + virNodeDeviceObjUnlock(dev); + new_device = false; + } /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ dev = virNodeDeviceAssignDef(&driver->devs, def); + if (dev == NULL) + goto cleanup; if (new_device) event = virNodeDeviceEventLifecycleNew(dev->def->name,