get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/756272/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 756272,
    "url": "http://patchwork.ozlabs.org/api/patches/756272/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/1493370083-7385-2-git-send-email-azhou@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": "<1493370083-7385-2-git-send-email-azhou@ovn.org>",
    "list_archive_url": null,
    "date": "2017-04-28T09:01:20",
    "name": "[ovs-dev,action,upcall,meter,v2,2/5] ofproto-dpif: Add 'meter_ids' to backer",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "fbac76029554bfb6cfc41153952c30f082e8f24c",
    "submitter": {
        "id": 67699,
        "url": "http://patchwork.ozlabs.org/api/people/67699/?format=api",
        "name": "Andy Zhou",
        "email": "azhou@ovn.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/1493370083-7385-2-git-send-email-azhou@ovn.org/mbox/",
    "series": [],
    "comments": "http://patchwork.ozlabs.org/api/patches/756272/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/756272/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"
        ],
        "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 3wDnrl10D9z9s89\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 28 Apr 2017 19:02:31 +1000 (AEST)",
            "from mail.linux-foundation.org (localhost [127.0.0.1])\n\tby mail.linuxfoundation.org (Postfix) with ESMTP id 4B2A3B6B;\n\tFri, 28 Apr 2017 09:01:44 +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 C8D9AB0B\n\tfor <dev@openvswitch.org>; Fri, 28 Apr 2017 09:01:40 +0000 (UTC)",
            "from mail-pg0-f67.google.com (mail-pg0-f67.google.com\n\t[74.125.83.67])\n\tby smtp1.linuxfoundation.org (Postfix) with ESMTPS id D001215B\n\tfor <dev@openvswitch.org>; Fri, 28 Apr 2017 09:01:39 +0000 (UTC)",
            "by mail-pg0-f67.google.com with SMTP id v20so1938049pgn.0\n\tfor <dev@openvswitch.org>; Fri, 28 Apr 2017 02:01:39 -0700 (PDT)",
            "from centos.hsd1.ca.comcast.net.\n\t([2601:647:4280:45d0:d6be:d9ff:fe69:1f8d])\n\tby smtp.gmail.com with ESMTPSA id\n\ts68sm9307944pfj.77.2017.04.28.02.01.38\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tFri, 28 Apr 2017 02:01:38 -0700 (PDT)"
        ],
        "X-Greylist": "whitelisted by SQLgrey-1.7.6",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:content-transfer-encoding;\n\tbh=3/9h2p5HRF4rI+MFYRIzIhUs+MeHQ29iD2PuIaO+/tc=;\n\tb=FCPHy1Gf23Amwdfjjj6QVfgmKerdIQvCC4amiu8sCkPrXMEvH+BCVEqN0/7FhEb6uW\n\tYPY/0o0hKWKQT5bhTpeTDThdc5Ctl183JuuQfA1yZ7xvroFpHqffsfqjp7YizwejJFDQ\n\t6xntyFCuWS+9cT/i2iOCiMNvPJEsUPBsW79kDNIccNxL7tm45VxhqbBI8EwKFlcobjhU\n\tLRrcyaOjbsno6Lbn/6h2VQ4Z+fP9Lg0i4o2dyk6LFXPCvXpi06K5Rd/HlQDa80jtzPZC\n\t1TYvht2DDGSpxL6n4x39naKjtCq39OdDHELb+Lzxjm205xoRbPd+s6fjV7RQJV60a61C\n\tMZOA==",
        "X-Gm-Message-State": "AN3rC/6/97s4pfOVpQJJeBIZW1ZEr/cAjKFVY9ir8J9Rmtw8tPuV9BVk\n\ttvsC7VgRJoo3lw==",
        "X-Received": "by 10.84.134.35 with SMTP id 32mr13297496plg.178.1493370099370; \n\tFri, 28 Apr 2017 02:01:39 -0700 (PDT)",
        "From": "Andy Zhou <azhou@ovn.org>",
        "To": "dev@openvswitch.org",
        "Date": "Fri, 28 Apr 2017 02:01:20 -0700",
        "Message-Id": "<1493370083-7385-2-git-send-email-azhou@ovn.org>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "In-Reply-To": "<1493370083-7385-1-git-send-email-azhou@ovn.org>",
        "References": "<1493370083-7385-1-git-send-email-azhou@ovn.org>",
        "X-Spam-Status": "No, score=-1.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1",
        "X-Spam-Checker-Version": "SpamAssassin 3.3.1 (2010-03-16) on\n\tsmtp1.linux-foundation.org",
        "Subject": "[ovs-dev] [action upcall meter v2 2/5] ofproto-dpif: Add\n\t'meter_ids' to backer",
        "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": "Add 'meter_ids', an id-pool object to manage datapath meter id, i.e.\nprovider_meter_id.\n\nCurrently, only userspace datapath supports meter, and it implements\nthe provider_meter_id management. Moving this function to 'backer'\nallows other datapath implementation to share the same logic.\n\nSigned-off-by: Andy Zhou <azhou@ovn.org>\n\n---\nv1-v2: fix typos\n---\n lib/dpif-netdev.c      | 24 ------------------------\n ofproto/ofproto-dpif.c | 44 ++++++++++++++++++++++++++++++++++++++++++--\n ofproto/ofproto-dpif.h |  4 ++++\n 3 files changed, 46 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c\nindex b3a080628d2b..f4de737e3751 100644\n--- a/lib/dpif-netdev.c\n+++ b/lib/dpif-netdev.c\n@@ -260,7 +260,6 @@ struct dp_netdev {\n     /* Meters. */\n     struct ovs_mutex meter_locks[N_METER_LOCKS];\n     struct dp_meter *meters[MAX_METERS]; /* Meter bands. */\n-    uint32_t meter_free;                 /* Next free meter. */\n \n     /* Protects access to ofproto-dpif-upcall interface during revalidator\n      * thread synchronization. */\n@@ -3896,9 +3895,6 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id *meter_id,\n     struct dp_meter *meter;\n     int i;\n \n-    if (mid == UINT32_MAX) {\n-        mid = dp->meter_free;\n-    }\n     if (mid >= MAX_METERS) {\n         return EFBIG; /* Meter_id out of range. */\n     }\n@@ -3958,21 +3954,6 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id *meter_id,\n         dp->meters[mid] = meter;\n         meter_unlock(dp, mid);\n \n-        meter_id->uint32 = mid; /* Store on success. */\n-\n-        /* Find next free meter */\n-        if (dp->meter_free == mid) { /* Now taken. */\n-            do {\n-                if (++mid >= MAX_METERS) { /* Wrap around */\n-                    mid = 0;\n-                }\n-                if (mid == dp->meter_free) { /* Full circle */\n-                    mid = MAX_METERS;\n-                    break;\n-                }\n-            } while (dp->meters[mid]);\n-            dp->meter_free = mid; /* Next free meter or MAX_METERS */\n-        }\n         return 0;\n     }\n     return ENOMEM;\n@@ -4027,11 +4008,6 @@ dpif_netdev_meter_del(struct dpif *dpif,\n         meter_lock(dp, meter_id);\n         dp_delete_meter(dp, meter_id);\n         meter_unlock(dp, meter_id);\n-\n-        /* Keep free meter index as low as possible */\n-        if (meter_id < dp->meter_free) {\n-            dp->meter_free = meter_id;\n-        }\n     }\n     return error;\n }\ndiff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c\nindex c73c2738c91c..30f18b302a77 100644\n--- a/ofproto/ofproto-dpif.c\n+++ b/ofproto/ofproto-dpif.c\n@@ -662,6 +662,7 @@ close_dpif_backer(struct dpif_backer *backer)\n     free(backer->type);\n     free(backer->dp_version_string);\n     dpif_close(backer->dpif);\n+    id_pool_destroy(backer->meter_ids);\n     free(backer);\n }\n \n@@ -787,6 +788,15 @@ open_dpif_backer(const char *type, struct dpif_backer **backerp)\n         = check_variable_length_userdata(backer);\n     backer->dp_version_string = dpif_get_dp_version(backer->dpif);\n \n+    /* Manage Datapath meter IDs if supported. */\n+    struct ofputil_meter_features features;\n+    dpif_meter_get_features(backer->dpif, &features);\n+    if (features.max_meters) {\n+        backer->meter_ids = id_pool_create(0, features.max_meters);\n+    } else {\n+        backer->meter_ids = NULL;\n+    }\n+\n     return error;\n }\n \n@@ -5439,6 +5449,17 @@ meter_set(struct ofproto *ofproto_, ofproto_meter_id *meter_id,\n {\n     struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);\n \n+    /* Provider ID unknown. Use backer to allocate a new DP meter */\n+    if (meter_id->uint32 == UINT32_MAX) {\n+        if (!ofproto->backer->meter_ids) {\n+            return EFBIG; /* Datapath does not support meter.  */\n+        }\n+\n+        if(!id_pool_alloc_id(ofproto->backer->meter_ids, &meter_id->uint32)) {\n+            return ENOMEM; /* Can't allocate a DP meter. */\n+        }\n+    }\n+\n     switch (dpif_meter_set(ofproto->backer->dpif, meter_id, config)) {\n     case 0:\n         return 0;\n@@ -5468,12 +5489,31 @@ meter_get(const struct ofproto *ofproto_, ofproto_meter_id meter_id,\n     return OFPERR_OFPMMFC_UNKNOWN_METER;\n }\n \n+struct free_meter_id_args {\n+    struct ofproto_dpif *ofproto;\n+    ofproto_meter_id meter_id;\n+};\n+\n+static void\n+free_meter_id(struct free_meter_id_args *args)\n+{\n+    struct ofproto_dpif *ofproto = args->ofproto;\n+\n+    dpif_meter_del(ofproto->backer->dpif, args->meter_id, NULL, 0);\n+    id_pool_free_id(ofproto->backer->meter_ids, args->meter_id.uint32);\n+    free(args);\n+}\n+\n static void\n meter_del(struct ofproto *ofproto_, ofproto_meter_id meter_id)\n {\n-    struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);\n+    struct free_meter_id_args *arg = xmalloc(sizeof *arg);\n \n-    dpif_meter_del(ofproto->backer->dpif, meter_id, NULL, 0);\n+    /* The 'meter_id' may still be in use the xlate code.\n+     * Only safe to delete after RCU grace period. */\n+    arg->ofproto = ofproto_dpif_cast(ofproto_);\n+    arg->meter_id = meter_id;\n+    ovsrcu_postpone(free_meter_id, arg);\n }\n \n const struct ofproto_class ofproto_dpif_class = {\ndiff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h\nindex 81a0bdfdad10..d14ab62ae195 100644\n--- a/ofproto/ofproto-dpif.h\n+++ b/ofproto/ofproto-dpif.h\n@@ -51,6 +51,7 @@\n #include \"hmapx.h\"\n #include \"odp-util.h\"\n #include \"openvswitch/ofp-util.h\"\n+#include \"id-pool.h\"\n #include \"ovs-thread.h\"\n #include \"ofproto-provider.h\"\n #include \"util.h\"\n@@ -221,6 +222,9 @@ struct dpif_backer {\n \n     bool recv_set_enable; /* Enables or disables receiving packets. */\n \n+    /* Meter. */\n+    struct id_pool *meter_ids;     /* Datapath meter allocation. */\n+\n     /* Version string of the datapath stored in OVSDB. */\n     char *dp_version_string;\n \n",
    "prefixes": [
        "ovs-dev",
        "action",
        "upcall",
        "meter",
        "v2",
        "2/5"
    ]
}