diff options
author | Alasdair G Kergon <agk@redhat.com> | 2016-08-18 14:06:13 +0100 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2016-08-18 14:06:13 +0100 |
commit | c27963c56630417b7a91d073c9a73f54f3fb5c99 (patch) | |
tree | 10daaf86ba601b1238c823accf771bca6d86eb86 | |
parent | 8c71fc1cc21272c8b9e8828b0c6962fd06ec3949 (diff) | |
download | lvm2-c27963c56630417b7a91d073c9a73f54f3fb5c99.tar.gz |
lib: Move lcm and gcd to lib/misc for wider use.
-rw-r--r-- | WHATS_NEW | 1 | ||||
-rw-r--r-- | include/.symlinks.in | 1 | ||||
-rw-r--r-- | lib/Makefile.in | 1 | ||||
-rw-r--r-- | lib/metadata/pool_manip.c | 24 | ||||
-rw-r--r-- | lib/misc/lib.h | 1 | ||||
-rw-r--r-- | lib/misc/lvm-maths.c | 38 | ||||
-rw-r--r-- | lib/misc/lvm-maths.h | 24 |
7 files changed, 67 insertions, 23 deletions
@@ -1,5 +1,6 @@ Version 2.02.165 - =================================== + Move lcm and gcd to lib/misc. Suppress some unnecessary --stripesize parameter warnings. Fix 'pvmove -n name ...' to prohibit collocation of RAID SubLVs diff --git a/include/.symlinks.in b/include/.symlinks.in index d1cc8268f..a1b5c1e05 100644 --- a/include/.symlinks.in +++ b/include/.symlinks.in @@ -50,6 +50,7 @@ @top_srcdir@/lib/misc/lvm-file.h @top_srcdir@/lib/misc/lvm-flock.h @top_srcdir@/lib/misc/lvm-globals.h +@top_srcdir@/lib/misc/lvm-maths.h @top_srcdir@/lib/misc/lvm-percent.h @top_srcdir@/lib/misc/lvm-signal.h @top_srcdir@/lib/misc/lvm-string.h diff --git a/lib/Makefile.in b/lib/Makefile.in index 451d96d8f..c75ffc2ae 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -112,6 +112,7 @@ SOURCES =\ misc/lvm-file.c \ misc/lvm-flock.c \ misc/lvm-globals.c \ + misc/lvm-maths.c \ misc/lvm-signal.c \ misc/lvm-string.c \ misc/lvm-wrappers.c \ diff --git a/lib/metadata/pool_manip.c b/lib/metadata/pool_manip.c index 87ca99255..f292a0c23 100644 --- a/lib/metadata/pool_manip.c +++ b/lib/metadata/pool_manip.c @@ -430,28 +430,6 @@ int validate_pool_chunk_size(struct cmd_context *cmd, return r; } -/* Greatest common divisor */ -static unsigned long _gcd(unsigned long n1, unsigned long n2) -{ - unsigned long remainder; - - do { - remainder = n1 % n2; - n1 = n2; - n2 = remainder; - } while (n2); - - return n1; -} - -/* Least common multiple */ -static unsigned long _lcm(unsigned long n1, unsigned long n2) -{ - if (!n1 || !n2) - return 0; - return (n1 * n2) / _gcd(n1, n2); -} - int recalculate_pool_chunk_size_with_dev_hints(struct logical_volume *pool_lv, int passed_args, int chunk_size_calc_policy) @@ -497,7 +475,7 @@ int recalculate_pool_chunk_size_with_dev_hints(struct logical_volume *pool_lv, continue; if (previous_hint) - hint = _lcm(previous_hint, hint); + hint = lcm(previous_hint, hint); previous_hint = hint; break; case AREA_LV: diff --git a/lib/misc/lib.h b/lib/misc/lib.h index 916ffefd0..8ed06f81d 100644 --- a/lib/misc/lib.h +++ b/lib/misc/lib.h @@ -89,6 +89,7 @@ # include "lvm-logging.h" # include "lvm-globals.h" # include "lvm-wrappers.h" +# include "lvm-maths.h" #endif #include <unistd.h> diff --git a/lib/misc/lvm-maths.c b/lib/misc/lvm-maths.c new file mode 100644 index 000000000..df3aa0af0 --- /dev/null +++ b/lib/misc/lvm-maths.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "lib.h" + +/* Greatest common divisor */ +unsigned long gcd(unsigned long n1, unsigned long n2) +{ + unsigned long remainder; + + do { + remainder = n1 % n2; + n1 = n2; + n2 = remainder; + } while (n2); + + return n1; +} + +/* Least common multiple */ +unsigned long lcm(unsigned long n1, unsigned long n2) +{ + if (!n1 || !n2) + return 0; + + return (n1 * n2) / gcd(n1, n2); +} diff --git a/lib/misc/lvm-maths.h b/lib/misc/lvm-maths.h new file mode 100644 index 000000000..f7fc0ad9e --- /dev/null +++ b/lib/misc/lvm-maths.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2016 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _LVM_MATH_H +#define _LVM_MATH_H + +/* Greatest common divisor */ +unsigned long gcd(unsigned long n1, unsigned long n2); + +/* Least common multiple */ +unsigned long lcm(unsigned long n1, unsigned long n2); + +#endif |