Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/815877/?format=api
{ "id": 815877, "url": "http://patchwork.ozlabs.org/api/patches/815877/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20170919220125.32535-12-blp@ovn.org/", "project": { "id": 47, "url": "http://patchwork.ozlabs.org/api/projects/47/?format=api", "name": "Open vSwitch", "link_name": "openvswitch", "list_id": "ovs-dev.openvswitch.org", "list_email": "ovs-dev@openvswitch.org", "web_url": "http://openvswitch.org/", "scm_url": "git@github.com:openvswitch/ovs.git", "webscm_url": "https://github.com/openvswitch/ovs", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170919220125.32535-12-blp@ovn.org>", "list_archive_url": null, "date": "2017-09-19T22:00:44", "name": "[ovs-dev,RFC,11/52] log: Allow client to specify magic.", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": false, "hash": "623f253298dbebf7404abd244c6daf629fc74489", "submitter": { "id": 67603, "url": "http://patchwork.ozlabs.org/api/people/67603/?format=api", "name": "Ben Pfaff", "email": "blp@ovn.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/20170919220125.32535-12-blp@ovn.org/mbox/", "series": [ { "id": 3975, "url": "http://patchwork.ozlabs.org/api/series/3975/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=3975", "date": "2017-09-19T22:00:34", "name": "clustering implementation", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/3975/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/815877/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/815877/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<ovs-dev-bounces@openvswitch.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "dev@openvswitch.org" ], "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "ovs-dev@mail.linuxfoundation.org" ], "Authentication-Results": "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=openvswitch.org\n\t(client-ip=140.211.169.12; helo=mail.linuxfoundation.org;\n\tenvelope-from=ovs-dev-bounces@openvswitch.org;\n\treceiver=<UNKNOWN>)", "Received": [ "from mail.linuxfoundation.org (mail.linuxfoundation.org\n\t[140.211.169.12])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xxcTv080yz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 20 Sep 2017 08:09:07 +1000 (AEST)", "from mail.linux-foundation.org (localhost [127.0.0.1])\n\tby mail.linuxfoundation.org (Postfix) with ESMTP id 21F85C9D;\n\tTue, 19 Sep 2017 22:01:59 +0000 (UTC)", "from smtp1.linuxfoundation.org (smtp1.linux-foundation.org\n\t[172.17.192.35])\n\tby mail.linuxfoundation.org (Postfix) with ESMTPS id 1E4D1C8F\n\tfor <dev@openvswitch.org>; Tue, 19 Sep 2017 22:01:52 +0000 (UTC)", "from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby smtp1.linuxfoundation.org (Postfix) with ESMTPS id 23A8E44D\n\tfor <dev@openvswitch.org>; Tue, 19 Sep 2017 22:01:51 +0000 (UTC)", "from sigabrt.benpfaff.org (unknown [208.91.2.3])\n\t(Authenticated sender: blp@ovn.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id D0CDA172097;\n\tWed, 20 Sep 2017 00:01:48 +0200 (CEST)" ], "X-Greylist": "domain auto-whitelisted by SQLgrey-1.7.6", "X-Originating-IP": "208.91.2.3", "From": "Ben Pfaff <blp@ovn.org>", "To": "dev@openvswitch.org", "Date": "Tue, 19 Sep 2017 15:00:44 -0700", "Message-Id": "<20170919220125.32535-12-blp@ovn.org>", "X-Mailer": "git-send-email 2.10.2", "In-Reply-To": "<20170919220125.32535-1-blp@ovn.org>", "References": "<20170919220125.32535-1-blp@ovn.org>", "X-Spam-Status": "No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW\n\tautolearn=disabled version=3.3.1", "X-Spam-Checker-Version": "SpamAssassin 3.3.1 (2010-03-16) on\n\tsmtp1.linux-foundation.org", "Cc": "Ben Pfaff <blp@ovn.org>", "Subject": "[ovs-dev] [PATCH RFC 11/52] log: Allow client to specify magic.", "X-BeenThere": "ovs-dev@openvswitch.org", "X-Mailman-Version": "2.1.12", "Precedence": "list", "List-Id": "<ovs-dev.openvswitch.org>", "List-Unsubscribe": "<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>", "List-Archive": "<http://mail.openvswitch.org/pipermail/ovs-dev/>", "List-Post": "<mailto:ovs-dev@openvswitch.org>", "List-Help": "<mailto:ovs-dev-request@openvswitch.org?subject=help>", "List-Subscribe": "<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Sender": "ovs-dev-bounces@openvswitch.org", "Errors-To": "ovs-dev-bounces@openvswitch.org" }, "content": "Until now, the logging code in ovsdb has only supported a single file\nformat, for OVSDB standalone database files. Upcoming commits will add\nsupport for another, incompatible format, which uses a different magic\nstring for identification. This commit allows the logging code to\nsupport both formats.\n\nSigned-off-by: Ben Pfaff <blp@ovn.org>\n---\n ovsdb/file.c | 5 +++--\n ovsdb/log.c | 54 ++++++++++++++++++++++++++++++++++++++++--------------\n ovsdb/log.h | 5 ++++-\n ovsdb/ovsdb-tool.c | 10 +++++-----\n tests/ovsdb-log.at | 27 +++++++++++++++++++++++++++\n tests/test-ovsdb.c | 17 ++++++++++++++---\n 6 files changed, 93 insertions(+), 25 deletions(-)", "diff": "diff --git a/ovsdb/file.c b/ovsdb/file.c\nindex 6a406da2a838..16461a75bfe5 100644\n--- a/ovsdb/file.c\n+++ b/ovsdb/file.c\n@@ -129,7 +129,7 @@ ovsdb_file_open_log(const char *file_name, enum ovsdb_log_open_mode open_mode,\n \n ovs_assert(logp || schemap);\n \n- error = ovsdb_log_open(file_name, open_mode, -1, &log);\n+ error = ovsdb_log_open(file_name, OVSDB_MAGIC, open_mode, -1, &log);\n if (error) {\n goto error;\n }\n@@ -440,7 +440,8 @@ ovsdb_file_save_copy__(const char *file_name, int locking,\n struct ovsdb_log *log;\n struct json *json;\n \n- error = ovsdb_log_open(file_name, OVSDB_LOG_CREATE, locking, &log);\n+ error = ovsdb_log_open(file_name, OVSDB_MAGIC,\n+ OVSDB_LOG_CREATE, locking, &log);\n if (error) {\n return error;\n }\ndiff --git a/ovsdb/log.c b/ovsdb/log.c\nindex 380f5e93d464..e6f66e668fe5 100644\n--- a/ovsdb/log.c\n+++ b/ovsdb/log.c\n@@ -1,4 +1,4 @@\n-/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.\n+/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2017 Nicira, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n@@ -42,6 +42,7 @@ struct ovsdb_log {\n off_t prev_offset;\n off_t offset;\n char *name;\n+ char *magic;\n struct lockfile *lockfile;\n FILE *stream;\n struct ovsdb_error *read_error;\n@@ -53,12 +54,17 @@ struct ovsdb_log {\n * the new log into '*filep' and returns NULL; otherwise returns NULL and\n * stores NULL into '*filep'.\n *\n+ * 'magic' is a short text string put at the beginning of every record and used\n+ * to distinguish one kind of log file from another. For a conventional OVSDB\n+ * log file, use OVSDB_MAGIC.\n+ *\n * Whether the file will be locked using lockfile_lock() depends on 'locking':\n * use true to lock it, false not to lock it, or -1 to lock it only if\n * 'open_mode' is a mode that allows writing.\n */\n struct ovsdb_error *\n-ovsdb_log_open(const char *name, enum ovsdb_log_open_mode open_mode,\n+ovsdb_log_open(const char *name, const char *magic,\n+ enum ovsdb_log_open_mode open_mode,\n int locking, struct ovsdb_log **filep)\n {\n struct lockfile *lockfile;\n@@ -118,10 +124,30 @@ ovsdb_log_open(const char *name, enum ovsdb_log_open_mode open_mode,\n goto error_unlock;\n }\n \n- if (!fstat(fd, &s) && s.st_size == 0) {\n- /* It's (probably) a new file so fsync() its parent directory to ensure\n- * that its directory entry is committed to disk. */\n- fsync_parent_dir(name);\n+ if (!fstat(fd, &s)) {\n+ if (s.st_size == 0) {\n+ /* It's (probably) a new file so fsync() its parent directory to\n+ * ensure that its directory entry is committed to disk. */\n+ fsync_parent_dir(name);\n+ } else if (s.st_size >= strlen(magic) && S_ISREG(s.st_mode)) {\n+ /* Try to read the magic from the first log record. If it's not\n+ * the magic we expect, this is the wrong kind of file, so reject\n+ * it immediately. */\n+ size_t magic_len = strlen(magic);\n+ char *buf = xzalloc(magic_len + 1);\n+ bool err = (read(fd, buf, magic_len) == magic_len\n+ && strcmp(buf, magic));\n+ free(buf);\n+ if (err) {\n+ error = ovsdb_error(NULL, \"%s: bad magic (unexpected \"\n+ \"kind of file)\", name);\n+ goto error_close;\n+ }\n+ if (lseek(fd, 0, SEEK_SET)) {\n+ error = ovsdb_io_error(errno, \"%s: seek failed\", name);\n+ goto error_close;\n+ }\n+ }\n }\n \n stream = fdopen(fd, open_mode == OVSDB_LOG_READ_ONLY ? \"rb\" : \"w+b\");\n@@ -132,6 +158,7 @@ ovsdb_log_open(const char *name, enum ovsdb_log_open_mode open_mode,\n \n file = xmalloc(sizeof *file);\n file->name = xstrdup(name);\n+ file->magic = xstrdup(magic);\n file->lockfile = lockfile;\n file->stream = stream;\n file->prev_offset = 0;\n@@ -162,21 +189,20 @@ ovsdb_log_close(struct ovsdb_log *file)\n }\n }\n \n-static const char magic[] = \"OVSDB JSON \";\n-\n static bool\n-parse_header(char *header, unsigned long int *length,\n+parse_header(const char *magic, char *header, unsigned long int *length,\n uint8_t sha1[SHA1_DIGEST_SIZE])\n {\n char *p;\n \n /* 'header' must consist of a magic string... */\n- if (strncmp(header, magic, strlen(magic))) {\n+ size_t magic_len = strlen(magic);\n+ if (strncmp(header, magic, magic_len) || header[magic_len] != ' ') {\n return false;\n }\n \n /* ...followed by a length in bytes... */\n- *length = strtoul(header + strlen(magic), &p, 10);\n+ *length = strtoul(header + magic_len + 1, &p, 10);\n if (!*length || *length == ULONG_MAX || *p != ' ') {\n return false;\n }\n@@ -256,7 +282,7 @@ ovsdb_log_read(struct ovsdb_log *file, struct json **jsonp)\n goto error;\n }\n \n- if (!parse_header(header, &data_length, expected_sha1)) {\n+ if (!parse_header(file->magic, header, &data_length, expected_sha1)) {\n error = ovsdb_syntax_error(NULL, NULL, \"%s: parse error at offset \"\n \"%lld in header line \\\"%.*s\\\"\",\n file->name, (long long int) file->offset,\n@@ -356,8 +382,8 @@ ovsdb_log_write(struct ovsdb_log *file, struct json *json)\n \n /* Compose header. */\n sha1_bytes(json_string, length, sha1);\n- snprintf(header, sizeof header, \"%s%\"PRIuSIZE\" \"SHA1_FMT\"\\n\",\n- magic, length, SHA1_ARGS(sha1));\n+ snprintf(header, sizeof header, \"%s %\"PRIuSIZE\" \"SHA1_FMT\"\\n\",\n+ file->magic, length, SHA1_ARGS(sha1));\n \n /* Write. */\n if (fwrite(header, strlen(header), 1, file->stream) != 1\ndiff --git a/ovsdb/log.h b/ovsdb/log.h\nindex 5fe636b4c387..fbcea1f2b991 100644\n--- a/ovsdb/log.h\n+++ b/ovsdb/log.h\n@@ -29,7 +29,10 @@ enum ovsdb_log_open_mode {\n OVSDB_LOG_CREATE /* Create new file, read/write. */\n };\n \n-struct ovsdb_error *ovsdb_log_open(const char *name, enum ovsdb_log_open_mode,\n+#define OVSDB_MAGIC \"OVSDB JSON\"\n+\n+struct ovsdb_error *ovsdb_log_open(const char *name, const char *magic,\n+ enum ovsdb_log_open_mode,\n int locking, struct ovsdb_log **)\n OVS_WARN_UNUSED_RESULT;\n void ovsdb_log_close(struct ovsdb_log *);\ndiff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c\nindex 8908bae3628a..45b3f7348c3d 100644\n--- a/ovsdb/ovsdb-tool.c\n+++ b/ovsdb/ovsdb-tool.c\n@@ -1,5 +1,5 @@\n /*\n- * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.\n+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2016, 2017 Nicira, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n@@ -217,8 +217,8 @@ do_create(struct ovs_cmdl_context *ctx)\n ovsdb_schema_destroy(schema);\n \n /* Create database file. */\n- check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_LOG_CREATE,\n- -1, &log));\n+ check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC,\n+ OVSDB_LOG_CREATE, -1, &log));\n check_ovsdb_error(ovsdb_log_write(log, json));\n check_ovsdb_error(ovsdb_log_commit(log));\n ovsdb_log_close(log);\n@@ -519,8 +519,8 @@ do_show_log(struct ovs_cmdl_context *ctx)\n struct ovsdb_schema *schema;\n unsigned int i;\n \n- check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_LOG_READ_ONLY,\n- -1, &log));\n+ check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC,\n+ OVSDB_LOG_READ_ONLY, -1, &log));\n shash_init(&names);\n schema = NULL;\n for (i = 0; ; i++) {\ndiff --git a/tests/ovsdb-log.at b/tests/ovsdb-log.at\nindex 3e7cdf828466..c8efaaec1a50 100644\n--- a/tests/ovsdb-log.at\n+++ b/tests/ovsdb-log.at\n@@ -73,6 +73,33 @@ file: read: end of log\n AT_CHECK([test -f .file.~lock~])\n AT_CLEANUP\n \n+AT_SETUP([write one, reread - alternative magic])\n+AT_KEYWORDS([ovsdb log])\n+AT_CAPTURE_FILE([file])\n+# Sometimes you just need more magic:\n+# http://www.catb.org/jargon/html/magic-story.html\n+AT_CHECK(\n+ [[test-ovsdb --magic=\"MORE MAGIC\" log-io file create 'write:[0]' 'write:[1]' 'write:[2]']], [0],\n+ [[file: open successful\n+file: write:[0] successful\n+file: write:[1] successful\n+file: write:[2] successful\n+]], [ignore])\n+AT_CHECK(\n+ [test-ovsdb --magic=\"MORE MAGIC\" log-io file read-only read read read read], [0],\n+ [[file: open successful\n+file: read: [0]\n+file: read: [1]\n+file: read: [2]\n+file: read: end of log\n+]], [ignore])\n+AT_CHECK(\n+ [test-ovsdb log-io file read-only], [1], [],\n+ [test-ovsdb: ovsdb error: file: bad magic (unexpected kind of file)\n+])\n+AT_CHECK([test -f .file.~lock~])\n+AT_CLEANUP\n+\n AT_SETUP([write one, reread, append])\n AT_KEYWORDS([ovsdb log])\n AT_CAPTURE_FILE([file])\ndiff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c\nindex 1760268b625c..36b23effff81 100644\n--- a/tests/test-ovsdb.c\n+++ b/tests/test-ovsdb.c\n@@ -55,6 +55,9 @@ struct test_ovsdb_pvt_context {\n bool track;\n };\n \n+/* Magic to pass to ovsdb_log_open(). */\n+static const char *magic = OVSDB_MAGIC;\n+\n OVS_NO_RETURN static void usage(void);\n static void parse_options(int argc, char *argv[],\n struct test_ovsdb_pvt_context *pvt);\n@@ -76,10 +79,14 @@ main(int argc, char *argv[])\n static void\n parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)\n {\n+ enum {\n+ OPT_MAGIC = CHAR_MAX + 1,\n+ };\n static const struct option long_options[] = {\n {\"timeout\", required_argument, NULL, 't'},\n {\"verbose\", optional_argument, NULL, 'v'},\n {\"change-track\", optional_argument, NULL, 'c'},\n+ {\"magic\", required_argument, NULL, OPT_MAGIC},\n {\"help\", no_argument, NULL, 'h'},\n {NULL, 0, NULL, 0},\n };\n@@ -116,6 +123,10 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)\n pvt->track = true;\n break;\n \n+ case OPT_MAGIC:\n+ magic = optarg;\n+ break;\n+\n case '?':\n exit(EXIT_FAILURE);\n \n@@ -131,8 +142,8 @@ usage(void)\n {\n printf(\"%s: Open vSwitch database test utility\\n\"\n \"usage: %s [OPTIONS] COMMAND [ARG...]\\n\\n\"\n- \" log-io FILE FLAGS COMMAND...\\n\"\n- \" open FILE with FLAGS, run COMMANDs\\n\"\n+ \" [--magic=MAGIC] log-io FILE FLAGS COMMAND...\\n\"\n+ \" open FILE with FLAGS (and MAGIC), run COMMANDs\\n\"\n \" default-atoms\\n\"\n \" test ovsdb_atom_default()\\n\"\n \" default-data\\n\"\n@@ -316,7 +327,7 @@ do_log_io(struct ovs_cmdl_context *ctx)\n ovs_fatal(0, \"unknown log-io open mode \\\"%s\\\"\", mode_string);\n }\n \n- check_ovsdb_error(ovsdb_log_open(name, mode, -1, &log));\n+ check_ovsdb_error(ovsdb_log_open(name, magic, mode, -1, &log));\n printf(\"%s: open successful\\n\", name);\n \n for (i = 3; i < ctx->argc; i++) {\n", "prefixes": [ "ovs-dev", "RFC", "11/52" ] }