All of lore.kernel.org
 help / color / mirror / Atom feed
From: 강상우 <kenneth.kang@lge.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <dsterba@suse.com>
Subject: RE: FW: btrfs-progs: android build
Date: Mon, 10 Aug 2015 16:30:58 +0900	[thread overview]
Message-ID: <001b01d0d33e$8043bb60$80cb3220$@lge.com> (raw)
In-Reply-To: <20150806143839.GK31669@twin.jikos.cz>

[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]

I change the code that you are suggest.
I consider wrapper function, but it was affected by blkid library on build time.
So I make CFLAG PLATFORM_ANDROID on Android.mk to using it for check the platform.

-----Original Message-----
From: linux-btrfs-owner@vger.kernel.org [mailto:linux-btrfs-owner@vger.kernel.org] On Behalf Of David Sterba
Sent: Thursday, August 06, 2015 11:39 PM
Cc: linux-btrfs@vger.kernel.org
Subject: Re: FW: btrfs-progs: android build

Hi,

On Thu, Aug 06, 2015 at 06:45:11PM +0900,        wrote:
> Hi, I made btrfs-progs android build script and test it.\

Thanks. The changes as they stand are too intrusive to be added but give me an idea what's needed.

The makefile part shares some variables with current make and adds some specific variables and includes. Ideally there's only one makefile but I think that we can live with a separate makefile for android as there seem to be specific quirks that would complicate the common makefile.

This means we'd have to keep the shared part in sync manually but it's not that hard. New files or new libs, this always requires more care.

> And need some help on btrfs_wipe_existing_sb().\ On the test it looks 
> work well.\

The code changes should be hidden in wrappers and pulled via a separate header file. If this is not possible, the ifdefs should be in the function implementations (eg. is_ssd, check_overwrite), not at the call sites.

Other than that, I don't mind adding support for android builds.  I don't have an android build environment at hand and cannot verify that it's always working, so the same holds as for musl libc, fixes are up to you.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: 0001-btrfs-progs-Add-Android-build-mk-file.patch --]
[-- Type: application/octet-stream, Size: 11329 bytes --]

>From 66bae04ded4feb8f218f0a6d30f360792430be7c Mon Sep 17 00:00:00 2001
From: "kenneth.kang" <kenneth.kang@lge.com>
Date: Wed, 5 Aug 2015 18:08:25 +0900
Subject: [PATCH] btrfs-progs: Add Android build mk file

Add Android.mk to use btrfs on android device.

To using this funtion, there are some limitation.
1) phread_cancel was changed to pthread_kill due to android didn't support
that.
2) This module needs lzo library on android/external folder.
3) blkid library doesn't support fully. So have to use -f option to
work.
---
 Android.mk      | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 chunk-recover.c |   8 ++++
 cmds-receive.c  |   4 ++
 cmds-restore.c  |   1 +
 cmds-scrub.c    |  22 ++++++++++-
 kerncompat.h    |   3 ++
 mkfs.c          |   9 +++++
 utils.c         |   9 +++--
 8 files changed, 162 insertions(+), 5 deletions(-)
 create mode 100644 Android.mk

diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..f6f3e28
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,111 @@
+LOCAL_PATH:= $(call my-dir)
+
+#include $(call all-subdir-makefiles)
+
+CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC
+
+LDFLAGS := -static -rdynamic
+
+LIBS := -luuid   -lblkid   -lz   -llzo2 -L. -lpthread
+LIBBTRFS_LIBS := $(LIBS)
+
+STATIC_CFLAGS := $(CFLAGS) -ffunction-sections -fdata-sections
+STATIC_LDFLAGS := -static -Wl,--gc-sections
+STATIC_LIBS := -luuid   -lblkid -luuid \
+              -lz   -llzo2 -L. -pthread
+
+btrfs_shared_libraries := libext2_uuid \
+			libext2_blkid
+
+objects := ctree.c disk-io.c radix-tree.c extent-tree.c print-tree.c \
+          root-tree.c dir-item.c file-item.c inode-item.c inode-map.c \
+          extent-cache.c extent_io.c volumes.c utils.c repair.c \
+          qgroup.c raid6.c free-space-cache.c list_sort.c props.c \
+          ulist.c qgroup-verify.c backref.c string-table.c task-utils.c \
+          inode.c file.c find-root.c
+cmds_objects := cmds-subvolume.c cmds-filesystem.c cmds-device.c cmds-scrub.c \
+               cmds-inspect.c cmds-balance.c cmds-send.c cmds-receive.c \
+               cmds-quota.c cmds-qgroup.c cmds-replace.c cmds-check.c \
+               cmds-restore.c cmds-rescue.c chunk-recover.c super-recover.c \
+               cmds-property.c cmds-fi-usage.c
+libbtrfs_objects := send-stream.c send-utils.c rbtree.c btrfs-list.c crc32c.c \
+                   uuid-tree.c utils-lib.c rbtree-utils.c
+libbtrfs_headers := send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
+                   crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
+                   extent_io.h ioctl.h ctree.h btrfsck.h version.h
+TESTS := fsck-tests.sh convert-tests.sh
+blkid_objects := partition/ superblocks/ topology/
+
+
+# external/e2fsprogs/lib is needed for uuid/uuid.h
+common_C_INCLUDES := $(LOCAL_PATH) external/e2fsprogs/lib/ external/lzo/include/ external/zlib/
+
+#----------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(libbtrfs_objects)
+LOCAL_CFLAGS := $(STATIC_CFLAGS)
+LOCAL_MODULE := libbtrfs
+LOCAL_C_INCLUDES := $(common_C_INCLUDES)
+include $(BUILD_STATIC_LIBRARY)
+
+#----------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := btrfs
+#LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_SRC_FILES := \
+		$(objects) \
+		$(cmds_objects) \
+		btrfs.c \
+		help.c \
+
+LOCAL_C_INCLUDES := $(common_C_INCLUDES)
+LOCAL_CFLAGS := $(STATIC_CFLAGS)
+#LOCAL_LDLIBS := $(LIBBTRFS_LIBS)
+#LOCAL_LDFLAGS := $(STATIC_LDFLAGS)
+LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries)
+LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static libz
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils
+
+LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES)
+#LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
+
+#----------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := mkfs.btrfs
+LOCAL_SRC_FILES := \
+                $(objects) \
+                mkfs.c
+
+LOCAL_C_INCLUDES := $(common_C_INCLUDES)
+LOCAL_CFLAGS := $(STATIC_CFLAGS)
+#LOCAL_LDLIBS := $(LIBBTRFS_LIBS)
+#LOCAL_LDFLAGS := $(STATIC_LDFLAGS)
+LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries)
+LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils
+
+LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES)
+#LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
+
+#---------------------------------------------------------------
+include $(CLEAR_VARS)
+LOCAL_MODULE := btrfstune
+LOCAL_SRC_FILES := \
+                $(objects) \
+                btrfstune.c
+
+LOCAL_C_INCLUDES := $(common_C_INCLUDES)
+LOCAL_CFLAGS := $(STATIC_CFLAGS)
+LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries)
+#LOCAL_LDLIBS := $(LIBBTRFS_LIBS)
+#LOCAL_LDFLAGS := $(STATIC_LDFLAGS)
+LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries)
+LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils
+
+LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES)
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
+#--------------------------------------------------------------
diff --git a/chunk-recover.c b/chunk-recover.c
index 832b3b1..7f793af 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -17,7 +17,9 @@
  */
 
 #include <stdio.h>
+#ifndef ANDROID
 #include <stdio_ext.h>
+#endif
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -755,9 +757,11 @@ static int scan_one_device(void *dev_scan_struct)
 	int fd = dev_scan->fd;
 	int oldtype;
 
+#ifndef ANDROID
 	ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 	if (ret)
 		return 1;
+#endif
 
 	buf = malloc(sizeof(*buf) + rc->leafsize);
 	if (!buf)
@@ -884,7 +888,11 @@ static int scan_devices(struct recover_control *rc)
 	}
 out1:
 	while (ret && (cancel_from <= cancel_to)) {
+#ifdef ANDROID
+		pthread_kill(t_scans[cancel_from], SIGUSR1);
+#else
 		pthread_cancel(t_scans[cancel_from]);
+#endif
 		cancel_from++;
 	}
 out2:
diff --git a/cmds-receive.c b/cmds-receive.c
index 071bea9..3e9d912 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -25,7 +25,11 @@
 #include <pthread.h>
 #include <math.h>
 #include <ftw.h>
+#ifndef ANDROID
 #include <wait.h>
+#else
+#include <sys/wait.h>
+#endif
 #include <assert.h>
 #include <getopt.h>
 
diff --git a/cmds-restore.c b/cmds-restore.c
index 8fc8b2a..9a53058 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -86,6 +86,7 @@ static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
 	(void)inflateEnd(&strm);
 	return 0;
 }
+
 static inline size_t read_compress_length(unsigned char *buf)
 {
 	__le32 dlen;
diff --git a/cmds-scrub.c b/cmds-scrub.c
index b7aa809..2b03f71 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -780,12 +780,13 @@ static int scrub_write_progress(pthread_mutex_t *m, const char *fsid,
 	int fd = -1;
 	int old;
 
+#ifndef ANDROID
 	ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old);
 	if (ret) {
 		err = -ret;
 		goto out3;
 	}
-
+#endif
 	ret = pthread_mutex_lock(m);
 	if (ret) {
 		err = -ret;
@@ -816,10 +817,11 @@ out1:
 		err = -ret;
 
 out2:
+#ifndef ANDROID
 	ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
 	if (ret && !err)
 		err = -ret;
-
+#endif
 out3:
 	return err;
 }
@@ -898,9 +900,11 @@ static void *scrub_progress_cycle(void *ctx)
 	struct sockaddr_un peer;
 	socklen_t peer_size = sizeof(peer);
 
+#ifndef ANDROID
 	perr = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
 	if (perr)
 		goto out;
+#endif
 
 	uuid_unparse(spc->fi->fsid, fsid);
 
@@ -952,10 +956,12 @@ static void *scrub_progress_cycle(void *ctx)
 			 * result we got for the current write and go
 			 * on. flag should be set on next cycle, then.
 			 */
+#ifndef ANDROID
 			perr = pthread_setcancelstate(
 					PTHREAD_CANCEL_DISABLE, &old);
 			if (perr)
 				goto out;
+#endif
 			perr = pthread_mutex_lock(&sp_shared->progress_mutex);
 			if (perr)
 				goto out;
@@ -964,20 +970,24 @@ static void *scrub_progress_cycle(void *ctx)
 						&sp_shared->progress_mutex);
 				if (perr)
 					goto out;
+#ifndef ANDROID
 				perr = pthread_setcancelstate(
 						PTHREAD_CANCEL_ENABLE, &old);
 				if (perr)
 					goto out;
+#endif
 				memcpy(sp, sp_last, sizeof(*sp));
 				continue;
 			}
 			perr = pthread_mutex_unlock(&sp_shared->progress_mutex);
 			if (perr)
 				goto out;
+#ifndef ANDROID
 			perr = pthread_setcancelstate(
 					PTHREAD_CANCEL_ENABLE, &old);
 			if (perr)
 				goto out;
+#endif
 			memcpy(sp, sp_shared, sizeof(*sp));
 			memcpy(sp_last, sp_shared, sizeof(*sp));
 		}
@@ -1506,7 +1516,11 @@ static int scrub_start(int argc, char **argv, int resume)
 		}
 	}
 
+#ifdef ANDROID
+	ret = pthread_kill(t_prog, SIGUSR1);
+#else
 	ret = pthread_cancel(t_prog);
+#endif
 	if (!ret)
 		ret = pthread_join(t_prog, &terr);
 
@@ -1517,7 +1531,11 @@ static int scrub_start(int argc, char **argv, int resume)
 	}
 
 	/* check for errors returned from the progress thread itself */
+#ifdef ANDROID
+	if (do_print && terr) {
+#else
 	if (do_print && terr && terr != PTHREAD_CANCELED) {
+#endif
 		fprintf(stderr, "ERROR: recording progress "
 			"failed: %s\n", strerror(-PTR_ERR(terr)));
 	}
diff --git a/kerncompat.h b/kerncompat.h
index 5d92856..ae5b724 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -134,6 +134,9 @@ typedef long long s64;
 typedef int s32;
 #endif
 
+#ifdef ANDROID
+typedef struct blkid_struct_probe *blkid_probe;
+#endif
 
 struct vma_shared { int prio_tree_node; };
 struct vm_area_struct {
diff --git a/mkfs.c b/mkfs.c
index dafd500..face183 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -25,7 +25,12 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifndef ANDROID
 #include <sys/dir.h>
+#else
+#include <dirent.h>
+#define direct dirent
+#endif
 #include <fcntl.h>
 #include <unistd.h>
 #include <getopt.h>
@@ -1359,7 +1364,11 @@ int main(int ac, char **av)
 	dev_cnt = ac - optind;
 
 	file = av[optind++];
+#ifndef ANDROID
 	ssd = is_ssd(file);
+#else
+	ssd = true;
+#endif
 
 	if (is_vol_small(file) || mixed) {
 		if (verbose)
diff --git a/utils.c b/utils.c
index 39b295a..24deb65 100644
--- a/utils.c
+++ b/utils.c
@@ -878,9 +878,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
 			file, strerror(-ret));
 		return 1;
 	}
-
+#ifndef ANDROID
 	btrfs_wipe_existing_sb(fd);
-
+#endif
 	*block_count_ret = block_count;
 	return 0;
 }
@@ -2267,7 +2267,6 @@ check_overwrite(
 		return 0;
 
 	ret = -1; /* will reset on success of all setup calls */
-
 	pr = blkid_new_probe_from_filename(device);
 	if (!pr)
 		goto out;
@@ -2436,7 +2435,11 @@ int test_dev_for_mkfs(char *file, int force_overwrite)
 		return 1;
 	}
 	if (!force_overwrite) {
+#ifndef ANDROID
 		if (check_overwrite(file)) {
+#else
+		{
+#endif
 			fprintf(stderr, "Use the -f option to force overwrite.\n");
 			return 1;
 		}
-- 
1.8.2


[-- Attachment #3: 0002-arrange-intrusive-point-on-Android-build-patch.patch --]
[-- Type: application/octet-stream, Size: 2441 bytes --]

>From a8c6477c88a2a44685058fb4f2c54ee71e83dc9f Mon Sep 17 00:00:00 2001
From: "kenneth.kang" <kenneth.kang@lge.com>
Date: Mon, 10 Aug 2015 13:24:56 +0900
Subject: [PATCH] arrange intrusive point on Android build patch

---
 Android.mk |  2 +-
 mkfs.c     |  7 +++----
 utils.c    | 14 ++++++++------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/Android.mk b/Android.mk
index f6f3e28..315e38a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
 
 #include $(call all-subdir-makefiles)
 
-CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC
+CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC -DPLATFORM_ANDROID=1
 
 LDFLAGS := -static -rdynamic
 
diff --git a/mkfs.c b/mkfs.c
index face183..47c930b 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1113,6 +1113,9 @@ static int is_ssd(const char *file)
 	char rotational;
 	int ret;
 
+	if (PLATFORM_ANDROID)
+		return 1;
+
 	probe = blkid_new_probe_from_filename(file);
 	if (!probe)
 		return 0;
@@ -1364,11 +1367,7 @@ int main(int ac, char **av)
 	dev_cnt = ac - optind;
 
 	file = av[optind++];
-#ifndef ANDROID
 	ssd = is_ssd(file);
-#else
-	ssd = true;
-#endif
 
 	if (is_vol_small(file) || mixed) {
 		if (verbose)
diff --git a/utils.c b/utils.c
index 24deb65..44f54cf 100644
--- a/utils.c
+++ b/utils.c
@@ -801,6 +801,9 @@ static void btrfs_wipe_existing_sb(int fd)
 	int rc = 0;
 	blkid_probe pr = NULL;
 
+	if (PLATFORM_ANDROID)
+		return;
+
 	pr = blkid_new_probe();
 	if (!pr)
 		return;
@@ -878,9 +881,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
 			file, strerror(-ret));
 		return 1;
 	}
-#ifndef ANDROID
+
 	btrfs_wipe_existing_sb(fd);
-#endif
+
 	*block_count_ret = block_count;
 	return 0;
 }
@@ -2263,6 +2266,9 @@ check_overwrite(
 	int		ret;
 	blkid_loff_t	size;
 
+	if (PLATFORM_ANDROID)
+		return 1;
+
 	if (!device || !*device)
 		return 0;
 
@@ -2435,11 +2441,7 @@ int test_dev_for_mkfs(char *file, int force_overwrite)
 		return 1;
 	}
 	if (!force_overwrite) {
-#ifndef ANDROID
 		if (check_overwrite(file)) {
-#else
-		{
-#endif
 			fprintf(stderr, "Use the -f option to force overwrite.\n");
 			return 1;
 		}
-- 
1.8.2


  reply	other threads:[~2015-08-10  7:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <003201d0d02c$3349fe10$99ddfa30$@lge.com>
2015-08-06  9:45 ` FW: btrfs-progs: android build 강상우
2015-08-06 14:38   ` David Sterba
2015-08-10  7:30     ` 강상우 [this message]
2015-08-26 14:44       ` David Sterba
2015-08-31 16:33         ` David Sterba
2015-10-30 15:54           ` David Sterba

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='001b01d0d33e$8043bb60$80cb3220$@lge.com' \
    --to=kenneth.kang@lge.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.