From: Philipp Reisner <philipp.reisner@linbit.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Subject: [PATCH 07/13] drbd: Split off netlink mandatory attribute handling into separate file
Date: Wed, 12 Oct 2011 14:27:29 +0200 [thread overview]
Message-ID: <1318422455-17539-8-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1318422455-17539-1-git-send-email-philipp.reisner@linbit.com>
From: Andreas Gruenbacher <agruen@linbit.com>
Duplicate this file in the kernel module and in user space; both sides need it.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
---
drivers/block/drbd/Makefile | 1 +
drivers/block/drbd/drbd_int.h | 6 ----
drivers/block/drbd/drbd_nl.c | 51 +--------------------------------
drivers/block/drbd/drbd_nla.c | 55 ++++++++++++++++++++++++++++++++++++
drivers/block/drbd/drbd_nla.h | 8 +++++
drivers/block/drbd/drbd_wrappers.h | 1 +
6 files changed, 66 insertions(+), 56 deletions(-)
create mode 100644 drivers/block/drbd/drbd_nla.c
create mode 100644 drivers/block/drbd/drbd_nla.h
diff --git a/drivers/block/drbd/Makefile b/drivers/block/drbd/Makefile
index 06fb445..8b45033 100644
--- a/drivers/block/drbd/Makefile
+++ b/drivers/block/drbd/Makefile
@@ -2,5 +2,6 @@ drbd-y := drbd_bitmap.o drbd_proc.o
drbd-y += drbd_worker.o drbd_receiver.o drbd_req.o drbd_actlog.o
drbd-y += drbd_main.o drbd_strings.o drbd_nl.o
drbd-y += drbd_interval.o drbd_state.o
+drbd-y += drbd_nla.o
obj-$(CONFIG_BLK_DEV_DRBD) += drbd.o
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index c584301..c301973 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1407,12 +1407,6 @@ extern bool conn_try_outdate_peer(struct drbd_tconn *tconn);
extern void conn_try_outdate_peer_async(struct drbd_tconn *tconn);
extern int drbd_khelper(struct drbd_conf *mdev, char *cmd);
-struct nla_policy;
-extern int drbd_nla_check_mandatory(int maxtype, struct nlattr *nla);
-extern int drbd_nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla,
- const struct nla_policy *policy);
-extern struct nlattr *drbd_nla_find_nested(int maxtype, struct nlattr *nla, int attrtype);
-
/* drbd_worker.c */
extern int drbd_worker(struct drbd_thread *thi);
enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor);
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index b75fde7..0c07baf 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -99,6 +99,7 @@ int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info);
int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb);
#include <linux/drbd_genl_api.h>
+#include "drbd_nla.h"
#include <linux/genl_magic_func.h>
/* used blkdev_get_by_path, to claim our meta data device(s) */
@@ -3266,53 +3267,3 @@ failed:
"Event seq:%u sib_reason:%u\n",
err, seq, sib->sib_reason);
}
-
-int drbd_nla_check_mandatory(int maxtype, struct nlattr *nla)
-{
- struct nlattr *head = nla_data(nla);
- int len = nla_len(nla);
- int rem;
-
- /*
- * validate_nla (called from nla_parse_nested) ignores attributes
- * beyond maxtype, and does not understand the DRBD_GENLA_F_MANDATORY flag.
- * In order to have it validate attributes with the DRBD_GENLA_F_MANDATORY
- * flag set also, check and remove that flag before calling
- * nla_parse_nested.
- */
-
- nla_for_each_attr(nla, head, len, rem) {
- if (nla->nla_type & DRBD_GENLA_F_MANDATORY) {
- nla->nla_type &= ~DRBD_GENLA_F_MANDATORY;
- if (nla_type(nla) > maxtype)
- return -EOPNOTSUPP;
- }
- }
- return 0;
-}
-
-int drbd_nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla,
- const struct nla_policy *policy)
-{
- int err;
-
- err = drbd_nla_check_mandatory(maxtype, nla);
- if (!err)
- err = nla_parse_nested(tb, maxtype, nla, policy);
-
- return err;
-}
-
-struct nlattr *drbd_nla_find_nested(int maxtype, struct nlattr *nla, int attrtype)
-{
- int err;
- /*
- * If any nested attribute has the DRBD_GENLA_F_MANDATORY flag set and
- * we don't know about that attribute, reject all the nested
- * attributes.
- */
- err = drbd_nla_check_mandatory(maxtype, nla);
- if (err)
- return ERR_PTR(err);
- return nla_find_nested(nla, attrtype);
-}
diff --git a/drivers/block/drbd/drbd_nla.c b/drivers/block/drbd/drbd_nla.c
new file mode 100644
index 0000000..fa672b6
--- /dev/null
+++ b/drivers/block/drbd/drbd_nla.c
@@ -0,0 +1,55 @@
+#include "drbd_wrappers.h"
+#include <linux/kernel.h>
+#include <net/netlink.h>
+#include <linux/drbd_genl_api.h>
+#include "drbd_nla.h"
+
+static int drbd_nla_check_mandatory(int maxtype, struct nlattr *nla)
+{
+ struct nlattr *head = nla_data(nla);
+ int len = nla_len(nla);
+ int rem;
+
+ /*
+ * validate_nla (called from nla_parse_nested) ignores attributes
+ * beyond maxtype, and does not understand the DRBD_GENLA_F_MANDATORY flag.
+ * In order to have it validate attributes with the DRBD_GENLA_F_MANDATORY
+ * flag set also, check and remove that flag before calling
+ * nla_parse_nested.
+ */
+
+ nla_for_each_attr(nla, head, len, rem) {
+ if (nla->nla_type & DRBD_GENLA_F_MANDATORY) {
+ nla->nla_type &= ~DRBD_GENLA_F_MANDATORY;
+ if (nla_type(nla) > maxtype)
+ return -EOPNOTSUPP;
+ }
+ }
+ return 0;
+}
+
+int drbd_nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla,
+ const struct nla_policy *policy)
+{
+ int err;
+
+ err = drbd_nla_check_mandatory(maxtype, nla);
+ if (!err)
+ err = nla_parse_nested(tb, maxtype, nla, policy);
+
+ return err;
+}
+
+struct nlattr *drbd_nla_find_nested(int maxtype, struct nlattr *nla, int attrtype)
+{
+ int err;
+ /*
+ * If any nested attribute has the DRBD_GENLA_F_MANDATORY flag set and
+ * we don't know about that attribute, reject all the nested
+ * attributes.
+ */
+ err = drbd_nla_check_mandatory(maxtype, nla);
+ if (err)
+ return ERR_PTR(err);
+ return nla_find_nested(nla, attrtype);
+}
diff --git a/drivers/block/drbd/drbd_nla.h b/drivers/block/drbd/drbd_nla.h
new file mode 100644
index 0000000..679c2d5
--- /dev/null
+++ b/drivers/block/drbd/drbd_nla.h
@@ -0,0 +1,8 @@
+#ifndef __DRBD_NLA_H
+#define __DRBD_NLA_H
+
+extern int drbd_nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla,
+ const struct nla_policy *policy);
+extern struct nlattr *drbd_nla_find_nested(int maxtype, struct nlattr *nla, int attrtype);
+
+#endif /* __DRBD_NLA_H */
diff --git a/drivers/block/drbd/drbd_wrappers.h b/drivers/block/drbd/drbd_wrappers.h
index 46a6d99..328f18e 100644
--- a/drivers/block/drbd/drbd_wrappers.h
+++ b/drivers/block/drbd/drbd_wrappers.h
@@ -3,6 +3,7 @@
#include <linux/ctype.h>
#include <linux/mm.h>
+#include "drbd_int.h"
/* see get_sb_bdev and bd_claim */
extern char *drbd_sec_holder;
--
1.7.4.1
next prev parent reply other threads:[~2011-10-12 12:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-12 12:27 [RFC 00/13] drbd: part 18 of adding multiple volume support to drbd Philipp Reisner
2011-10-12 12:27 ` [PATCH 01/13] drbd: Lower log priority for an event that is definitely not an error Philipp Reisner
2011-10-12 12:27 ` [PATCH 02/13] drbd: Use DRBD_MINOR_COUNT_DEF in one more place Philipp Reisner
2011-10-12 12:27 ` [PATCH 03/13] drbd: cosmetic: fix accidental division instead of modulo when pretty printing Philipp Reisner
2011-10-12 12:27 ` [PATCH 04/13] drbd: spelling fix: too small Philipp Reisner
2011-10-12 12:27 ` [PATCH 05/13] drbd: Use the terminology suggested by the command names in the source code and messages Philipp Reisner
2011-10-12 12:27 ` [PATCH 06/13] drbd: Also need to check for DRBD_GENLA_F_MANDATORY flags before nla_find_nested() Philipp Reisner
2011-10-12 12:27 ` Philipp Reisner [this message]
2011-10-12 12:27 ` [PATCH 08/13] drbd: Rename DRBD_ADM_NEED_{CONN -> RESOURCE} Philipp Reisner
2011-10-12 12:27 ` [PATCH 09/13] drbd: Convert the generic netlink interface to accept connection endpoints Philipp Reisner
2011-10-12 12:27 ` [PATCH 10/13] drbd: Allow to pass resource options to the new-resource command Philipp Reisner
2011-10-12 12:27 ` [PATCH 11/13] drbd: Remove dead code Philipp Reisner
2011-10-12 12:27 ` [PATCH 12/13] drbd: Rename --dry-run to --tentative Philipp Reisner
2011-10-12 12:27 ` [PATCH 13/13] DRBD: Fix comparison always false warning due to long/long long compare Philipp Reisner
2011-10-12 13:35 ` Geert Uytterhoeven
2011-10-13 8:25 ` [Drbd-dev] " Philipp Reisner
2011-10-13 8:43 ` Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318422455-17539-8-git-send-email-philipp.reisner@linbit.com \
--to=philipp.reisner@linbit.com \
--cc=axboe@kernel.dk \
--cc=drbd-dev@lists.linbit.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®