License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2009-10-07 02:31:13 +08:00
|
|
|
#ifndef __CEPH_DECODE_H
|
|
|
|
#define __CEPH_DECODE_H
|
|
|
|
|
2012-07-11 21:24:45 +08:00
|
|
|
#include <linux/err.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <linux/bug.h>
|
2016-06-08 03:57:15 +08:00
|
|
|
#include <linux/slab.h>
|
2010-02-03 08:11:19 +08:00
|
|
|
#include <linux/time.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <asm/unaligned.h>
|
2009-10-07 02:31:13 +08:00
|
|
|
|
2012-10-03 01:01:25 +08:00
|
|
|
#include <linux/ceph/types.h>
|
2009-10-15 00:59:09 +08:00
|
|
|
|
2009-10-07 02:31:13 +08:00
|
|
|
/*
|
|
|
|
* in all cases,
|
|
|
|
* void **p pointer to position pointer
|
|
|
|
* void *end pointer to end of buffer (last byte + 1)
|
|
|
|
*/
|
|
|
|
|
2009-10-15 00:59:09 +08:00
|
|
|
static inline u64 ceph_decode_64(void **p)
|
|
|
|
{
|
|
|
|
u64 v = get_unaligned_le64(*p);
|
|
|
|
*p += sizeof(u64);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
static inline u32 ceph_decode_32(void **p)
|
|
|
|
{
|
|
|
|
u32 v = get_unaligned_le32(*p);
|
|
|
|
*p += sizeof(u32);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
static inline u16 ceph_decode_16(void **p)
|
|
|
|
{
|
|
|
|
u16 v = get_unaligned_le16(*p);
|
|
|
|
*p += sizeof(u16);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
static inline u8 ceph_decode_8(void **p)
|
|
|
|
{
|
|
|
|
u8 v = *(u8 *)*p;
|
|
|
|
(*p)++;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
static inline void ceph_decode_copy(void **p, void *pv, size_t n)
|
|
|
|
{
|
|
|
|
memcpy(pv, *p, n);
|
|
|
|
*p += n;
|
|
|
|
}
|
|
|
|
|
2009-10-07 02:31:13 +08:00
|
|
|
/*
|
|
|
|
* bounds check input.
|
|
|
|
*/
|
2016-03-25 17:18:39 +08:00
|
|
|
static inline bool ceph_has_room(void **p, void *end, size_t n)
|
2012-04-21 04:49:44 +08:00
|
|
|
{
|
|
|
|
return end >= *p && n <= end - *p;
|
|
|
|
}
|
|
|
|
|
2012-11-01 21:39:27 +08:00
|
|
|
#define ceph_decode_need(p, end, n, bad) \
|
|
|
|
do { \
|
|
|
|
if (!likely(ceph_has_room(p, end, n))) \
|
|
|
|
goto bad; \
|
2009-10-07 02:31:13 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_decode_64_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, sizeof(u64), bad); \
|
2009-10-15 00:59:09 +08:00
|
|
|
v = ceph_decode_64(p); \
|
2009-10-07 02:31:13 +08:00
|
|
|
} while (0)
|
|
|
|
#define ceph_decode_32_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, sizeof(u32), bad); \
|
2009-10-15 00:59:09 +08:00
|
|
|
v = ceph_decode_32(p); \
|
2009-10-07 02:31:13 +08:00
|
|
|
} while (0)
|
|
|
|
#define ceph_decode_16_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, sizeof(u16), bad); \
|
2009-10-15 00:59:09 +08:00
|
|
|
v = ceph_decode_16(p); \
|
2009-10-07 02:31:13 +08:00
|
|
|
} while (0)
|
2010-02-03 08:11:19 +08:00
|
|
|
#define ceph_decode_8_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, sizeof(u8), bad); \
|
|
|
|
v = ceph_decode_8(p); \
|
|
|
|
} while (0)
|
2009-10-07 02:31:13 +08:00
|
|
|
|
|
|
|
#define ceph_decode_copy_safe(p, end, pv, n, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, n, bad); \
|
|
|
|
ceph_decode_copy(p, pv, n); \
|
|
|
|
} while (0)
|
|
|
|
|
2012-07-11 21:24:45 +08:00
|
|
|
/*
|
|
|
|
* Allocate a buffer big enough to hold the wire-encoded string, and
|
|
|
|
* decode the string into it. The resulting string will always be
|
|
|
|
* terminated with '\0'. If successful, *p will be advanced
|
|
|
|
* past the decoded data. Also, if lenp is not a null pointer, the
|
|
|
|
* length (not including the terminating '\0') will be recorded in
|
|
|
|
* *lenp. Note that a zero-length string is a valid return value.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the newly-allocated string buffer, or a
|
|
|
|
* pointer-coded errno if an error occurs. Neither *p nor *lenp
|
|
|
|
* will have been updated if an error is returned.
|
|
|
|
*
|
|
|
|
* There are two possible failures:
|
|
|
|
* - converting the string would require accessing memory at or
|
2012-11-01 21:39:27 +08:00
|
|
|
* beyond the "end" pointer provided (-ERANGE)
|
|
|
|
* - memory could not be allocated for the result (-ENOMEM)
|
2012-07-11 21:24:45 +08:00
|
|
|
*/
|
|
|
|
static inline char *ceph_extract_encoded_string(void **p, void *end,
|
|
|
|
size_t *lenp, gfp_t gfp)
|
|
|
|
{
|
|
|
|
u32 len;
|
|
|
|
void *sp = *p;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
ceph_decode_32_safe(&sp, end, len, bad);
|
|
|
|
if (!ceph_has_room(&sp, end, len))
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
buf = kmalloc(len + 1, gfp);
|
|
|
|
if (!buf)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
memcpy(buf, sp, len);
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
*p = (char *) *p + sizeof (u32) + len;
|
|
|
|
if (lenp)
|
|
|
|
*lenp = (size_t) len;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
return ERR_PTR(-ERANGE);
|
|
|
|
}
|
|
|
|
|
2017-06-21 23:27:17 +08:00
|
|
|
/*
|
|
|
|
* skip helpers
|
|
|
|
*/
|
|
|
|
#define ceph_decode_skip_n(p, end, n, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_decode_need(p, end, n, bad); \
|
|
|
|
*p += n; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_64(p, end, bad) \
|
|
|
|
ceph_decode_skip_n(p, end, sizeof(u64), bad)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_32(p, end, bad) \
|
|
|
|
ceph_decode_skip_n(p, end, sizeof(u32), bad)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_16(p, end, bad) \
|
|
|
|
ceph_decode_skip_n(p, end, sizeof(u16), bad)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_8(p, end, bad) \
|
|
|
|
ceph_decode_skip_n(p, end, sizeof(u8), bad)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_string(p, end, bad) \
|
|
|
|
do { \
|
|
|
|
u32 len; \
|
|
|
|
\
|
|
|
|
ceph_decode_32_safe(p, end, len, bad); \
|
|
|
|
ceph_decode_skip_n(p, end, len, bad); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_set(p, end, type, bad) \
|
|
|
|
do { \
|
|
|
|
u32 len; \
|
|
|
|
\
|
|
|
|
ceph_decode_32_safe(p, end, len, bad); \
|
|
|
|
while (len--) \
|
|
|
|
ceph_decode_skip_##type(p, end, bad); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_map(p, end, ktype, vtype, bad) \
|
|
|
|
do { \
|
|
|
|
u32 len; \
|
|
|
|
\
|
|
|
|
ceph_decode_32_safe(p, end, len, bad); \
|
|
|
|
while (len--) { \
|
|
|
|
ceph_decode_skip_##ktype(p, end, bad); \
|
|
|
|
ceph_decode_skip_##vtype(p, end, bad); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_decode_skip_map_of_map(p, end, ktype1, ktype2, vtype2, bad) \
|
|
|
|
do { \
|
|
|
|
u32 len; \
|
|
|
|
\
|
|
|
|
ceph_decode_32_safe(p, end, len, bad); \
|
|
|
|
while (len--) { \
|
|
|
|
ceph_decode_skip_##ktype1(p, end, bad); \
|
|
|
|
ceph_decode_skip_map(p, end, ktype2, vtype2, bad); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2009-10-07 02:31:13 +08:00
|
|
|
/*
|
2018-07-14 04:18:34 +08:00
|
|
|
* struct ceph_timespec <-> struct timespec64
|
2009-10-07 02:31:13 +08:00
|
|
|
*/
|
2018-07-14 04:18:34 +08:00
|
|
|
static inline void ceph_decode_timespec64(struct timespec64 *ts,
|
|
|
|
const struct ceph_timespec *tv)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This will still overflow in year 2106. We could extend
|
|
|
|
* the protocol to steal two more bits from tv_nsec to
|
|
|
|
* add three more 136 year epochs after that the way ext4
|
|
|
|
* does if necessary.
|
|
|
|
*/
|
|
|
|
ts->tv_sec = (time64_t)le32_to_cpu(tv->tv_sec);
|
|
|
|
ts->tv_nsec = (long)le32_to_cpu(tv->tv_nsec);
|
|
|
|
}
|
|
|
|
static inline void ceph_encode_timespec64(struct ceph_timespec *tv,
|
|
|
|
const struct timespec64 *ts)
|
|
|
|
{
|
|
|
|
tv->tv_sec = cpu_to_le32((u32)ts->tv_sec);
|
|
|
|
tv->tv_nsec = cpu_to_le32((u32)ts->tv_nsec);
|
2009-10-15 00:59:09 +08:00
|
|
|
}
|
2009-10-07 02:31:13 +08:00
|
|
|
|
2009-11-04 07:17:56 +08:00
|
|
|
/*
|
|
|
|
* sockaddr_storage <-> ceph_sockaddr
|
|
|
|
*/
|
2019-06-17 18:57:25 +08:00
|
|
|
#define CEPH_ENTITY_ADDR_TYPE_NONE 0
|
|
|
|
#define CEPH_ENTITY_ADDR_TYPE_LEGACY __cpu_to_le32(1)
|
2020-10-30 20:30:51 +08:00
|
|
|
#define CEPH_ENTITY_ADDR_TYPE_MSGR2 __cpu_to_le32(2)
|
2020-11-19 23:59:08 +08:00
|
|
|
#define CEPH_ENTITY_ADDR_TYPE_ANY __cpu_to_le32(3)
|
2019-06-17 18:57:25 +08:00
|
|
|
|
2019-06-17 21:24:31 +08:00
|
|
|
static inline void ceph_encode_banner_addr(struct ceph_entity_addr *a)
|
2009-11-04 07:17:56 +08:00
|
|
|
{
|
2010-06-12 07:58:48 +08:00
|
|
|
__be16 ss_family = htons(a->in_addr.ss_family);
|
|
|
|
a->in_addr.ss_family = *(__u16 *)&ss_family;
|
2019-06-17 18:57:25 +08:00
|
|
|
|
|
|
|
/* Banner addresses require TYPE_NONE */
|
|
|
|
a->type = CEPH_ENTITY_ADDR_TYPE_NONE;
|
2009-11-04 07:17:56 +08:00
|
|
|
}
|
2019-06-17 21:24:31 +08:00
|
|
|
static inline void ceph_decode_banner_addr(struct ceph_entity_addr *a)
|
2009-11-04 07:17:56 +08:00
|
|
|
{
|
2010-06-12 07:58:48 +08:00
|
|
|
__be16 ss_family = *(__be16 *)&a->in_addr.ss_family;
|
|
|
|
a->in_addr.ss_family = ntohs(ss_family);
|
2009-11-19 08:19:57 +08:00
|
|
|
WARN_ON(a->in_addr.ss_family == 512);
|
2019-06-17 18:57:25 +08:00
|
|
|
a->type = CEPH_ENTITY_ADDR_TYPE_LEGACY;
|
2009-11-04 07:17:56 +08:00
|
|
|
}
|
|
|
|
|
2019-06-04 02:45:16 +08:00
|
|
|
extern int ceph_decode_entity_addr(void **p, void *end,
|
|
|
|
struct ceph_entity_addr *addr);
|
2020-10-30 20:30:51 +08:00
|
|
|
int ceph_decode_entity_addrvec(void **p, void *end, bool msgr2,
|
|
|
|
struct ceph_entity_addr *addr);
|
|
|
|
|
2020-11-19 23:59:08 +08:00
|
|
|
int ceph_entity_addr_encoding_len(const struct ceph_entity_addr *addr);
|
|
|
|
void ceph_encode_entity_addr(void **p, const struct ceph_entity_addr *addr);
|
|
|
|
|
2009-10-07 02:31:13 +08:00
|
|
|
/*
|
|
|
|
* encoders
|
|
|
|
*/
|
2009-10-15 00:59:09 +08:00
|
|
|
static inline void ceph_encode_64(void **p, u64 v)
|
|
|
|
{
|
|
|
|
put_unaligned_le64(v, (__le64 *)*p);
|
|
|
|
*p += sizeof(u64);
|
|
|
|
}
|
|
|
|
static inline void ceph_encode_32(void **p, u32 v)
|
|
|
|
{
|
|
|
|
put_unaligned_le32(v, (__le32 *)*p);
|
|
|
|
*p += sizeof(u32);
|
|
|
|
}
|
|
|
|
static inline void ceph_encode_16(void **p, u16 v)
|
|
|
|
{
|
|
|
|
put_unaligned_le16(v, (__le16 *)*p);
|
|
|
|
*p += sizeof(u16);
|
|
|
|
}
|
|
|
|
static inline void ceph_encode_8(void **p, u8 v)
|
|
|
|
{
|
|
|
|
*(u8 *)*p = v;
|
|
|
|
(*p)++;
|
|
|
|
}
|
2009-11-19 08:19:57 +08:00
|
|
|
static inline void ceph_encode_copy(void **p, const void *s, int len)
|
|
|
|
{
|
|
|
|
memcpy(*p, s, len);
|
|
|
|
*p += len;
|
|
|
|
}
|
2009-10-07 02:31:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* filepath, string encoders
|
|
|
|
*/
|
|
|
|
static inline void ceph_encode_filepath(void **p, void *end,
|
|
|
|
u64 ino, const char *path)
|
|
|
|
{
|
|
|
|
u32 len = path ? strlen(path) : 0;
|
2012-07-04 05:01:18 +08:00
|
|
|
BUG_ON(*p + 1 + sizeof(ino) + sizeof(len) + len > end);
|
2010-01-28 06:28:10 +08:00
|
|
|
ceph_encode_8(p, 1);
|
2009-10-07 02:31:13 +08:00
|
|
|
ceph_encode_64(p, ino);
|
|
|
|
ceph_encode_32(p, len);
|
|
|
|
if (len)
|
|
|
|
memcpy(*p, path, len);
|
|
|
|
*p += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ceph_encode_string(void **p, void *end,
|
|
|
|
const char *s, u32 len)
|
|
|
|
{
|
|
|
|
BUG_ON(*p + sizeof(len) + len > end);
|
|
|
|
ceph_encode_32(p, len);
|
|
|
|
if (len)
|
|
|
|
memcpy(*p, s, len);
|
|
|
|
*p += len;
|
|
|
|
}
|
|
|
|
|
2016-06-02 20:23:32 +08:00
|
|
|
/*
|
|
|
|
* version and length starting block encoders/decoders
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* current code version (u8) + compat code version (u8) + len of struct (u32) */
|
|
|
|
#define CEPH_ENCODING_START_BLK_LEN 6
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ceph_start_encoding - start encoding block
|
|
|
|
* @struct_v: current (code) version of the encoding
|
|
|
|
* @struct_compat: oldest code version that can decode it
|
|
|
|
* @struct_len: length of struct encoding
|
|
|
|
*/
|
|
|
|
static inline void ceph_start_encoding(void **p, u8 struct_v, u8 struct_compat,
|
|
|
|
u32 struct_len)
|
|
|
|
{
|
|
|
|
ceph_encode_8(p, struct_v);
|
|
|
|
ceph_encode_8(p, struct_compat);
|
|
|
|
ceph_encode_32(p, struct_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ceph_start_decoding - start decoding block
|
|
|
|
* @v: current version of the encoding that the code supports
|
|
|
|
* @name: name of the struct (free-form)
|
|
|
|
* @struct_v: out param for the encoding version
|
|
|
|
* @struct_len: out param for the length of struct encoding
|
|
|
|
*
|
|
|
|
* Validates the length of struct encoding, so unsafe ceph_decode_*
|
|
|
|
* variants can be used for decoding.
|
|
|
|
*/
|
|
|
|
static inline int ceph_start_decoding(void **p, void *end, u8 v,
|
|
|
|
const char *name, u8 *struct_v,
|
|
|
|
u32 *struct_len)
|
|
|
|
{
|
|
|
|
u8 struct_compat;
|
|
|
|
|
|
|
|
ceph_decode_need(p, end, CEPH_ENCODING_START_BLK_LEN, bad);
|
|
|
|
*struct_v = ceph_decode_8(p);
|
|
|
|
struct_compat = ceph_decode_8(p);
|
|
|
|
if (v < struct_compat) {
|
|
|
|
pr_warn("got struct_v %d struct_compat %d > %d of %s\n",
|
|
|
|
*struct_v, struct_compat, v, name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*struct_len = ceph_decode_32(p);
|
|
|
|
ceph_decode_need(p, end, *struct_len, bad);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2012-11-01 21:39:27 +08:00
|
|
|
#define ceph_encode_need(p, end, n, bad) \
|
|
|
|
do { \
|
|
|
|
if (!likely(ceph_has_room(p, end, n))) \
|
|
|
|
goto bad; \
|
2010-02-03 08:11:19 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_encode_64_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, sizeof(u64), bad); \
|
|
|
|
ceph_encode_64(p, v); \
|
|
|
|
} while (0)
|
|
|
|
#define ceph_encode_32_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, sizeof(u32), bad); \
|
2012-11-01 21:39:27 +08:00
|
|
|
ceph_encode_32(p, v); \
|
2010-02-03 08:11:19 +08:00
|
|
|
} while (0)
|
|
|
|
#define ceph_encode_16_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, sizeof(u16), bad); \
|
2012-11-01 21:39:27 +08:00
|
|
|
ceph_encode_16(p, v); \
|
|
|
|
} while (0)
|
|
|
|
#define ceph_encode_8_safe(p, end, v, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, sizeof(u8), bad); \
|
|
|
|
ceph_encode_8(p, v); \
|
2010-02-03 08:11:19 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ceph_encode_copy_safe(p, end, pv, n, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, n, bad); \
|
|
|
|
ceph_encode_copy(p, pv, n); \
|
|
|
|
} while (0)
|
2010-05-19 07:38:08 +08:00
|
|
|
#define ceph_encode_string_safe(p, end, s, n, bad) \
|
|
|
|
do { \
|
|
|
|
ceph_encode_need(p, end, n, bad); \
|
|
|
|
ceph_encode_string(p, end, s, n); \
|
|
|
|
} while (0)
|
2010-02-03 08:11:19 +08:00
|
|
|
|
2009-10-07 02:31:13 +08:00
|
|
|
|
|
|
|
#endif
|