Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Some non-inline ceph helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/ceph/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * return true if @layout appears to be valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) int ceph_file_layout_is_valid(const struct ceph_file_layout *layout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	__u32 su = layout->stripe_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	__u32 sc = layout->stripe_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	__u32 os = layout->object_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	/* stripe unit, object size must be non-zero, 64k increment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	if (!su || (su & (CEPH_MIN_STRIPE_UNIT-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (!os || (os & (CEPH_MIN_STRIPE_UNIT-1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	/* object size must be a multiple of stripe unit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	if (os < su || os % su)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	/* stripe count must be non-zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	if (!sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void ceph_file_layout_from_legacy(struct ceph_file_layout *fl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 				  struct ceph_file_layout_legacy *legacy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	fl->stripe_unit = le32_to_cpu(legacy->fl_stripe_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	fl->stripe_count = le32_to_cpu(legacy->fl_stripe_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	fl->object_size = le32_to_cpu(legacy->fl_object_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	fl->pool_id = le32_to_cpu(legacy->fl_pg_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (fl->pool_id == 0 && fl->stripe_unit == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	    fl->stripe_count == 0 && fl->object_size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		fl->pool_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) void ceph_file_layout_to_legacy(struct ceph_file_layout *fl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				struct ceph_file_layout_legacy *legacy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	legacy->fl_stripe_unit = cpu_to_le32(fl->stripe_unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	legacy->fl_stripe_count = cpu_to_le32(fl->stripe_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	legacy->fl_object_size = cpu_to_le32(fl->object_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (fl->pool_id >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		legacy->fl_pg_pool = cpu_to_le32(fl->pool_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		legacy->fl_pg_pool = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int ceph_flags_to_mode(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #ifdef O_DIRECTORY  /* fixme */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if ((flags & O_DIRECTORY) == O_DIRECTORY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return CEPH_FILE_MODE_PIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	switch (flags & O_ACCMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	case O_WRONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		mode = CEPH_FILE_MODE_WR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	case O_RDONLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		mode = CEPH_FILE_MODE_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	case O_RDWR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	case O_ACCMODE: /* this is what the VFS does */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		mode = CEPH_FILE_MODE_RDWR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #ifdef O_LAZY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (flags & O_LAZY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		mode |= CEPH_FILE_MODE_LAZY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) int ceph_caps_for_mode(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int caps = CEPH_CAP_PIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (mode & CEPH_FILE_MODE_RD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		caps |= CEPH_CAP_FILE_SHARED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (mode & CEPH_FILE_MODE_WR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		caps |= CEPH_CAP_FILE_EXCL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (mode & CEPH_FILE_MODE_LAZY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		caps |= CEPH_CAP_FILE_LAZYIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }