From nobody Wed May 1 23:23:42 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509546698119930.349987619351; Wed, 1 Nov 2017 07:31:38 -0700 (PDT) Received: from localhost ([::1]:56098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u3A-0006FR-Db for importer@patchew.org; Wed, 01 Nov 2017 10:31:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u1f-0005WQ-9f for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9u1a-00083y-SW for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:51 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:12847) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9u1a-00081x-KH for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:46 -0400 X-IronPort-AV: E=Sophos;i="5.44,329,1505779200"; d="scan'208";a="457268871" From: Ross Lagerwall To: Date: Wed, 1 Nov 2017 14:25:23 +0000 Message-ID: <20171101142526.1006-2-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171101142526.1006-1-ross.lagerwall@citrix.com> References: <20171101142526.1006-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH v2 1/4] migration: Don't leak IO channels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ross Lagerwall , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since qemu_fopen_channel_{in,out}put take references on the underlying IO channels, make sure to release our references to them. Signed-off-by: Ross Lagerwall Reviewed-by: Daniel P. Berrange --- New in v2. migration/savevm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 4a88228..87557dd 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2259,6 +2259,7 @@ void qmp_xen_save_devices_state(const char *filename,= Error **errp) } qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state"); f =3D qemu_fopen_channel_output(QIO_CHANNEL(ioc)); + object_unref(OBJECT(ioc)); ret =3D qemu_save_device_state(f); qemu_fclose(f); if (ret < 0) { @@ -2292,6 +2293,7 @@ void qmp_xen_load_devices_state(const char *filename,= Error **errp) } qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state"); f =3D qemu_fopen_channel_input(QIO_CHANNEL(ioc)); + object_unref(OBJECT(ioc)); =20 ret =3D qemu_loadvm_state(f); qemu_fclose(f); --=20 2.9.5 From nobody Wed May 1 23:23:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509546817032814.4355316600914; Wed, 1 Nov 2017 07:33:37 -0700 (PDT) Received: from localhost ([::1]:56109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u58-0007XN-BG for importer@patchew.org; Wed, 01 Nov 2017 10:33:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u1f-0005WS-Ah for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9u1b-00084i-PU for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:51 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:45989) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9u1b-00083e-Bh for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:47 -0400 X-IronPort-AV: E=Sophos;i="5.44,329,1505779200"; d="scan'208";a="457268875" From: Ross Lagerwall To: Date: Wed, 1 Nov 2017 14:25:24 +0000 Message-ID: <20171101142526.1006-3-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171101142526.1006-1-ross.lagerwall@citrix.com> References: <20171101142526.1006-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH v2 2/4] io: Fix QIOChannelFile when creating and opening read-write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ross Lagerwall Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The code wrongly passes the mode to open() only if O_WRONLY is set. Instead, the mode should be passed when O_CREAT is set (or O_TMPFILE on Linux). Fix this by always passing the mode since open() will correctly ignore the mode if it is not needed. Add a testcase which exercises this bug and also change the existing testcase to check that the mode of the created file is correct. Signed-off-by: Ross Lagerwall Reviewed-by: Daniel P. Berrange --- Changed in v2: * Separated from qemu_open() change. include/io/channel-file.h | 2 +- io/channel-file.c | 6 +----- tests/test-io-channel-file.c | 29 +++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/io/channel-file.h b/include/io/channel-file.h index 79245f1..ebfe54e 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -73,7 +73,7 @@ qio_channel_file_new_fd(int fd); * qio_channel_file_new_path: * @path: the file path * @flags: the open flags (O_RDONLY|O_WRONLY|O_RDWR, etc) - * @mode: the file creation mode if O_WRONLY is set in @flags + * @mode: the file creation mode if O_CREAT is set in @flags * @errp: pointer to initialized error object * * Create a new IO channel object for a file represented diff --git a/io/channel-file.c b/io/channel-file.c index b383273..16bf7ed 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -50,11 +50,7 @@ qio_channel_file_new_path(const char *path, =20 ioc =3D QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE)); =20 - if (flags & O_WRONLY) { - ioc->fd =3D open(path, flags, mode); - } else { - ioc->fd =3D open(path, flags); - } + ioc->fd =3D open(path, flags, mode); if (ioc->fd < 0) { object_unref(OBJECT(ioc)); error_setg_errno(errp, errno, diff --git a/tests/test-io-channel-file.c b/tests/test-io-channel-file.c index 6bfede6..2e94f63 100644 --- a/tests/test-io-channel-file.c +++ b/tests/test-io-channel-file.c @@ -24,16 +24,21 @@ #include "io-channel-helpers.h" #include "qapi/error.h" =20 -static void test_io_channel_file(void) +#define TEST_FILE "tests/test-io-channel-file.txt" +#define TEST_MASK 0600 + +static void test_io_channel_file_helper(int flags) { QIOChannel *src, *dst; QIOChannelTest *test; + struct stat st; + mode_t mask; + int ret; =20 -#define TEST_FILE "tests/test-io-channel-file.txt" unlink(TEST_FILE); src =3D QIO_CHANNEL(qio_channel_file_new_path( TEST_FILE, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600, + flags, TEST_MASK, &error_abort)); dst =3D QIO_CHANNEL(qio_channel_file_new_path( TEST_FILE, @@ -45,18 +50,33 @@ static void test_io_channel_file(void) qio_channel_test_run_reader(test, dst); qio_channel_test_validate(test); =20 + /* Check that the requested mode took effect. */ + mask =3D umask(0); + umask(mask); + ret =3D stat(TEST_FILE, &st); + g_assert_cmpint(ret, >, -1); + g_assert_cmpuint(TEST_MASK & ~mask, =3D=3D, st.st_mode & 0777); + unlink(TEST_FILE); object_unref(OBJECT(src)); object_unref(OBJECT(dst)); } =20 +static void test_io_channel_file(void) +{ + test_io_channel_file_helper(O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); +} + +static void test_io_channel_file_rdwr(void) +{ + test_io_channel_file_helper(O_RDWR | O_CREAT | O_TRUNC | O_BINARY); +} =20 static void test_io_channel_fd(void) { QIOChannel *ioc; int fd =3D -1; =20 -#define TEST_FILE "tests/test-io-channel-file.txt" fd =3D open(TEST_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0600); g_assert_cmpint(fd, >, -1); =20 @@ -114,6 +134,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); =20 g_test_add_func("/io/channel/file", test_io_channel_file); + g_test_add_func("/io/channel/file/rdwr", test_io_channel_file_rdwr); g_test_add_func("/io/channel/file/fd", test_io_channel_fd); #ifndef _WIN32 g_test_add_func("/io/channel/pipe/sync", test_io_channel_pipe_sync); --=20 2.9.5 From nobody Wed May 1 23:23:42 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509546698118145.3492578434275; Wed, 1 Nov 2017 07:31:38 -0700 (PDT) Received: from localhost ([::1]:56097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u37-0006Dm-NZ for importer@patchew.org; Wed, 01 Nov 2017 10:31:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u1f-0005WP-9f for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9u1b-00084L-Ck for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:51 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:12847) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9u1b-00081x-4L for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:47 -0400 X-IronPort-AV: E=Sophos;i="5.44,329,1505779200"; d="scan'208";a="457268872" From: Ross Lagerwall To: Date: Wed, 1 Nov 2017 14:25:25 +0000 Message-ID: <20171101142526.1006-4-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171101142526.1006-1-ross.lagerwall@citrix.com> References: <20171101142526.1006-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH v2 3/4] io: Don't call close multiple times in QIOChannelFile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ross Lagerwall Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the file descriptor underlying QIOChannelFile is closed in the io_close() method, don't close it again in the finalize() method since the file descriptor number may have been reused in the meantime. Signed-off-by: Ross Lagerwall Reviewed-by: Daniel P. Berrange Reviewed-by: Marc-Andr=C3=A9 Lureau --- New in v2. io/channel-file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/io/channel-file.c b/io/channel-file.c index 16bf7ed..1f2f710 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -178,6 +178,7 @@ static int qio_channel_file_close(QIOChannel *ioc, "Unable to close file"); return -1; } + fioc->fd =3D -1; return 0; } =20 --=20 2.9.5 From nobody Wed May 1 23:23:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509546912438914.8231374267222; Wed, 1 Nov 2017 07:35:12 -0700 (PDT) Received: from localhost ([::1]:56116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u6f-0008Qw-Qm for importer@patchew.org; Wed, 01 Nov 2017 10:35:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9u1f-0005WT-Aj for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9u1b-00084a-Nk for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:51 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:12847) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9u1b-00081x-Gm for qemu-devel@nongnu.org; Wed, 01 Nov 2017 10:29:47 -0400 X-IronPort-AV: E=Sophos;i="5.44,329,1505779200"; d="scan'208";a="457268876" From: Ross Lagerwall To: Date: Wed, 1 Nov 2017 14:25:26 +0000 Message-ID: <20171101142526.1006-5-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171101142526.1006-1-ross.lagerwall@citrix.com> References: <20171101142526.1006-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH v2 4/4] io: Add /dev/fdset/ support to QIOChannelFile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ross Lagerwall Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add /dev/fdset/ support to QIOChannelFile by calling qemu_open() instead of open() and qemu_close() instead of close(). There is a subtle semantic change since qemu_open() automatically sets O_CLOEXEC, but this doesn't affect any of the users of the function. Signed-off-by: Ross Lagerwall Reviewed-by: Daniel P. Berrange Reviewed-by: Marc-Andr=C3=A9 Lureau --- Changed in v2: * Split into separate patch. io/channel-file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/io/channel-file.c b/io/channel-file.c index 1f2f710..db948ab 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -50,7 +50,7 @@ qio_channel_file_new_path(const char *path, =20 ioc =3D QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE)); =20 - ioc->fd =3D open(path, flags, mode); + ioc->fd =3D qemu_open(path, flags, mode); if (ioc->fd < 0) { object_unref(OBJECT(ioc)); error_setg_errno(errp, errno, @@ -74,7 +74,7 @@ static void qio_channel_file_finalize(Object *obj) { QIOChannelFile *ioc =3D QIO_CHANNEL_FILE(obj); if (ioc->fd !=3D -1) { - close(ioc->fd); + qemu_close(ioc->fd); ioc->fd =3D -1; } } @@ -173,7 +173,7 @@ static int qio_channel_file_close(QIOChannel *ioc, { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); =20 - if (close(fioc->fd) < 0) { + if (qemu_close(fioc->fd) < 0) { error_setg_errno(errp, errno, "Unable to close file"); return -1; --=20 2.9.5