ClusterLabs / ClusterLabs/resource-agents

iSCSITarget (lio-t): portals not created — targetcli ignores auto_add_default_portal=false

Open
#2,128 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
519
Forks
608
Avg merge
6d 1h
Merged PRs (30d)
7

Description

The `iSCSITarget` agent in `lio-t` mode doesn't create network portals when the
`portals` is set to a specific IP. The iSCSI target starts but with `Portals: 0` (no listener on 3260). Pacemaker things the target has started nonetheless.

This is different from #1026, which addresses duplicate target creation. This is specifically about portal creation failing silently.

## Environment

- resource-agents 4.16.0-3+deb13u1 (Debian trixie/PVE 9.1)
- targetcli-fb 2.1.57
- Linux 6.17.2-1-pve
- LIO kernel target (lio-t implementation)
(Same code is present in current `main` branch)

## Steps to Reproduce

1. Configure an iSCSITarget with a specific portal IP:
```bash
pcs resource create iscsi_target ocf:heartbeat:iSCSITarget implementation=lio-t \
iqn=iqn.2026-01.example:target portals="10.0.0.1:3260"
```

2. Start the target (or let Pacemaker start it on failover).

3. Check the target:
```bash
targetcli ls /iscsi/iqn.2026-01.example:target/tpg1/portals
# Shows: Portals: 0
ss -tlnp | grep 3260
# Shows: nothing
```
The resource agent returns success, Pacemaker reports "Started", but
no portals exist and iSCSI initiators can't connect.

## Cause

Two bugs interact in the `iSCSITarget_start()` function's `lio-t` section:

### Bug A: `auto_add_default_portal=false` is ignored by targetcli

Line 350 sets global preference:
```ocf_run targetcli /iscsi set global auto_add_default_portal=false```

On 353, `targetcli /iscsi create` yields:
```bash
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
```

The setting is silently reverted by targetcli during target creation, and creation of default portal `0.0.0.0:3260`. It looks like the global preference is doesn't persist.

### Bug B: Portal creation loop skips the default portal (355-358)

```bash
for portal in ${OCF_RESKEY_portals}; do
if [ $portal != ${OCF_RESKEY_portals_default} ] ; then
...create portal...
fi
done
```

When `portals` is a non-default value (e.g., `10.0.0.1:3260`), it doesn't match `OCF_RESKEY_portals_default` (`0.0.0.0:3260`), so the RA tries to create it. The default portal from Bug A is already bound to 3260, so portal creation fails:
```Could not create NetworkPortal in configFS```

When `portals` is left as `0.0.0.0:3260`, the loop skips portal creation entirely. Due to Bug A, this sometimes works and sometimes doesn't (race condition).

### Outcome

- Custom portal IP **always fails**: default portal blocks 3260 and RA exits with error
- Default portal **is unreliable**: loop skips creation; auto-creation success depends on timing

In either case, targets can end with no open portals, but still report success.

### Related

**#1026** (iSCSITarget always fails to start (LIO-T mode)). PR #1239 addressed idempotency but didn't fix portal creation.

**#1425** (iSCSILogicalUnit assumes portal runs on 0.0.0.0 when using LIO-t). Different agent (`iSCSILogicalUnit` vs `iSCSITarget`), same issue. Custom portals fail due to assumption of default portal.

## Potential Fix

**Please note**: I used an LLM to assist in building the code below; I don't know this project's policy, but I wanted to add the warning.

After creating the target, unconditionally delete the default portal if it exists and explicitly create all configured portals without skipping.

```diff
ocf_run targetcli /iscsi set global auto_add_default_portal=false || exit $OCF_ERR_GENERIC
if ! [ -d /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn} ] ; then
ocf_run targetcli /iscsi create ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
fi
+# targetcli may ignore auto_add_default_portal=false & create default portal (0.0.0.0:3260).
+# Delete so we can explicitly create only configured portals.
+ocf_run -warn targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/portals delete 0.0.0.0 3260 2>/dev/null || true
for portal in ${OCF_RESKEY_portals}; do
- if [ $portal != ${OCF_RESKEY_portals_default} ] ; then
- IFS=':' read -a sep_portal <<< "$portal"
- ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/portals create "${sep_portal[0]}" "${sep_portal[1]}" || exit $OCF_ERR_GENERIC
- fi
+ IFS=':' read -a sep_portal <<< "$portal"
+ ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/portals \
+ create "${sep_portal[0]}" "${sep_portal[1]}" || exit $OCF_ERR_GENERIC
done```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the iSCSITarget_start() lio-t section around lines 350-358 and inspect the targetcli commands that create the target and portals. Reproduce with a specific portal, then check targetcli's portal listing and ss on port 3260. Done means configured portals are created reliably and the resource agent reports failure when portal creation fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
infrastructure, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.